home *** CD-ROM | disk | FTP | other *** search
- /*==================================================================
- File: Win32ZStringToolsDlg.cpp
-
- Contains: Tool for creating override libraries for
- ZStrings on the Windows
-
- Written by: Nalini Prakash
-
- Copyright: 2000-2001 Connectix Corporation
-
- This source has been placed into the public domain by
- Connectix Corporation. You have the right to modify,
- distribute or use this code without any legal limitations
- or finanicial/licensing requirements. Connectix is not
- liable for any problems that result from the use of this
- code.
-
- If you have comments, feedback, questions, or would like
- to submit bug fixes or updates to this code, please email
- opensource@connectix.com.
- ==================================================================*/
-
- #include "StdAfx.h"
-
- #include "Win32ZStringTools.h"
- #include "Win32ZStringToolsDlg.h"
- #include "Win32ZStringExtractTool.h"
- #include "Win32ZStringCompareTool.h"
- #include "Win32ZStringOverrideTool.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
-
- char * CWin32ZStringToolsDlg::sSourceFileTitle = "Please Select Source File";
- char * CWin32ZStringToolsDlg::sCompareFileTitle = "Please Select Comparison File";
- char * CWin32ZStringToolsDlg::sDestFileTitle = "Please Select Destination File";
-
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
-
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
-
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
-
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
-
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
-
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
-
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CWin32ZStringToolsDlg dialog
-
- CWin32ZStringToolsDlg::CWin32ZStringToolsDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CWin32ZStringToolsDlg::IDD, pParent), mCtrlCompareFile(false),
- mCtrlDestFile(false), mCtrlSourceFile(false)
- {
- //{{AFX_DATA_INIT(CWin32ZStringToolsDlg)
- mCompareFileName = _T("");
- mDestFileName = _T("");
- mSourceFileName = _T("");
- mCategorizeOutput = TRUE;
- mAllowTagSemicolon = FALSE;
- mOutputTagFormat = kOutputNumericTag;
- mFlagDuplicates = FALSE;
- mOutputWarnings = TRUE;
- mConvertHighASCIIChar = TRUE;
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
-
- void
- CWin32ZStringToolsDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CWin32ZStringToolsDlg)
- DDX_Control(pDX, IDC_EDIT_SourceFileName, mCtrlSourceFile);
- DDX_Control(pDX, IDC_EDIT_CompareFileName, mCtrlCompareFile);
- DDX_Control(pDX, IDC_EDIT_DestFileName, mCtrlDestFile);
- DDX_Text(pDX, IDC_EDIT_CompareFileName, mCompareFileName);
- DDX_Text(pDX, IDC_EDIT_DestFileName, mDestFileName);
- DDX_Text(pDX, IDC_EDIT_SourceFileName, mSourceFileName);
- DDX_Check(pDX, IDC_CHECK_Categorize, mCategorizeOutput);
- DDX_Check(pDX, IDC_CHECK_Semicolon, mAllowTagSemicolon);
- DDX_Radio(pDX, IDC_RADIO_TagFormat, mOutputTagFormat);
- DDX_Check(pDX, IDC_CHECK_FlagDuplicates, mFlagDuplicates);
- DDX_Check(pDX, IDC_CHECK_ShowWarnings, mOutputWarnings);
- DDX_Check(pDX, IDC_CHECK_ConvertHighASCII, mConvertHighASCIIChar);
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CWin32ZStringToolsDlg, CDialog)
- //{{AFX_MSG_MAP(CWin32ZStringToolsDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDExtract, OnExtract)
- ON_BN_CLICKED(IDOverride, OnOverride)
- ON_BN_CLICKED(IDOK, OnOk)
- ON_EN_CHANGE(IDC_EDIT_CompareFileName, OnChangeEDITBoxes)
- ON_BN_CLICKED(IDC_BrowseSrc, OnBrowseSource)
- ON_BN_CLICKED(IDC_BrowseDest, OnBrowseDestination)
- ON_BN_CLICKED(IDC_BrowseCmp, OnBrowseCompare)
- ON_WM_CREATE()
- ON_EN_CHANGE(IDC_EDIT_DestFileName, OnChangeEDITBoxes)
- ON_EN_CHANGE(IDC_EDIT_SourceFileName, OnChangeEDITBoxes)
- ON_BN_CLICKED(IDCompare, OnCompare)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CWin32ZStringToolsDlg message handlers
-
- BOOL
- CWin32ZStringToolsDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // Add "About..." menu item to system menu.
-
- // IDM_ABOUTBOX must be in the system command range.
- 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);
- }
- }
-
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- UpdateData(FALSE);
-
- // Enable drag & drop
- mCtrlSourceFile.DragAcceptFiles(TRUE);
- mCtrlCompareFile.DragAcceptFiles(TRUE);
- mCtrlDestFile.DragAcceptFiles(TRUE);
-
- mCtrlSourceFile.RegisterForDrop();
- mCtrlCompareFile.RegisterForDrop();
- mCtrlDestFile.RegisterForDrop();
-
- UpdateButtons();
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
- void
- CWin32ZStringToolsDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
-
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
-
- void
- CWin32ZStringToolsDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
-
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
-
- // Center icon in client rectangle
- 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;
-
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
-
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CWin32ZStringToolsDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
-
-
- /*------------------------------------------------------------------
- OnExtract
- ------------------------------------------------------------------*/
-
- void
- CWin32ZStringToolsDlg::OnExtract()
- {
- UpdateData();
- Win32ZStringExtractTool extractTool;
- ZToolOptions options(mOutputTagFormat == kOutputNumericTag, mCategorizeOutput,
- mAllowTagSemicolon, mFlagDuplicates, mOutputWarnings,
- mConvertHighASCIIChar);
- if (extractTool.ExtractZStrings(mSourceFileName, mDestFileName, options))
- {
- mSourceFileName = _T("");
- mDestFileName = _T("");
- UpdateData(FALSE);
- UpdateButtons();
- }
- }
-
-
- /*------------------------------------------------------------------
- OnCompare
- ------------------------------------------------------------------*/
-
- void
- CWin32ZStringToolsDlg::OnCompare()
- {
- UpdateData();
- Win32ZStringCompareTool compareTool;
- ZToolOptions options(mOutputTagFormat==kOutputNumericTag, mCategorizeOutput,
- mAllowTagSemicolon, mFlagDuplicates, mOutputWarnings,
- mConvertHighASCIIChar);
- if(compareTool.CompareZStrings(mSourceFileName, mCompareFileName, mDestFileName, options))
- {
- mSourceFileName = _T("");
- mCompareFileName = _T("");
- mDestFileName = _T("");
- UpdateData(FALSE);
- UpdateButtons();
- }
- }
-
-
- /*------------------------------------------------------------------
- OnOverride
- ------------------------------------------------------------------*/
-
- void
- CWin32ZStringToolsDlg::OnOverride()
- {
- UpdateData();
- Win32ZStringOverrideTool overrideTool;
- ZToolOptions options(mOutputTagFormat==kOutputNumericTag, mCategorizeOutput,
- mAllowTagSemicolon, mFlagDuplicates, mOutputWarnings,
- mConvertHighASCIIChar);
- options.mPrintErrorsOnly = true;
- if(overrideTool.CreateOverrideDictionary(mSourceFileName, mDestFileName, options))
- {
- mSourceFileName = _T("");
- mDestFileName = _T("");
- UpdateData(FALSE);
- UpdateButtons();
- }
- }
-
-
- /*------------------------------------------------------------------
- OnOk
- ------------------------------------------------------------------*/
-
- void
- CWin32ZStringToolsDlg::OnOk()
- {
- EndDialog(IDOK);
- }
-
-
- /*------------------------------------------------------------------
- OnCancel
- ------------------------------------------------------------------*/
-
- void
- CWin32ZStringToolsDlg::OnCancel()
- {
- EndDialog(IDCANCEL);
- CDialog::OnCancel();
- }
-
- /*------------------------------------------------------------------
- UpdateButtons
- ------------------------------------------------------------------*/
-
- void
- CWin32ZStringToolsDlg::UpdateButtons()
- {
- CWnd* bExtract;
- CWnd* bCompare;
- CWnd* bOverride;
-
- CString src, dest;
-
- bExtract = GetDlgItem(IDExtract);
- bOverride = GetDlgItem(IDOverride);
- bCompare = GetDlgItem(IDCompare);
-
- if (!bExtract || !bOverride || !bCompare)
- goto Error;
-
- bCompare->EnableWindow(FALSE);
- bExtract->EnableWindow(FALSE);
- bOverride->EnableWindow(FALSE);
-
- // Extract and override require a source and a destination file.
- if (!mSourceFileName.IsEmpty() && !mDestFileName.IsEmpty())
- {
- src = mSourceFileName;
- src.MakeLower();
- dest = mDestFileName;
- dest.MakeLower();
-
- if (!mCompareFileName.IsEmpty())
- bCompare->EnableWindow(TRUE);
- else if ((src.Find(".exe")!=-1 || src.Find(".html")!=-1) && dest.Find(".html")!=-1)
- bExtract->EnableWindow(TRUE);
- else if (dest.Find(".dict")!=-1)
- bOverride->EnableWindow(TRUE);
- }
-
- Error:
- return;
- }
-
- /*------------------------------------------------------------------
- OnChangeEDITBoxes
- ------------------------------------------------------------------*/
-
- void
- CWin32ZStringToolsDlg::OnChangeEDITBoxes()
- {
- UpdateData();
- UpdateButtons();
- }
-
-
- /*------------------------------------------------------------------
- GetFileName
- ------------------------------------------------------------------*/
-
- CString
- CWin32ZStringToolsDlg::GetFileName(
- char * dialogTitle)
- {
- // Ask for the new file name.
- static char * filterBinary = "Binary Files (*.exe)|*.exe|HTML Files (*.html)|*.html|Dictionary Files (*.dict)|*.dict|All Files (*.*)|*.*||";
- char * extension = "exe";
-
- CFileDialog fileDlg(true, extension, (LPCTSTR)NULL,
- OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST, filterBinary);
-
- // Change title of Standard Open file dialog.
- fileDlg.m_ofn.lStructSize = sizeof (OPENFILENAME);
- fileDlg.m_ofn.lpstrTitle = dialogTitle;
- if (fileDlg.DoModal() != IDOK)
- return _T("");
-
- return fileDlg.GetPathName();
- }
-
- /*------------------------------------------------------------------
- OnBrowseSource
- ------------------------------------------------------------------*/
-
- void
- CWin32ZStringToolsDlg::OnBrowseSource()
- {
- UpdateData();
- mSourceFileName = GetFileName(sSourceFileTitle);
- UpdateData(FALSE);
- UpdateButtons();
- }
-
- /*------------------------------------------------------------------
- OnBrowseCompare
- ------------------------------------------------------------------*/
-
- void
- CWin32ZStringToolsDlg::OnBrowseCompare()
- {
- UpdateData();
- mCompareFileName = GetFileName(sCompareFileTitle);
- UpdateData(FALSE);
- UpdateButtons();
- }
-
-
- /*------------------------------------------------------------------
- OnBrowseDestination
- ------------------------------------------------------------------*/
-
- void
- CWin32ZStringToolsDlg::OnBrowseDestination()
- {
- // Ask for the name of the output file.
- char * filterReport = "HTML Files (*.html)|*.html|Dictionary Files (*.dict)|*.dict|All Files (*.*)|*.*||";
- const char * outExtension = "html";
-
- CFileDialog outDlg(false, outExtension, NULL,
- OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, filterReport, NULL);
-
- // Change title of Standard Save file dialog.
- outDlg.m_ofn.lpstrTitle = sDestFileTitle;
- if (outDlg.DoModal() != IDOK)
- return;
-
- UpdateData();
- mDestFileName = outDlg.GetPathName();
- UpdateData(FALSE);
- UpdateButtons();
- }
-
-
-