acl/app/jencode/JencodeDlg.cpp

455 lines
12 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

阿// JencodeDlg.cpp : 瀹çµå¹‡é<E280A1>å¦æ¬¢
//
#include "stdafx.h"
#include "Jencode.h"
#include "Gb2Utf8.h"
#include "AclTrans.h"
#include "IdxTrans.h"
#include "JencodeDlg.h"
#include "DelBOM.h"
#include "AddBOM.h"
#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
// é<>¢ã„¤ç°¬æ<C2AC>´æ—敤ç»å¬ªç°­éˆ¥æ»ƒå<C692>§æµœåº˜â¬æ¿Šå½<C3A5>é<EFBFBD>—æ¢ã€<C3A3>é<EFBFBD>¨„ CAboutDlg 瀵硅瘽妗†
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// 瀵硅瘽妗嗘暟鎹®
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV é<>€îˆå¯”
// 瀹炵幇
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 瀵硅瘽妗†
CJencodeDlg::CJencodeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CJencodeDlg::IDD, pParent)
, m_sIdxPath(_T(""))
, m_fsPath(_T(""))
{
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)
ON_BN_CLICKED(IDC_ADD_BOM, &CJencodeDlg::OnBnClickedAddBom)
END_MESSAGE_MAP()
// CJencodeDlg 娑堟伅澶勭悊绋嬪簭
BOOL CJencodeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// ç<><C3A7>哱鈥滃å<C692>§æµœŽ...\鈥濊å½<C3A5>é<EFBFBD>—æ¢ã€<C3A3>娣诲姞é<C5BE>扮郴ç¼<C3A7>熻å½<C3A5>é<EFBFBD>—æšè…銆
// IDM_ABOUTBOX 蹇å´ã€<C3A3>é<EFBFBD>¦ã„§éƒ´ç¼<C3A7>熷懡浠ãˆå¯é<E28093>¥æ<C2A5>唴銆
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL) {
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty()) {
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// ç<C3A7>剧ç†å§<C3A5>ã…ç‡æ¿‡î”é<E280B9>¨å«æµ˜é<CB9C><C3A9>å¥â¬åšç¶æ<E280B9>´æ—敤ç»å¬ªç°­æ¶“è<E2809C>¤ç<C2A4>¥é<C2A5>™ï½„笉é<E280B0>„ç‡æ¿‡î”é<E280B9>ƒè®¹ç´<C3A7>妗嗘ç<CB9C>¦ç<C2A6><C3A7>å—šåšœé<C593>”¨
// 鎵цî”å§<C3A5>ã†æ<E280A0>·æµ£œ
SetIcon(m_hIcon, TRUE); // ç<C3A7>剧ç†æ¾¶Ñƒæµ˜é<CB9C><C3A9>
SetIcon(m_hIcon, FALSE); // ç<C3A7>剧ç†ç<E280A0><C3A7>忓浘é<CB9C><C3A9>
// TODO: é<>¦ã„¦î„<C3AE>娣诲姞棰濆é<C2BB>¨å«åžµæ¿®å¬ªå¯²æµ ï½‡çˆœ
acl::log::open("jencode.log", "jencode");
logger("started!");
//freopen("CONOUT$","w+t",stdout);
// 娣诲姞é<C5BE>˜èˆµâ¬ä½¹çˆ®
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("ç<EFBFBD><EFBFBD>辩å<EFBFBD>Ž", 0, 0);
m_wndStatus.SetText("", 1, 0);
return TRUE; // é—„ã‰æ½ªç<C3A7>剧ç†æµœå—˜å¸¶æµ å‰<C3A5>æ®é<E28098>︾å<C2BE>£é”å±½æƒ<C3A6>é<EFBFBD>æ¬ç¹é<E28098>¥ž TRUE
}
void CJencodeDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX) {
CAboutDlg dlgAbout;
dlgAbout.DoModal();
} else {
CDialog::OnSysCommand(nID, lParam);
}
}
// æ¿¡åç<E280BA>‰é<E280B0>šæˆ<C3A6>ç‡æ¿‡î”娣诲姞é<C5BE>ˆâ¬ç<C2AC><C3A7>忓寲鎸å¤<C3A5>挳é”屽垯闇â¬ç•ä½·ç¬…闈㈢æ®æµ ï½‡çˆœ
// é<>‰ãƒ§ç²¯é<C2AF>惰é<C5A1>¥ç¬çˆ£éŠ†åšî‡®æµœåº<C3A5>娇é<E280A1>¢ã„¦æžƒå¦—£/ç™å——浘妯″瀷é<C2B7>¨„ MFC æ<>´æ—敤ç»å¬ªç°­é”Œ
// æ<>©æ¬<C3A6>皢é<C2A2>¢è¾¨î”é<E280B9>惰嚜é<C593>”ㄥ畬鎴愩â¬
void CJencodeDlg::OnPaint()
{
if (IsIconic()) {
CPaintDC dc(this); // é<>¢ã„¤ç°¬ç¼<C3A7>樺埗é<E28094>¨å®î†•æ¾¶å¦ç¬æ¶“嬫枃
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 浣垮浘é<CB9C><C3A9>å§æ¹ªå®¸ãƒ¤ç¶”é<E2809D>­â•<C3A2>舰涓眳涓­
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;
// ç¼<C3A7>樺埗é<E28094>¥ç¬çˆ£
dc.DrawIcon(x, y, m_hIcon);
} else {
CDialog::OnPaint();
}
}
//褰æ¶æ•¤éŽ´é”å«é<E280B9>”ㄦ渶ç<C2B6><C3A7>忓寲ç»<C3A7>楀å½é<E280BA>ƒå‰<C3A5>郴ç¼<C3A7>熻皟é<C5B8>¢ã„¦î„<C3AE>é<EFBFBD>芥暟é<C5B8>™æ §ç·±é<C2B1><C3A9>å¤çˆ£é<C2A3>„剧ã<C2A7>šéŠ†
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);
GetDlgItem(IDC_ADD_BOM)->EnableWindow(TRUE);
}
BOOL CJencodeDlg::CheckPath(void)
{
UpdateData(TRUE);
GetDlgItem(IDC_EDIT_SPATH)->GetWindowText(m_sPath);
//MessageBox(m_sPath);
if (m_sPath.GetLength() == 0) {
MessageBox("璇烽€夋嫨婧愮洰褰•...");
return FALSE;
}
m_dPath = m_sPath;
//GetDlgItem(IDC_EDIT_DPATH)->GetWindowText(m_dPath);
//if (m_dPath.GetLength() == 0)
//{
// MessageBox("ç‡çƒ½â¬å¤å«¨é<C2A8>©î†¾æ®é<E28098>©î†¼ç¶<C3A7>...");
// 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);
GetDlgItem(IDC_ADD_BOM)->EnableWindow(FALSE);
}
void CJencodeDlg::OnBnClickedButtonGb2utf()
{
// TODO: é<>¦ã„¦î„<C3AE>娣诲姞鎺Ñ欢é«æ°±ç…¡æ¾¶å­æŠç»å¬ªç°­æµ ï½‡çˆœ
if (!CheckPath()) {
return;
}
static CGb2Utf8 gb2Utf8("gbk", "UTF-8");
gb2Utf8.Init(this->GetSafeHwnd(), m_sPath, m_dPath);
gb2Utf8.OnTransEnd(WM_USER_TRANS_OVER);
gb2Utf8.start();
m_wndStatus.SetText("æ<EFBFBD>©æ„¯î”", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedButtonUtf2gb()
{
// TODO: é<>¦ã„¦î„<C3AE>娣诲姞鎺Ñ欢é«æ°±ç…¡æ¾¶å­æŠç»å¬ªç°­æµ ï½‡çˆœ
if (!CheckPath()) {
MessageBox(m_sPath);
return;
}
static CGb2Utf8 utf2gb("utf-8", "gbk");
utf2gb.Init(this->GetSafeHwnd(), m_sPath, m_dPath);
utf2gb.OnTransEnd(WM_USER_TRANS_OVER);
utf2gb.start();
m_wndStatus.SetText("æ<EFBFBD>©æ„¯î”", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedButtonGb2uni()
{
// TODO: é<>¦ã„¦î„<C3AE>娣诲姞鎺Ñ欢é«æ°±ç…¡æ¾¶å­æŠç»å¬ªç°­æµ ï½‡çˆœ
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);
gb2uni.start();
m_wndStatus.SetText("æ<EFBFBD>©æ„¯î”", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedButton2()
{
// TODO: é<>¦ã„¦î„<C3AE>娣诲姞鎺Ñ欢é«æ°±ç…¡æ¾¶å­æŠç»å¬ªç°­æµ ï½‡çˆœ
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();
if (sPath.Right(1) != "\\") {
sPath += "\\";
}
GetDlgItem(IDC_EDIT_SPATH)->SetWindowText(sPath);
// CFileDialog file(TRUE,"é<>å¦æ¬¢","result.txt",OFN_HIDEREADONLY,"FILE(*.*)|*.*||",NULL);
// if(file.DoModal()==IDOK)
// {
// CString pathname;
//
// pathname=file.GetPathName();
// GetDlgItem(IDC_EDIT_SPATH)->SetWindowText(pathname);
// }
}
void CJencodeDlg::OnBnClickedButton3()
{
// TODO: é<>¦ã„¦î„<C3AE>娣诲姞鎺Ñ欢é«æ°±ç…¡æ¾¶å­æŠç»å¬ªç°­æµ ï½‡çˆœ
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();
if (sPath.Right(1) != "\\") {
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);
m_wndStatus.SetText(msg, 1, 0);
return 0;
}
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);
m_wndStatus.SetText(msg, 1, 0);
return 0;
}
void CJencodeDlg::OnBnClickedAclTrans()
{
// TODO: é<>¦ã„¦î„<C3AE>娣诲姞鎺Ñ欢é«æ°±ç…¡æ¾¶å­æŠç»å¬ªç°­æµ ï½‡çˆœ
if (!CheckPath()) {
return;
}
static CAclTrans aclTrans;
aclTrans.Init(this->GetSafeHwnd(), m_sPath);
aclTrans.OnTransEnd(WM_USER_TRANS_OVER);
aclTrans.Run();
m_wndStatus.SetText("æ<EFBFBD>©æ„¯î”", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedAclRestore()
{
// TODO: é<>¦ã„¦î„<C3AE>娣诲姞鎺Ñ欢é«æ°±ç…¡æ¾¶å­æŠç»å¬ªç°­æµ ï½‡çˆœ
if (!CheckPath()) {
return;
}
static CAclTrans aclTrans;
aclTrans.Init(this->GetSafeHwnd(), m_sPath);
aclTrans.OnTransEnd(WM_USER_TRANS_OVER);
aclTrans.Run(FALSE);
m_wndStatus.SetText("æ<EFBFBD>©æ„¯î”", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedDelBom()
{
// TODO: é<>¦ã„¦î„<C3AE>娣诲姞鎺Ñ欢é«æ°±ç…¡æ¾¶å­æŠç»å¬ªç°­æµ ï½‡çˆœ
if (!CheckPath()) {
return;
}
static CDelBOM delBom;
delBom.Init(this->GetSafeHwnd(), m_sPath);
delBom.OnDeleted(WM_USER_TRANS_OVER);
delBom.start();
m_wndStatus.SetText("æ<EFBFBD>©æ„¯î”", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedAddBom()
{
// TODO: é<>¦ã„¦î„<C3AE>娣诲姞鎺Ñ欢é«æ°±ç…¡æ¾¶å­æŠç»å¬ªç°­æµ ï½‡çˆœ
if (!CheckPath()) {
return;
}
static CAddBOM addBom;
addBom.Init(this->GetSafeHwnd(), m_sPath);
addBom.OnAdded(WM_USER_TRANS_OVER);
addBom.start();
m_wndStatus.SetText("æ<EFBFBD>©æ„¯î”", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedIdxSelect()
{
// TODO: é<>¦ã„¦î„<C3AE>娣诲姞鎺Ñ欢é«æ°±ç…¡æ¾¶å­æŠç»å¬ªç°­æµ ï½‡çˆœ
CFileDialog file(TRUE,"é<EFBFBD>å¦æ¬¢","search.idx",OFN_HIDEREADONLY,"FILE(*.*)|*.*||",NULL);
if(file.DoModal()==IDOK) {
CString pathname;
pathname=file.GetPathName();
GetDlgItem(IDC_IDX_PATH)->SetWindowText(pathname);
}
}
void CJencodeDlg::OnBnClickedTransIdx()
{
// TODO: é<>¦ã„¦î„<C3AE>娣诲姞鎺Ñ欢é«æ°±ç…¡æ¾¶å­æŠç»å¬ªç°­æµ ï½‡çˆœ
static CIdxTrans idxTrans;
UpdateData(TRUE);
GetDlgItem(IDC_IDX_PATH)->GetWindowText(m_fsPath);
if (m_fsPath.GetLength() == 0) {
MessageBox("ç‡çƒ½â¬å¤å«¨ç»±ãˆ ç´©é<EFBFBD>å¦æ¬¢...");
return;
}
GetDlgItem(IDC_TRANS_IDX)->EnableWindow(FALSE);
idxTrans.Init(this->GetSafeHwnd(), m_fsPath);
idxTrans.OnTransEnd(WM_USER_TRANS_OVER2);
idxTrans.Run();
m_wndStatus.SetText("æ<EFBFBD>©æ„¯î”", 0, 0);
m_nBegin = time(NULL);
}