Index: src/ch/ch.cpp =================================================================== diff -u -rcdf6a22ddf857f56ce2e27e26d8cd6f0b8034b2e -rb6b8ac5b0a1ab85b4ac788e5429be860d2f20bd5 --- src/ch/ch.cpp (.../ch.cpp) (revision cdf6a22ddf857f56ce2e27e26d8cd6f0b8034b2e) +++ src/ch/ch.cpp (.../ch.cpp) (revision b6b8ac5b0a1ab85b4ac788e5429be860d2f20bd5) @@ -1,23 +1,21 @@ -/************************************************************************ - Copy Handler 1.x - program for copying data in Microsoft Windows - systems. - Copyright (C) 2001-2004 Ixen Gerthannes (copyhandler@o2.pl) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*************************************************************************/ - +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ #include "stdafx.h" #include "ch.h" @@ -26,7 +24,7 @@ #include "..\common\ipcstructs.h" #include #include "CrashDlg.h" -#include "version.h" +#include "../common/version.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -74,29 +72,9 @@ // CCopyHandlerApp construction // main routing function - routes any message that comes from modules -LRESULT MainRouter(ULONGLONG ullDst, UINT uiMsg, WPARAM wParam, LPARAM lParam) +void ResManCallback(uint_t uiMsg) { - TRACE("Main routing func received ullDst=%I64u, uiMsg=%lu, wParam=%lu, lParam=%lu\n", ullDst, uiMsg, wParam, lParam); - ULONGLONG ullOperation=ullDst & 0xff00000000000000; - ullDst &= 0x00ffffffffffffff; // get rid of operation - - switch (ullOperation) - { - case ROT_EVERYWHERE: - { - // now additional processing - switch (uiMsg) - { - case WM_RMNOTIFY: - theApp.OnResManNotify((UINT)wParam, lParam); - break; - } - - break; - } - } - - return (LRESULT)TRUE; + theApp.OnResManNotify(uiMsg); } void ConfigPropertyChangedCallback(uint_t uiPropID, ptr_t /*pParam*/) @@ -109,7 +87,6 @@ m_cfgSettings(icpf::config::eIni) { m_pMainWindow=NULL; - m_szHelpPath[0]=_T('\0'); // this is the one-instance application InitProtection(); @@ -136,7 +113,7 @@ return &theApp; } -CResourceManager* GetResManager() +ictranslate::CResourceManager* GetResManager() { return &theApp.m_resManager; } @@ -162,13 +139,14 @@ // generate the current filename - uses language from config TCHAR szBuffer[_MAX_PATH]; - GetConfig()->get_string(PP_PHELPDIR, szBuffer, _MAX_PATH); + _tcscpy(szBuffer, _T("\\Help\\")); ExpandPath(szBuffer); _tcscat(szBuffer, GetResManager()->m_ld.GetHelpName()); - if (_tcscmp(szBuffer, m_szHelpPath) != 0) + if(_tcscmp(szBuffer, m_pszHelpFilePath) != 0) { + free((void*)m_pszHelpFilePath); + m_pszHelpFilePath = _tcsdup(szBuffer); bChanged=true; - _tcscpy(m_szHelpPath, szBuffer); } return bChanged; @@ -225,8 +203,22 @@ BOOL CCopyHandlerApp::InitInstance() { + // set the exception handler to catch the crash dumps SetUnhandledExceptionFilter(&MyUnhandledExceptionFilter); + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + EnableHtmlHelp(); + //SetHelpMode(afxHTMLHelp); + CWinApp::InitInstance(); m_hMapObject = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(CSharedConfigStruct), _T("CHLMFile")); @@ -240,16 +232,20 @@ // load configuration m_cfgSettings.set_callback(ConfigPropertyChangedCallback, NULL); - TCHAR szPath[_MAX_PATH]; - _tcscpy(szPath, GetProgramPath()); - _tcscat(szPath, _T("\\ch.ini")); - try + CString strPath; + // note that the GetProgramDataPath() below should create a directory; ExpandPath() could + // depend on the directory to be created earlier + if(GetProgramDataPath(strPath)) { - m_cfgSettings.read(szPath); + strPath += _T("\\ch.ini"); + try + { + m_cfgSettings.read(strPath); + } + catch(...) + { + } } - catch(...) - { - } // register all properties RegisterProperties(&m_cfgSettings); @@ -259,8 +255,9 @@ ::SetPriorityClass(hProcess, (DWORD)m_cfgSettings.get_signed_num(PP_PPROCESSPRIORITYCLASS)); // set current language + TCHAR szPath[_MAX_PATH]; m_resManager.Init(AfxGetInstanceHandle()); - m_resManager.SetCallback((PFNNOTIFYCALLBACK)MainRouter); + m_resManager.SetCallback(ResManCallback); m_cfgSettings.get_string(PP_PLANGUAGE, szPath, _MAX_PATH); TRACE(_T("Help path=%s\n"), szPath); if (!m_resManager.SetLanguage(ExpandPath(szPath))) @@ -271,11 +268,10 @@ return FALSE; } - // load crash string just in case - m_strCrashInfo = m_resManager.LoadString(IDS_CRASH_STRING); + UpdateHelpPaths(); // for dialogs - CLanguageDialog::SetResManager(&m_resManager); + ictranslate::CLanguageDialog::SetResManager(&m_resManager); // initialize log file m_cfgSettings.get_string(PP_LOGPATH, szPath, _MAX_PATH); @@ -290,7 +286,7 @@ #ifndef _DEBUG // for easier writing the program - doesn't collide with std CH // set "run with system" registry settings - SetAutorun(m_cfgManager.GetBoolValue(PP_PRELOADAFTERRESTART)); + SetAutorun(m_cfgSettings.get_bool(PP_PRELOADAFTERRESTART)); #endif // check instance - return false if it's the second one @@ -319,31 +315,26 @@ m_cfgSettings.get_string(PP_PLANGUAGE, szPath, _MAX_PATH); m_resManager.SetLanguage(ExpandPath(szPath)); } - if(uiPropID == PP_PHELPDIR) - { - if(UpdateHelpPaths()) - HtmlHelp(HH_CLOSE_ALL, NULL); - } } -void CCopyHandlerApp::OnResManNotify(UINT uiType, LPARAM /*lParam*/) +void CCopyHandlerApp::OnResManNotify(UINT uiType) { if (uiType == RMNT_LANGCHANGE) { // language has been changed - close the current help file if (UpdateHelpPaths()) - HtmlHelp(HH_CLOSE_ALL, NULL); + HtmlHelp(NULL, HH_CLOSE_ALL); } } HWND CCopyHandlerApp::HHelp(HWND hwndCaller, LPCTSTR pszFile, UINT uCommand, DWORD dwData) { PCTSTR pszPath=NULL; WIN32_FIND_DATA wfd; - HANDLE handle=::FindFirstFile(m_szHelpPath, &wfd); + HANDLE handle=::FindFirstFile(m_pszHelpFilePath, &wfd); if (handle != INVALID_HANDLE_VALUE) { - pszPath=m_szHelpPath; + pszPath=m_pszHelpFilePath; ::FindClose(handle); } @@ -361,25 +352,25 @@ return ::HtmlHelp(hwndCaller, pszPath, uCommand, dwData); } -bool CCopyHandlerApp::HtmlHelp(UINT uiCommand, LPARAM lParam) +void CCopyHandlerApp::HtmlHelp(DWORD_PTR dwData, UINT nCmd) { - switch (uiCommand) + switch (nCmd) { case HH_DISPLAY_TOPIC: case HH_HELP_CONTEXT: { - return HHelp(GetDesktopWindow(), NULL, uiCommand, lParam) != NULL; + HHelp(GetDesktopWindow(), NULL, nCmd, dwData); break; } case HH_CLOSE_ALL: - return ::HtmlHelp(NULL, NULL, HH_CLOSE_ALL, NULL) != NULL; + ::HtmlHelp(NULL, NULL, HH_CLOSE_ALL, NULL); break; case HH_DISPLAY_TEXT_POPUP: { - HELPINFO* pHelp=(HELPINFO*)lParam; + HELPINFO* pHelp=(HELPINFO*)dwData; if ( pHelp->dwContextId == 0 || pHelp->iCtrlId == 0 || ::GetWindowContextHelpId((HWND)pHelp->hItemHandle) == 0) - return false; + return; HH_POPUP hhp; hhp.cbStruct=sizeof(HH_POPUP); @@ -398,11 +389,9 @@ TCHAR szPath[_MAX_PATH]; _sntprintf(szPath, _MAX_PATH, _T("::/%lu.txt"), (pHelp->dwContextId >> 16) & 0x7fff); - return (HHelp(GetDesktopWindow(), szPath, HH_DISPLAY_TEXT_POPUP, (DWORD)&hhp) != NULL); + HHelp(GetDesktopWindow(), szPath, HH_DISPLAY_TEXT_POPUP, (DWORD)&hhp); break; } } - - return true; }