acl/app/jencode/JencodeDlg.cpp

455 lines
12 KiB
C++
Raw Normal View History

<EFBFBD>// JencodeDlg.cpp : 瀹炵幇鏂囦欢
2014-11-19 00:25:21 +08:00
//
#include "stdafx.h"
#include "Jencode.h"
#include "Gb2Utf8.h"
#include "AclTrans.h"
#include "IdxTrans.h"
#include "JencodeDlg.h"
#include "DelBOM.h"
2019-07-26 16:09:45 +08:00
#include "AddBOM.h"
2014-11-19 00:25:21 +08:00
#include "JencodeDlg.h"
#include ".\jencodedlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#define WM_USER_TRANS_OVER WM_USER + 100
#define WM_USER_TRANS_OVER2 WM_USER + 101
// 鐢ㄤ簬搴旂敤绋嬪簭鈥滃叧浜庘€濊彍鍗曢」鐨<E3808D> CAboutDlg 瀵硅瘽妗<E798BD>
2014-11-19 00:25:21 +08:00
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// 瀵硅瘽妗嗘暟鎹<E69A9F>
2014-11-19 00:25:21 +08:00
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 鏀寔
2014-11-19 00:25:21 +08:00
// 瀹炵幇
2014-11-19 00:25:21 +08:00
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CJencodeDlg 瀵硅瘽妗<E798BD>
2014-11-19 00:25:21 +08:00
CJencodeDlg::CJencodeDlg(CWnd* pParent /*=NULL*/)
2019-07-26 17:27:39 +08:00
: CDialog(CJencodeDlg::IDD, pParent)
, m_sIdxPath(_T(""))
, m_fsPath(_T(""))
2014-11-19 00:25:21 +08:00
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CJencodeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CJencodeDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON_GB2UTF, OnBnClickedButtonGb2utf)
ON_BN_CLICKED(IDC_BUTTON_UTF2GB, OnBnClickedButtonUtf2gb)
ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedButton3)
ON_MESSAGE(WM_USER_TRANS_OVER, OnTransOver)
ON_MESSAGE(WM_USER_TRANS_OVER2, OnTransOver2)
ON_BN_CLICKED(IDC_ACL_TRANS, OnBnClickedAclTrans)
ON_BN_CLICKED(IDC_ACL_RESTORE, OnBnClickedAclRestore)
ON_BN_CLICKED(IDC_IDX_SELECT, OnBnClickedIdxSelect)
ON_BN_CLICKED(IDC_TRANS_IDX, OnBnClickedTransIdx)
ON_BN_CLICKED(IDC_DEL_BOM, OnBnClickedDelBom)
ON_BN_CLICKED(IDC_BUTTON_GB2UNI, &CJencodeDlg::OnBnClickedButtonGb2uni)
2019-07-26 16:09:45 +08:00
ON_BN_CLICKED(IDC_ADD_BOM, &CJencodeDlg::OnBnClickedAddBom)
2014-11-19 00:25:21 +08:00
END_MESSAGE_MAP()
// CJencodeDlg 娑堟伅澶勭悊绋嬪簭
2014-11-19 00:25:21 +08:00
BOOL CJencodeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 灏哱鈥滃叧浜<E58FA7>...\鈥濊彍鍗曢」娣诲姞鍒扮郴缁熻彍鍗曚腑銆<E88591>
2014-11-19 00:25:21 +08:00
// IDM_ABOUTBOX 蹇呴』鍦ㄧ郴缁熷懡浠よ寖鍥村唴銆<E594B4>
2014-11-19 00:25:21 +08:00
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
2019-07-26 17:27:39 +08:00
if (pSysMenu != NULL) {
2014-11-19 00:25:21 +08:00
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
2019-07-26 17:27:39 +08:00
if (!strAboutMenu.IsEmpty()) {
2014-11-19 00:25:21 +08:00
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 璁剧疆姝ゅ璇濇鐨勫浘鏍囥€傚綋搴旂敤绋嬪簭涓荤獥鍙笉鏄璇濇鏃讹紝妗嗘灦灏嗚嚜鍔<E59A9C>
// 鎵ц姝ゆ搷浣<E690B7>
SetIcon(m_hIcon, TRUE); // 璁剧疆澶у浘鏍<E6B598>
SetIcon(m_hIcon, FALSE); // 璁剧疆灏忓浘鏍<E6B598>
2014-11-19 00:25:21 +08:00
// TODO: 鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲浠g爜
2014-11-19 00:25:21 +08:00
2019-07-26 16:09:45 +08:00
acl::log::open("jencode.log", "jencode");
logger("started!");
//freopen("CONOUT$","w+t",stdout);
// 娣诲姞鐘舵€佹爮
2014-11-19 00:25:21 +08:00
int aWidths[2] = {50, -1};
m_wndStatus.Create(WS_CHILD | WS_VISIBLE | WS_BORDER
| CCS_BOTTOM | SBARS_SIZEGRIP,
CRect(0,0,0,0), this, 0);
m_wndStatus.SetParts(2, aWidths);
m_wndStatus.SetText("灏辩华", 0, 0);
2014-11-19 00:25:21 +08:00
m_wndStatus.SetText("", 1, 0);
return TRUE; // 闄ら潪璁剧疆浜嗘帶浠剁殑鐒︾偣锛屽惁鍒欒繑鍥<E7B991> TRUE
2014-11-19 00:25:21 +08:00
}
void CJencodeDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
2019-07-26 17:27:39 +08:00
if ((nID & 0xFFF0) == IDM_ABOUTBOX) {
2014-11-19 00:25:21 +08:00
CAboutDlg dlgAbout;
dlgAbout.DoModal();
2019-07-26 17:27:39 +08:00
} else {
2014-11-19 00:25:21 +08:00
CDialog::OnSysCommand(nID, lParam);
}
}
// 濡傛灉鍚戝璇濇娣诲姞鏈€灏忓寲鎸夐挳锛屽垯闇€瑕佷笅闈㈢殑浠g爜
// 鏉ョ粯鍒惰鍥炬爣銆傚浜庝娇鐢ㄦ枃妗<E69E83>/瑙嗗浘妯″瀷鐨<E780B7> MFC 搴旂敤绋嬪簭锛<E7B0AD>
// 杩欏皢鐢辨鏋惰嚜鍔ㄥ畬鎴愩€<E684A9>
2014-11-19 00:25:21 +08:00
void CJencodeDlg::OnPaint()
{
2019-07-26 17:27:39 +08:00
if (IsIconic()) {
CPaintDC dc(this); // 鐢ㄤ簬缁樺埗鐨勮澶囦笂涓嬫枃
2014-11-19 00:25:21 +08:00
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 浣垮浘鏍囧湪宸ヤ綔鐭╁舰涓眳涓<E79CB3>
2014-11-19 00:25:21 +08:00
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// 缁樺埗鍥炬爣
2014-11-19 00:25:21 +08:00
dc.DrawIcon(x, y, m_hIcon);
2019-07-26 17:27:39 +08:00
} else {
2014-11-19 00:25:21 +08:00
CDialog::OnPaint();
}
}
//褰撶敤鎴锋嫋鍔ㄦ渶灏忓寲绐楀彛鏃剁郴缁熻皟鐢ㄦ鍑芥暟鍙栧緱鍏夋爣鏄剧ず銆<E3819A>
2014-11-19 00:25:21 +08:00
HCURSOR CJencodeDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CJencodeDlg::ButtonsEnable(void)
{
GetDlgItem(IDC_BUTTON_GB2UTF)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON_UTF2GB)->EnableWindow(TRUE);
GetDlgItem(IDC_ACL_TRANS)->EnableWindow(TRUE);
GetDlgItem(IDC_ACL_RESTORE)->EnableWindow(TRUE);
GetDlgItem(IDC_DEL_BOM)->EnableWindow(TRUE);
2019-07-26 16:09:45 +08:00
GetDlgItem(IDC_ADD_BOM)->EnableWindow(TRUE);
2014-11-19 00:25:21 +08:00
}
BOOL CJencodeDlg::CheckPath(void)
{
UpdateData(TRUE);
GetDlgItem(IDC_EDIT_SPATH)->GetWindowText(m_sPath);
//MessageBox(m_sPath);
2019-07-26 17:27:39 +08:00
if (m_sPath.GetLength() == 0) {
MessageBox("璇烽€夋嫨婧愮洰褰<EFBFBD>...");
2014-11-19 00:25:21 +08:00
return FALSE;
}
m_dPath = m_sPath;
//GetDlgItem(IDC_EDIT_DPATH)->GetWindowText(m_dPath);
//if (m_dPath.GetLength() == 0)
//{
// MessageBox("璇烽€夋嫨鐩殑鐩綍...");
2014-11-19 00:25:21 +08:00
// return FALSE;
//}
return TRUE;
}
void CJencodeDlg::ButtonsDisable(void)
{
GetDlgItem(IDC_BUTTON_GB2UTF)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_UTF2GB)->EnableWindow(FALSE);
GetDlgItem(IDC_ACL_TRANS)->EnableWindow(FALSE);
GetDlgItem(IDC_ACL_RESTORE)->EnableWindow(FALSE);
GetDlgItem(IDC_DEL_BOM)->EnableWindow(FALSE);
2019-07-26 16:09:45 +08:00
GetDlgItem(IDC_ADD_BOM)->EnableWindow(FALSE);
2014-11-19 00:25:21 +08:00
}
void CJencodeDlg::OnBnClickedButtonGb2utf()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
2019-07-26 17:27:39 +08:00
if (!CheckPath()) {
2014-11-19 00:25:21 +08:00
return;
2019-07-26 17:27:39 +08:00
}
2014-11-19 00:25:21 +08:00
static CGb2Utf8 gb2Utf8("gbk", "UTF-8");
2014-11-19 00:25:21 +08:00
gb2Utf8.Init(this->GetSafeHwnd(), m_sPath, m_dPath);
gb2Utf8.OnTransEnd(WM_USER_TRANS_OVER);
2019-07-26 17:27:39 +08:00
gb2Utf8.start();
m_wndStatus.SetText("杩愯", 0, 0);
2014-11-19 00:25:21 +08:00
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedButtonUtf2gb()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
2019-07-26 17:27:39 +08:00
if (!CheckPath()) {
2014-11-19 00:25:21 +08:00
MessageBox(m_sPath);
return;
}
static CGb2Utf8 utf2gb("utf-8", "gbk");
utf2gb.Init(this->GetSafeHwnd(), m_sPath, m_dPath);
utf2gb.OnTransEnd(WM_USER_TRANS_OVER);
2019-07-26 17:27:39 +08:00
utf2gb.start();
m_wndStatus.SetText("杩愯", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedButtonGb2uni()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
2019-07-26 17:27:39 +08:00
if (!CheckPath()) {
MessageBox(m_sPath);
return;
}
return;
static CGb2Utf8 gb2uni("gbk", "UCS2LE");
gb2uni.Init(this->GetSafeHwnd(), m_sPath, m_dPath);
gb2uni.OnTransEnd(WM_USER_TRANS_OVER);
2019-07-26 17:27:39 +08:00
gb2uni.start();
m_wndStatus.SetText("杩愯", 0, 0);
2014-11-19 00:25:21 +08:00
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedButton2()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
2014-11-19 00:25:21 +08:00
CString sPath;
BROWSEINFO bi;
char name[MAX_PATH];
ZeroMemory(&bi, sizeof(BROWSEINFO));
bi.hwndOwner = GetSafeHwnd();
bi.pszDisplayName = name;
bi.lpszTitle = "Select folder";
bi.ulFlags = BIF_RETURNONLYFSDIRS;
LPITEMIDLIST idl = SHBrowseForFolder(&bi);
if(idl == NULL)
return;
SHGetPathFromIDList(idl, sPath.GetBuffer(MAX_PATH));
sPath.ReleaseBuffer();
2019-07-26 17:27:39 +08:00
if (sPath.Right(1) != "\\") {
2014-11-19 00:25:21 +08:00
sPath += "\\";
}
GetDlgItem(IDC_EDIT_SPATH)->SetWindowText(sPath);
// CFileDialog file(TRUE,"鏂囦欢","result.txt",OFN_HIDEREADONLY,"FILE(*.*)|*.*||",NULL);
2014-11-19 00:25:21 +08:00
// if(file.DoModal()==IDOK)
// {
// CString pathname;
//
// pathname=file.GetPathName();
// GetDlgItem(IDC_EDIT_SPATH)->SetWindowText(pathname);
// }
}
void CJencodeDlg::OnBnClickedButton3()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
2014-11-19 00:25:21 +08:00
CString sPath;
BROWSEINFO bi;
char name[MAX_PATH];
ZeroMemory(&bi, sizeof(BROWSEINFO));
bi.hwndOwner = GetSafeHwnd();
bi.pszDisplayName = name;
bi.lpszTitle = "Select folder";
bi.ulFlags = BIF_RETURNONLYFSDIRS;
LPITEMIDLIST idl = SHBrowseForFolder(&bi);
if(idl == NULL)
return;
SHGetPathFromIDList(idl, sPath.GetBuffer(MAX_PATH));
sPath.ReleaseBuffer();
2019-07-26 17:27:39 +08:00
if (sPath.Right(1) != "\\") {
2014-11-19 00:25:21 +08:00
sPath += "\\";
}
GetDlgItem(IDC_EDIT_DPATH)->SetWindowText(sPath);
}
afx_msg LRESULT CJencodeDlg::OnTransOver(WPARAM uID, LPARAM lEvent)
{
CString msg;
ButtonsEnable();
msg.Format("鑰楁椂锛<EFBFBD>%d 绉<>", time(NULL) - m_nBegin);
m_wndStatus.SetText("瀹屾垚", 0, 0);
2014-11-19 00:25:21 +08:00
m_wndStatus.SetText(msg, 1, 0);
2019-07-26 17:27:39 +08:00
return 0;
2014-11-19 00:25:21 +08:00
}
afx_msg LRESULT CJencodeDlg::OnTransOver2(WPARAM uID, LPARAM lEvent)
{
CString msg;
GetDlgItem(IDC_TRANS_IDX)->EnableWindow(TRUE);
msg.Format("鑰楁椂锛<EFBFBD>%d 绉<>", time(NULL) - m_nBegin);
m_wndStatus.SetText("瀹屾垚!", 0, 0);
2014-11-19 00:25:21 +08:00
m_wndStatus.SetText(msg, 1, 0);
2019-07-26 17:27:39 +08:00
return 0;
2014-11-19 00:25:21 +08:00
}
void CJencodeDlg::OnBnClickedAclTrans()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
2019-07-26 17:27:39 +08:00
if (!CheckPath()) {
2014-11-19 00:25:21 +08:00
return;
2019-07-26 17:27:39 +08:00
}
2014-11-19 00:25:21 +08:00
static CAclTrans aclTrans;
aclTrans.Init(this->GetSafeHwnd(), m_sPath);
aclTrans.OnTransEnd(WM_USER_TRANS_OVER);
aclTrans.Run();
m_wndStatus.SetText("杩愯", 0, 0);
2014-11-19 00:25:21 +08:00
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedAclRestore()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
2019-07-26 17:27:39 +08:00
if (!CheckPath()) {
2014-11-19 00:25:21 +08:00
return;
2019-07-26 17:27:39 +08:00
}
2014-11-19 00:25:21 +08:00
static CAclTrans aclTrans;
aclTrans.Init(this->GetSafeHwnd(), m_sPath);
aclTrans.OnTransEnd(WM_USER_TRANS_OVER);
aclTrans.Run(FALSE);
m_wndStatus.SetText("杩愯", 0, 0);
2014-11-19 00:25:21 +08:00
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedDelBom()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
2019-07-26 17:27:39 +08:00
if (!CheckPath()) {
2014-11-19 00:25:21 +08:00
return;
2019-07-26 17:27:39 +08:00
}
2014-11-19 00:25:21 +08:00
static CDelBOM delBom;
delBom.Init(this->GetSafeHwnd(), m_sPath);
delBom.OnDeleted(WM_USER_TRANS_OVER);
2019-07-26 16:09:45 +08:00
delBom.start();
m_wndStatus.SetText("杩愯", 0, 0);
2019-07-26 16:09:45 +08:00
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedAddBom()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
2019-07-26 17:27:39 +08:00
if (!CheckPath()) {
2019-07-26 16:09:45 +08:00
return;
2019-07-26 17:27:39 +08:00
}
2019-07-26 16:09:45 +08:00
static CAddBOM addBom;
addBom.Init(this->GetSafeHwnd(), m_sPath);
addBom.OnAdded(WM_USER_TRANS_OVER);
addBom.start();
m_wndStatus.SetText("杩愯", 0, 0);
2014-11-19 00:25:21 +08:00
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedIdxSelect()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
CFileDialog file(TRUE,"鏂囦欢","search.idx",OFN_HIDEREADONLY,"FILE(*.*)|*.*||",NULL);
2019-07-26 17:27:39 +08:00
if(file.DoModal()==IDOK) {
2014-11-19 00:25:21 +08:00
CString pathname;
pathname=file.GetPathName();
GetDlgItem(IDC_IDX_PATH)->SetWindowText(pathname);
}
}
void CJencodeDlg::OnBnClickedTransIdx()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
2014-11-19 00:25:21 +08:00
static CIdxTrans idxTrans;
UpdateData(TRUE);
GetDlgItem(IDC_IDX_PATH)->GetWindowText(m_fsPath);
2019-07-26 17:27:39 +08:00
if (m_fsPath.GetLength() == 0) {
MessageBox("璇烽€夋嫨绱㈠紩鏂囦欢...");
2014-11-19 00:25:21 +08:00
return;
}
GetDlgItem(IDC_TRANS_IDX)->EnableWindow(FALSE);
idxTrans.Init(this->GetSafeHwnd(), m_fsPath);
idxTrans.OnTransEnd(WM_USER_TRANS_OVER2);
idxTrans.Run();
m_wndStatus.SetText("杩愯", 0, 0);
2014-11-19 00:25:21 +08:00
m_nBegin = time(NULL);
}