Index: ch.sln =================================================================== diff -u -N --- ch.sln (revision 0) +++ ch.sln (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,34 @@ +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Copy Handler", "ch\ch.vcproj", "{4B215B9A-58CA-4987-AC95-7DFC3043E100}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CopyHandlerShellExt", "chext\chext.vcproj", "{7CE8B0C5-8CD4-4551-ACBF-EC4749E15E69}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + Debug = Debug + Release = Release + Release MinDependency = Release MinDependency + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {4B215B9A-58CA-4987-AC95-7DFC3043E100}.Debug.ActiveCfg = Debug|Win32 + {4B215B9A-58CA-4987-AC95-7DFC3043E100}.Debug.Build.0 = Debug|Win32 + {4B215B9A-58CA-4987-AC95-7DFC3043E100}.Release.ActiveCfg = Release|Win32 + {4B215B9A-58CA-4987-AC95-7DFC3043E100}.Release.Build.0 = Release|Win32 + {4B215B9A-58CA-4987-AC95-7DFC3043E100}.Release MinDependency.ActiveCfg = Release|Win32 + {4B215B9A-58CA-4987-AC95-7DFC3043E100}.Release MinDependency.Build.0 = Release|Win32 + {7CE8B0C5-8CD4-4551-ACBF-EC4749E15E69}.Debug.ActiveCfg = Debug|Win32 + {7CE8B0C5-8CD4-4551-ACBF-EC4749E15E69}.Debug.Build.0 = Debug|Win32 + {7CE8B0C5-8CD4-4551-ACBF-EC4749E15E69}.Release.ActiveCfg = Release MinDependency|Win32 + {7CE8B0C5-8CD4-4551-ACBF-EC4749E15E69}.Release.Build.0 = Release MinDependency|Win32 + {7CE8B0C5-8CD4-4551-ACBF-EC4749E15E69}.Release MinDependency.ActiveCfg = Release MinDependency|Win32 + {7CE8B0C5-8CD4-4551-ACBF-EC4749E15E69}.Release MinDependency.Build.0 = Release MinDependency|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal Index: Copy Handler.sln =================================================================== diff -u -N --- Copy Handler.sln (revision 125baa60fb7ffbffa0a3b81802f1164f5123e919) +++ Copy Handler.sln (revision 0) @@ -1,34 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Copy Handler", "Copy Handler\Copy Handler.vcproj", "{4B215B9A-58CA-4987-AC95-7DFC3043E100}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CopyHandlerShellExt", "CopyHandlerShellExt\CopyHandlerShellExt.vcproj", "{7CE8B0C5-8CD4-4551-ACBF-EC4749E15E69}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release - Release MinDependency = Release MinDependency - EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {4B215B9A-58CA-4987-AC95-7DFC3043E100}.Debug.ActiveCfg = Debug|Win32 - {4B215B9A-58CA-4987-AC95-7DFC3043E100}.Debug.Build.0 = Debug|Win32 - {4B215B9A-58CA-4987-AC95-7DFC3043E100}.Release.ActiveCfg = Release|Win32 - {4B215B9A-58CA-4987-AC95-7DFC3043E100}.Release.Build.0 = Release|Win32 - {4B215B9A-58CA-4987-AC95-7DFC3043E100}.Release MinDependency.ActiveCfg = Release|Win32 - {4B215B9A-58CA-4987-AC95-7DFC3043E100}.Release MinDependency.Build.0 = Release|Win32 - {7CE8B0C5-8CD4-4551-ACBF-EC4749E15E69}.Debug.ActiveCfg = Debug|Win32 - {7CE8B0C5-8CD4-4551-ACBF-EC4749E15E69}.Debug.Build.0 = Debug|Win32 - {7CE8B0C5-8CD4-4551-ACBF-EC4749E15E69}.Release.ActiveCfg = Release MinDependency|Win32 - {7CE8B0C5-8CD4-4551-ACBF-EC4749E15E69}.Release.Build.0 = Release MinDependency|Win32 - {7CE8B0C5-8CD4-4551-ACBF-EC4749E15E69}.Release MinDependency.ActiveCfg = Release MinDependency|Win32 - {7CE8B0C5-8CD4-4551-ACBF-EC4749E15E69}.Release MinDependency.Build.0 = Release MinDependency|Win32 - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution - EndGlobalSection -EndGlobal Index: ch/AppHelper.cpp =================================================================== diff -u -N --- ch/AppHelper.cpp (revision 0) +++ ch/AppHelper.cpp (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,285 @@ +#include "stdafx.h" +#include "AppHelper.h" +#include "shlobj.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +CAppHelper::CAppHelper() +{ + // read program paths + RetrievePaths(); + + // retrieve VERSION-based info + RetrieveAppInfo(); + + // single-instance protection + m_bFirstInstance=true; + m_hMutex=NULL; + + // name of the protection mutex + m_pszMutexName=new TCHAR[_tcslen(m_pszAppName)+sizeof(_T("__ instance"))/sizeof(TCHAR)+1]; + _stprintf(m_pszMutexName, _T("_%s_ instance"), m_pszAppName); + _tcslwr(m_pszMutexName+2); // first letter of appname has to be of predefined case +} + +CAppHelper::~CAppHelper() +{ + if (m_hMutex) + ReleaseMutex(m_hMutex); + + delete [] m_pszProgramPath; + delete [] m_pszProgramName; + delete [] m_pszAppName; + delete [] m_pszAppNameVer; + delete [] m_pszAppVersion; + delete [] m_pszMutexName; +} + +// inits mutex app protection +void CAppHelper::InitProtection() +{ + m_hMutex=CreateMutex(NULL, TRUE, m_pszMutexName); + m_bFirstInstance=(m_hMutex != NULL && GetLastError() != ERROR_ALREADY_EXISTS); +} + +// retrieves application path +void CAppHelper::RetrievePaths() +{ + // try to find '\\' in path to see if this is only exe name or fully qualified path + TCHAR* pszName=_tcsrchr(__argv[0], _T('\\')); + if (pszName != NULL) + { + // copy name + m_pszProgramName=new TCHAR[_tcslen(pszName+1)+1]; + _tcscpy(m_pszProgramName, pszName+1); + + // path + UINT uiSize=(UINT)(pszName-__argv[0]); + m_pszProgramPath=new TCHAR[uiSize+1]; + _tcsncpy(m_pszProgramPath, __argv[0], uiSize); + m_pszProgramPath[uiSize]=_T('\0'); + } + else + { + // copy name + m_pszProgramName=new TCHAR[_tcslen(__argv[0])+1]; + _tcscpy(m_pszProgramName, __argv[0]); + + // path + TCHAR szPath[_MAX_PATH]; + UINT uiSize=GetCurrentDirectory(_MAX_PATH, szPath); + _tcscat(szPath, _T("\\")); + m_pszProgramPath=new TCHAR[uiSize+2]; + _tcsncpy(m_pszProgramPath, szPath, uiSize+2); + } +} + +void CAppHelper::RetrieveAppInfo() +{ + if (m_pszAppName) + { + delete [] m_pszAppName; + m_pszAppName=NULL; + } + if (m_pszAppNameVer) + { + delete [] m_pszAppNameVer; + m_pszAppNameVer=NULL; + } + if (m_pszAppVersion) + { + delete [] m_pszAppVersion; + m_pszAppVersion=NULL; + } + + TCHAR *pszPath=new TCHAR[_tcslen(m_pszProgramPath)+_tcslen(m_pszProgramName)+2]; + _tcscpy(pszPath, m_pszProgramPath); + _tcscat(pszPath, _T("\\")); + _tcscat(pszPath, m_pszProgramName); + + DWORD dwHandle; + DWORD dwSize=GetFileVersionInfoSize(pszPath, &dwHandle); + if (dwSize) + { + BYTE *pbyBuffer=new BYTE[dwSize]; + if (GetFileVersionInfo(pszPath, 0, dwSize, pbyBuffer)) + { + TCHAR* pszProp; + UINT uiLen; + // product name with short version number + if (VerQueryValue(pbyBuffer, _T("\\StringFileInfo\\040904b0\\ProductName"), (LPVOID*)&pszProp, &uiLen)) + { + m_pszAppNameVer=new TCHAR[uiLen]; + _tcscpy(m_pszAppNameVer, pszProp); + } + + // product long version + if (VerQueryValue(pbyBuffer, _T("\\StringFileInfo\\040904b0\\ProductVersion"), (LPVOID*)&pszProp, &uiLen)) + { + m_pszAppVersion=new TCHAR[uiLen]; + _tcscpy(m_pszAppVersion, pszProp); + } + + // product name without version number + if (VerQueryValue(pbyBuffer, _T("\\StringFileInfo\\040904b0\\InternalName"), (LPVOID*)&pszProp, &uiLen)) + { + m_pszAppName=new TCHAR[uiLen]; + _tcscpy(m_pszAppName, pszProp); + } + } + + delete [] pbyBuffer; + } + delete [] pszPath; + + if (m_pszAppNameVer == NULL) + { + m_pszAppNameVer=new TCHAR[sizeof(_T("Unknown App 1.0"))/sizeof(TCHAR)]; + _tcscpy(m_pszAppNameVer, _T("Unknown App 1.0")); + } + if (m_pszAppVersion == NULL) + { + m_pszAppVersion=new TCHAR[sizeof(_T("1.0.0.0"))/sizeof(TCHAR)]; + _tcscpy(m_pszAppVersion, _T("1.0.0.0")); + } + if (m_pszAppName == NULL) + { + m_pszAppName=new TCHAR[sizeof(_T("Unknown App"))/sizeof(TCHAR)]; + _tcscpy(m_pszAppName, _T("Unknown App")); + } +} + +// internal func - safe getting special folder locations +UINT CAppHelper::GetFolderLocation(int iFolder, PTSTR pszBuffer) +{ + LPITEMIDLIST piid; + HRESULT h=SHGetSpecialFolderLocation(NULL, iFolder, &piid); + if (!SUCCEEDED(h)) + return false; + + // get path + BOOL bRes=SHGetPathFromIDList(piid, pszBuffer); + + // free piid + LPMALLOC lpm; + if (!SUCCEEDED(SHGetMalloc(&lpm))) + return 0; + + lpm->Free((void*)piid); + lpm->Release(); + + // check for error + if (!bRes) + return 0; + + // strip the last '\\' + UINT uiLen=(UINT)_tcslen(pszBuffer); + if (pszBuffer[uiLen-1] == _T('\\')) + { + pszBuffer[uiLen-1]=_T('\0'); + return uiLen-1; + } + else + return uiLen; +} + +// expands given path +PTSTR CAppHelper::ExpandPath(PTSTR pszString) +{ + // check if there is need to perform all these checkings + if (pszString[0] != _T('<')) + return pszString; + + TCHAR szStr[_MAX_PATH]; + szStr[0]=_T('\0'); + + // search for string to replace + // _T(""), _T(""), _T(""), _T(""), _T(""), + // _T(""), _T("") + if (_tcsnicmp(pszString, _T(""), 9) == 0) + { + // get windows path + _tcscpy(szStr, m_pszProgramPath); + _tcscat(szStr, pszString+9); + } + else if (_tcsnicmp(pszString, _T(""), 9) == 0) + { + // get windows path + UINT uiSize=GetWindowsDirectory(szStr, _MAX_PATH); + if (szStr[uiSize-1] == _T('\\')) + szStr[uiSize-1]=_T('\0'); + _tcscat(szStr, pszString+9); + } + else if (_tcsnicmp(pszString, _T(""), 6) == 0) // temp dir + { + // get windows path + UINT uiSize=GetTempPath(_MAX_PATH, szStr); + if (szStr[uiSize-1] == _T('\\')) + szStr[uiSize-1]=_T('\0'); + _tcscat(szStr, pszString+6); + } + else if (_tcsnicmp(pszString, _T(""), 8) == 0) // system + { + // get windows path + UINT uiSize=GetSystemDirectory(szStr, _MAX_PATH); + if (szStr[uiSize-1] == _T('\\')) + szStr[uiSize-1]=_T('\0'); + _tcscat(szStr, pszString+8); + } + else if (_tcsnicmp(pszString, _T(""), 9) == 0) // app data + { + // get windows path + UINT uiSize=GetFolderLocation(CSIDL_APPDATA, szStr); + if (szStr[uiSize-1] == _T('\\')) + szStr[uiSize-1]=_T('\0'); + _tcscat(szStr, pszString+9); + } + else if (_tcsnicmp(pszString, _T(""), 9) == 0) // desktop + { + // get windows path + UINT uiSize=GetFolderLocation(CSIDL_DESKTOPDIRECTORY, szStr); + if (szStr[uiSize-1] == _T('\\')) + szStr[uiSize-1]=_T('\0'); + _tcscat(szStr, pszString+9); + } + else if (_tcsnicmp(pszString, _T(""), 10) == 0) // personal... + { + // get windows path + UINT uiSize=GetFolderLocation(CSIDL_PERSONAL, szStr); + if (szStr[uiSize-1] == _T('\\')) + szStr[uiSize-1]=_T('\0'); + _tcscat(szStr, pszString+10); + } + + // copy to src string + if (szStr[0] != _T('\0')) + _tcscpy(pszString, szStr); + + return pszString; +} + +void CAppHelper::SetAutorun(bool bState) +{ + // storing key in registry + HKEY hkeyRun; + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_ALL_ACCESS, &hkeyRun) != ERROR_SUCCESS) + return; + + if (bState) + { + TCHAR *pszPath=new TCHAR[_tcslen(m_pszProgramPath)+_tcslen(m_pszProgramName)+2]; + _tcscpy(pszPath, m_pszProgramPath); + _tcscat(pszPath, _T("\\")); + _tcscat(pszPath, m_pszProgramName); + + RegSetValueEx(hkeyRun, m_pszAppName, 0, REG_SZ, (BYTE*)pszPath, (DWORD)(_tcslen(pszPath)+1)*sizeof(TCHAR)); + + delete [] pszPath; + } + else + RegDeleteValue(hkeyRun, m_pszAppName); + + RegCloseKey(hkeyRun); +} Index: modules/App Framework/AppHelper.cpp =================================================================== diff -u -N --- modules/App Framework/AppHelper.cpp (revision 7d997aef1e72f049ed1bc199e1b765d737d9963a) +++ modules/App Framework/AppHelper.cpp (revision 0) @@ -1,285 +0,0 @@ -#include "stdafx.h" -#include "AppHelper.h" -#include "shlobj.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -CAppHelper::CAppHelper() -{ - // read program paths - RetrievePaths(); - - // retrieve VERSION-based info - RetrieveAppInfo(); - - // single-instance protection - m_bFirstInstance=true; - m_hMutex=NULL; - - // name of the protection mutex - m_pszMutexName=new TCHAR[_tcslen(m_pszAppName)+sizeof(_T("__ instance"))/sizeof(TCHAR)+1]; - _stprintf(m_pszMutexName, _T("_%s_ instance"), m_pszAppName); - _tcslwr(m_pszMutexName+2); // first letter of appname has to be of predefined case -} - -CAppHelper::~CAppHelper() -{ - if (m_hMutex) - ReleaseMutex(m_hMutex); - - delete [] m_pszProgramPath; - delete [] m_pszProgramName; - delete [] m_pszAppName; - delete [] m_pszAppNameVer; - delete [] m_pszAppVersion; - delete [] m_pszMutexName; -} - -// inits mutex app protection -void CAppHelper::InitProtection() -{ - m_hMutex=CreateMutex(NULL, TRUE, m_pszMutexName); - m_bFirstInstance=(m_hMutex != NULL && GetLastError() != ERROR_ALREADY_EXISTS); -} - -// retrieves application path -void CAppHelper::RetrievePaths() -{ - // try to find '\\' in path to see if this is only exe name or fully qualified path - TCHAR* pszName=_tcsrchr(__argv[0], _T('\\')); - if (pszName != NULL) - { - // copy name - m_pszProgramName=new TCHAR[_tcslen(pszName+1)+1]; - _tcscpy(m_pszProgramName, pszName+1); - - // path - UINT uiSize=(UINT)(pszName-__argv[0]); - m_pszProgramPath=new TCHAR[uiSize+1]; - _tcsncpy(m_pszProgramPath, __argv[0], uiSize); - m_pszProgramPath[uiSize]=_T('\0'); - } - else - { - // copy name - m_pszProgramName=new TCHAR[_tcslen(__argv[0])+1]; - _tcscpy(m_pszProgramName, __argv[0]); - - // path - TCHAR szPath[_MAX_PATH]; - UINT uiSize=GetCurrentDirectory(_MAX_PATH, szPath); - _tcscat(szPath, _T("\\")); - m_pszProgramPath=new TCHAR[uiSize+2]; - _tcsncpy(m_pszProgramPath, szPath, uiSize+2); - } -} - -void CAppHelper::RetrieveAppInfo() -{ - if (m_pszAppName) - { - delete [] m_pszAppName; - m_pszAppName=NULL; - } - if (m_pszAppNameVer) - { - delete [] m_pszAppNameVer; - m_pszAppNameVer=NULL; - } - if (m_pszAppVersion) - { - delete [] m_pszAppVersion; - m_pszAppVersion=NULL; - } - - TCHAR *pszPath=new TCHAR[_tcslen(m_pszProgramPath)+_tcslen(m_pszProgramName)+2]; - _tcscpy(pszPath, m_pszProgramPath); - _tcscat(pszPath, _T("\\")); - _tcscat(pszPath, m_pszProgramName); - - DWORD dwHandle; - DWORD dwSize=GetFileVersionInfoSize(pszPath, &dwHandle); - if (dwSize) - { - BYTE *pbyBuffer=new BYTE[dwSize]; - if (GetFileVersionInfo(pszPath, 0, dwSize, pbyBuffer)) - { - TCHAR* pszProp; - UINT uiLen; - // product name with short version number - if (VerQueryValue(pbyBuffer, _T("\\StringFileInfo\\040904b0\\ProductName"), (LPVOID*)&pszProp, &uiLen)) - { - m_pszAppNameVer=new TCHAR[uiLen]; - _tcscpy(m_pszAppNameVer, pszProp); - } - - // product long version - if (VerQueryValue(pbyBuffer, _T("\\StringFileInfo\\040904b0\\ProductVersion"), (LPVOID*)&pszProp, &uiLen)) - { - m_pszAppVersion=new TCHAR[uiLen]; - _tcscpy(m_pszAppVersion, pszProp); - } - - // product name without version number - if (VerQueryValue(pbyBuffer, _T("\\StringFileInfo\\040904b0\\InternalName"), (LPVOID*)&pszProp, &uiLen)) - { - m_pszAppName=new TCHAR[uiLen]; - _tcscpy(m_pszAppName, pszProp); - } - } - - delete [] pbyBuffer; - } - delete [] pszPath; - - if (m_pszAppNameVer == NULL) - { - m_pszAppNameVer=new TCHAR[sizeof(_T("Unknown App 1.0"))/sizeof(TCHAR)]; - _tcscpy(m_pszAppNameVer, _T("Unknown App 1.0")); - } - if (m_pszAppVersion == NULL) - { - m_pszAppVersion=new TCHAR[sizeof(_T("1.0.0.0"))/sizeof(TCHAR)]; - _tcscpy(m_pszAppVersion, _T("1.0.0.0")); - } - if (m_pszAppName == NULL) - { - m_pszAppName=new TCHAR[sizeof(_T("Unknown App"))/sizeof(TCHAR)]; - _tcscpy(m_pszAppName, _T("Unknown App")); - } -} - -// internal func - safe getting special folder locations -UINT CAppHelper::GetFolderLocation(int iFolder, PTSTR pszBuffer) -{ - LPITEMIDLIST piid; - HRESULT h=SHGetSpecialFolderLocation(NULL, iFolder, &piid); - if (!SUCCEEDED(h)) - return false; - - // get path - BOOL bRes=SHGetPathFromIDList(piid, pszBuffer); - - // free piid - LPMALLOC lpm; - if (!SUCCEEDED(SHGetMalloc(&lpm))) - return 0; - - lpm->Free((void*)piid); - lpm->Release(); - - // check for error - if (!bRes) - return 0; - - // strip the last '\\' - UINT uiLen=(UINT)_tcslen(pszBuffer); - if (pszBuffer[uiLen-1] == _T('\\')) - { - pszBuffer[uiLen-1]=_T('\0'); - return uiLen-1; - } - else - return uiLen; -} - -// expands given path -PTSTR CAppHelper::ExpandPath(PTSTR pszString) -{ - // check if there is need to perform all these checkings - if (pszString[0] != _T('<')) - return pszString; - - TCHAR szStr[_MAX_PATH]; - szStr[0]=_T('\0'); - - // search for string to replace - // _T(""), _T(""), _T(""), _T(""), _T(""), - // _T(""), _T("") - if (_tcsnicmp(pszString, _T(""), 9) == 0) - { - // get windows path - _tcscpy(szStr, m_pszProgramPath); - _tcscat(szStr, pszString+9); - } - else if (_tcsnicmp(pszString, _T(""), 9) == 0) - { - // get windows path - UINT uiSize=GetWindowsDirectory(szStr, _MAX_PATH); - if (szStr[uiSize-1] == _T('\\')) - szStr[uiSize-1]=_T('\0'); - _tcscat(szStr, pszString+9); - } - else if (_tcsnicmp(pszString, _T(""), 6) == 0) // temp dir - { - // get windows path - UINT uiSize=GetTempPath(_MAX_PATH, szStr); - if (szStr[uiSize-1] == _T('\\')) - szStr[uiSize-1]=_T('\0'); - _tcscat(szStr, pszString+6); - } - else if (_tcsnicmp(pszString, _T(""), 8) == 0) // system - { - // get windows path - UINT uiSize=GetSystemDirectory(szStr, _MAX_PATH); - if (szStr[uiSize-1] == _T('\\')) - szStr[uiSize-1]=_T('\0'); - _tcscat(szStr, pszString+8); - } - else if (_tcsnicmp(pszString, _T(""), 9) == 0) // app data - { - // get windows path - UINT uiSize=GetFolderLocation(CSIDL_APPDATA, szStr); - if (szStr[uiSize-1] == _T('\\')) - szStr[uiSize-1]=_T('\0'); - _tcscat(szStr, pszString+9); - } - else if (_tcsnicmp(pszString, _T(""), 9) == 0) // desktop - { - // get windows path - UINT uiSize=GetFolderLocation(CSIDL_DESKTOPDIRECTORY, szStr); - if (szStr[uiSize-1] == _T('\\')) - szStr[uiSize-1]=_T('\0'); - _tcscat(szStr, pszString+9); - } - else if (_tcsnicmp(pszString, _T(""), 10) == 0) // personal... - { - // get windows path - UINT uiSize=GetFolderLocation(CSIDL_PERSONAL, szStr); - if (szStr[uiSize-1] == _T('\\')) - szStr[uiSize-1]=_T('\0'); - _tcscat(szStr, pszString+10); - } - - // copy to src string - if (szStr[0] != _T('\0')) - _tcscpy(pszString, szStr); - - return pszString; -} - -void CAppHelper::SetAutorun(bool bState) -{ - // storing key in registry - HKEY hkeyRun; - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_ALL_ACCESS, &hkeyRun) != ERROR_SUCCESS) - return; - - if (bState) - { - TCHAR *pszPath=new TCHAR[_tcslen(m_pszProgramPath)+_tcslen(m_pszProgramName)+2]; - _tcscpy(pszPath, m_pszProgramPath); - _tcscat(pszPath, _T("\\")); - _tcscat(pszPath, m_pszProgramName); - - RegSetValueEx(hkeyRun, m_pszAppName, 0, REG_SZ, (BYTE*)pszPath, (DWORD)(_tcslen(pszPath)+1)*sizeof(TCHAR)); - - delete [] pszPath; - } - else - RegDeleteValue(hkeyRun, m_pszAppName); - - RegCloseKey(hkeyRun); -} Index: ch/AppHelper.h =================================================================== diff -u -N --- ch/AppHelper.h (revision 0) +++ ch/AppHelper.h (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,42 @@ +#ifndef __APPHELPER_H__ +#define __APPHELPER_H__ + +class CAppHelper +{ +public: + CAppHelper(); + ~CAppHelper(); + + void SetAutorun(bool bState); // changes state of "run with system" option + PTSTR ExpandPath(PTSTR pszString); // expands path string - ie. into c:\windows + + bool IsFirstInstance() const { return m_bFirstInstance; }; + + PCTSTR GetAppName() const { return m_pszAppName; }; + PCTSTR GetAppNameVer() const { return m_pszAppNameVer; }; + PCTSTR GetAppVersion() const { return m_pszAppVersion; }; + + PCTSTR GetProgramPath() const { return m_pszProgramPath; }; + PCTSTR GetProgramName() const { return m_pszProgramName; }; + +protected: + void InitProtection(); // optional call - protects from running multiple instance + void RetrievePaths(); // reads program's path and name + void RetrieveAppInfo(); // reads app name and version from VERSION resource + UINT GetFolderLocation(int iFolder, PTSTR pszBuffer); + +protected: + HANDLE m_hMutex; + bool m_bFirstInstance; // tells if it is first instance(true) or second(or third, ...) + TCHAR *m_pszMutexName; // name of the protection mutex + + // program placement + TCHAR* m_pszProgramPath; // path from which this program was run + TCHAR* m_pszProgramName; // name of this program (ie. CH.exe) + + TCHAR* m_pszAppName; // app-name string of this app + TCHAR* m_pszAppNameVer; // extended app-name-with small version + TCHAR* m_pszAppVersion; // app-version string of this app (VERSION based) +}; + +#endif \ No newline at end of file Index: modules/App Framework/AppHelper.h =================================================================== diff -u -N --- modules/App Framework/AppHelper.h (revision 3e1186252ab31f63d86d86c4b0ff593cfffbefde) +++ modules/App Framework/AppHelper.h (revision 0) @@ -1,42 +0,0 @@ -#ifndef __APPHELPER_H__ -#define __APPHELPER_H__ - -class CAppHelper -{ -public: - CAppHelper(); - ~CAppHelper(); - - void SetAutorun(bool bState); // changes state of "run with system" option - PTSTR ExpandPath(PTSTR pszString); // expands path string - ie. into c:\windows - - bool IsFirstInstance() const { return m_bFirstInstance; }; - - PCTSTR GetAppName() const { return m_pszAppName; }; - PCTSTR GetAppNameVer() const { return m_pszAppNameVer; }; - PCTSTR GetAppVersion() const { return m_pszAppVersion; }; - - PCTSTR GetProgramPath() const { return m_pszProgramPath; }; - PCTSTR GetProgramName() const { return m_pszProgramName; }; - -protected: - void InitProtection(); // optional call - protects from running multiple instance - void RetrievePaths(); // reads program's path and name - void RetrieveAppInfo(); // reads app name and version from VERSION resource - UINT GetFolderLocation(int iFolder, PTSTR pszBuffer); - -protected: - HANDLE m_hMutex; - bool m_bFirstInstance; // tells if it is first instance(true) or second(or third, ...) - TCHAR *m_pszMutexName; // name of the protection mutex - - // program placement - TCHAR* m_pszProgramPath; // path from which this program was run - TCHAR* m_pszProgramName; // name of this program (ie. CH.exe) - - TCHAR* m_pszAppName; // app-name string of this app - TCHAR* m_pszAppNameVer; // extended app-name-with small version - TCHAR* m_pszAppVersion; // app-version string of this app (VERSION based) -}; - -#endif \ No newline at end of file Index: ch/ConfigManager.cpp =================================================================== diff -u -N --- ch/ConfigManager.cpp (revision 0) +++ ch/ConfigManager.cpp (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,806 @@ +/************************************************************************ + Copy Handler 1.x - program for copying data in Microsoft Windows + systems. + Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. +*************************************************************************/ + +#include "stdafx.h" +#include "ConfigManager.h" +#ifndef DISABLE_CRYPT +#include "crypt.h" +#include "conv.h" +#endif + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +#define CFG_PROFILE _T("Common") +#define CFG_SECTION _T("Config") +#define CFG_KEY _T("Current configuration name") +#define CFG_DEFAULTSECTION _T("Default") + +#define CFG_MAXCOMPOUND 500 /* max count of items in a compound property */ + +/////////////////////////////////////////////////////////////// +// Opens configuration file. +// This function should be called only once - isn't thread safe +// Doesn't throw any file exception. If physical file couldn't +// be opened - this class does not require it. Could work +// without saving options to file, or with read-only files. +// pszFilename [in] - path to the configuration file +/////////////////////////////////////////////////////////////// +void CConfigManager::Open(LPCTSTR pszFilename) +{ + // load text file, and process it in ini file + try + { + ((CIniFile*)this)->Open(pszFilename, NULL, false); + } + catch(CFileExceptionEx* e) + { + // report error + TCHAR szData[1024]; + szData[1023]=_T('\0'); + _sntprintf(szData, 1023, _T("[Config Manager]: Couldn't open file %s to read initial data;\r\n\tReason: %s."), pszFilename, e->m_pszReason); + Report(szData); + + delete e; // get rid of this exception (file works doesn't work) + + // file couldn't be loaded... - create default section + m_pszCurrentConfig=new TCHAR[8]; + _tcscpy(m_pszCurrentConfig, CFG_DEFAULTSECTION); + SetString(CFG_PROFILE, CFG_SECTION, CFG_KEY, m_pszCurrentConfig); + return; + } + + // now - read current config name from cfg + if (!GetStr(CFG_PROFILE, CFG_SECTION, CFG_KEY, m_szBuffer, _T(""))) + { + // current config not found - the first found would be current + vector<_PROFILE*>::const_iterator it=m_vConfigProfiles.begin(); + + while (it != m_vConfigProfiles.end()) + { + // check if element 0 isn't + if (_tcsicmp((*it)->pszProfileName, CFG_PROFILE) != 0) + { + // set current cfg to the found one + m_pszCurrentConfig=new TCHAR[_tcslen((*it)->pszProfileName)+1]; + _tcscpy(m_pszCurrentConfig, (*it)->pszProfileName); + + // save current selection + SetString(CFG_PROFILE, CFG_SECTION, CFG_KEY, m_pszCurrentConfig); + break; // we've found what was needed - stop processing + } + it++; + } + + // if not found - create default + if (m_pszCurrentConfig == NULL) + { + m_pszCurrentConfig=new TCHAR[8]; + _tcscpy(m_pszCurrentConfig, CFG_DEFAULTSECTION); + SetString(CFG_PROFILE, CFG_SECTION, CFG_KEY, m_pszCurrentConfig); + } + } + else + { + // section found - copy it + m_pszCurrentConfig=new TCHAR[_tcslen(m_szBuffer)+1]; + _tcscpy(m_pszCurrentConfig, m_szBuffer); + } +} + +/////////////////////////////////////////////////////////////// +// Tries to save settings to the configuration file. If +// couldn't be saved - function reports it through Report func +// and doesn't save data to file (this allows to use read-only +// attribute on config file). +/////////////////////////////////////////////////////////////// +void CConfigManager::Save() +{ + EnterCriticalSection(&m_cs); + // copy data into ini file object + vector<_CFGENTRY*>::const_iterator it=m_vCfgData.begin(); + while (it != m_vCfgData.end()) + WriteProperty(*it++); + + // save file + try + { + ((CIniFile*)this)->Save(); + } + catch(CFileExceptionEx* e) + { + TCHAR szData[1024]; + e->GetInfo(_T("[Config Manager]: Couldn't save configuration file."), szData, 1024); + Report(szData); + delete e; + + LeaveCriticalSection(&m_cs); + return; + } + catch(...) + { + LeaveCriticalSection(&m_cs); + throw; + } + + LeaveCriticalSection(&m_cs); +} + +/////////////////////////////////////////////////////////////// +// Closes this configuration file (saves data before closing). +// If couldn't be saved/closed - it reports the fact and allows +// to continue (allows usage of read-only files). +/////////////////////////////////////////////////////////////// +void CConfigManager::Close() +{ + // store all data into .ini object + EnterCriticalSection(&m_cs); + vector<_CFGENTRY*>::const_iterator it=m_vCfgData.begin(); + while (it != m_vCfgData.end()) + { + WriteProperty(*it); + FreeEntry(*it++); + } + + // free all + m_vCfgData.clear(); + + // free current config name + delete [] m_pszCurrentConfig; + m_pszCurrentConfig=NULL; + + // destroy base... + try + { + ((CIniFile*)this)->Close(); // storing data, closing file in a base class + } + catch(CFileExceptionEx* e) + { + TCHAR szData[1024]; + e->GetInfo(_T("[Config Manager]: Couldn't properly save/close file."), szData, 1024); + Report(szData); + + delete e; + + LeaveCriticalSection(&m_cs); + return; + } + catch(...) + { + LeaveCriticalSection(&m_cs); + throw; + } + + LeaveCriticalSection(&m_cs); +} + +#ifndef DISABLE_CRYPT +/////////////////////////////////////////////////////////////// +// +/////////////////////////////////////////////////////////////// +void CConfigManager::SetPassword(PCTSTR pszPass) +{ + // gen new 256b password + TCHAR szNewPass[64+1], szLine[8192]; + StringToKey256(pszPass, szNewPass); + + // recrypt the old data if needed + if (m_pszPassword) + { + // if there already was a password + for (vector<_CFGENTRY*>::iterator it=m_vCfgData.begin();it!=m_vCfgData.end();it++) + { + // reencrypt every encrypted item + if ((*it)->dwFlags & RF_ENCRYPTED && (*it)->cType == PT_STRING) + { + // decrypt the old data + if (AES256DecipherString((*it)->val.pszValue, m_pszPassword, szLine) < 0) + continue; + + // encrypt to the new one + if (AES256CipherString(szLine, szNewPass, szLine) < 0) + continue; + + // store the new value + delete [] (*it)->val.pszValue; + (*it)->val.pszValue=new TCHAR[_tcslen(szLine)+1]; + _tcscpy((*it)->val.pszValue, szLine); + (*it)->bModified=true; // set the modified flag + } + } + + delete [] m_pszPassword; // delete old password + } + m_pszPassword=new TCHAR[64+1]; + _tcscpy(m_pszPassword, szNewPass); +} + +#endif +/////////////////////////////////////////////////////////////// +// Registers some property given filled _CFGENTRY struct. +// pEntry [in] - specifies all possible information about the +// attribute being registered. +// Ret Value [out] - ID of registered property. It must be +// used when accessing this property. +/////////////////////////////////////////////////////////////// +UINT CConfigManager::RegisterProperty(_CFGENTRY* pEntry) +{ + _ASSERT(pEntry != NULL); + + EnterCriticalSection(&m_cs); + ReadProperty(pEntry); + m_vCfgData.push_back(pEntry); + UINT uiRet=(UINT)(m_vCfgData.size()-1); + LeaveCriticalSection(&m_cs); + return uiRet; +} + +/////////////////////////////////////////////////////////////// +// Registers int64 property. +// pszSection [in] - section in which resides given property +// pszKey [in] - key in which resides given property +// llDefault [in] - default value of this property (used if the +// config file doesn't contain it) +// cDetailLevel [in] - specifies "level" of this property. It +// could be simple property (for all users) or +// something that only some paranoics will use. +// Ret Value [out] - ID of registered property. It must be +// used when accessing this property. +/////////////////////////////////////////////////////////////// +UINT CConfigManager::RegisterInt64Property(LPCTSTR pszSection, LPCTSTR pszKey, __int64 llDefault, char cDetailLevel) +{ + // create config entry + _CFGENTRY* pcfg=new _CFGENTRY; + pcfg->pszSection=new TCHAR[_tcslen(pszSection)+1]; + _tcscpy(pcfg->pszSection, pszSection); + pcfg->pszKey=new TCHAR[_tcslen(pszKey)+1]; + _tcscpy(pcfg->pszKey, pszKey); + pcfg->cType=PT_INT64; + pcfg->def.llValue=llDefault; + pcfg->bModified=false; + pcfg->cDetailLevel=cDetailLevel; + pcfg->dwFlags=RF_NONE; + + // register + return RegisterProperty(pcfg); +} + +/////////////////////////////////////////////////////////////// +// Registers int property. +// pszSection [in] - section in which resides given property +// pszKey [in] - key in which resides given property +// iDefault [in] - default value of this property (used if the +// config file doesn't contain it) +// cDetailLevel [in] - specifies "level" of this property. It +// could be simple property (for all users) or +// something that only some paranoics will use. +// Ret Value [out] - ID of registered property. It must be +// used when accessing this property. +/////////////////////////////////////////////////////////////// +UINT CConfigManager::RegisterIntProperty(LPCTSTR pszSection, LPCTSTR pszKey, int iDefault, char cDetailLevel) +{ + // create config entry + _CFGENTRY* pcfg=new _CFGENTRY; + pcfg->pszSection=new TCHAR[_tcslen(pszSection)+1]; + _tcscpy(pcfg->pszSection, pszSection); + pcfg->pszKey=new TCHAR[_tcslen(pszKey)+1]; + _tcscpy(pcfg->pszKey, pszKey); + pcfg->cType=PT_INT; + pcfg->def.iValue=iDefault; + pcfg->bModified=false; + pcfg->cDetailLevel=cDetailLevel; + pcfg->dwFlags=RF_NONE; + + // register + return RegisterProperty(pcfg); +} + +/////////////////////////////////////////////////////////////// +// Registers bool property. +// pszSection [in] - section in which resides given property +// pszKey [in] - key in which resides given property +// bDefault [in] - default value of this property (used if the +// config file doesn't contain it) +// cDetailLevel [in] - specifies "level" of this property. It +// could be simple property (for all users) or +// something that only some paranoics will use. +// Ret Value [out] - ID of registered property. It must be +// used when accessing this property. +/////////////////////////////////////////////////////////////// +UINT CConfigManager::RegisterBoolProperty(LPCTSTR pszSection, LPCTSTR pszKey, bool bDefault, char cDetailLevel) +{ + // create config entry + _CFGENTRY* pcfg=new _CFGENTRY; + pcfg->pszSection=new TCHAR[_tcslen(pszSection)+1]; + _tcscpy(pcfg->pszSection, pszSection); + pcfg->pszKey=new TCHAR[_tcslen(pszKey)+1]; + _tcscpy(pcfg->pszKey, pszKey); + pcfg->cType=PT_BOOL; + pcfg->def.bValue=bDefault; + pcfg->bModified=false; + pcfg->cDetailLevel=cDetailLevel; + pcfg->dwFlags=RF_NONE; + + // register + return RegisterProperty(pcfg); +} + +/////////////////////////////////////////////////////////////// +// Registers string property. +// pszSection [in] - section in which resides given property +// pszKey [in] - key in which resides given property +// pszDefault [in] - default value of this property (used if +// the config file doesn't contain it) +// cDetailLevel [in] - specifies "level" of this property. It +// could be simple property (for all users) or +// something that only some paranoics will use. +// Ret Value [out] - ID of registered property. It must be +// used when accessing this property. +/////////////////////////////////////////////////////////////// +UINT CConfigManager::RegisterStringProperty(LPCTSTR pszSection, LPCTSTR pszKey, LPCTSTR pszDefault, DWORD dwFlags, char cDetailLevel) +{ + // create config entry + _CFGENTRY* pcfg=new _CFGENTRY; + pcfg->pszSection=new TCHAR[_tcslen(pszSection)+1]; + _tcscpy(pcfg->pszSection, pszSection); + pcfg->pszKey=new TCHAR[_tcslen(pszKey)+1]; + _tcscpy(pcfg->pszKey, pszKey); + pcfg->cType=PT_STRING; + pcfg->def.pszValue=new TCHAR[_tcslen(pszDefault)+1]; + _tcscpy(pcfg->def.pszValue, pszDefault); + pcfg->bModified=false; + pcfg->cDetailLevel=cDetailLevel; + pcfg->dwFlags=dwFlags; + + // register + return RegisterProperty(pcfg); +} + +UINT CConfigManager::RegisterStringArrayProperty(LPCTSTR pszSection, char cDetailLevel) +{ + _CFGENTRY* pcfg=new _CFGENTRY; + pcfg->pszSection=new TCHAR[_tcslen(pszSection)+1]; + _tcscpy(pcfg->pszSection, pszSection); + pcfg->pszKey=NULL; + pcfg->cType=PT_ASTRING; + pcfg->bModified=false; + pcfg->cDetailLevel=cDetailLevel; + pcfg->val.pvszValue=new char_vector; + pcfg->dwFlags=RF_NONE; + + return RegisterProperty(pcfg); +} + +/////////////////////////////////////////////////////////////// +// Returns value of int property given property ID +// uiPropID [in] - property ID (returned by RegisterProperty..) +// Ret Value [out] - value of this property (either from file +// or the default one specified at registration) +/////////////////////////////////////////////////////////////// +int CConfigManager::GetIntValue(UINT uiPropID) +{ + EnterCriticalSection(&m_cs); + int iRet=m_vCfgData.at(uiPropID)->val.iValue; + LeaveCriticalSection(&m_cs); + return iRet; +} + +/////////////////////////////////////////////////////////////// +// Sets value of a given property (by it's ID) +// uiPropID [in] - property ID (returned by RegisterProperty..) +// iValue [in] - the new value of this property +/////////////////////////////////////////////////////////////// +void CConfigManager::SetIntValue(UINT uiPropID, int iValue) +{ + EnterCriticalSection(&m_cs); + m_vCfgData.at(uiPropID)->val.iValue=iValue; + m_vCfgData.at(uiPropID)->bModified=true; + LeaveCriticalSection(&m_cs); + + if (m_pfnCallback) + (*m_pfnCallback)(0, WM_CFGNOTIFY, CNFT_PROPERTYCHANGE, uiPropID); +} + +/////////////////////////////////////////////////////////////// +// Returns value of int64 property given property ID +// uiPropID [in] - property ID (returned by RegisterProperty..) +// Ret Value [out] - value of this property (either from file +// or the default one specified at registration) +/////////////////////////////////////////////////////////////// +__int64 CConfigManager::GetInt64Value(UINT uiPropID) +{ + EnterCriticalSection(&m_cs); + __int64 llRet=m_vCfgData.at(uiPropID)->val.llValue; + LeaveCriticalSection(&m_cs); + return llRet; +} + +/////////////////////////////////////////////////////////////// +// Sets value of a given property (by it's ID) +// uiPropID [in] - property ID (returned by RegisterProperty..) +// llValue [in] - the new value of this property +/////////////////////////////////////////////////////////////// +void CConfigManager::SetInt64Value(UINT uiPropID, __int64 llValue) +{ + EnterCriticalSection(&m_cs); + m_vCfgData.at(uiPropID)->val.llValue=llValue; + m_vCfgData.at(uiPropID)->bModified=true; + LeaveCriticalSection(&m_cs); + + if (m_pfnCallback) + (*m_pfnCallback)(0, WM_CFGNOTIFY, CNFT_PROPERTYCHANGE, uiPropID); +} + +/////////////////////////////////////////////////////////////// +// Returns value of bool property given property ID +// uiPropID [in] - property ID (returned by RegisterProperty..) +// Ret Value [out] - value of this property (either from file +// or the default one specified at registration) +/////////////////////////////////////////////////////////////// +bool CConfigManager::GetBoolValue(UINT uiPropID) +{ + EnterCriticalSection(&m_cs); + bool bRet=m_vCfgData.at(uiPropID)->val.bValue; + LeaveCriticalSection(&m_cs); + return bRet; +} + +/////////////////////////////////////////////////////////////// +// Sets value of a given property (by it's ID) +// uiPropID [in] - property ID (returned by RegisterProperty..) +// bValue [in] - the new value of this property +/////////////////////////////////////////////////////////////// +void CConfigManager::SetBoolValue(UINT uiPropID, bool bValue) +{ + EnterCriticalSection(&m_cs); + m_vCfgData.at(uiPropID)->val.bValue=bValue; + m_vCfgData.at(uiPropID)->bModified=true; + LeaveCriticalSection(&m_cs); + + if (m_pfnCallback) + (*m_pfnCallback)(0, WM_CFGNOTIFY, CNFT_PROPERTYCHANGE, uiPropID); +} + +/////////////////////////////////////////////////////////////// +// Returns value of string property given property ID +// uiPropID [in] - property ID (returned by RegisterProperty..) +// Ret Value [out] - value of this property (either from file +// or the default one specified at registration) +/////////////////////////////////////////////////////////////// +PCTSTR CConfigManager::GetStringValue(UINT uiPropID, PTSTR pszBuffer, int iSize) +{ + EnterCriticalSection(&m_cs); + +#ifndef DISABLE_CRYPT + if (m_vCfgData.at(uiPropID)->dwFlags & RF_ENCRYPTED) + { + // make sure password has been set already + _ASSERT(m_pszPassword); + + TCHAR szLine[8192]; + if (AES256DecipherString(m_vCfgData.at(uiPropID)->val.pszValue, m_pszPassword, szLine) <= 0) + { + // return + _tcscpy(pszBuffer, _T("")); + LeaveCriticalSection(&m_cs); + return pszBuffer; + } + + // copy the decrypted data + _tcsncpy(pszBuffer, szLine, iSize); + pszBuffer[iSize-1]=_T('\0'); + } + else +#endif + _tcsncpy(pszBuffer, m_vCfgData.at(uiPropID)->val.pszValue, iSize); + + if (m_vCfgData.at(uiPropID)->dwFlags & RF_PATH) + { + if (pszBuffer[_tcslen(pszBuffer)-1] != _T('\\')) + _tcscat(pszBuffer, _T("\\")); + } + + LeaveCriticalSection(&m_cs); + + return pszBuffer; +} + +/////////////////////////////////////////////////////////////// +// Sets value of a given property (by it's ID) +// uiPropID [in] - property ID (returned by RegisterProperty..) +// pszValue [in] - the new value of this property +/////////////////////////////////////////////////////////////// +void CConfigManager::SetStringValue(UINT uiPropID, LPCTSTR pszValue) +{ + EnterCriticalSection(&m_cs); +#ifndef DISABLE_CRYPT + // encrypt the data before setting the property text + if (m_vCfgData.at(uiPropID)->dwFlags & RF_ENCRYPTED) + { + // make sure password has been set already + _ASSERT(m_pszPassword); + + TCHAR szLine[8192]; + if (AES256CipherString(pszValue, m_pszPassword, szLine) < 0) + { + _ASSERT(false); + TRACE("Cannot cipher string - what to do ????\n"); + } + + // store encrypted value + delete [] m_vCfgData.at(uiPropID)->val.pszValue; // delete old value + m_vCfgData.at(uiPropID)->val.pszValue=new TCHAR[_tcslen(szLine)+1]; // create space for new + _tcscpy(m_vCfgData.at(uiPropID)->val.pszValue, szLine); // copy the new one + m_vCfgData.at(uiPropID)->bModified=true; // modified state + } + else + { +#endif + delete [] m_vCfgData.at(uiPropID)->val.pszValue; // delete old value + m_vCfgData.at(uiPropID)->val.pszValue=new TCHAR[_tcslen(pszValue)+1]; // create space for new + _tcscpy(m_vCfgData.at(uiPropID)->val.pszValue, pszValue); // copy the new one + m_vCfgData.at(uiPropID)->bModified=true; // modified state +#ifndef DISABLE_CRYPT + } +#endif + LeaveCriticalSection(&m_cs); + + if (m_pfnCallback) + (*m_pfnCallback)(0, WM_CFGNOTIFY, CNFT_PROPERTYCHANGE, uiPropID); +} + +void CConfigManager::GetStringArrayValue(UINT uiPropID, char_vector* pcVector) +{ + EnterCriticalSection(&m_cs); + _CFGENTRY* pentry=m_vCfgData.at(uiPropID); + pcVector->assign(pentry->val.pvszValue->begin(), pentry->val.pvszValue->end(), true, true); + LeaveCriticalSection(&m_cs); +} + +void CConfigManager::SetStringArrayValue(UINT uiPropID, char_vector* pcVector) +{ + EnterCriticalSection(&m_cs); + _CFGENTRY* pentry=m_vCfgData.at(uiPropID); + pentry->val.pvszValue->assign(pcVector->begin(), pcVector->end(), true, true); + LeaveCriticalSection(&m_cs); + + if (m_pfnCallback) + (*m_pfnCallback)(0, WM_CFGNOTIFY, CNFT_PROPERTYCHANGE, uiPropID); +} + +/////////////////////////////////////////////////////////////// +// Selects new profile +// pszCfgName [in] - new profile name +/////////////////////////////////////////////////////////////// +void CConfigManager::SelectProfile(LPCTSTR pszCfgName) +{ + // store config into ini file + vector<_CFGENTRY*>::const_iterator it=m_vCfgData.begin(); + while (it != m_vCfgData.end()) + WriteProperty(*it++); + + // change config + delete [] m_pszCurrentConfig; + m_pszCurrentConfig=new TCHAR[_tcslen(pszCfgName)+1]; + _tcscpy(m_pszCurrentConfig, pszCfgName); + + // read data from ini file + it=m_vCfgData.begin(); + while (it != m_vCfgData.end()) + ReadProperty(*it++); + + // set data in ini file + SetString(CFG_PROFILE, CFG_SECTION, CFG_KEY, pszCfgName); + + if (m_pfnCallback) + (*m_pfnCallback)(0, WM_CFGNOTIFY, CNFT_PROFILECHANGE, (LPARAM)pszCfgName); +} + +/////////////////////////////////////////////////////////////// +// (Internal) Frees one of the profile entries +// pEntry [in] - address of profile entry +/////////////////////////////////////////////////////////////// +void CConfigManager::FreeEntry(_CFGENTRY* pEntry) +{ + // free section and key + delete [] pEntry->pszSection; + delete [] pEntry->pszKey; + + // if this is a string property - free it + switch(pEntry->cType) + { + case PT_STRING: + delete [] pEntry->def.pszValue; + delete [] pEntry->val.pszValue; + break; + case PT_ASTRING: + { + pEntry->val.pvszValue->clear(true); + delete pEntry->val.pvszValue; + break; + } + } + + // last - delete object itself + delete pEntry; +} + +/////////////////////////////////////////////////////////////// +// Reads value of a given property entry from .ini file +// pEntry [in] - filled property entry structure +/////////////////////////////////////////////////////////////// +void CConfigManager::ReadProperty(_CFGENTRY* pEntry) +{ + // process each attribute + switch (pEntry->cType) + { + case PT_INT64: + { + pEntry->val.llValue=GetInt64(m_pszCurrentConfig, pEntry->pszSection, pEntry->pszKey, pEntry->def.llValue, m_szBuffer); + break; + } + case PT_STRING: + { + GetString(m_pszCurrentConfig, pEntry->pszSection, pEntry->pszKey, m_szBuffer, pEntry->def.pszValue); + pEntry->val.pszValue=new TCHAR[_tcslen(m_szBuffer)+1]; + _tcscpy(pEntry->val.pszValue, m_szBuffer); + break; + } + case PT_BOOL: + { + pEntry->val.bValue=GetBool(m_pszCurrentConfig, pEntry->pszSection, pEntry->pszKey, pEntry->def.bValue, m_szBuffer); + break; + } + case PT_INT: + { + pEntry->val.iValue=GetInt(m_pszCurrentConfig, pEntry->pszSection, pEntry->pszKey, pEntry->def.iValue, m_szBuffer); + break; + } + case PT_ASTRING: + { + TCHAR szNum[8]; + for (int i=0;ipszSection, szNum, m_szBuffer, _T(""))) + pEntry->val.pvszValue->push_back(m_szBuffer, true); + else + break; + } + + break; + } + default: + _ASSERT(false); // unknown property type + } + + // set modified if this wasn't read from a file + pEntry->bModified=m_bDefault; // if this is a default value - store it when needed +} + +/////////////////////////////////////////////////////////////// +// Writes property to the .ini file +// pEntry [in] - filled property entry struct +/////////////////////////////////////////////////////////////// +void CConfigManager::WriteProperty(_CFGENTRY* pEntry) +{ + if (pEntry->bModified) + { + switch (pEntry->cType) + { + case PT_INT64: + { + SetInt64(m_pszCurrentConfig, pEntry->pszSection, pEntry->pszKey, pEntry->val.llValue); + pEntry->bModified=false; + break; + } + case PT_STRING: + { + SetString(m_pszCurrentConfig, pEntry->pszSection, pEntry->pszKey, pEntry->val.pszValue); + pEntry->bModified=false; + break; + } + case PT_BOOL: + { + SetBool(m_pszCurrentConfig, pEntry->pszSection, pEntry->pszKey, pEntry->val.bValue); + pEntry->bModified=false; + break; + } + case PT_INT: + { + SetInt(m_pszCurrentConfig, pEntry->pszSection, pEntry->pszKey, pEntry->val.iValue); + pEntry->bModified=false; + break; + } + case PT_ASTRING: + { + TCHAR szNum[8]; + for (int i=0;ival.pvszValue->size()) + { + // add string + SetString(m_pszCurrentConfig, pEntry->pszSection, szNum, pEntry->val.pvszValue->at(i)); + } + else + { + // remove string + RemoveKey(m_pszCurrentConfig, pEntry->pszSection, szNum, true); + break; + } + } + pEntry->bModified=false; + + break; + } + } + } +} + +LRESULT CConfigManager::MsgRouter(UINT uiMsg, WPARAM wParam, LPARAM lParam) +{ + switch(uiMsg) + { + case CCMI_REGISTERPROPERTY: + return (LRESULT)RegisterProperty((_CFGENTRY*)lParam); + case CCMI_GETINTVALUE: + return (LRESULT)GetIntValue((UINT)wParam); + case CCMI_SETINTVALUE: + SetIntValue((UINT)wParam, (int)lParam); + return (LRESULT)0; + case CCMI_GETINT64VALUE: + { + if (lParam) + { + *((__int64*)lParam)=GetInt64Value((UINT)wParam); + return (LRESULT)0; + } + else + return (LRESULT)1; + } + case CCMI_SETINT64VALUE: + { + if (lParam) + { + SetInt64Value((UINT)wParam, *((__int64*)lParam)); + return (LRESULT)0; + } + else + return (LRESULT)1; + } + case CCMI_GETBOOLVALUE: + return (LRESULT)GetBoolValue((UINT)wParam); + case CCMI_SETBOOLVALUE: + SetBoolValue((UINT)wParam, lParam != 0); + return (LRESULT)0; + case CCMI_GETSTRINGVALUE: + GetStringValue((UINT)wParam, (LPTSTR)lParam, 1024); + return (LRESULT)0; + case CCMI_SETSTRINGVALUE: + SetStringValue((UINT)wParam, (LPCTSTR)lParam); + return (LRESULT)0; + case CCMI_SELECTPROFILE: + SelectProfile((LPCTSTR)lParam); + return (LRESULT)0; + } + return (LRESULT)1; +} Index: modules/App Framework/ConfigManager.cpp =================================================================== diff -u -N --- modules/App Framework/ConfigManager.cpp (revision 7d997aef1e72f049ed1bc199e1b765d737d9963a) +++ modules/App Framework/ConfigManager.cpp (revision 0) @@ -1,806 +0,0 @@ -/************************************************************************ - Copy Handler 1.x - program for copying data in Microsoft Windows - systems. - Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. -*************************************************************************/ - -#include "stdafx.h" -#include "ConfigManager.h" -#ifndef DISABLE_CRYPT -#include "crypt.h" -#include "conv.h" -#endif - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -#define CFG_PROFILE _T("Common") -#define CFG_SECTION _T("Config") -#define CFG_KEY _T("Current configuration name") -#define CFG_DEFAULTSECTION _T("Default") - -#define CFG_MAXCOMPOUND 500 /* max count of items in a compound property */ - -/////////////////////////////////////////////////////////////// -// Opens configuration file. -// This function should be called only once - isn't thread safe -// Doesn't throw any file exception. If physical file couldn't -// be opened - this class does not require it. Could work -// without saving options to file, or with read-only files. -// pszFilename [in] - path to the configuration file -/////////////////////////////////////////////////////////////// -void CConfigManager::Open(LPCTSTR pszFilename) -{ - // load text file, and process it in ini file - try - { - ((CIniFile*)this)->Open(pszFilename, NULL, false); - } - catch(CFileExceptionEx* e) - { - // report error - TCHAR szData[1024]; - szData[1023]=_T('\0'); - _sntprintf(szData, 1023, _T("[Config Manager]: Couldn't open file %s to read initial data;\r\n\tReason: %s."), pszFilename, e->m_pszReason); - Report(szData); - - delete e; // get rid of this exception (file works doesn't work) - - // file couldn't be loaded... - create default section - m_pszCurrentConfig=new TCHAR[8]; - _tcscpy(m_pszCurrentConfig, CFG_DEFAULTSECTION); - SetString(CFG_PROFILE, CFG_SECTION, CFG_KEY, m_pszCurrentConfig); - return; - } - - // now - read current config name from cfg - if (!GetStr(CFG_PROFILE, CFG_SECTION, CFG_KEY, m_szBuffer, _T(""))) - { - // current config not found - the first found would be current - vector<_PROFILE*>::const_iterator it=m_vConfigProfiles.begin(); - - while (it != m_vConfigProfiles.end()) - { - // check if element 0 isn't - if (_tcsicmp((*it)->pszProfileName, CFG_PROFILE) != 0) - { - // set current cfg to the found one - m_pszCurrentConfig=new TCHAR[_tcslen((*it)->pszProfileName)+1]; - _tcscpy(m_pszCurrentConfig, (*it)->pszProfileName); - - // save current selection - SetString(CFG_PROFILE, CFG_SECTION, CFG_KEY, m_pszCurrentConfig); - break; // we've found what was needed - stop processing - } - it++; - } - - // if not found - create default - if (m_pszCurrentConfig == NULL) - { - m_pszCurrentConfig=new TCHAR[8]; - _tcscpy(m_pszCurrentConfig, CFG_DEFAULTSECTION); - SetString(CFG_PROFILE, CFG_SECTION, CFG_KEY, m_pszCurrentConfig); - } - } - else - { - // section found - copy it - m_pszCurrentConfig=new TCHAR[_tcslen(m_szBuffer)+1]; - _tcscpy(m_pszCurrentConfig, m_szBuffer); - } -} - -/////////////////////////////////////////////////////////////// -// Tries to save settings to the configuration file. If -// couldn't be saved - function reports it through Report func -// and doesn't save data to file (this allows to use read-only -// attribute on config file). -/////////////////////////////////////////////////////////////// -void CConfigManager::Save() -{ - EnterCriticalSection(&m_cs); - // copy data into ini file object - vector<_CFGENTRY*>::const_iterator it=m_vCfgData.begin(); - while (it != m_vCfgData.end()) - WriteProperty(*it++); - - // save file - try - { - ((CIniFile*)this)->Save(); - } - catch(CFileExceptionEx* e) - { - TCHAR szData[1024]; - e->GetInfo(_T("[Config Manager]: Couldn't save configuration file."), szData, 1024); - Report(szData); - delete e; - - LeaveCriticalSection(&m_cs); - return; - } - catch(...) - { - LeaveCriticalSection(&m_cs); - throw; - } - - LeaveCriticalSection(&m_cs); -} - -/////////////////////////////////////////////////////////////// -// Closes this configuration file (saves data before closing). -// If couldn't be saved/closed - it reports the fact and allows -// to continue (allows usage of read-only files). -/////////////////////////////////////////////////////////////// -void CConfigManager::Close() -{ - // store all data into .ini object - EnterCriticalSection(&m_cs); - vector<_CFGENTRY*>::const_iterator it=m_vCfgData.begin(); - while (it != m_vCfgData.end()) - { - WriteProperty(*it); - FreeEntry(*it++); - } - - // free all - m_vCfgData.clear(); - - // free current config name - delete [] m_pszCurrentConfig; - m_pszCurrentConfig=NULL; - - // destroy base... - try - { - ((CIniFile*)this)->Close(); // storing data, closing file in a base class - } - catch(CFileExceptionEx* e) - { - TCHAR szData[1024]; - e->GetInfo(_T("[Config Manager]: Couldn't properly save/close file."), szData, 1024); - Report(szData); - - delete e; - - LeaveCriticalSection(&m_cs); - return; - } - catch(...) - { - LeaveCriticalSection(&m_cs); - throw; - } - - LeaveCriticalSection(&m_cs); -} - -#ifndef DISABLE_CRYPT -/////////////////////////////////////////////////////////////// -// -/////////////////////////////////////////////////////////////// -void CConfigManager::SetPassword(PCTSTR pszPass) -{ - // gen new 256b password - TCHAR szNewPass[64+1], szLine[8192]; - StringToKey256(pszPass, szNewPass); - - // recrypt the old data if needed - if (m_pszPassword) - { - // if there already was a password - for (vector<_CFGENTRY*>::iterator it=m_vCfgData.begin();it!=m_vCfgData.end();it++) - { - // reencrypt every encrypted item - if ((*it)->dwFlags & RF_ENCRYPTED && (*it)->cType == PT_STRING) - { - // decrypt the old data - if (AES256DecipherString((*it)->val.pszValue, m_pszPassword, szLine) < 0) - continue; - - // encrypt to the new one - if (AES256CipherString(szLine, szNewPass, szLine) < 0) - continue; - - // store the new value - delete [] (*it)->val.pszValue; - (*it)->val.pszValue=new TCHAR[_tcslen(szLine)+1]; - _tcscpy((*it)->val.pszValue, szLine); - (*it)->bModified=true; // set the modified flag - } - } - - delete [] m_pszPassword; // delete old password - } - m_pszPassword=new TCHAR[64+1]; - _tcscpy(m_pszPassword, szNewPass); -} - -#endif -/////////////////////////////////////////////////////////////// -// Registers some property given filled _CFGENTRY struct. -// pEntry [in] - specifies all possible information about the -// attribute being registered. -// Ret Value [out] - ID of registered property. It must be -// used when accessing this property. -/////////////////////////////////////////////////////////////// -UINT CConfigManager::RegisterProperty(_CFGENTRY* pEntry) -{ - _ASSERT(pEntry != NULL); - - EnterCriticalSection(&m_cs); - ReadProperty(pEntry); - m_vCfgData.push_back(pEntry); - UINT uiRet=(UINT)(m_vCfgData.size()-1); - LeaveCriticalSection(&m_cs); - return uiRet; -} - -/////////////////////////////////////////////////////////////// -// Registers int64 property. -// pszSection [in] - section in which resides given property -// pszKey [in] - key in which resides given property -// llDefault [in] - default value of this property (used if the -// config file doesn't contain it) -// cDetailLevel [in] - specifies "level" of this property. It -// could be simple property (for all users) or -// something that only some paranoics will use. -// Ret Value [out] - ID of registered property. It must be -// used when accessing this property. -/////////////////////////////////////////////////////////////// -UINT CConfigManager::RegisterInt64Property(LPCTSTR pszSection, LPCTSTR pszKey, __int64 llDefault, char cDetailLevel) -{ - // create config entry - _CFGENTRY* pcfg=new _CFGENTRY; - pcfg->pszSection=new TCHAR[_tcslen(pszSection)+1]; - _tcscpy(pcfg->pszSection, pszSection); - pcfg->pszKey=new TCHAR[_tcslen(pszKey)+1]; - _tcscpy(pcfg->pszKey, pszKey); - pcfg->cType=PT_INT64; - pcfg->def.llValue=llDefault; - pcfg->bModified=false; - pcfg->cDetailLevel=cDetailLevel; - pcfg->dwFlags=RF_NONE; - - // register - return RegisterProperty(pcfg); -} - -/////////////////////////////////////////////////////////////// -// Registers int property. -// pszSection [in] - section in which resides given property -// pszKey [in] - key in which resides given property -// iDefault [in] - default value of this property (used if the -// config file doesn't contain it) -// cDetailLevel [in] - specifies "level" of this property. It -// could be simple property (for all users) or -// something that only some paranoics will use. -// Ret Value [out] - ID of registered property. It must be -// used when accessing this property. -/////////////////////////////////////////////////////////////// -UINT CConfigManager::RegisterIntProperty(LPCTSTR pszSection, LPCTSTR pszKey, int iDefault, char cDetailLevel) -{ - // create config entry - _CFGENTRY* pcfg=new _CFGENTRY; - pcfg->pszSection=new TCHAR[_tcslen(pszSection)+1]; - _tcscpy(pcfg->pszSection, pszSection); - pcfg->pszKey=new TCHAR[_tcslen(pszKey)+1]; - _tcscpy(pcfg->pszKey, pszKey); - pcfg->cType=PT_INT; - pcfg->def.iValue=iDefault; - pcfg->bModified=false; - pcfg->cDetailLevel=cDetailLevel; - pcfg->dwFlags=RF_NONE; - - // register - return RegisterProperty(pcfg); -} - -/////////////////////////////////////////////////////////////// -// Registers bool property. -// pszSection [in] - section in which resides given property -// pszKey [in] - key in which resides given property -// bDefault [in] - default value of this property (used if the -// config file doesn't contain it) -// cDetailLevel [in] - specifies "level" of this property. It -// could be simple property (for all users) or -// something that only some paranoics will use. -// Ret Value [out] - ID of registered property. It must be -// used when accessing this property. -/////////////////////////////////////////////////////////////// -UINT CConfigManager::RegisterBoolProperty(LPCTSTR pszSection, LPCTSTR pszKey, bool bDefault, char cDetailLevel) -{ - // create config entry - _CFGENTRY* pcfg=new _CFGENTRY; - pcfg->pszSection=new TCHAR[_tcslen(pszSection)+1]; - _tcscpy(pcfg->pszSection, pszSection); - pcfg->pszKey=new TCHAR[_tcslen(pszKey)+1]; - _tcscpy(pcfg->pszKey, pszKey); - pcfg->cType=PT_BOOL; - pcfg->def.bValue=bDefault; - pcfg->bModified=false; - pcfg->cDetailLevel=cDetailLevel; - pcfg->dwFlags=RF_NONE; - - // register - return RegisterProperty(pcfg); -} - -/////////////////////////////////////////////////////////////// -// Registers string property. -// pszSection [in] - section in which resides given property -// pszKey [in] - key in which resides given property -// pszDefault [in] - default value of this property (used if -// the config file doesn't contain it) -// cDetailLevel [in] - specifies "level" of this property. It -// could be simple property (for all users) or -// something that only some paranoics will use. -// Ret Value [out] - ID of registered property. It must be -// used when accessing this property. -/////////////////////////////////////////////////////////////// -UINT CConfigManager::RegisterStringProperty(LPCTSTR pszSection, LPCTSTR pszKey, LPCTSTR pszDefault, DWORD dwFlags, char cDetailLevel) -{ - // create config entry - _CFGENTRY* pcfg=new _CFGENTRY; - pcfg->pszSection=new TCHAR[_tcslen(pszSection)+1]; - _tcscpy(pcfg->pszSection, pszSection); - pcfg->pszKey=new TCHAR[_tcslen(pszKey)+1]; - _tcscpy(pcfg->pszKey, pszKey); - pcfg->cType=PT_STRING; - pcfg->def.pszValue=new TCHAR[_tcslen(pszDefault)+1]; - _tcscpy(pcfg->def.pszValue, pszDefault); - pcfg->bModified=false; - pcfg->cDetailLevel=cDetailLevel; - pcfg->dwFlags=dwFlags; - - // register - return RegisterProperty(pcfg); -} - -UINT CConfigManager::RegisterStringArrayProperty(LPCTSTR pszSection, char cDetailLevel) -{ - _CFGENTRY* pcfg=new _CFGENTRY; - pcfg->pszSection=new TCHAR[_tcslen(pszSection)+1]; - _tcscpy(pcfg->pszSection, pszSection); - pcfg->pszKey=NULL; - pcfg->cType=PT_ASTRING; - pcfg->bModified=false; - pcfg->cDetailLevel=cDetailLevel; - pcfg->val.pvszValue=new char_vector; - pcfg->dwFlags=RF_NONE; - - return RegisterProperty(pcfg); -} - -/////////////////////////////////////////////////////////////// -// Returns value of int property given property ID -// uiPropID [in] - property ID (returned by RegisterProperty..) -// Ret Value [out] - value of this property (either from file -// or the default one specified at registration) -/////////////////////////////////////////////////////////////// -int CConfigManager::GetIntValue(UINT uiPropID) -{ - EnterCriticalSection(&m_cs); - int iRet=m_vCfgData.at(uiPropID)->val.iValue; - LeaveCriticalSection(&m_cs); - return iRet; -} - -/////////////////////////////////////////////////////////////// -// Sets value of a given property (by it's ID) -// uiPropID [in] - property ID (returned by RegisterProperty..) -// iValue [in] - the new value of this property -/////////////////////////////////////////////////////////////// -void CConfigManager::SetIntValue(UINT uiPropID, int iValue) -{ - EnterCriticalSection(&m_cs); - m_vCfgData.at(uiPropID)->val.iValue=iValue; - m_vCfgData.at(uiPropID)->bModified=true; - LeaveCriticalSection(&m_cs); - - if (m_pfnCallback) - (*m_pfnCallback)(0, WM_CFGNOTIFY, CNFT_PROPERTYCHANGE, uiPropID); -} - -/////////////////////////////////////////////////////////////// -// Returns value of int64 property given property ID -// uiPropID [in] - property ID (returned by RegisterProperty..) -// Ret Value [out] - value of this property (either from file -// or the default one specified at registration) -/////////////////////////////////////////////////////////////// -__int64 CConfigManager::GetInt64Value(UINT uiPropID) -{ - EnterCriticalSection(&m_cs); - __int64 llRet=m_vCfgData.at(uiPropID)->val.llValue; - LeaveCriticalSection(&m_cs); - return llRet; -} - -/////////////////////////////////////////////////////////////// -// Sets value of a given property (by it's ID) -// uiPropID [in] - property ID (returned by RegisterProperty..) -// llValue [in] - the new value of this property -/////////////////////////////////////////////////////////////// -void CConfigManager::SetInt64Value(UINT uiPropID, __int64 llValue) -{ - EnterCriticalSection(&m_cs); - m_vCfgData.at(uiPropID)->val.llValue=llValue; - m_vCfgData.at(uiPropID)->bModified=true; - LeaveCriticalSection(&m_cs); - - if (m_pfnCallback) - (*m_pfnCallback)(0, WM_CFGNOTIFY, CNFT_PROPERTYCHANGE, uiPropID); -} - -/////////////////////////////////////////////////////////////// -// Returns value of bool property given property ID -// uiPropID [in] - property ID (returned by RegisterProperty..) -// Ret Value [out] - value of this property (either from file -// or the default one specified at registration) -/////////////////////////////////////////////////////////////// -bool CConfigManager::GetBoolValue(UINT uiPropID) -{ - EnterCriticalSection(&m_cs); - bool bRet=m_vCfgData.at(uiPropID)->val.bValue; - LeaveCriticalSection(&m_cs); - return bRet; -} - -/////////////////////////////////////////////////////////////// -// Sets value of a given property (by it's ID) -// uiPropID [in] - property ID (returned by RegisterProperty..) -// bValue [in] - the new value of this property -/////////////////////////////////////////////////////////////// -void CConfigManager::SetBoolValue(UINT uiPropID, bool bValue) -{ - EnterCriticalSection(&m_cs); - m_vCfgData.at(uiPropID)->val.bValue=bValue; - m_vCfgData.at(uiPropID)->bModified=true; - LeaveCriticalSection(&m_cs); - - if (m_pfnCallback) - (*m_pfnCallback)(0, WM_CFGNOTIFY, CNFT_PROPERTYCHANGE, uiPropID); -} - -/////////////////////////////////////////////////////////////// -// Returns value of string property given property ID -// uiPropID [in] - property ID (returned by RegisterProperty..) -// Ret Value [out] - value of this property (either from file -// or the default one specified at registration) -/////////////////////////////////////////////////////////////// -PCTSTR CConfigManager::GetStringValue(UINT uiPropID, PTSTR pszBuffer, int iSize) -{ - EnterCriticalSection(&m_cs); - -#ifndef DISABLE_CRYPT - if (m_vCfgData.at(uiPropID)->dwFlags & RF_ENCRYPTED) - { - // make sure password has been set already - _ASSERT(m_pszPassword); - - TCHAR szLine[8192]; - if (AES256DecipherString(m_vCfgData.at(uiPropID)->val.pszValue, m_pszPassword, szLine) <= 0) - { - // return - _tcscpy(pszBuffer, _T("")); - LeaveCriticalSection(&m_cs); - return pszBuffer; - } - - // copy the decrypted data - _tcsncpy(pszBuffer, szLine, iSize); - pszBuffer[iSize-1]=_T('\0'); - } - else -#endif - _tcsncpy(pszBuffer, m_vCfgData.at(uiPropID)->val.pszValue, iSize); - - if (m_vCfgData.at(uiPropID)->dwFlags & RF_PATH) - { - if (pszBuffer[_tcslen(pszBuffer)-1] != _T('\\')) - _tcscat(pszBuffer, _T("\\")); - } - - LeaveCriticalSection(&m_cs); - - return pszBuffer; -} - -/////////////////////////////////////////////////////////////// -// Sets value of a given property (by it's ID) -// uiPropID [in] - property ID (returned by RegisterProperty..) -// pszValue [in] - the new value of this property -/////////////////////////////////////////////////////////////// -void CConfigManager::SetStringValue(UINT uiPropID, LPCTSTR pszValue) -{ - EnterCriticalSection(&m_cs); -#ifndef DISABLE_CRYPT - // encrypt the data before setting the property text - if (m_vCfgData.at(uiPropID)->dwFlags & RF_ENCRYPTED) - { - // make sure password has been set already - _ASSERT(m_pszPassword); - - TCHAR szLine[8192]; - if (AES256CipherString(pszValue, m_pszPassword, szLine) < 0) - { - _ASSERT(false); - TRACE("Cannot cipher string - what to do ????\n"); - } - - // store encrypted value - delete [] m_vCfgData.at(uiPropID)->val.pszValue; // delete old value - m_vCfgData.at(uiPropID)->val.pszValue=new TCHAR[_tcslen(szLine)+1]; // create space for new - _tcscpy(m_vCfgData.at(uiPropID)->val.pszValue, szLine); // copy the new one - m_vCfgData.at(uiPropID)->bModified=true; // modified state - } - else - { -#endif - delete [] m_vCfgData.at(uiPropID)->val.pszValue; // delete old value - m_vCfgData.at(uiPropID)->val.pszValue=new TCHAR[_tcslen(pszValue)+1]; // create space for new - _tcscpy(m_vCfgData.at(uiPropID)->val.pszValue, pszValue); // copy the new one - m_vCfgData.at(uiPropID)->bModified=true; // modified state -#ifndef DISABLE_CRYPT - } -#endif - LeaveCriticalSection(&m_cs); - - if (m_pfnCallback) - (*m_pfnCallback)(0, WM_CFGNOTIFY, CNFT_PROPERTYCHANGE, uiPropID); -} - -void CConfigManager::GetStringArrayValue(UINT uiPropID, char_vector* pcVector) -{ - EnterCriticalSection(&m_cs); - _CFGENTRY* pentry=m_vCfgData.at(uiPropID); - pcVector->assign(pentry->val.pvszValue->begin(), pentry->val.pvszValue->end(), true, true); - LeaveCriticalSection(&m_cs); -} - -void CConfigManager::SetStringArrayValue(UINT uiPropID, char_vector* pcVector) -{ - EnterCriticalSection(&m_cs); - _CFGENTRY* pentry=m_vCfgData.at(uiPropID); - pentry->val.pvszValue->assign(pcVector->begin(), pcVector->end(), true, true); - LeaveCriticalSection(&m_cs); - - if (m_pfnCallback) - (*m_pfnCallback)(0, WM_CFGNOTIFY, CNFT_PROPERTYCHANGE, uiPropID); -} - -/////////////////////////////////////////////////////////////// -// Selects new profile -// pszCfgName [in] - new profile name -/////////////////////////////////////////////////////////////// -void CConfigManager::SelectProfile(LPCTSTR pszCfgName) -{ - // store config into ini file - vector<_CFGENTRY*>::const_iterator it=m_vCfgData.begin(); - while (it != m_vCfgData.end()) - WriteProperty(*it++); - - // change config - delete [] m_pszCurrentConfig; - m_pszCurrentConfig=new TCHAR[_tcslen(pszCfgName)+1]; - _tcscpy(m_pszCurrentConfig, pszCfgName); - - // read data from ini file - it=m_vCfgData.begin(); - while (it != m_vCfgData.end()) - ReadProperty(*it++); - - // set data in ini file - SetString(CFG_PROFILE, CFG_SECTION, CFG_KEY, pszCfgName); - - if (m_pfnCallback) - (*m_pfnCallback)(0, WM_CFGNOTIFY, CNFT_PROFILECHANGE, (LPARAM)pszCfgName); -} - -/////////////////////////////////////////////////////////////// -// (Internal) Frees one of the profile entries -// pEntry [in] - address of profile entry -/////////////////////////////////////////////////////////////// -void CConfigManager::FreeEntry(_CFGENTRY* pEntry) -{ - // free section and key - delete [] pEntry->pszSection; - delete [] pEntry->pszKey; - - // if this is a string property - free it - switch(pEntry->cType) - { - case PT_STRING: - delete [] pEntry->def.pszValue; - delete [] pEntry->val.pszValue; - break; - case PT_ASTRING: - { - pEntry->val.pvszValue->clear(true); - delete pEntry->val.pvszValue; - break; - } - } - - // last - delete object itself - delete pEntry; -} - -/////////////////////////////////////////////////////////////// -// Reads value of a given property entry from .ini file -// pEntry [in] - filled property entry structure -/////////////////////////////////////////////////////////////// -void CConfigManager::ReadProperty(_CFGENTRY* pEntry) -{ - // process each attribute - switch (pEntry->cType) - { - case PT_INT64: - { - pEntry->val.llValue=GetInt64(m_pszCurrentConfig, pEntry->pszSection, pEntry->pszKey, pEntry->def.llValue, m_szBuffer); - break; - } - case PT_STRING: - { - GetString(m_pszCurrentConfig, pEntry->pszSection, pEntry->pszKey, m_szBuffer, pEntry->def.pszValue); - pEntry->val.pszValue=new TCHAR[_tcslen(m_szBuffer)+1]; - _tcscpy(pEntry->val.pszValue, m_szBuffer); - break; - } - case PT_BOOL: - { - pEntry->val.bValue=GetBool(m_pszCurrentConfig, pEntry->pszSection, pEntry->pszKey, pEntry->def.bValue, m_szBuffer); - break; - } - case PT_INT: - { - pEntry->val.iValue=GetInt(m_pszCurrentConfig, pEntry->pszSection, pEntry->pszKey, pEntry->def.iValue, m_szBuffer); - break; - } - case PT_ASTRING: - { - TCHAR szNum[8]; - for (int i=0;ipszSection, szNum, m_szBuffer, _T(""))) - pEntry->val.pvszValue->push_back(m_szBuffer, true); - else - break; - } - - break; - } - default: - _ASSERT(false); // unknown property type - } - - // set modified if this wasn't read from a file - pEntry->bModified=m_bDefault; // if this is a default value - store it when needed -} - -/////////////////////////////////////////////////////////////// -// Writes property to the .ini file -// pEntry [in] - filled property entry struct -/////////////////////////////////////////////////////////////// -void CConfigManager::WriteProperty(_CFGENTRY* pEntry) -{ - if (pEntry->bModified) - { - switch (pEntry->cType) - { - case PT_INT64: - { - SetInt64(m_pszCurrentConfig, pEntry->pszSection, pEntry->pszKey, pEntry->val.llValue); - pEntry->bModified=false; - break; - } - case PT_STRING: - { - SetString(m_pszCurrentConfig, pEntry->pszSection, pEntry->pszKey, pEntry->val.pszValue); - pEntry->bModified=false; - break; - } - case PT_BOOL: - { - SetBool(m_pszCurrentConfig, pEntry->pszSection, pEntry->pszKey, pEntry->val.bValue); - pEntry->bModified=false; - break; - } - case PT_INT: - { - SetInt(m_pszCurrentConfig, pEntry->pszSection, pEntry->pszKey, pEntry->val.iValue); - pEntry->bModified=false; - break; - } - case PT_ASTRING: - { - TCHAR szNum[8]; - for (int i=0;ival.pvszValue->size()) - { - // add string - SetString(m_pszCurrentConfig, pEntry->pszSection, szNum, pEntry->val.pvszValue->at(i)); - } - else - { - // remove string - RemoveKey(m_pszCurrentConfig, pEntry->pszSection, szNum, true); - break; - } - } - pEntry->bModified=false; - - break; - } - } - } -} - -LRESULT CConfigManager::MsgRouter(UINT uiMsg, WPARAM wParam, LPARAM lParam) -{ - switch(uiMsg) - { - case CCMI_REGISTERPROPERTY: - return (LRESULT)RegisterProperty((_CFGENTRY*)lParam); - case CCMI_GETINTVALUE: - return (LRESULT)GetIntValue((UINT)wParam); - case CCMI_SETINTVALUE: - SetIntValue((UINT)wParam, (int)lParam); - return (LRESULT)0; - case CCMI_GETINT64VALUE: - { - if (lParam) - { - *((__int64*)lParam)=GetInt64Value((UINT)wParam); - return (LRESULT)0; - } - else - return (LRESULT)1; - } - case CCMI_SETINT64VALUE: - { - if (lParam) - { - SetInt64Value((UINT)wParam, *((__int64*)lParam)); - return (LRESULT)0; - } - else - return (LRESULT)1; - } - case CCMI_GETBOOLVALUE: - return (LRESULT)GetBoolValue((UINT)wParam); - case CCMI_SETBOOLVALUE: - SetBoolValue((UINT)wParam, lParam != 0); - return (LRESULT)0; - case CCMI_GETSTRINGVALUE: - GetStringValue((UINT)wParam, (LPTSTR)lParam, 1024); - return (LRESULT)0; - case CCMI_SETSTRINGVALUE: - SetStringValue((UINT)wParam, (LPCTSTR)lParam); - return (LRESULT)0; - case CCMI_SELECTPROFILE: - SelectProfile((LPCTSTR)lParam); - return (LRESULT)0; - } - return (LRESULT)1; -} Index: ch/ConfigManager.h =================================================================== diff -u -N --- ch/ConfigManager.h (revision 0) +++ ch/ConfigManager.h (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,186 @@ +/************************************************************************ + Copy Handler 1.x - program for copying data in Microsoft Windows + systems. + Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. +*************************************************************************/ +/************************************************************************* + File: ConfigManager.h + Version: 1.0 + Author: Ixen Gerthannes (ixen@interia.pl) + File description: + Contains structs/classes for handling configuration + settings in application. + Classes: + CConfigManager + - support access to properties by it's ID + - supports registering additional properties when + the program works. + - supports multiple levels of property detail + - special meaning - ; [Config]; + "Current configuration name=xxx" - specifies + current active profile (the one that will be used + as a source for getting data for properties). + Structures: + _CFGENTRY - contain information about one property. +*************************************************************************/ + +#ifndef __CONFIG_MANAGER_H__ +#define __CONFIG_MANAGER_H__ + +#include "IniFile.h" +#include "charvect.h" +#include "af_defs.h" + +using namespace std; + +// property types in CConfigEntry +#define PT_INT64 0 +#define PT_STRING 1 +#define PT_BOOL 2 +#define PT_INT 3 +#define PT_ASTRING 4 /* array of strings */ + +// flags when registering +#define RF_NONE 0x00 +#define RF_PATH 0x01 + +#ifndef DISABLE_CRYPT +#define RF_ENCRYPTED 0x02 +#endif + +// property detail level +// general properties - for everyone +#define PDL_GENERAL 0 +// advanced properties - for advanced users +#define PDL_ADVANCED 1 +// paranoid type - for only a few individuals who want to configure everything +#define PDL_PARANOID 2 + +// types of notifications (going out) +// CNFT_PROFILECHANGE - this notification is sent when something changes the current configuration profile +// LPARAM - address of new profile string +#define CNFT_PROFILECHANGE 0x0001 +// CNFT_PROPERTYCHANGE - tells about changing value of a property +// LPARAM - (UINT) property ID +#define CNFT_PROPERTYCHANGE 0x0002 + +// messages that goes into this class +#define CCMI_REGISTERPROPERTY 0x0001 +#define CCMI_GETINTVALUE 0x0002 +#define CCMI_SETINTVALUE 0x0003 +#define CCMI_GETINT64VALUE 0x0004 +#define CCMI_SETINT64VALUE 0x0005 +#define CCMI_GETBOOLVALUE 0x0006 +#define CCMI_SETBOOLVALUE 0x0007 +#define CCMI_GETSTRINGVALUE 0x0008 +#define CCMI_SETSTRINGVALUE 0x0009 +#define CCMI_SELECTPROFILE 0x000a + + +// defines one of the attributes +struct _CFGENTRY +{ + TCHAR* pszSection; // section name + TCHAR* pszKey; // key name + char cDetailLevel; // detail level of this property (GENERAL (for everyone), ADVANCED (for advanced users), PARANOID) + bool bModified; // if property is in modified state (it wasn't saved from last change) + char cType; // type of property + DWORD dwFlags; // if set and property is string then we need to append '\\' at the end + union DATA + { + __int64 llValue; // __int64 value type + TCHAR* pszValue; // string value type + int iValue; // int value type + bool bValue; // bool value type + char_vector* pvszValue; // compound string table + } val, def; +}; + + +class CConfigManager : public CIniFile +{ +public: + CConfigManager() : CIniFile() { m_pszCurrentConfig=NULL; m_pfnCallback=NULL; +#ifndef DISABLE_CRYPT + m_pszPassword=NULL; +#endif + InitializeCriticalSection(&m_cs); }; + ~CConfigManager() { Close(); +#ifndef DISABLE_CRYPT + delete [] m_pszPassword; +#endif + DeleteCriticalSection(&m_cs); }; + + void SetCallback(PFNNOTIFYCALLBACK pfn) { m_pfnCallback=pfn; }; + + LRESULT MsgRouter(UINT uiMsg, WPARAM wParam, LPARAM lParam); + + // open/close funcs + void Open(LPCTSTR pszFilename); // reads all registered attributes from file + void Save(); // saves data to file + void Close(); // destroys everything + +#ifndef DISABLE_CRYPT + // encryption options + void SetPassword(PCTSTR pszPass); // sets the encrypt/decrypt password +#endif + + // properties registration funcs + UINT RegisterProperty(_CFGENTRY* pEntry); // just adds pointer to a vector + UINT RegisterInt64Property(LPCTSTR pszSection, LPCTSTR pszKey, __int64 llDefault, char cDetailLevel=PDL_GENERAL); + UINT RegisterIntProperty(LPCTSTR pszSection, LPCTSTR pszKey, int iDefault, char cDetailLevel=PDL_GENERAL); + UINT RegisterBoolProperty(LPCTSTR pszSection, LPCTSTR pszKey, bool bDefault, char cDetailLevel=PDL_GENERAL); + UINT RegisterStringProperty(LPCTSTR pszSection, LPCTSTR pszKey, LPCTSTR pszDefault, DWORD dwFlags=RF_NONE, char cDetailLevel=PDL_GENERAL); + UINT RegisterStringArrayProperty(LPCTSTR pszSection, char cDetailLevel=PDL_GENERAL); + + // property get/set funcs + int GetIntValue(UINT uiPropID); + void SetIntValue(UINT uiPropID, int iValue); + __int64 GetInt64Value(UINT uiPropID); + void SetInt64Value(UINT uiPropID, __int64 llValue); + bool GetBoolValue(UINT uiPropID); + void SetBoolValue(UINT uiPropID, bool bValue); + PCTSTR GetStringValue(UINT uiPropID, PTSTR pszBuffer, int iSize); + void SetStringValue(UINT uiPropID, LPCTSTR pszValue); + void GetStringArrayValue(UINT uiPropID, char_vector* pcVector); + void SetStringArrayValue(UINT uiPropID, char_vector* pcVector); + + // config profiles management + void SelectProfile(LPCTSTR pszCfgName); + +protected: + void ReadProperty(_CFGENTRY* pEntry); // reads value from ini file... + void WriteProperty(_CFGENTRY* pEntry); // store value to ini file + void FreeEntry(_CFGENTRY* pEntry); // frees entry with data + + void Report(LPCTSTR /*pszReportString*/) { /* currently nothing */ }; // reports errors and others + +protected: + TCHAR* m_pszCurrentConfig; // name of current config + vector<_CFGENTRY*> m_vCfgData; // config data - all attributes + TCHAR m_szBuffer[1024]; // internal buffer + +#ifndef DISABLE_CRYPT + // passwd + TCHAR* m_pszPassword; // password for the encrypted properties +#endif + + PFNNOTIFYCALLBACK m_pfnCallback; // callback func for reporting some data + CRITICAL_SECTION m_cs; +}; + +#endif \ No newline at end of file Index: modules/App Framework/ConfigManager.h =================================================================== diff -u -N --- modules/App Framework/ConfigManager.h (revision 3e1186252ab31f63d86d86c4b0ff593cfffbefde) +++ modules/App Framework/ConfigManager.h (revision 0) @@ -1,186 +0,0 @@ -/************************************************************************ - Copy Handler 1.x - program for copying data in Microsoft Windows - systems. - Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. -*************************************************************************/ -/************************************************************************* - File: ConfigManager.h - Version: 1.0 - Author: Ixen Gerthannes (ixen@interia.pl) - File description: - Contains structs/classes for handling configuration - settings in application. - Classes: - CConfigManager - - support access to properties by it's ID - - supports registering additional properties when - the program works. - - supports multiple levels of property detail - - special meaning - ; [Config]; - "Current configuration name=xxx" - specifies - current active profile (the one that will be used - as a source for getting data for properties). - Structures: - _CFGENTRY - contain information about one property. -*************************************************************************/ - -#ifndef __CONFIG_MANAGER_H__ -#define __CONFIG_MANAGER_H__ - -#include "IniFile.h" -#include "charvect.h" -#include "af_defs.h" - -using namespace std; - -// property types in CConfigEntry -#define PT_INT64 0 -#define PT_STRING 1 -#define PT_BOOL 2 -#define PT_INT 3 -#define PT_ASTRING 4 /* array of strings */ - -// flags when registering -#define RF_NONE 0x00 -#define RF_PATH 0x01 - -#ifndef DISABLE_CRYPT -#define RF_ENCRYPTED 0x02 -#endif - -// property detail level -// general properties - for everyone -#define PDL_GENERAL 0 -// advanced properties - for advanced users -#define PDL_ADVANCED 1 -// paranoid type - for only a few individuals who want to configure everything -#define PDL_PARANOID 2 - -// types of notifications (going out) -// CNFT_PROFILECHANGE - this notification is sent when something changes the current configuration profile -// LPARAM - address of new profile string -#define CNFT_PROFILECHANGE 0x0001 -// CNFT_PROPERTYCHANGE - tells about changing value of a property -// LPARAM - (UINT) property ID -#define CNFT_PROPERTYCHANGE 0x0002 - -// messages that goes into this class -#define CCMI_REGISTERPROPERTY 0x0001 -#define CCMI_GETINTVALUE 0x0002 -#define CCMI_SETINTVALUE 0x0003 -#define CCMI_GETINT64VALUE 0x0004 -#define CCMI_SETINT64VALUE 0x0005 -#define CCMI_GETBOOLVALUE 0x0006 -#define CCMI_SETBOOLVALUE 0x0007 -#define CCMI_GETSTRINGVALUE 0x0008 -#define CCMI_SETSTRINGVALUE 0x0009 -#define CCMI_SELECTPROFILE 0x000a - - -// defines one of the attributes -struct _CFGENTRY -{ - TCHAR* pszSection; // section name - TCHAR* pszKey; // key name - char cDetailLevel; // detail level of this property (GENERAL (for everyone), ADVANCED (for advanced users), PARANOID) - bool bModified; // if property is in modified state (it wasn't saved from last change) - char cType; // type of property - DWORD dwFlags; // if set and property is string then we need to append '\\' at the end - union DATA - { - __int64 llValue; // __int64 value type - TCHAR* pszValue; // string value type - int iValue; // int value type - bool bValue; // bool value type - char_vector* pvszValue; // compound string table - } val, def; -}; - - -class CConfigManager : public CIniFile -{ -public: - CConfigManager() : CIniFile() { m_pszCurrentConfig=NULL; m_pfnCallback=NULL; -#ifndef DISABLE_CRYPT - m_pszPassword=NULL; -#endif - InitializeCriticalSection(&m_cs); }; - ~CConfigManager() { Close(); -#ifndef DISABLE_CRYPT - delete [] m_pszPassword; -#endif - DeleteCriticalSection(&m_cs); }; - - void SetCallback(PFNNOTIFYCALLBACK pfn) { m_pfnCallback=pfn; }; - - LRESULT MsgRouter(UINT uiMsg, WPARAM wParam, LPARAM lParam); - - // open/close funcs - void Open(LPCTSTR pszFilename); // reads all registered attributes from file - void Save(); // saves data to file - void Close(); // destroys everything - -#ifndef DISABLE_CRYPT - // encryption options - void SetPassword(PCTSTR pszPass); // sets the encrypt/decrypt password -#endif - - // properties registration funcs - UINT RegisterProperty(_CFGENTRY* pEntry); // just adds pointer to a vector - UINT RegisterInt64Property(LPCTSTR pszSection, LPCTSTR pszKey, __int64 llDefault, char cDetailLevel=PDL_GENERAL); - UINT RegisterIntProperty(LPCTSTR pszSection, LPCTSTR pszKey, int iDefault, char cDetailLevel=PDL_GENERAL); - UINT RegisterBoolProperty(LPCTSTR pszSection, LPCTSTR pszKey, bool bDefault, char cDetailLevel=PDL_GENERAL); - UINT RegisterStringProperty(LPCTSTR pszSection, LPCTSTR pszKey, LPCTSTR pszDefault, DWORD dwFlags=RF_NONE, char cDetailLevel=PDL_GENERAL); - UINT RegisterStringArrayProperty(LPCTSTR pszSection, char cDetailLevel=PDL_GENERAL); - - // property get/set funcs - int GetIntValue(UINT uiPropID); - void SetIntValue(UINT uiPropID, int iValue); - __int64 GetInt64Value(UINT uiPropID); - void SetInt64Value(UINT uiPropID, __int64 llValue); - bool GetBoolValue(UINT uiPropID); - void SetBoolValue(UINT uiPropID, bool bValue); - PCTSTR GetStringValue(UINT uiPropID, PTSTR pszBuffer, int iSize); - void SetStringValue(UINT uiPropID, LPCTSTR pszValue); - void GetStringArrayValue(UINT uiPropID, char_vector* pcVector); - void SetStringArrayValue(UINT uiPropID, char_vector* pcVector); - - // config profiles management - void SelectProfile(LPCTSTR pszCfgName); - -protected: - void ReadProperty(_CFGENTRY* pEntry); // reads value from ini file... - void WriteProperty(_CFGENTRY* pEntry); // store value to ini file - void FreeEntry(_CFGENTRY* pEntry); // frees entry with data - - void Report(LPCTSTR /*pszReportString*/) { /* currently nothing */ }; // reports errors and others - -protected: - TCHAR* m_pszCurrentConfig; // name of current config - vector<_CFGENTRY*> m_vCfgData; // config data - all attributes - TCHAR m_szBuffer[1024]; // internal buffer - -#ifndef DISABLE_CRYPT - // passwd - TCHAR* m_pszPassword; // password for the encrypted properties -#endif - - PFNNOTIFYCALLBACK m_pfnCallback; // callback func for reporting some data - CRITICAL_SECTION m_cs; -}; - -#endif \ No newline at end of file Index: ch/Copy Handler.dsp =================================================================== diff -u -N --- ch/Copy Handler.dsp (revision 6472716fec44f80b223922d89f269e365aeaba60) +++ ch/Copy Handler.dsp (revision 0) @@ -1,813 +0,0 @@ -# Microsoft Developer Studio Project File - Name="Copy Handler" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Application" 0x0101 - -CFG=Copy Handler - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "Copy Handler.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "Copy Handler.mak" CFG="Copy Handler - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "Copy Handler - Win32 Release" (based on "Win32 (x86) Application") -!MESSAGE "Copy Handler - Win32 Debug" (based on "Win32 (x86) Application") -!MESSAGE "Copy Handler - Win32 Final Release" (based on "Win32 (x86) Application") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "Copy Handler" -# PROP Scc_LocalPath "." -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "Copy Handler - Win32 Release" - -# PROP BASE Use_MFC 2 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 2 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /Yu"stdafx.h" /FD /c -# ADD CPP /nologo /G5 /MD /W4 /GX /O2 /Ob2 /I "..\..\..\MODULES" /I "..\..\MODULES\\" /I "..\..\..\MODULES\App Framework" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_AFXDLL" /FAs /Yu"stdafx.h" /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "NDEBUG" /d "_AFXDLL" -# ADD RSC /l 0x409 /d "NDEBUG" /d "_AFXDLL" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 /nologo /subsystem:windows /machine:I386 -# ADD LINK32 winmm.lib imagehlp.lib version.lib htmlhelp.lib /nologo /subsystem:windows /machine:I386 /out:"../BIN/Release/ch.exe" -# SUBTRACT LINK32 /profile /debug /nodefaultlib -# Begin Special Build Tool -WkspDir=. -TargetPath=\projects\c++\working\Copy Handler\BIN\Release\ch.exe -SOURCE="$(InputPath)" -PostBuild_Cmds="BuildManager" "Release builds" "$(WkspDir)\ch_count.txt" upx.exe -9 -v "$(TargetPath)" -# End Special Build Tool - -!ELSEIF "$(CFG)" == "Copy Handler - Win32 Debug" - -# PROP BASE Use_MFC 2 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 2 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /Yu"stdafx.h" /FD /GZ /c -# ADD CPP /nologo /MDd /W3 /Gm /Gi /GX /ZI /Od /I "..\..\..\MODULES\App Framework" /I "..\..\..\MODULES" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_AFXDLL" /FR /Yu"stdafx.h" /FD /GZ /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "_DEBUG" /d "_AFXDLL" -# ADD RSC /l 0x409 /d "_DEBUG" /d "_AFXDLL" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept -# ADD LINK32 winmm.lib imagehlp.lib version.lib htmlhelp.lib /nologo /subsystem:windows /profile /debug /machine:I386 /out:"../BIN/Debug/ch.exe" -# SUBTRACT LINK32 /map -# Begin Special Build Tool -WkspDir=. -SOURCE="$(InputPath)" -PostBuild_Cmds="BuildManager" "Debug builds" "$(WkspDir)\ch_count.txt" -# End Special Build Tool - -!ELSEIF "$(CFG)" == "Copy Handler - Win32 Final Release" - -# PROP BASE Use_MFC 2 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Copy_Handler___Win32_Final_Release" -# PROP BASE Intermediate_Dir "Copy_Handler___Win32_Final_Release" -# PROP BASE Ignore_Export_Lib 0 -# PROP BASE Target_Dir "" -# PROP Use_MFC 2 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Copy_Handler___Win32_Final_Release" -# PROP Intermediate_Dir "Copy_Handler___Win32_Final_Release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /G5 /MD /W4 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_AFXDLL" /FAs /Yu"stdafx.h" /FD /c -# ADD CPP /nologo /G5 /MD /W4 /GX /O2 /Ob2 /I "..\..\..\MODULES" /I "..\..\MODULES\\" /I "..\..\..\MODULES\App Framework" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_AFXDLL" /FAs /Yu"stdafx.h" /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "NDEBUG" /d "_AFXDLL" -# ADD RSC /l 0x409 /d "NDEBUG" /d "_AFXDLL" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 winmm.lib imagehlp.lib version.lib htmlhelp.lib /nologo /subsystem:windows /machine:I386 /out:"../BIN/Release/ch.exe" -# SUBTRACT BASE LINK32 /profile /debug /nodefaultlib -# ADD LINK32 winmm.lib imagehlp.lib version.lib htmlhelp.lib /nologo /subsystem:windows /machine:I386 /out:"../BIN/Release/ch.exe" -# SUBTRACT LINK32 /profile /debug /nodefaultlib -# Begin Special Build Tool -WkspDir=. -TargetPath=\projects\c++\working\Copy Handler\BIN\Release\ch.exe -SOURCE="$(InputPath)" -PostBuild_Cmds="BuildManager" "Release builds" "$(WkspDir)\ch_count.txt" upx.exe -9 -v "$(TargetPath)" -# End Special Build Tool - -!ENDIF - -# Begin Target - -# Name "Copy Handler - Win32 Release" -# Name "Copy Handler - Win32 Debug" -# Name "Copy Handler - Win32 Final Release" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\AboutDlg.cpp -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\AppHelper.cpp" -# End Source File -# Begin Source File - -SOURCE=.\BufferSizeDlg.cpp -# End Source File -# Begin Source File - -SOURCE=.\CfgProperties.cpp -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\ConfigManager.cpp" -# End Source File -# Begin Source File - -SOURCE=".\COPY HANDLER.cpp" -# End Source File -# Begin Source File - -SOURCE=".\COPY HANDLER.rc" - -!IF "$(CFG)" == "Copy Handler - Win32 Release" - -# PROP Ignore_Default_Tool 1 -# Begin Custom Build - Compiling resources $(InputPath) -InputDir=. -OutDir=.\Release -WkspDir=. -TargetDir=\projects\c++\working\Copy Handler\BIN\Release -InputPath=".\COPY HANDLER.rc" -InputName=COPY HANDLER - -"$(OutDir)\$(InputName).res" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - "BuildManager" "$(WkspDir)\ch_count.txt" $(InputPath) /rcupd - Exe2Lng.exe $(InputPath) "$(InputDir)\Scripts\header.lng" "$(OutDir)\chtmp.rc" "$(TargetDir)\..\..\other\Langs\English.lng" $(InputDir)\resource.h "$(MSDEVDIR)\..\..\VC98\MFC\Include\afxres.h" - rc.exe /l 0x409 /d "NDEBUG" /d "_AFXDLL" /fo"$(OutDir)\$(InputName).res" "$(OutDir)\chtmp.rc" - del "$(OutDir)\chtmp.rc" - -# End Custom Build - -!ELSEIF "$(CFG)" == "Copy Handler - Win32 Debug" - -# PROP Ignore_Default_Tool 1 -# Begin Custom Build - Compiling resources $(InputPath) -InputDir=. -OutDir=.\Debug -WkspDir=. -TargetDir=\projects\c++\working\Copy Handler\BIN\Debug -InputPath=".\COPY HANDLER.rc" -InputName=COPY HANDLER - -"$(OutDir)\$(InputName).res" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - "BuildManager" "$(WkspDir)\ch_count.txt" $(InputPath) /rcupd - Exe2Lng.exe $(InputPath) "$(InputDir)\Scripts\header.lng" "$(OutDir)\chtmp.rc" "$(TargetDir)\..\..\other\Langs\English.lng" $(InputDir)\resource.h "$(MSDEVDIR)\..\..\VC98\MFC\Include\afxres.h" - rc.exe /l 0x409 /d "_DEBUG" /d "_AFXDLL" /fo"$(OutDir)\$(InputName).res" "$(OutDir)\chtmp.rc" - del "$(OutDir)\chtmp.rc" - -# End Custom Build - -!ELSEIF "$(CFG)" == "Copy Handler - Win32 Final Release" - -# PROP BASE Ignore_Default_Tool 1 -# PROP Ignore_Default_Tool 1 - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\crc32.cpp" -# End Source File -# Begin Source File - -SOURCE=.\CustomCopyDlg.cpp -# End Source File -# Begin Source File - -SOURCE=.\DataBuffer.cpp -# End Source File -# Begin Source File - -SOURCE=.\DestPath.cpp -# End Source File -# Begin Source File - -SOURCE=.\Dialogs.cpp -# End Source File -# Begin Source File - -SOURCE=.\DirTreeCtrl.cpp -# End Source File -# Begin Source File - -SOURCE=.\DstFileErrorDlg.cpp -# End Source File -# Begin Source File - -SOURCE=.\FFListCtrl.cpp -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\FileEx.cpp" -# End Source File -# Begin Source File - -SOURCE=.\FileInfo.cpp -# End Source File -# Begin Source File - -SOURCE=..\Common\FileSupport.cpp -# End Source File -# Begin Source File - -SOURCE=.\FilterDlg.cpp -# End Source File -# Begin Source File - -SOURCE=.\FolderDialog.cpp -# End Source File -# Begin Source File - -SOURCE=.\HelpLngDialog.cpp -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\IniFile.cpp" -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\LanguageDialog.cpp" -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\LogFile.cpp" -# End Source File -# Begin Source File - -SOURCE=.\MainWnd.cpp -# End Source File -# Begin Source File - -SOURCE=.\MiniViewDlg.cpp -# End Source File -# Begin Source File - -SOURCE=.\NotEnoughRoomDlg.cpp -# End Source File -# Begin Source File - -SOURCE=.\OptionsDlg.cpp -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\Plugin.cpp" -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\PluginContainer.cpp" -# End Source File -# Begin Source File - -SOURCE=.\ProgressListBox.cpp -# End Source File -# Begin Source File - -SOURCE=.\PropertyListCtrl.cpp -# End Source File -# Begin Source File - -SOURCE=.\RecentDlg.cpp -# End Source File -# Begin Source File - -SOURCE=.\register.cpp -# End Source File -# Begin Source File - -SOURCE=.\ReplaceFilesDlg.cpp -# End Source File -# Begin Source File - -SOURCE=.\ReplaceOnlyDlg.cpp -# End Source File -# Begin Source File - -SOURCE=.\ReplacePathsDlg.cpp -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\ResourceManager.cpp" -# End Source File -# Begin Source File - -SOURCE=.\shortcuts.cpp -# End Source File -# Begin Source File - -SOURCE=.\ShortcutsDlg.cpp -# End Source File -# Begin Source File - -SOURCE=.\ShutdownDlg.cpp -# End Source File -# Begin Source File - -SOURCE=.\SmallReplaceFilesDlg.cpp -# End Source File -# Begin Source File - -SOURCE=.\StaticEx.cpp -# End Source File -# Begin Source File - -SOURCE=.\StatusDlg.cpp -# End Source File -# Begin Source File - -SOURCE=.\stdafx.cpp -# ADD CPP /Yc"stdafx.h" -# End Source File -# Begin Source File - -SOURCE=.\StringHelpers.cpp -# End Source File -# Begin Source File - -SOURCE=.\structs.cpp -# End Source File -# Begin Source File - -SOURCE=".\Theme Helpers.cpp" -# End Source File -# Begin Source File - -SOURCE=.\ThemedButton.cpp -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\TrayIcon.cpp" -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\AboutDlg.h -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\af_defs.h" -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\AppHelper.h" -# End Source File -# Begin Source File - -SOURCE=.\btnIDs.h -# End Source File -# Begin Source File - -SOURCE=.\BufferSizeDlg.h -# End Source File -# Begin Source File - -SOURCE=.\CfgProperties.h -# End Source File -# Begin Source File - -SOURCE=.\charvect.h -# End Source File -# Begin Source File - -SOURCE=..\Common\CHPluginCore.h -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\ConfigEntry.h" -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\ConfigManager.h" -# End Source File -# Begin Source File - -SOURCE=".\COPY HANDLER.h" -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\crc32.h" -# End Source File -# Begin Source File - -SOURCE=.\CustomCopyDlg.h -# End Source File -# Begin Source File - -SOURCE=.\DataBuffer.h -# End Source File -# Begin Source File - -SOURCE=.\DestPath.h -# End Source File -# Begin Source File - -SOURCE=".\Device IO.h" -# End Source File -# Begin Source File - -SOURCE=.\Dialogs.h -# End Source File -# Begin Source File - -SOURCE=.\DirTreeCtrl.h -# End Source File -# Begin Source File - -SOURCE=.\DstFileErrorDlg.h -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\ExceptionEx.h" -# End Source File -# Begin Source File - -SOURCE=.\FFListCtrl.h -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\FileEx.h" -# End Source File -# Begin Source File - -SOURCE=.\FileInfo.h -# End Source File -# Begin Source File - -SOURCE=..\Common\FileSupport.h -# End Source File -# Begin Source File - -SOURCE=.\FilterDlg.h -# End Source File -# Begin Source File - -SOURCE=.\FolderDialog.h -# End Source File -# Begin Source File - -SOURCE=.\HelpLngDialog.h -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\IniFile.h" -# End Source File -# Begin Source File - -SOURCE=..\Common\ipcstructs.h -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\LanguageDialog.h" -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\LogFile.h" -# End Source File -# Begin Source File - -SOURCE=.\MainWnd.h -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\MemDC.h" -# End Source File -# Begin Source File - -SOURCE=.\MiniViewDlg.h -# End Source File -# Begin Source File - -SOURCE=.\NotEnoughRoomDlg.h -# End Source File -# Begin Source File - -SOURCE=.\OptionsDlg.h -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\Plugin.h" -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\PluginContainer.h" -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\PluginCore.h" -# End Source File -# Begin Source File - -SOURCE=.\ProgressListBox.h -# End Source File -# Begin Source File - -SOURCE=.\PropertyListCtrl.h -# End Source File -# Begin Source File - -SOURCE=.\RecentDlg.h -# End Source File -# Begin Source File - -SOURCE=.\register.h -# End Source File -# Begin Source File - -SOURCE=.\ReplaceFilesDlg.h -# End Source File -# Begin Source File - -SOURCE=.\ReplaceOnlyDlg.h -# End Source File -# Begin Source File - -SOURCE=.\ReplacePathsDlg.h -# End Source File -# Begin Source File - -SOURCE=.\resource.h - -!IF "$(CFG)" == "Copy Handler - Win32 Release" - -# PROP Ignore_Default_Tool 1 -# Begin Custom Build - Generating html help include file... -InputPath=.\resource.h - -"..\other\Help\HTMLDefines.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - call makehelpmap.bat "$(InputPath)" "..\other\Help\HTMLDefines.h" - -# End Custom Build - -!ELSEIF "$(CFG)" == "Copy Handler - Win32 Debug" - -# PROP Ignore_Default_Tool 1 -# Begin Custom Build - Generating html help include file... -InputPath=.\resource.h - -"..\other\Help\HTMLDefines.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - call makehelpmap.bat "$(InputPath)" "..\other\Help\HTMLDefines.h" - -# End Custom Build - -!ELSEIF "$(CFG)" == "Copy Handler - Win32 Final Release" - -# PROP BASE Ignore_Default_Tool 1 -# PROP Ignore_Default_Tool 1 -# Begin Custom Build - Generating html help include file... -InputPath=.\resource.h - -"..\other\Help\HTMLDefines.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - call makehelpmap.bat "$(InputPath)" "..\other\Help\HTMLDefines.h" - -# End Custom Build - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\ResourceManager.h" -# End Source File -# Begin Source File - -SOURCE=.\shortcuts.h -# End Source File -# Begin Source File - -SOURCE=.\ShortcutsDlg.h -# End Source File -# Begin Source File - -SOURCE=.\ShutdownDlg.h -# End Source File -# Begin Source File - -SOURCE=.\SmallReplaceFilesDlg.h -# End Source File -# Begin Source File - -SOURCE=.\StaticEx.h -# End Source File -# Begin Source File - -SOURCE=.\StatusDlg.h -# End Source File -# Begin Source File - -SOURCE=.\stdafx.h -# End Source File -# Begin Source File - -SOURCE=.\StringHelpers.h -# End Source File -# Begin Source File - -SOURCE=.\structs.h -# End Source File -# Begin Source File - -SOURCE=".\Theme Helpers.h" -# End Source File -# Begin Source File - -SOURCE=.\ThemedButton.h -# End Source File -# Begin Source File - -SOURCE="..\..\..\MODULES\App Framework\TrayIcon.h" -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# Begin Source File - -SOURCE=.\res\addshort.ico -# End Source File -# Begin Source File - -SOURCE=.\res\cancelled.ico -# End Source File -# Begin Source File - -SOURCE=.\res\cd.ico -# End Source File -# Begin Source File - -SOURCE=.\help\ch.gif -# End Source File -# Begin Source File - -SOURCE=..\Documentation\Help\EN\ch.gif -# End Source File -# Begin Source File - -SOURCE=..\Documentation\Help\PL\ch.gif -# End Source File -# Begin Source File - -SOURCE=".\res\COPY HANDLER.ico" -# End Source File -# Begin Source File - -SOURCE=".\res\COPY HANDLER.rc2" -# End Source File -# Begin Source File - -SOURCE=.\res\delshort.ico -# End Source File -# Begin Source File - -SOURCE=.\res\diskette.ico -# End Source File -# Begin Source File - -SOURCE=.\res\err.ico -# End Source File -# Begin Source File - -SOURCE=.\res\error.ico -# End Source File -# Begin Source File - -SOURCE=.\res\finished.ico -# End Source File -# Begin Source File - -SOURCE=.\res\folder.ico -# End Source File -# Begin Source File - -SOURCE=.\res\hd.ico -# End Source File -# Begin Source File - -SOURCE=.\res\Hd2.ico -# End Source File -# Begin Source File - -SOURCE=.\res\info.ico -# End Source File -# Begin Source File - -SOURCE=.\res\large.ico -# End Source File -# Begin Source File - -SOURCE=.\res\list.ico -# End Source File -# Begin Source File - -SOURCE=.\res\main_toolbar.bmp -# End Source File -# Begin Source File - -SOURCE=.\res\net.ico -# End Source File -# Begin Source File - -SOURCE=.\res\newdir.ico -# End Source File -# Begin Source File - -SOURCE=.\res\paused.ico -# End Source File -# Begin Source File - -SOURCE=.\res\question.ico -# End Source File -# Begin Source File - -SOURCE=.\res\report.ico -# End Source File -# Begin Source File - -SOURCE=.\res\shut.ico -# End Source File -# Begin Source File - -SOURCE=.\res\small.ico -# End Source File -# Begin Source File - -SOURCE=.\res\tribe.ico -# End Source File -# Begin Source File - -SOURCE=.\res\waiting.ico -# End Source File -# Begin Source File - -SOURCE=.\res\warning.ico -# End Source File -# Begin Source File - -SOURCE=.\res\working.ico -# End Source File -# End Group -# Begin Source File - -SOURCE=.\res\manifest.txt -# End Source File -# Begin Source File - -SOURCE=.\RES\Thanks.txt -# End Source File -# Begin Source File - -SOURCE=..\other\TODO.TXT -# End Source File -# End Target -# End Project Index: ch/ExceptionEx.h =================================================================== diff -u -N --- ch/ExceptionEx.h (revision 0) +++ ch/ExceptionEx.h (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,212 @@ +/************************************************************************ + Copy Handler 1.x - program for copying data in Microsoft Windows + systems. + Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. +*************************************************************************/ +/************************************************************************* + File: Exception.h + Version: 1.0 + Author: Ixen Gerthannes (ixen@interia.pl) + File description: + Contain CException class - a base for any other exception + types. + Classes: + CException + - provides basic exception functionality. + - when used with MFC class name is CExceptionEx (it's + not based on MFC CException!). +*************************************************************************/ +#ifndef __EXCEPTION_H__ +#define __EXCEPTION_H__ + +#include "stdio.h" + +#define THROW_EXCEPTIONEX(str_reason, app_code, last_error) throw new CExceptionEx(__FILE__, __LINE__, __FUNCTION__, str_reason, app_code, last_error) + +// not too specific - use specialised classes based on this one (this also could be used) +class CExceptionEx +{ +protected: + enum PropType { dtString, dtPtrToString, dtDword, dtSysError }; + + struct __EXCPROPINFO + { + TCHAR szName[64]; // name of the property (ie."Source file") + PropType eType; // type of the property (string, dword, bool, ...) + void* pData; // pointer to the value of the property + }; + +public: + CExceptionEx(PCTSTR pszSrcFile, DWORD dwLine, PCTSTR pszFunc, PCTSTR pszReason, DWORD dwReason, DWORD dwLastError=0) + { + // init the object with a given values + _tcsncpy(m_szSourceFile, pszSrcFile, _MAX_PATH); + m_szSourceFile[_MAX_PATH-1]=_T('\0'); + m_dwSourceLine=dwLine; + _tcsncpy(m_szFunction, pszFunc, _MAX_PATH); + m_szFunction[_MAX_PATH-1]=_T('\0'); + SetReason(pszReason); + m_dwReason=dwReason; + m_dwError=dwLastError; + }; + CExceptionEx(PCTSTR pszSrcFile, DWORD dwLine, PCTSTR pszFunc, TCHAR* pszReason, DWORD dwReason, DWORD dwLastError=0) + { + _tcsncpy(m_szSourceFile, pszSrcFile, _MAX_PATH); + m_szSourceFile[_MAX_PATH-1]=_T('\0'); + m_dwSourceLine=dwLine; + _tcsncpy(m_szFunction, pszFunc, _MAX_PATH); + m_szFunction[_MAX_PATH-1]=_T('\0'); + m_pszReason=pszReason; + m_dwReason=dwReason; + m_dwError=dwLastError; + }; + + virtual ~CExceptionEx() { delete [] m_pszReason; }; + + virtual int RegisterInfo(__EXCPROPINFO* pInfo) + { + // if the pInfo is null - return count of a needed props + if (pInfo == NULL) + return 6; // +baseClass::RegisterInfo + + // call base class RegisterInfo + + // function has to register the info to be displayed (called from within GetInfo) + RegisterProp(pInfo+0, _T("Source file"), PropType::dtString, &m_szSourceFile); + RegisterProp(pInfo+1, _T("Line"), PropType::dtDword, &m_dwSourceLine); + RegisterProp(pInfo+2, _T("Function"), PropType::dtString, &m_szFunction); + RegisterProp(pInfo+3, _T("Reason"), PropType::dtPtrToString, &m_pszReason); + RegisterProp(pInfo+4, _T("App error"), PropType::dtDword, &m_dwReason); + RegisterProp(pInfo+5, _T("System error"), PropType::dtSysError, &m_dwError); + + return 6; + }; + +public: + // helpers + static TCHAR* FormatReason(PCTSTR pszReason, ...) + { + TCHAR szBuf[1024]; + va_list marker; + va_start(marker, pszReason); + _vstprintf(szBuf, pszReason, marker); + va_end(marker); + TCHAR *pszData=new TCHAR[_tcslen(szBuf)+1]; + _tcscpy(pszData, szBuf); + return pszData; + }; + + // formats max info about this exception + virtual TCHAR* GetInfo(LPCTSTR pszDesc, TCHAR* pszStr, DWORD dwMaxLen) + { + // get the properties + int iCount=RegisterInfo(NULL); + __EXCPROPINFO *pepi=new __EXCPROPINFO[iCount]; + RegisterInfo(pepi); // register all the properties + + // add the desc to the out + if (pszDesc) + { + _tcsncpy(pszStr, pszDesc, dwMaxLen-1); + pszStr[dwMaxLen-1]=_T('\0'); + } + else + pszStr[0]=_T('\0'); + + size_t tIndex=_tcslen(pszStr); + + // format the info accordingly + TCHAR szData[1024]; + for (int i=0;iszName, pszName, 63); + pInfo->szName[63]=_T('\0'); + pInfo->eType=type; + pInfo->pData=pData; + }; + +public: + // exception information + TCHAR m_szSourceFile[_MAX_PATH]; // source file from where the exception is being thrown + DWORD m_dwSourceLine; // line in the source file from where exception has been thrown + TCHAR m_szFunction[_MAX_PATH]; // name of the function in which the exception occured + TCHAR *m_pszReason; // description of this error (in english - internal error code - description - human readable) + DWORD m_dwReason; // numerical value that states app-level error number + DWORD m_dwError; // in most cases GetLastError() when it has any sense +}; + +#endif \ No newline at end of file Index: modules/App Framework/ExceptionEx.h =================================================================== diff -u -N --- modules/App Framework/ExceptionEx.h (revision 3e1186252ab31f63d86d86c4b0ff593cfffbefde) +++ modules/App Framework/ExceptionEx.h (revision 0) @@ -1,212 +0,0 @@ -/************************************************************************ - Copy Handler 1.x - program for copying data in Microsoft Windows - systems. - Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. -*************************************************************************/ -/************************************************************************* - File: Exception.h - Version: 1.0 - Author: Ixen Gerthannes (ixen@interia.pl) - File description: - Contain CException class - a base for any other exception - types. - Classes: - CException - - provides basic exception functionality. - - when used with MFC class name is CExceptionEx (it's - not based on MFC CException!). -*************************************************************************/ -#ifndef __EXCEPTION_H__ -#define __EXCEPTION_H__ - -#include "stdio.h" - -#define THROW_EXCEPTIONEX(str_reason, app_code, last_error) throw new CExceptionEx(__FILE__, __LINE__, __FUNCTION__, str_reason, app_code, last_error) - -// not too specific - use specialised classes based on this one (this also could be used) -class CExceptionEx -{ -protected: - enum PropType { dtString, dtPtrToString, dtDword, dtSysError }; - - struct __EXCPROPINFO - { - TCHAR szName[64]; // name of the property (ie."Source file") - PropType eType; // type of the property (string, dword, bool, ...) - void* pData; // pointer to the value of the property - }; - -public: - CExceptionEx(PCTSTR pszSrcFile, DWORD dwLine, PCTSTR pszFunc, PCTSTR pszReason, DWORD dwReason, DWORD dwLastError=0) - { - // init the object with a given values - _tcsncpy(m_szSourceFile, pszSrcFile, _MAX_PATH); - m_szSourceFile[_MAX_PATH-1]=_T('\0'); - m_dwSourceLine=dwLine; - _tcsncpy(m_szFunction, pszFunc, _MAX_PATH); - m_szFunction[_MAX_PATH-1]=_T('\0'); - SetReason(pszReason); - m_dwReason=dwReason; - m_dwError=dwLastError; - }; - CExceptionEx(PCTSTR pszSrcFile, DWORD dwLine, PCTSTR pszFunc, TCHAR* pszReason, DWORD dwReason, DWORD dwLastError=0) - { - _tcsncpy(m_szSourceFile, pszSrcFile, _MAX_PATH); - m_szSourceFile[_MAX_PATH-1]=_T('\0'); - m_dwSourceLine=dwLine; - _tcsncpy(m_szFunction, pszFunc, _MAX_PATH); - m_szFunction[_MAX_PATH-1]=_T('\0'); - m_pszReason=pszReason; - m_dwReason=dwReason; - m_dwError=dwLastError; - }; - - virtual ~CExceptionEx() { delete [] m_pszReason; }; - - virtual int RegisterInfo(__EXCPROPINFO* pInfo) - { - // if the pInfo is null - return count of a needed props - if (pInfo == NULL) - return 6; // +baseClass::RegisterInfo - - // call base class RegisterInfo - - // function has to register the info to be displayed (called from within GetInfo) - RegisterProp(pInfo+0, _T("Source file"), PropType::dtString, &m_szSourceFile); - RegisterProp(pInfo+1, _T("Line"), PropType::dtDword, &m_dwSourceLine); - RegisterProp(pInfo+2, _T("Function"), PropType::dtString, &m_szFunction); - RegisterProp(pInfo+3, _T("Reason"), PropType::dtPtrToString, &m_pszReason); - RegisterProp(pInfo+4, _T("App error"), PropType::dtDword, &m_dwReason); - RegisterProp(pInfo+5, _T("System error"), PropType::dtSysError, &m_dwError); - - return 6; - }; - -public: - // helpers - static TCHAR* FormatReason(PCTSTR pszReason, ...) - { - TCHAR szBuf[1024]; - va_list marker; - va_start(marker, pszReason); - _vstprintf(szBuf, pszReason, marker); - va_end(marker); - TCHAR *pszData=new TCHAR[_tcslen(szBuf)+1]; - _tcscpy(pszData, szBuf); - return pszData; - }; - - // formats max info about this exception - virtual TCHAR* GetInfo(LPCTSTR pszDesc, TCHAR* pszStr, DWORD dwMaxLen) - { - // get the properties - int iCount=RegisterInfo(NULL); - __EXCPROPINFO *pepi=new __EXCPROPINFO[iCount]; - RegisterInfo(pepi); // register all the properties - - // add the desc to the out - if (pszDesc) - { - _tcsncpy(pszStr, pszDesc, dwMaxLen-1); - pszStr[dwMaxLen-1]=_T('\0'); - } - else - pszStr[0]=_T('\0'); - - size_t tIndex=_tcslen(pszStr); - - // format the info accordingly - TCHAR szData[1024]; - for (int i=0;iszName, pszName, 63); - pInfo->szName[63]=_T('\0'); - pInfo->eType=type; - pInfo->pData=pData; - }; - -public: - // exception information - TCHAR m_szSourceFile[_MAX_PATH]; // source file from where the exception is being thrown - DWORD m_dwSourceLine; // line in the source file from where exception has been thrown - TCHAR m_szFunction[_MAX_PATH]; // name of the function in which the exception occured - TCHAR *m_pszReason; // description of this error (in english - internal error code - description - human readable) - DWORD m_dwReason; // numerical value that states app-level error number - DWORD m_dwError; // in most cases GetLastError() when it has any sense -}; - -#endif \ No newline at end of file Index: ch/FileEx.cpp =================================================================== diff -u -N --- ch/FileEx.cpp (revision 0) +++ ch/FileEx.cpp (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,917 @@ +/************************************************************************ + Copy Handler 1.x - program for copying data in Microsoft Windows + systems. + Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. +*************************************************************************/ + +#include "stdafx.h" +#include "FileEx.h" +#include "crc32.h" +#ifndef DISABLE_CRYPT +#include "crypt.h" +#endif + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +#pragma warning( disable : 4127 ) + +// serialization buffer add on every reallocation +#define SERIALBUFFER_DELTA 4096UL + +/////////////////////////////////////////////////////////////// +// Opens file +// pszFilename [in] - name of the file to open +// dwAccess [in] - type of access to this file (R, W, RW, APPEND) +// dwBufferSize [in] - size of internal buffer when using buffered +// operations. +/////////////////////////////////////////////////////////////// +void CFileEx::Open(PCTSTR pszFilename, DWORD dwAccess, DWORD dwBufferSize) +{ + // check if this object is ready to open a file + if (m_hFile) + Close(); + + HANDLE hFile=NULL; + switch (dwAccess & FA_OPERATION) + { + case FA_READ: + hFile=CreateFile(pszFilename, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + break; + case FA_WRITE: + hFile=CreateFile(pszFilename, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + break; + case FA_RW: + case FA_APPEND: + hFile=CreateFile(pszFilename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + break; + default: + _ASSERT(false); // unknown File access value + } + + // check if operation succeeded + if (hFile == INVALID_HANDLE_VALUE) + THROW_FILEEXCEPTIONEX(_T("Cannot open the specified file (CreateFile failed)."), pszFilename, FERR_OPEN, GetLastError()); + else + { + // store hFile + m_hFile=hFile; + + // remember path of this file + m_pszFilename=new TCHAR[_tcslen(pszFilename)+1]; + _tcscpy(m_pszFilename, pszFilename); + + // remember the mode + m_dwMode=dwAccess; + + // is this buffered ? + SetBuffering((dwAccess & 0x8000) != 0, dwBufferSize); + } + + // if this is the "FA_APPEND" access mode - seek to end + if ((dwAccess & FA_OPERATION) == FA_APPEND) + InternalSeek(0, FILE_END); +} + +/////////////////////////////////////////////////////////////// +// Closes the file (could be used on non-opened files +/////////////////////////////////////////////////////////////// +void CFileEx::Close() +{ + // only if the file has been opened + if (m_hFile) + { + // flush all data + Flush(); + + // close da file + if (!CloseHandle(m_hFile)) + { + // error closing + THROW_FILEEXCEPTIONEX(_T("Cannot close the handle associated with a file (CloseHandle failed)."), m_pszFilename, FERR_CLOSE, GetLastError()); + } + else + m_hFile=NULL; + + // free strings and other data + delete [] m_pszFilename; + m_pszFilename=NULL; + delete [] m_pbyBuffer; + m_pbyBuffer=NULL; + } +} + +/////////////////////////////////////////////////////////////// +// Flushes internal buffers when using buffered operations +// may be used in non-buffered mode and for not opened files +// sets file pointer to the place resulting from position +// in internal buffer +/////////////////////////////////////////////////////////////// +void CFileEx::Flush() +{ + if (m_hFile && m_bBuffered && m_dwDataCount > 0) + { + if (m_bLastOperation) + { + // last operation - storing data + WritePacket(); + } + else + { + // last - reading data + // set file pointer to position current-(m_dwDataCount-m_dwCurrentPos) + InternalSeek(-(long)(m_dwDataCount-m_dwCurrentPos), FILE_CURRENT); + m_dwCurrentPos=0; + m_dwDataCount=0; + } + } +} + +/////////////////////////////////////////////////////////////// +// Reads some data from file (buffered or not) +// pBuffer [in/out] - buffer for data +// dwSize [in] - size of data to read +// Ret Value [out] - count of bytes read (could differ from +// dwSize) +/////////////////////////////////////////////////////////////// +DWORD CFileEx::ReadBuffer(void* pBuffer, DWORD dwSize) +{ + _ASSERT(m_hFile); // forgot to open the file ? + + // flush if needed + if (m_bLastOperation) + { + Flush(); + m_bLastOperation=false; + } + + if (!m_bBuffered) + { + // unbuffered operation (read what is needed) + DWORD dwRD=0; + if (!ReadFile(m_hFile, pBuffer, dwSize, &dwRD, NULL)) + THROW_FILEEXCEPTIONEX(_T("Cannot read data from file (ReadFile failed)."), m_pszFilename, FERR_READ, GetLastError()); + + return dwRD; // if 0 - eof (not treated as exception) + } + else + { + // reads must be done by packets + DWORD dwCurrPos=0; // position in external buffer + while (dwCurrPos 0); // couldn't use 0-sized internal buffer + + // flush + Flush(); + + // delete old buffer + if (m_bBuffered && (!bEnable || dwSize != m_dwBufferSize)) + { + delete [] m_pbyBuffer; + m_pbyBuffer=NULL; + } + + // alloc new buffer if needed + if (bEnable && (!m_bBuffered || dwSize != m_dwBufferSize)) + m_pbyBuffer=new BYTE[dwSize]; + + m_bBuffered=bEnable; + m_dwBufferSize=dwSize; +} + +/////////////////////////////////////////////////////////////// +// Changes current mode to unbuffered. If already unbuffered +// function returns doing nothing +/////////////////////////////////////////////////////////////// +void CFileEx::SwitchToUnbuffered() +{ + if (!m_bBuffered) + return; // it's already unbuffered - leave it as is + else + { + m_bRememberedState=true; // mark that we change state to a different one + SetBuffering(false, m_dwBufferSize); // do no change internal buffer size + } +} + +/////////////////////////////////////////////////////////////// +// Changes current mode to buffered. If already buffered +// function returns doing nothing +/////////////////////////////////////////////////////////////// +void CFileEx::SwitchToBuffered() +{ + if (m_bBuffered) + return; // already buffered + else + { + m_bRememberedState=true; + SetBuffering(true, m_dwBufferSize); + } +} + +/////////////////////////////////////////////////////////////// +// Function restores (un)buffered state previously remembered +// with SwitchToXXX. If SwitchToXXX doesn't change the state +// - this function also doesn't. +/////////////////////////////////////////////////////////////// +void CFileEx::RestoreState() +{ + // restore state only if changed + if (m_bRememberedState) + { + SetBuffering(!m_bBuffered, m_dwBufferSize); + m_bRememberedState=false; + } +} + +/////////////////////////////////////////////////////////////// +// (Internal) Reads next packet of data from file (when using +// buffered operations it cause next data of size of internal +// buffer to be read from file +// Ret Value [out] - Count of data that was read +/////////////////////////////////////////////////////////////// +DWORD CFileEx::ReadPacket() +{ + _ASSERT(m_hFile); + + // read data + DWORD dwRD=0; + if (!ReadFile(m_hFile, m_pbyBuffer, m_dwBufferSize, &dwRD, NULL)) + THROW_FILEEXCEPTIONEX(_T("Cannot read data from a file (ReadFile failed)."), m_pszFilename, FERR_READ, GetLastError()); + + // reset internal members + m_dwDataCount=dwRD; + m_dwCurrentPos=0; + + return dwRD; +} + +/////////////////////////////////////////////////////////////// +// (Internal) Function writes all data from internal buffer to +// a file. +// Ret Value [out] - count of bytes written +/////////////////////////////////////////////////////////////// +DWORD CFileEx::WritePacket() +{ + _ASSERT(m_hFile); + + DWORD dwWR=0; + if (!WriteFile(m_hFile, m_pbyBuffer, m_dwDataCount, &dwWR, NULL)) + THROW_FILEEXCEPTIONEX(_T("Cannot write data to a file (WriteFile failed)."), m_pszFilename, FERR_WRITE, GetLastError()); + + // reset internal members + m_dwDataCount=0; + m_dwCurrentPos=0; + + return dwWR; +} + +#ifndef DISABLE_CRYPT +/////////////////////////////////////////////////////////////// +// +/////////////////////////////////////////////////////////////// +void CFileEx::SetPassword(PCTSTR pszPass) +{ + // delete the old password + if (m_pszPassword) + delete [] m_pszPassword; // delete old password + + // generate the SHA256 from this password + m_pszPassword=new TCHAR[64+1]; + StringToKey256(pszPass, m_pszPassword); +} + +#endif + +/////////////////////////////////////////////////////////////// +// +/////////////////////////////////////////////////////////////// +void CFileEx::BeginDataBlock(DWORD dwFlags) +{ + // do not call begin data block within another data block + _ASSERT(!m_bSerializing && m_pbySerialBuffer == NULL); + + // alloc the new buffer and insert there a header (a few bytes) + m_pbySerialBuffer=new BYTE[SERIALBUFFER_DELTA]; + m_dwSerialBufferSize=SERIALBUFFER_DELTA; + + // determine action from read or write flag + bool bWrite=false; + switch(m_dwMode & FA_OPERATION) + { + case FA_READ: + bWrite=false; + break; + case FA_WRITE: + bWrite=true; + break; + case FA_RW: + case FA_APPEND: + _ASSERT(FALSE); // cannot use serialization with files opened in rw mode + break; + } + + // action + if (bWrite) + { + // reserve some space for a header + m_dwSerialBufferPos=sizeof(SERIALIZEINFOHEADER); + } + else + { + // we need to read the block from a file + if (ReadBuffer(m_pbySerialBuffer, sizeof(SERIALIZEINFOHEADER)) != sizeof(SERIALIZEINFOHEADER)) + { + ClearSerialization(); + THROW_FILEEXCEPTIONEX(_T("Cannot read the specified amount of data from a file (reading serialization header)."), m_pszFilename, FERR_SERIALIZE, GetLastError()); + } + + // move forward + m_dwSerialBufferPos=sizeof(SERIALIZEINFOHEADER); + + // determine the size of the remaining data in file + SERIALIZEINFOHEADER* psih=(SERIALIZEINFOHEADER*)m_pbySerialBuffer; + DWORD dwSize=psih->dwToRead-sizeof(SERIALIZEINFOHEADER); + + // check the header crc + DWORD dwhc=icpf::crc32(m_pbySerialBuffer, sizeof(SERIALIZEINFOHEADER)-sizeof(DWORD)); + if (dwhc != psih->dwHeaderCRC32) + { + ClearSerialization(); + THROW_FILEEXCEPTIONEX(_T("Block corrupted. Header CRC check failed."), m_pszFilename, FERR_SERIALIZE, 0); + } + + // resize the buffer + ResizeSerialBuffer(psih->dwToRead); + + // refresh the psih + psih=(SERIALIZEINFOHEADER*)m_pbySerialBuffer; + + // read the remaining data + if (ReadBuffer(m_pbySerialBuffer+m_dwSerialBufferPos, dwSize) != dwSize) + { + ClearSerialization(); + THROW_FILEEXCEPTIONEX(_T("Cannot read specified amount of data from file (reading the after-header data)."), m_pszFilename, FERR_SERIALIZE, GetLastError()); + } + +#ifndef DISABLE_CRYPT + // decrypt the data + if (dwFlags & BF_ENCRYPTED) + { + if (AES256Decrypt(m_pbySerialBuffer+m_dwSerialBufferPos, dwSize, m_pszPassword, m_pbySerialBuffer+m_dwSerialBufferPos) < 0) + { + ClearSerialization(); + THROW_FILEEXCEPTIONEX(_T("Cannot decrypt the data read from the serialization file."), m_pszFilename, FERR_CRYPT, 0); + } + } +#endif + // NOTE: do not update the position - we need ptr at the beginning of data + + // now we are almost ready to retrieve data - only the crc check for the data + DWORD dwCRC=icpf::crc32(m_pbySerialBuffer+sizeof(SERIALIZEINFOHEADER), psih->dwDataSize-sizeof(SERIALIZEINFOHEADER)); + if (psih->dwCRC32 != dwCRC) + { + ClearSerialization(); + THROW_FILEEXCEPTIONEX(_T("CRC check of the data read from file failed."), m_pszFilename, FERR_SERIALIZE, GetLastError()); + } + } + + // make a mark + m_dwDataBlockFlags=dwFlags; + m_bSerializing=true; +} + +/////////////////////////////////////////////////////////////// +// +/////////////////////////////////////////////////////////////// +void CFileEx::EndDataBlock() +{ + // make sure everything is ok + _ASSERT(m_bSerializing && m_pbySerialBuffer != NULL); + + // type of operation + bool bWrite=false; + switch(m_dwMode & FA_OPERATION) + { + case FA_READ: + bWrite=false; + break; + case FA_WRITE: + bWrite=true; + break; + case FA_RW: + case FA_APPEND: + _ASSERT(FALSE); // cannot use serialization with files opened in rw mode + break; + } + + // when writing - make a header, ...; when reading - do nothing important + if (bWrite) + { + // check if there is any data + if (m_dwSerialBufferPos == sizeof(SERIALIZEINFOHEADER)) + return; // no data has been serialized + + // fill the header (real data information) + SERIALIZEINFOHEADER *psih=(SERIALIZEINFOHEADER*)m_pbySerialBuffer; + psih->dwDataSize=m_dwSerialBufferPos; + psih->dwCRC32=icpf::crc32(m_pbySerialBuffer+sizeof(SERIALIZEINFOHEADER), m_dwSerialBufferPos-sizeof(SERIALIZEINFOHEADER)); + +#ifndef DISABLE_CRYPT + // we could encrypt the data here if needed + if (m_dwDataBlockFlags & BF_ENCRYPTED) + { + int iRes=AES256Crypt(m_pbySerialBuffer+sizeof(SERIALIZEINFOHEADER), m_dwSerialBufferPos-sizeof(SERIALIZEINFOHEADER), m_pszPassword, m_pbySerialBuffer+sizeof(SERIALIZEINFOHEADER)); + if (iRes < 0) + { + ClearSerialization(); + THROW_FILEEXCEPTIONEX(_T("Cannot encrypt the data to store."), m_pszFilename, FERR_CRYPT, 0); + } + + // fill the header + psih->dwToRead=iRes+sizeof(SERIALIZEINFOHEADER); + } + else + { +#endif + // the rest of header + psih->dwToRead=m_dwSerialBufferPos; +#ifndef DISABLE_CRYPT + } +#endif + + // calc the header crc + psih->dwHeaderCRC32=icpf::crc32(m_pbySerialBuffer, sizeof(SERIALIZEINFOHEADER)-sizeof(DWORD)); + + // write the buffer + WriteBuffer(m_pbySerialBuffer, psih->dwToRead); + } + + // remove all the traces of serializing + ClearSerialization(); +} + +/////////////////////////////////////////////////////////////// +// +/////////////////////////////////////////////////////////////// +void CFileEx::SWrite(void* pData, DWORD dwSize) +{ + InternalAppendSerialBuffer(pData, dwSize); +} + +/////////////////////////////////////////////////////////////// +// +/////////////////////////////////////////////////////////////// +void CFileEx::SRead(void* pData, DWORD dwSize) +{ + InternalReadSerialBuffer(pData, dwSize); +} + +#ifdef _MFC_VER + +CFileEx& CFileEx::operator<<(CString strData) +{ + DWORD dwLen=strData.GetLength(); + SWrite(&dwLen, sizeof(DWORD)); + SWrite(strData.GetBuffer(1), dwLen); + strData.ReleaseBuffer(); + return *this; +} + +CFileEx& CFileEx::operator>>(CString& strData) +{ + DWORD dwLen; + SRead(&dwLen, sizeof(DWORD)); + PTSTR pszData=strData.GetBuffer(dwLen+1); + try + { + SRead(pszData, dwLen); + } + catch(...) + { + pszData[dwLen]=_T('\0'); + strData.ReleaseBuffer(); + throw; + } + + pszData[dwLen]=_T('\0'); + strData.ReleaseBuffer(); + return *this; +} + +#endif + +/////////////////////////////////////////////////////////////// +// +/////////////////////////////////////////////////////////////// +void CFileEx::ClearSerialization() +{ + // remove all the traces of serializing + delete [] m_pbySerialBuffer; + m_pbySerialBuffer=NULL; + m_dwSerialBufferSize=0; + m_dwSerialBufferPos=0; + m_bSerializing=false; +} + +/////////////////////////////////////////////////////////////// +// +/////////////////////////////////////////////////////////////// +void CFileEx::InternalReadSerialBuffer(void* pData, DWORD dwLen) +{ + // check if we are reading + _ASSERT((m_dwMode & FA_OPERATION) == FA_READ); + + // check the ranges + if (m_dwSerialBufferPos+dwLen > m_dwSerialBufferSize) + { + // throw an exception - read beyond the data range in a given object + THROW_FILEEXCEPTIONEX(_T("Trying to read the serialization data beyond the range."), m_pszFilename, FERR_MEMORY, GetLastError()); + } + + // read the data + memcpy(pData, m_pbySerialBuffer+m_dwSerialBufferPos, dwLen); + m_dwSerialBufferPos+=dwLen; +} + +/////////////////////////////////////////////////////////////// +// +/////////////////////////////////////////////////////////////// +void CFileEx::InternalAppendSerialBuffer(void* pData, DWORD dwCount) +{ + // check if we are writing + _ASSERT((m_dwMode & FA_OPERATION) == FA_WRITE); + + // check serial buffer size (if there is enough room for the data) + if (m_dwSerialBufferPos+dwCount > m_dwSerialBufferSize) + { + // we need a buffer reallocation + DWORD dwDelta=((dwCount/SERIALBUFFER_DELTA)+1)*SERIALBUFFER_DELTA; + + // alloc the new buffer + ResizeSerialBuffer(m_dwSerialBufferSize+dwDelta); + } + + // real storage of the data + if (dwCount > 0) + { + memcpy(m_pbySerialBuffer+m_dwSerialBufferPos, pData, dwCount); + m_dwSerialBufferPos+=dwCount; + } +} + +/////////////////////////////////////////////////////////////// +// +/////////////////////////////////////////////////////////////// +void CFileEx::ResizeSerialBuffer(DWORD dwNewLen) +{ + // alloc the new buffer + BYTE* pbyNewBuffer=new BYTE[dwNewLen]; + + // copy the old data into the new one + DWORD dwCount=min(m_dwSerialBufferPos, dwNewLen); + if (m_dwSerialBufferPos > 0) + memcpy(pbyNewBuffer, m_pbySerialBuffer, dwCount); + + // delete the old buffer + delete [] m_pbySerialBuffer; + + // set the new buffer inplace and update the internal size + m_pbySerialBuffer=pbyNewBuffer; + m_dwSerialBufferSize=dwNewLen; +} + +/////////////////////////////////////////////////////////////// +// (Internal) Functions reads line of text from text file +// Only for buffered operation +// pszStr [out] - string that was read from file +// dwMaxLen [in] - size of the string buffer +/////////////////////////////////////////////////////////////// +bool CFileEx::InternalReadString(TCHAR* pszStr, DWORD dwMaxLen) +{ + _ASSERT(m_hFile != NULL); // file wasn't opened - error opening or you've forgotten to do so ? + + // last time was writing - free buffer + if (m_bLastOperation) + { + Flush(); + m_bLastOperation=false; + } + + // zero all the string + memset(pszStr, 0, dwMaxLen*sizeof(TCHAR)); + + // additional vars + DWORD dwStrPos=0; // current pos in external buffer + bool bSecondPass=false; // if there is need to check data for 0x0a char + + // copy each char into pszString + while(true) + { + // if buffer is empty - fill it + if (m_dwDataCount == 0 || m_dwCurrentPos == m_dwDataCount) + { + if (ReadPacket() == 0) + return _tcslen(pszStr) != 0; + } + + // skipping 0x0a in second pass + if (bSecondPass) + { + if (m_pbyBuffer[m_dwCurrentPos] == 0x0a) + m_dwCurrentPos++; + return true; + } + + // now process chars + while (m_dwCurrentPos < m_dwDataCount) + { + if (m_pbyBuffer[m_dwCurrentPos] == 0x0d) + { + bSecondPass=true; + m_dwCurrentPos++; + break; + } + else if (m_pbyBuffer[m_dwCurrentPos] == 0x0a) + { + m_dwCurrentPos++; + return true; + } + else + { + if (dwStrPos < dwMaxLen-1) + pszStr[dwStrPos++]=m_pbyBuffer[m_dwCurrentPos]; + m_dwCurrentPos++; + } + } + } + + return false; +} + +/////////////////////////////////////////////////////////////// +// (Internal) Sets file pointer in a file +// llOffset [in] - position to move to +// uiFrom [in] - type of moving (see Platform SDK on +// SetFilePointer) +/////////////////////////////////////////////////////////////// +LONGLONG CFileEx::InternalSeek(LONGLONG llOffset, UINT uiFrom) +{ + LARGE_INTEGER li; + li.QuadPart = llOffset; + li.LowPart = SetFilePointer (m_hFile, li.LowPart, &li.HighPart, uiFrom); + + if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) + { + // error seeking - throw an exception + THROW_FILEEXCEPTIONEX(_T("Seek error."), m_pszFilename, FERR_SEEK, GetLastError()); + } + + return li.QuadPart; +} Index: modules/App Framework/FileEx.cpp =================================================================== diff -u -N --- modules/App Framework/FileEx.cpp (revision 5d5f6e5b4a377c3b01a0ef17ad079770319f30ff) +++ modules/App Framework/FileEx.cpp (revision 0) @@ -1,917 +0,0 @@ -/************************************************************************ - Copy Handler 1.x - program for copying data in Microsoft Windows - systems. - Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. -*************************************************************************/ - -#include "stdafx.h" -#include "FileEx.h" -#include "crc32.h" -#ifndef DISABLE_CRYPT -#include "crypt.h" -#endif - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -#pragma warning( disable : 4127 ) - -// serialization buffer add on every reallocation -#define SERIALBUFFER_DELTA 4096UL - -/////////////////////////////////////////////////////////////// -// Opens file -// pszFilename [in] - name of the file to open -// dwAccess [in] - type of access to this file (R, W, RW, APPEND) -// dwBufferSize [in] - size of internal buffer when using buffered -// operations. -/////////////////////////////////////////////////////////////// -void CFileEx::Open(PCTSTR pszFilename, DWORD dwAccess, DWORD dwBufferSize) -{ - // check if this object is ready to open a file - if (m_hFile) - Close(); - - HANDLE hFile=NULL; - switch (dwAccess & FA_OPERATION) - { - case FA_READ: - hFile=CreateFile(pszFilename, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - break; - case FA_WRITE: - hFile=CreateFile(pszFilename, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - break; - case FA_RW: - case FA_APPEND: - hFile=CreateFile(pszFilename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - break; - default: - _ASSERT(false); // unknown File access value - } - - // check if operation succeeded - if (hFile == INVALID_HANDLE_VALUE) - THROW_FILEEXCEPTIONEX(_T("Cannot open the specified file (CreateFile failed)."), pszFilename, FERR_OPEN, GetLastError()); - else - { - // store hFile - m_hFile=hFile; - - // remember path of this file - m_pszFilename=new TCHAR[_tcslen(pszFilename)+1]; - _tcscpy(m_pszFilename, pszFilename); - - // remember the mode - m_dwMode=dwAccess; - - // is this buffered ? - SetBuffering((dwAccess & 0x8000) != 0, dwBufferSize); - } - - // if this is the "FA_APPEND" access mode - seek to end - if ((dwAccess & FA_OPERATION) == FA_APPEND) - InternalSeek(0, FILE_END); -} - -/////////////////////////////////////////////////////////////// -// Closes the file (could be used on non-opened files -/////////////////////////////////////////////////////////////// -void CFileEx::Close() -{ - // only if the file has been opened - if (m_hFile) - { - // flush all data - Flush(); - - // close da file - if (!CloseHandle(m_hFile)) - { - // error closing - THROW_FILEEXCEPTIONEX(_T("Cannot close the handle associated with a file (CloseHandle failed)."), m_pszFilename, FERR_CLOSE, GetLastError()); - } - else - m_hFile=NULL; - - // free strings and other data - delete [] m_pszFilename; - m_pszFilename=NULL; - delete [] m_pbyBuffer; - m_pbyBuffer=NULL; - } -} - -/////////////////////////////////////////////////////////////// -// Flushes internal buffers when using buffered operations -// may be used in non-buffered mode and for not opened files -// sets file pointer to the place resulting from position -// in internal buffer -/////////////////////////////////////////////////////////////// -void CFileEx::Flush() -{ - if (m_hFile && m_bBuffered && m_dwDataCount > 0) - { - if (m_bLastOperation) - { - // last operation - storing data - WritePacket(); - } - else - { - // last - reading data - // set file pointer to position current-(m_dwDataCount-m_dwCurrentPos) - InternalSeek(-(long)(m_dwDataCount-m_dwCurrentPos), FILE_CURRENT); - m_dwCurrentPos=0; - m_dwDataCount=0; - } - } -} - -/////////////////////////////////////////////////////////////// -// Reads some data from file (buffered or not) -// pBuffer [in/out] - buffer for data -// dwSize [in] - size of data to read -// Ret Value [out] - count of bytes read (could differ from -// dwSize) -/////////////////////////////////////////////////////////////// -DWORD CFileEx::ReadBuffer(void* pBuffer, DWORD dwSize) -{ - _ASSERT(m_hFile); // forgot to open the file ? - - // flush if needed - if (m_bLastOperation) - { - Flush(); - m_bLastOperation=false; - } - - if (!m_bBuffered) - { - // unbuffered operation (read what is needed) - DWORD dwRD=0; - if (!ReadFile(m_hFile, pBuffer, dwSize, &dwRD, NULL)) - THROW_FILEEXCEPTIONEX(_T("Cannot read data from file (ReadFile failed)."), m_pszFilename, FERR_READ, GetLastError()); - - return dwRD; // if 0 - eof (not treated as exception) - } - else - { - // reads must be done by packets - DWORD dwCurrPos=0; // position in external buffer - while (dwCurrPos 0); // couldn't use 0-sized internal buffer - - // flush - Flush(); - - // delete old buffer - if (m_bBuffered && (!bEnable || dwSize != m_dwBufferSize)) - { - delete [] m_pbyBuffer; - m_pbyBuffer=NULL; - } - - // alloc new buffer if needed - if (bEnable && (!m_bBuffered || dwSize != m_dwBufferSize)) - m_pbyBuffer=new BYTE[dwSize]; - - m_bBuffered=bEnable; - m_dwBufferSize=dwSize; -} - -/////////////////////////////////////////////////////////////// -// Changes current mode to unbuffered. If already unbuffered -// function returns doing nothing -/////////////////////////////////////////////////////////////// -void CFileEx::SwitchToUnbuffered() -{ - if (!m_bBuffered) - return; // it's already unbuffered - leave it as is - else - { - m_bRememberedState=true; // mark that we change state to a different one - SetBuffering(false, m_dwBufferSize); // do no change internal buffer size - } -} - -/////////////////////////////////////////////////////////////// -// Changes current mode to buffered. If already buffered -// function returns doing nothing -/////////////////////////////////////////////////////////////// -void CFileEx::SwitchToBuffered() -{ - if (m_bBuffered) - return; // already buffered - else - { - m_bRememberedState=true; - SetBuffering(true, m_dwBufferSize); - } -} - -/////////////////////////////////////////////////////////////// -// Function restores (un)buffered state previously remembered -// with SwitchToXXX. If SwitchToXXX doesn't change the state -// - this function also doesn't. -/////////////////////////////////////////////////////////////// -void CFileEx::RestoreState() -{ - // restore state only if changed - if (m_bRememberedState) - { - SetBuffering(!m_bBuffered, m_dwBufferSize); - m_bRememberedState=false; - } -} - -/////////////////////////////////////////////////////////////// -// (Internal) Reads next packet of data from file (when using -// buffered operations it cause next data of size of internal -// buffer to be read from file -// Ret Value [out] - Count of data that was read -/////////////////////////////////////////////////////////////// -DWORD CFileEx::ReadPacket() -{ - _ASSERT(m_hFile); - - // read data - DWORD dwRD=0; - if (!ReadFile(m_hFile, m_pbyBuffer, m_dwBufferSize, &dwRD, NULL)) - THROW_FILEEXCEPTIONEX(_T("Cannot read data from a file (ReadFile failed)."), m_pszFilename, FERR_READ, GetLastError()); - - // reset internal members - m_dwDataCount=dwRD; - m_dwCurrentPos=0; - - return dwRD; -} - -/////////////////////////////////////////////////////////////// -// (Internal) Function writes all data from internal buffer to -// a file. -// Ret Value [out] - count of bytes written -/////////////////////////////////////////////////////////////// -DWORD CFileEx::WritePacket() -{ - _ASSERT(m_hFile); - - DWORD dwWR=0; - if (!WriteFile(m_hFile, m_pbyBuffer, m_dwDataCount, &dwWR, NULL)) - THROW_FILEEXCEPTIONEX(_T("Cannot write data to a file (WriteFile failed)."), m_pszFilename, FERR_WRITE, GetLastError()); - - // reset internal members - m_dwDataCount=0; - m_dwCurrentPos=0; - - return dwWR; -} - -#ifndef DISABLE_CRYPT -/////////////////////////////////////////////////////////////// -// -/////////////////////////////////////////////////////////////// -void CFileEx::SetPassword(PCTSTR pszPass) -{ - // delete the old password - if (m_pszPassword) - delete [] m_pszPassword; // delete old password - - // generate the SHA256 from this password - m_pszPassword=new TCHAR[64+1]; - StringToKey256(pszPass, m_pszPassword); -} - -#endif - -/////////////////////////////////////////////////////////////// -// -/////////////////////////////////////////////////////////////// -void CFileEx::BeginDataBlock(DWORD dwFlags) -{ - // do not call begin data block within another data block - _ASSERT(!m_bSerializing && m_pbySerialBuffer == NULL); - - // alloc the new buffer and insert there a header (a few bytes) - m_pbySerialBuffer=new BYTE[SERIALBUFFER_DELTA]; - m_dwSerialBufferSize=SERIALBUFFER_DELTA; - - // determine action from read or write flag - bool bWrite=false; - switch(m_dwMode & FA_OPERATION) - { - case FA_READ: - bWrite=false; - break; - case FA_WRITE: - bWrite=true; - break; - case FA_RW: - case FA_APPEND: - _ASSERT(FALSE); // cannot use serialization with files opened in rw mode - break; - } - - // action - if (bWrite) - { - // reserve some space for a header - m_dwSerialBufferPos=sizeof(SERIALIZEINFOHEADER); - } - else - { - // we need to read the block from a file - if (ReadBuffer(m_pbySerialBuffer, sizeof(SERIALIZEINFOHEADER)) != sizeof(SERIALIZEINFOHEADER)) - { - ClearSerialization(); - THROW_FILEEXCEPTIONEX(_T("Cannot read the specified amount of data from a file (reading serialization header)."), m_pszFilename, FERR_SERIALIZE, GetLastError()); - } - - // move forward - m_dwSerialBufferPos=sizeof(SERIALIZEINFOHEADER); - - // determine the size of the remaining data in file - SERIALIZEINFOHEADER* psih=(SERIALIZEINFOHEADER*)m_pbySerialBuffer; - DWORD dwSize=psih->dwToRead-sizeof(SERIALIZEINFOHEADER); - - // check the header crc - DWORD dwhc=icpf::crc32(m_pbySerialBuffer, sizeof(SERIALIZEINFOHEADER)-sizeof(DWORD)); - if (dwhc != psih->dwHeaderCRC32) - { - ClearSerialization(); - THROW_FILEEXCEPTIONEX(_T("Block corrupted. Header CRC check failed."), m_pszFilename, FERR_SERIALIZE, 0); - } - - // resize the buffer - ResizeSerialBuffer(psih->dwToRead); - - // refresh the psih - psih=(SERIALIZEINFOHEADER*)m_pbySerialBuffer; - - // read the remaining data - if (ReadBuffer(m_pbySerialBuffer+m_dwSerialBufferPos, dwSize) != dwSize) - { - ClearSerialization(); - THROW_FILEEXCEPTIONEX(_T("Cannot read specified amount of data from file (reading the after-header data)."), m_pszFilename, FERR_SERIALIZE, GetLastError()); - } - -#ifndef DISABLE_CRYPT - // decrypt the data - if (dwFlags & BF_ENCRYPTED) - { - if (AES256Decrypt(m_pbySerialBuffer+m_dwSerialBufferPos, dwSize, m_pszPassword, m_pbySerialBuffer+m_dwSerialBufferPos) < 0) - { - ClearSerialization(); - THROW_FILEEXCEPTIONEX(_T("Cannot decrypt the data read from the serialization file."), m_pszFilename, FERR_CRYPT, 0); - } - } -#endif - // NOTE: do not update the position - we need ptr at the beginning of data - - // now we are almost ready to retrieve data - only the crc check for the data - DWORD dwCRC=icpf::crc32(m_pbySerialBuffer+sizeof(SERIALIZEINFOHEADER), psih->dwDataSize-sizeof(SERIALIZEINFOHEADER)); - if (psih->dwCRC32 != dwCRC) - { - ClearSerialization(); - THROW_FILEEXCEPTIONEX(_T("CRC check of the data read from file failed."), m_pszFilename, FERR_SERIALIZE, GetLastError()); - } - } - - // make a mark - m_dwDataBlockFlags=dwFlags; - m_bSerializing=true; -} - -/////////////////////////////////////////////////////////////// -// -/////////////////////////////////////////////////////////////// -void CFileEx::EndDataBlock() -{ - // make sure everything is ok - _ASSERT(m_bSerializing && m_pbySerialBuffer != NULL); - - // type of operation - bool bWrite=false; - switch(m_dwMode & FA_OPERATION) - { - case FA_READ: - bWrite=false; - break; - case FA_WRITE: - bWrite=true; - break; - case FA_RW: - case FA_APPEND: - _ASSERT(FALSE); // cannot use serialization with files opened in rw mode - break; - } - - // when writing - make a header, ...; when reading - do nothing important - if (bWrite) - { - // check if there is any data - if (m_dwSerialBufferPos == sizeof(SERIALIZEINFOHEADER)) - return; // no data has been serialized - - // fill the header (real data information) - SERIALIZEINFOHEADER *psih=(SERIALIZEINFOHEADER*)m_pbySerialBuffer; - psih->dwDataSize=m_dwSerialBufferPos; - psih->dwCRC32=icpf::crc32(m_pbySerialBuffer+sizeof(SERIALIZEINFOHEADER), m_dwSerialBufferPos-sizeof(SERIALIZEINFOHEADER)); - -#ifndef DISABLE_CRYPT - // we could encrypt the data here if needed - if (m_dwDataBlockFlags & BF_ENCRYPTED) - { - int iRes=AES256Crypt(m_pbySerialBuffer+sizeof(SERIALIZEINFOHEADER), m_dwSerialBufferPos-sizeof(SERIALIZEINFOHEADER), m_pszPassword, m_pbySerialBuffer+sizeof(SERIALIZEINFOHEADER)); - if (iRes < 0) - { - ClearSerialization(); - THROW_FILEEXCEPTIONEX(_T("Cannot encrypt the data to store."), m_pszFilename, FERR_CRYPT, 0); - } - - // fill the header - psih->dwToRead=iRes+sizeof(SERIALIZEINFOHEADER); - } - else - { -#endif - // the rest of header - psih->dwToRead=m_dwSerialBufferPos; -#ifndef DISABLE_CRYPT - } -#endif - - // calc the header crc - psih->dwHeaderCRC32=icpf::crc32(m_pbySerialBuffer, sizeof(SERIALIZEINFOHEADER)-sizeof(DWORD)); - - // write the buffer - WriteBuffer(m_pbySerialBuffer, psih->dwToRead); - } - - // remove all the traces of serializing - ClearSerialization(); -} - -/////////////////////////////////////////////////////////////// -// -/////////////////////////////////////////////////////////////// -void CFileEx::SWrite(void* pData, DWORD dwSize) -{ - InternalAppendSerialBuffer(pData, dwSize); -} - -/////////////////////////////////////////////////////////////// -// -/////////////////////////////////////////////////////////////// -void CFileEx::SRead(void* pData, DWORD dwSize) -{ - InternalReadSerialBuffer(pData, dwSize); -} - -#ifdef _MFC_VER - -CFileEx& CFileEx::operator<<(CString strData) -{ - DWORD dwLen=strData.GetLength(); - SWrite(&dwLen, sizeof(DWORD)); - SWrite(strData.GetBuffer(1), dwLen); - strData.ReleaseBuffer(); - return *this; -} - -CFileEx& CFileEx::operator>>(CString& strData) -{ - DWORD dwLen; - SRead(&dwLen, sizeof(DWORD)); - PTSTR pszData=strData.GetBuffer(dwLen+1); - try - { - SRead(pszData, dwLen); - } - catch(...) - { - pszData[dwLen]=_T('\0'); - strData.ReleaseBuffer(); - throw; - } - - pszData[dwLen]=_T('\0'); - strData.ReleaseBuffer(); - return *this; -} - -#endif - -/////////////////////////////////////////////////////////////// -// -/////////////////////////////////////////////////////////////// -void CFileEx::ClearSerialization() -{ - // remove all the traces of serializing - delete [] m_pbySerialBuffer; - m_pbySerialBuffer=NULL; - m_dwSerialBufferSize=0; - m_dwSerialBufferPos=0; - m_bSerializing=false; -} - -/////////////////////////////////////////////////////////////// -// -/////////////////////////////////////////////////////////////// -void CFileEx::InternalReadSerialBuffer(void* pData, DWORD dwLen) -{ - // check if we are reading - _ASSERT((m_dwMode & FA_OPERATION) == FA_READ); - - // check the ranges - if (m_dwSerialBufferPos+dwLen > m_dwSerialBufferSize) - { - // throw an exception - read beyond the data range in a given object - THROW_FILEEXCEPTIONEX(_T("Trying to read the serialization data beyond the range."), m_pszFilename, FERR_MEMORY, GetLastError()); - } - - // read the data - memcpy(pData, m_pbySerialBuffer+m_dwSerialBufferPos, dwLen); - m_dwSerialBufferPos+=dwLen; -} - -/////////////////////////////////////////////////////////////// -// -/////////////////////////////////////////////////////////////// -void CFileEx::InternalAppendSerialBuffer(void* pData, DWORD dwCount) -{ - // check if we are writing - _ASSERT((m_dwMode & FA_OPERATION) == FA_WRITE); - - // check serial buffer size (if there is enough room for the data) - if (m_dwSerialBufferPos+dwCount > m_dwSerialBufferSize) - { - // we need a buffer reallocation - DWORD dwDelta=((dwCount/SERIALBUFFER_DELTA)+1)*SERIALBUFFER_DELTA; - - // alloc the new buffer - ResizeSerialBuffer(m_dwSerialBufferSize+dwDelta); - } - - // real storage of the data - if (dwCount > 0) - { - memcpy(m_pbySerialBuffer+m_dwSerialBufferPos, pData, dwCount); - m_dwSerialBufferPos+=dwCount; - } -} - -/////////////////////////////////////////////////////////////// -// -/////////////////////////////////////////////////////////////// -void CFileEx::ResizeSerialBuffer(DWORD dwNewLen) -{ - // alloc the new buffer - BYTE* pbyNewBuffer=new BYTE[dwNewLen]; - - // copy the old data into the new one - DWORD dwCount=min(m_dwSerialBufferPos, dwNewLen); - if (m_dwSerialBufferPos > 0) - memcpy(pbyNewBuffer, m_pbySerialBuffer, dwCount); - - // delete the old buffer - delete [] m_pbySerialBuffer; - - // set the new buffer inplace and update the internal size - m_pbySerialBuffer=pbyNewBuffer; - m_dwSerialBufferSize=dwNewLen; -} - -/////////////////////////////////////////////////////////////// -// (Internal) Functions reads line of text from text file -// Only for buffered operation -// pszStr [out] - string that was read from file -// dwMaxLen [in] - size of the string buffer -/////////////////////////////////////////////////////////////// -bool CFileEx::InternalReadString(TCHAR* pszStr, DWORD dwMaxLen) -{ - _ASSERT(m_hFile != NULL); // file wasn't opened - error opening or you've forgotten to do so ? - - // last time was writing - free buffer - if (m_bLastOperation) - { - Flush(); - m_bLastOperation=false; - } - - // zero all the string - memset(pszStr, 0, dwMaxLen*sizeof(TCHAR)); - - // additional vars - DWORD dwStrPos=0; // current pos in external buffer - bool bSecondPass=false; // if there is need to check data for 0x0a char - - // copy each char into pszString - while(true) - { - // if buffer is empty - fill it - if (m_dwDataCount == 0 || m_dwCurrentPos == m_dwDataCount) - { - if (ReadPacket() == 0) - return _tcslen(pszStr) != 0; - } - - // skipping 0x0a in second pass - if (bSecondPass) - { - if (m_pbyBuffer[m_dwCurrentPos] == 0x0a) - m_dwCurrentPos++; - return true; - } - - // now process chars - while (m_dwCurrentPos < m_dwDataCount) - { - if (m_pbyBuffer[m_dwCurrentPos] == 0x0d) - { - bSecondPass=true; - m_dwCurrentPos++; - break; - } - else if (m_pbyBuffer[m_dwCurrentPos] == 0x0a) - { - m_dwCurrentPos++; - return true; - } - else - { - if (dwStrPos < dwMaxLen-1) - pszStr[dwStrPos++]=m_pbyBuffer[m_dwCurrentPos]; - m_dwCurrentPos++; - } - } - } - - return false; -} - -/////////////////////////////////////////////////////////////// -// (Internal) Sets file pointer in a file -// llOffset [in] - position to move to -// uiFrom [in] - type of moving (see Platform SDK on -// SetFilePointer) -/////////////////////////////////////////////////////////////// -LONGLONG CFileEx::InternalSeek(LONGLONG llOffset, UINT uiFrom) -{ - LARGE_INTEGER li; - li.QuadPart = llOffset; - li.LowPart = SetFilePointer (m_hFile, li.LowPart, &li.HighPart, uiFrom); - - if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) - { - // error seeking - throw an exception - THROW_FILEEXCEPTIONEX(_T("Seek error."), m_pszFilename, FERR_SEEK, GetLastError()); - } - - return li.QuadPart; -} Index: ch/FileEx.h =================================================================== diff -u -N --- ch/FileEx.h (revision 0) +++ ch/FileEx.h (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,249 @@ +/************************************************************************ + Copy Handler 1.x - program for copying data in Microsoft Windows + systems. + Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. +*************************************************************************/ +/************************************************************************* + File: File.h + Version: 1.0 + Author: Ixen Gerthannes (ixen@interia.pl) + File description: + Contain class that handle buffered and unbuffered access to + file. Primarily designed to work without mfc. Possible use + with ms foundation classes. + Classes: + CFileException (based on CException) + - exception class designed for usage with class CFile + (not MFC based). + - when used with MFC class name is CFileExException + CFile + - handles file-based operations (buffered and + unbuffered): + - reading/writing of data buffers + - reading/writing of text lines (for text files) + - reading/writing values of internal types (int, + ...) + - when used with MFC class name is CFileEx +*************************************************************************/ +#ifndef __FILE_H__ +#define __FILE_H__ + +#pragma warning (disable : 4786) + +#include "ExceptionEx.h" + +#ifndef __FUNCTION__ + #define __FUNCTION__ "" +#endif + +#define THROW_FILEEXCEPTIONEX(str_reason, filename, app_code, last_error) throw new CFileExceptionEx(__FILE__, __LINE__, __FUNCTION__, str_reason, filename, app_code, last_error) + +// File exception errors +#define FERR_UNKNOWN 0 +#define FERR_OPEN 1 +#define FERR_CLOSE 2 +#define FERR_READ 3 +#define FERR_WRITE 4 +#define FERR_SEEK 5 +#define FERR_EOF 6 /* eof encountered - currently unused*/ +#define FERR_SETEOF 7 /* error while setting an eof in file */ +#define FERR_GETSIZE 8 /* error getting file size */ +#define FERR_SERIALIZE 9 /* serialization error */ +#define FERR_MEMORY 10 /* trying to read the data beyond the index */ +#define FERR_CRYPT 11 /* encryption/decryption error */ + +class CFileExceptionEx : public CExceptionEx +{ +public: + CFileExceptionEx(PCTSTR pszSrcFile, DWORD dwLine, PCTSTR pszFunc, PCTSTR pszReason, PCTSTR pszFilename, DWORD dwReason=FERR_UNKNOWN, DWORD dwLastError=0) : CExceptionEx(pszSrcFile, dwLine, pszFunc, pszReason, dwReason, dwLastError) { SetFilename(pszFilename); }; + CFileExceptionEx(PCTSTR pszSrcFile, DWORD dwLine, PCTSTR pszFunc, TCHAR* pszReason, PCTSTR pszFilename, DWORD dwReason=FERR_UNKNOWN, DWORD dwLastError=0) : CExceptionEx(pszSrcFile, dwLine, pszFunc, pszReason, dwReason, dwLastError) { SetFilename(pszFilename); }; + virtual ~CFileExceptionEx() { delete [] m_pszFilename; }; + + virtual int RegisterInfo(__EXCPROPINFO* pInfo) + { + // if the pInfo is null - return count of a needed props + if (pInfo == NULL) + return 1+CExceptionEx::RegisterInfo(NULL); + + // call base class RegisterInfo + size_t tIndex=CExceptionEx::RegisterInfo(pInfo); + + // function has to register the info to be displayed (called from within GetInfo) + RegisterProp(pInfo+tIndex+0, _T("Filename"), PropType::dtPtrToString, &m_pszFilename); + + return 1; + }; + +protected: + void SetFilename(PCTSTR pszFilename) { if (pszFilename) { m_pszFilename=new TCHAR[_tcslen(pszFilename)+1]; _tcscpy(m_pszFilename, pszFilename); } else m_pszFilename=NULL; }; + +public: + TCHAR* m_pszFilename; +}; + +// header information for serialziation block +struct SERIALIZEINFOHEADER +{ + // main header + DWORD dwDataSize; // size of the meaningful data (with the header size) + DWORD dwToRead; // count of data to read at once (may be greater than dwDataSize) + DWORD dwCRC32; // crc32 of the data (only the data part) + + // helper + DWORD dwHeaderCRC32; // the above's header crc +}; + +// file access modes +#define FA_OPERATION 0x7fff +#define FA_READ 0 +#define FA_WRITE 1 +#define FA_RW 2 +#define FA_APPEND 3 /* second rw access but with seek to end */ + +// additional mode mods +#define FA_BUFFERED 0x8000 /* if this is buffered */ + +// begin data block flags +#define BF_NONE 0x00 +#define BF_ENCRYPTED 0x01 + +// currently CSerializer will be the same as CFileEx (later it may change) +#define CSerializer CFileEx + +// real file class +class CFileEx +{ +public: + // construction/destruction + CFileEx() { m_hFile=NULL; m_pszFilename=NULL; m_dwMode=0; + m_dwBufferSize=0; m_pbyBuffer=NULL; m_dwCurrentPos=0; + m_dwDataCount=0; m_bBuffered=false; m_bLastOperation=false; m_bRememberedState=false; + m_pbySerialBuffer=NULL; m_dwSerialBufferSize=NULL; m_dwSerialBufferPos=0; m_bSerializing=0; +#ifndef DISABLE_CRYPT + m_pszPassword=NULL; +#endif + }; + ~CFileEx() { Close(); +#ifndef DISABLE_CRYPT + delete [] m_pszPassword; +#endif + }; + + // opening/closing file + void Open(PCTSTR pszFilename, DWORD dwAccess, DWORD dwBufferSize=4096); + void Close(); + + // flushing (flushes all the internal's buffer data to the external file) + void Flush(); + + // reads or writes the data from/to a file (uses buffering for this if enabled) + DWORD ReadBuffer(void* pBuffer, DWORD dwSize); + DWORD WriteBuffer(void* pBuffer, DWORD dwSize); + + // handling the lines of text in a file (autodetecting the windows/unix style of line ending) + bool ReadLine(TCHAR* pszStr, DWORD dwMaxLen); + void WriteLine(TCHAR* pszString); + + // position related functions + void Seek(LONGLONG llOffset, UINT uiFrom); // seeks in a file - flushes buffers before + LONGLONG GetPos(); // returns the current position of a file pointer (corrected by a pos in the internal buffer) + + // size related functions + void SetEndOfFile(); // sets the end of file in the current file pointer place + LONGLONG GetSize(); // retrieves the size of this file + + // buffered/unbuffered state managing + void SetBuffering(bool bEnable=true, DWORD dwSize=4096); // on-the-fly changing operation types + bool IsBuffered() { return m_bBuffered; }; + DWORD GetBufferSize() { return m_dwBufferSize; }; + + void SwitchToUnbuffered(); // remembers current state and changes to unbuffered + void SwitchToBuffered(); // remembers current state and changes to buffered + void RestoreState(); // restores (un)buffered last state + + // serialization (block operation) + void BeginDataBlock(DWORD dwFlags=BF_NONE); + void EndDataBlock(); + +#ifndef DISABLE_CRYPT + void SetPassword(PCTSTR pszPass); +#endif + // serialization stuff + void SWrite(void* pData, DWORD dwSize); + void SRead(void* pData, DWORD dwSize); + + bool IsStoring() { return (m_dwMode & FA_OPERATION) == FA_WRITE; }; + bool IsLoading() { return (m_dwMode & FA_OPERATION) == FA_READ; }; + + // storing data + template CFileEx& operator<<(T tData) { SWrite(&tData, sizeof(T)); return *this; }; + +#ifdef _MFC_VER + CFileEx& operator<<(CString strData); +#endif + + // reading data + template CFileEx& operator>>(T& tData) { SRead(&tData, sizeof(T)); return *this; }; + +#ifdef _MFC_VER + CFileEx& operator>>(CString& strData); +#endif + +protected: + // serialization related internal functions + void InternalAppendSerialBuffer(void* pData, DWORD dwCount); + void ResizeSerialBuffer(DWORD dwNewLen); + void InternalReadSerialBuffer(void* pData, DWORD dwLen); + void ClearSerialization(); + + // file-buffering related operations + DWORD ReadPacket(); // reads next packet of data - for buffered operations + DWORD WritePacket(); // writes next packet of data - buffered only + + bool InternalReadString(TCHAR* pszStr, DWORD dwMaxLen); + LONGLONG InternalSeek(LONGLONG llOffset, UINT uiFrom); // real seek-w/o any flushing + +protected: + HANDLE m_hFile; // handle to file + TCHAR* m_pszFilename; // path to this file + DWORD m_dwMode; // mode in which this file has been opened + + bool m_bLastOperation; // false=>READ, true=>WRITE + + // read/write buffering + bool m_bBuffered; // is this file additionally buffered ? + DWORD m_dwBufferSize; // specifies internal buffer size + BYTE* m_pbyBuffer; // internal buffer address + DWORD m_dwCurrentPos; // current position in above buffer + DWORD m_dwDataCount; // count of data in buffer (counting from beginning) + + // serialization stuff + bool m_bSerializing; // are we currently serializing (between BeginDataBlock and EndDataBlock) ? + BYTE* m_pbySerialBuffer; // buffer used for serialization + DWORD m_dwSerialBufferSize; // current size of the serialization buffer + DWORD m_dwSerialBufferPos; // current position in the serialization buffer + DWORD m_dwDataBlockFlags; // flags used in begin data block + +#ifndef DISABLE_CRYPT + // encryption related + TCHAR *m_pszPassword; +#endif + // state + bool m_bRememberedState; // was state remembered (it means also that last state was different) ? +}; + +#endif Index: modules/App Framework/FileEx.h =================================================================== diff -u -N --- modules/App Framework/FileEx.h (revision 3e1186252ab31f63d86d86c4b0ff593cfffbefde) +++ modules/App Framework/FileEx.h (revision 0) @@ -1,249 +0,0 @@ -/************************************************************************ - Copy Handler 1.x - program for copying data in Microsoft Windows - systems. - Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. -*************************************************************************/ -/************************************************************************* - File: File.h - Version: 1.0 - Author: Ixen Gerthannes (ixen@interia.pl) - File description: - Contain class that handle buffered and unbuffered access to - file. Primarily designed to work without mfc. Possible use - with ms foundation classes. - Classes: - CFileException (based on CException) - - exception class designed for usage with class CFile - (not MFC based). - - when used with MFC class name is CFileExException - CFile - - handles file-based operations (buffered and - unbuffered): - - reading/writing of data buffers - - reading/writing of text lines (for text files) - - reading/writing values of internal types (int, - ...) - - when used with MFC class name is CFileEx -*************************************************************************/ -#ifndef __FILE_H__ -#define __FILE_H__ - -#pragma warning (disable : 4786) - -#include "ExceptionEx.h" - -#ifndef __FUNCTION__ - #define __FUNCTION__ "" -#endif - -#define THROW_FILEEXCEPTIONEX(str_reason, filename, app_code, last_error) throw new CFileExceptionEx(__FILE__, __LINE__, __FUNCTION__, str_reason, filename, app_code, last_error) - -// File exception errors -#define FERR_UNKNOWN 0 -#define FERR_OPEN 1 -#define FERR_CLOSE 2 -#define FERR_READ 3 -#define FERR_WRITE 4 -#define FERR_SEEK 5 -#define FERR_EOF 6 /* eof encountered - currently unused*/ -#define FERR_SETEOF 7 /* error while setting an eof in file */ -#define FERR_GETSIZE 8 /* error getting file size */ -#define FERR_SERIALIZE 9 /* serialization error */ -#define FERR_MEMORY 10 /* trying to read the data beyond the index */ -#define FERR_CRYPT 11 /* encryption/decryption error */ - -class CFileExceptionEx : public CExceptionEx -{ -public: - CFileExceptionEx(PCTSTR pszSrcFile, DWORD dwLine, PCTSTR pszFunc, PCTSTR pszReason, PCTSTR pszFilename, DWORD dwReason=FERR_UNKNOWN, DWORD dwLastError=0) : CExceptionEx(pszSrcFile, dwLine, pszFunc, pszReason, dwReason, dwLastError) { SetFilename(pszFilename); }; - CFileExceptionEx(PCTSTR pszSrcFile, DWORD dwLine, PCTSTR pszFunc, TCHAR* pszReason, PCTSTR pszFilename, DWORD dwReason=FERR_UNKNOWN, DWORD dwLastError=0) : CExceptionEx(pszSrcFile, dwLine, pszFunc, pszReason, dwReason, dwLastError) { SetFilename(pszFilename); }; - virtual ~CFileExceptionEx() { delete [] m_pszFilename; }; - - virtual int RegisterInfo(__EXCPROPINFO* pInfo) - { - // if the pInfo is null - return count of a needed props - if (pInfo == NULL) - return 1+CExceptionEx::RegisterInfo(NULL); - - // call base class RegisterInfo - size_t tIndex=CExceptionEx::RegisterInfo(pInfo); - - // function has to register the info to be displayed (called from within GetInfo) - RegisterProp(pInfo+tIndex+0, _T("Filename"), PropType::dtPtrToString, &m_pszFilename); - - return 1; - }; - -protected: - void SetFilename(PCTSTR pszFilename) { if (pszFilename) { m_pszFilename=new TCHAR[_tcslen(pszFilename)+1]; _tcscpy(m_pszFilename, pszFilename); } else m_pszFilename=NULL; }; - -public: - TCHAR* m_pszFilename; -}; - -// header information for serialziation block -struct SERIALIZEINFOHEADER -{ - // main header - DWORD dwDataSize; // size of the meaningful data (with the header size) - DWORD dwToRead; // count of data to read at once (may be greater than dwDataSize) - DWORD dwCRC32; // crc32 of the data (only the data part) - - // helper - DWORD dwHeaderCRC32; // the above's header crc -}; - -// file access modes -#define FA_OPERATION 0x7fff -#define FA_READ 0 -#define FA_WRITE 1 -#define FA_RW 2 -#define FA_APPEND 3 /* second rw access but with seek to end */ - -// additional mode mods -#define FA_BUFFERED 0x8000 /* if this is buffered */ - -// begin data block flags -#define BF_NONE 0x00 -#define BF_ENCRYPTED 0x01 - -// currently CSerializer will be the same as CFileEx (later it may change) -#define CSerializer CFileEx - -// real file class -class CFileEx -{ -public: - // construction/destruction - CFileEx() { m_hFile=NULL; m_pszFilename=NULL; m_dwMode=0; - m_dwBufferSize=0; m_pbyBuffer=NULL; m_dwCurrentPos=0; - m_dwDataCount=0; m_bBuffered=false; m_bLastOperation=false; m_bRememberedState=false; - m_pbySerialBuffer=NULL; m_dwSerialBufferSize=NULL; m_dwSerialBufferPos=0; m_bSerializing=0; -#ifndef DISABLE_CRYPT - m_pszPassword=NULL; -#endif - }; - ~CFileEx() { Close(); -#ifndef DISABLE_CRYPT - delete [] m_pszPassword; -#endif - }; - - // opening/closing file - void Open(PCTSTR pszFilename, DWORD dwAccess, DWORD dwBufferSize=4096); - void Close(); - - // flushing (flushes all the internal's buffer data to the external file) - void Flush(); - - // reads or writes the data from/to a file (uses buffering for this if enabled) - DWORD ReadBuffer(void* pBuffer, DWORD dwSize); - DWORD WriteBuffer(void* pBuffer, DWORD dwSize); - - // handling the lines of text in a file (autodetecting the windows/unix style of line ending) - bool ReadLine(TCHAR* pszStr, DWORD dwMaxLen); - void WriteLine(TCHAR* pszString); - - // position related functions - void Seek(LONGLONG llOffset, UINT uiFrom); // seeks in a file - flushes buffers before - LONGLONG GetPos(); // returns the current position of a file pointer (corrected by a pos in the internal buffer) - - // size related functions - void SetEndOfFile(); // sets the end of file in the current file pointer place - LONGLONG GetSize(); // retrieves the size of this file - - // buffered/unbuffered state managing - void SetBuffering(bool bEnable=true, DWORD dwSize=4096); // on-the-fly changing operation types - bool IsBuffered() { return m_bBuffered; }; - DWORD GetBufferSize() { return m_dwBufferSize; }; - - void SwitchToUnbuffered(); // remembers current state and changes to unbuffered - void SwitchToBuffered(); // remembers current state and changes to buffered - void RestoreState(); // restores (un)buffered last state - - // serialization (block operation) - void BeginDataBlock(DWORD dwFlags=BF_NONE); - void EndDataBlock(); - -#ifndef DISABLE_CRYPT - void SetPassword(PCTSTR pszPass); -#endif - // serialization stuff - void SWrite(void* pData, DWORD dwSize); - void SRead(void* pData, DWORD dwSize); - - bool IsStoring() { return (m_dwMode & FA_OPERATION) == FA_WRITE; }; - bool IsLoading() { return (m_dwMode & FA_OPERATION) == FA_READ; }; - - // storing data - template CFileEx& operator<<(T tData) { SWrite(&tData, sizeof(T)); return *this; }; - -#ifdef _MFC_VER - CFileEx& operator<<(CString strData); -#endif - - // reading data - template CFileEx& operator>>(T& tData) { SRead(&tData, sizeof(T)); return *this; }; - -#ifdef _MFC_VER - CFileEx& operator>>(CString& strData); -#endif - -protected: - // serialization related internal functions - void InternalAppendSerialBuffer(void* pData, DWORD dwCount); - void ResizeSerialBuffer(DWORD dwNewLen); - void InternalReadSerialBuffer(void* pData, DWORD dwLen); - void ClearSerialization(); - - // file-buffering related operations - DWORD ReadPacket(); // reads next packet of data - for buffered operations - DWORD WritePacket(); // writes next packet of data - buffered only - - bool InternalReadString(TCHAR* pszStr, DWORD dwMaxLen); - LONGLONG InternalSeek(LONGLONG llOffset, UINT uiFrom); // real seek-w/o any flushing - -protected: - HANDLE m_hFile; // handle to file - TCHAR* m_pszFilename; // path to this file - DWORD m_dwMode; // mode in which this file has been opened - - bool m_bLastOperation; // false=>READ, true=>WRITE - - // read/write buffering - bool m_bBuffered; // is this file additionally buffered ? - DWORD m_dwBufferSize; // specifies internal buffer size - BYTE* m_pbyBuffer; // internal buffer address - DWORD m_dwCurrentPos; // current position in above buffer - DWORD m_dwDataCount; // count of data in buffer (counting from beginning) - - // serialization stuff - bool m_bSerializing; // are we currently serializing (between BeginDataBlock and EndDataBlock) ? - BYTE* m_pbySerialBuffer; // buffer used for serialization - DWORD m_dwSerialBufferSize; // current size of the serialization buffer - DWORD m_dwSerialBufferPos; // current position in the serialization buffer - DWORD m_dwDataBlockFlags; // flags used in begin data block - -#ifndef DISABLE_CRYPT - // encryption related - TCHAR *m_pszPassword; -#endif - // state - bool m_bRememberedState; // was state remembered (it means also that last state was different) ? -}; - -#endif Index: ch/IniFile.cpp =================================================================== diff -u -N --- ch/IniFile.cpp (revision 0) +++ ch/IniFile.cpp (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,817 @@ +/************************************************************************ + Copy Handler 1.x - program for copying data in Microsoft Windows + systems. + Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. +*************************************************************************/ + +#include "stdafx.h" +#include "IniFile.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +#define MAX_LINE 8192 + +/////////////////////////////////////////////////////////////// +// Opens .ini file, reads all lines from it and keep in memory +// pszFilename [in] - path to .ini file +// pszOneSection [in] - ptr to a string with section's name +// which we want to read +/////////////////////////////////////////////////////////////// +void CIniFile::Open(LPCTSTR pszFilename, PCTSTR pszOneSection, bool bEscapeConversion) +{ + // remember file name + m_pszFilename=new TCHAR[_tcslen(pszFilename)+1]; + _tcscpy(m_pszFilename, pszFilename); + + // count the length of a section member + size_t tSectionLen=(size_t)-1; + if (pszOneSection) + tSectionLen=_tcslen(pszOneSection); + + // open file + CFileEx file; + file.Open(pszFilename, FA_READ | FA_BUFFERED); // may throw an exception + + // read all lines from file and process it + TCHAR szLine[MAX_LINE]; + size_t ulLen; + + // config object - zero members + _PROFILE* pcfg=NULL; // current config object + _SECTION* psect=NULL; // current section + _ENTRY* pentry=NULL; // current entry + TCHAR* pszSeparator; // used for separating keys from values + + while(file.ReadLine(szLine, MAX_LINE)) + { + // process + ulLen=_tcslen(szLine); // length of read string + + if (ulLen == 0 || szLine[0] == '#') + continue; + + // if it's config-selector <...> + if (ulLen > 1 && szLine[0] == _T('<') && szLine[ulLen-1] == _T('>')) + { + // config-selector + // create new profile + pcfg=new _PROFILE; + pcfg->pszProfileName=new TCHAR[ulLen-1]; + _tcsncpy(pcfg->pszProfileName, szLine+1, ulLen-2); + pcfg->pszProfileName[ulLen-2]=_T('\0'); + m_vConfigProfiles.push_back(pcfg); + } + else if (ulLen > 1 && szLine[0] == _T('[') && szLine[ulLen-1] == _T(']')) + { + if (pszOneSection && psect != NULL) // break if the needed section has been read already + break; + + if (!pszOneSection || (ulLen-2 == tSectionLen && _tcsncmp(pszOneSection, szLine+1, ulLen-2) == 0)) + { + // section-selector + if (pcfg == NULL) + { + // encountered section without config-selector - create default one + pcfg=new _PROFILE; + pcfg->pszProfileName=new TCHAR[4]; + _tcscpy(pcfg->pszProfileName, _T("000")); + m_vConfigProfiles.push_back(pcfg); + } + + // new section + psect=new _SECTION; + psect->pszSectionName=new TCHAR[ulLen-1]; + _tcsncpy(psect->pszSectionName, szLine+1, ulLen-2); + psect->pszSectionName[ulLen-2]=_T('\0'); + pcfg->vSections.push_back(psect); + } + } + else + { + if (!pszOneSection || psect != NULL) + { + // normal line (not empty) + if (pcfg == NULL) + { + // config-selector doesn't exist - create default + pcfg=new _PROFILE; + pcfg->pszProfileName=new TCHAR[4]; + _tcscpy(pcfg->pszProfileName, _T("000")); + m_vConfigProfiles.push_back(pcfg); + } + + if (psect == NULL) + { + // section doesn't exist -create default + psect=new _SECTION; + psect->pszSectionName=new TCHAR[4]; + _tcscpy(psect->pszSectionName, _T("000")); + pcfg->vSections.push_back(psect); + } + + // analyze string and copy data + pentry=new _ENTRY; + pszSeparator=_tcschr(szLine, _T('=')); + if (pszSeparator != NULL) + { + pszSeparator[0]=_T('\0'); + pszSeparator++; + + pentry->pszKey=new TCHAR[_tcslen(szLine)+1]; + _tcscpy(pentry->pszKey, szLine); + + // now the value - correct the ansi escape sequences if needed + if (bEscapeConversion) + { +// int iLen=_tcslen(pszSeparator); + UnescapeString(pszSeparator); + } + pentry->pszValue=new TCHAR[_tcslen(pszSeparator)+1]; + _tcscpy(pentry->pszValue, pszSeparator); + } + else + { + // no '=' sign in the line + pentry->pszKey=NULL; + if (bEscapeConversion) + UnescapeString(szLine); + pentry->pszValue=new TCHAR[_tcslen(szLine)+1]; + _tcscpy(pentry->pszValue, szLine); + } + + psect->vEntries.push_back(pentry); + } + } + } + + file.Close(); +} + +void CIniFile::UnescapeString(PTSTR pszData) +{ + PTSTR pszOut=pszData; + while (*pszData != 0) + { + if (*pszData == _T('\\')) + { + pszData++; + switch(*pszData++) + { + case _T('t'): + *pszOut++=_T('\t'); + break; + case _T('r'): + *pszOut++=_T('\r'); + break; + case _T('n'): + *pszOut++=_T('\n'); + break; + default: + *pszOut++=_T('\\'); + } + } + else + *pszOut++=*pszData++; + } + *pszOut=_T('\0'); +} + +/////////////////////////////////////////////////////////////// +// Saves data from memory to an .ini file +/////////////////////////////////////////////////////////////// +void CIniFile::Save() +{ + // if saving data is needed + if (!m_bModified) + return; + + _ASSERT(m_pszFilename); // is there a filename + + // open file for writing + CFileEx file; + file.Open(m_pszFilename, FA_WRITE | FA_BUFFERED); // may throw an exception + + // enumerate through all data and store it to the file + TCHAR szLine[MAX_LINE]; + int iLen; + vector<_PROFILE*>::const_iterator cit=m_vConfigProfiles.begin(); + vector<_SECTION*>::const_iterator sit; + vector<_ENTRY*>::const_iterator eit; + while (cit != m_vConfigProfiles.end()) + { + // store profile name + iLen=_stprintf(szLine, _T("<%s>"), (*cit)->pszProfileName); + file.WriteLine(szLine); + + // enumerate through sections + sit=(*cit)->vSections.begin(); + while (sit != (*cit)->vSections.end()) + { + // write section name + iLen=_stprintf(szLine, _T("[%s]"), (*sit)->pszSectionName); + file.WriteLine(szLine); + + // enumerate through attributes + eit=(*sit)->vEntries.begin(); + while(eit != (*sit)->vEntries.end()) + { + // store data + iLen=_stprintf(szLine, _T("%s=%s"), (*eit)->pszKey, (*eit)->pszValue); + file.WriteLine(szLine); + + // analyze next element + eit++; + } + + // cosmetics + file.WriteLine(_T("")); + + // analyze next section + sit++; + } + + // analyze next profile + cit++; + } + + // close file + file.Close(); + + m_bModified=false; +} + +/////////////////////////////////////////////////////////////// +// Closes the .ini file. Causes data from memory to be saved, +// and frees all the memory. +/////////////////////////////////////////////////////////////// +void CIniFile::Close() +{ + // save file and free all data (doesn't matter if save succeeded) + try + { + Save(); + } + catch(...) + { + FreeData(); + throw; + } + FreeData(); +} + +/////////////////////////////////////////////////////////////// +// Gets a string from .ini file (more precisely from the data +// from memory). +// pszConfig [in] - profile name +// pszSection [in] - section name +// pszKey [in] - key name +// pszValue [out] - value name (read from file or default) +// pszDefault [in/out] - default value if there wasn't pszKey +// in .ini file. +// Ret Value [out] - if the pszValue was read from file (=true) +// or is the default one (=false) +/////////////////////////////////////////////////////////////// +bool CIniFile::GetStr(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, LPTSTR pszValue, LPCTSTR pszDefault) +{ + // localize config + vector<_PROFILE*>::const_iterator cit=m_vConfigProfiles.begin(); + while (cit != m_vConfigProfiles.end()) + { + // if this is not a config name - enumerate next + if (_tcsicmp((*cit)->pszProfileName, pszConfig) != 0) + { + cit++; + continue; + } + + // config found - check for section + vector<_SECTION*>::const_iterator sit=(*cit)->vSections.begin(); + while (sit != (*cit)->vSections.end()) + { + // continue if this is not the needed section + if (_tcsicmp((*sit)->pszSectionName, pszSection) != 0) + { + sit++; + continue; + } + + // now - localize key in section + vector<_ENTRY*>::const_iterator eit=(*sit)->vEntries.begin(); + while (eit != (*sit)->vEntries.end()) + { + // continue if needed + if (_tcsicmp((*eit)->pszKey, pszKey) != 0) + { + eit++; + continue; + } + + // read associated value - from file + _tcscpy(pszValue, (*eit)->pszValue); + m_bDefault=false; + return true; + } + + // section was found, but key in it wasn't + _tcscpy(pszValue, pszDefault); + m_bDefault=true; + return false; + } + + // section not found + _tcscpy(pszValue, pszDefault); + m_bDefault=true; + return false; + } + + // nothing + _tcscpy(pszValue, pszDefault); + m_bDefault=true; + return false; +} + +/////////////////////////////////////////////////////////////// +// Reads string from .ini file +// Look @ CIniFile::GetStr for param desc +// Ret Value [out] - string that was read (or the default one) +/////////////////////////////////////////////////////////////// +LPTSTR CIniFile::GetString(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, LPTSTR pszValue, LPCTSTR pszDefault) +{ + GetStr(pszConfig, pszSection, pszKey, pszValue, pszDefault); + return pszValue; +} + +/////////////////////////////////////////////////////////////// +// Writes string to .ini file (to memory) +// For param desc's look @GetStr +// pszValue [in] - string to store under pszKey +/////////////////////////////////////////////////////////////// +void CIniFile::SetString(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, LPCTSTR pszValue) +{ + // localize config + vector<_PROFILE*>::const_iterator cit=m_vConfigProfiles.begin(); + _PROFILE* pcfg=NULL; + while (cit != m_vConfigProfiles.end()) + { + // if this is not a config name - enumerate next + if (_tcsicmp((*cit)->pszProfileName, pszConfig) != 0) + { + cit++; + continue; + } + + // found + pcfg=*cit; + break; + } + + // if section doesn't exist - create it + if (pcfg == NULL) + { + pcfg=new _PROFILE; + pcfg->pszProfileName=new TCHAR[_tcslen(pszConfig)+1]; + _tcscpy(pcfg->pszProfileName, pszConfig); + m_vConfigProfiles.push_back(pcfg); + } + + // config is ready - now search for section + vector<_SECTION*>::const_iterator sit=pcfg->vSections.begin(); + _SECTION* psect=NULL; + while (sit != pcfg->vSections.end()) + { + // continue if this is not the needed section + if (_tcsicmp((*sit)->pszSectionName, pszSection) != 0) + { + sit++; + continue; + } + + // found + psect=*sit; + break; + } + + // create section if doesn't exist + if (psect == NULL) + { + psect=new _SECTION; + psect->pszSectionName=new TCHAR[_tcslen(pszSection)+1]; + _tcscpy(psect->pszSectionName, pszSection); + pcfg->vSections.push_back(psect); + } + + // now entry... + vector<_ENTRY*>::const_iterator eit=psect->vEntries.begin(); + _ENTRY* pentry=NULL; + while (eit != psect->vEntries.end()) + { + // continue if needed + if (_tcsicmp((*eit)->pszKey, pszKey) != 0) + { + eit++; + continue; + } + + // found + pentry=*eit; + break; + } + + // create entry if needed + if (pentry == NULL) + { + pentry=new _ENTRY; + pentry->pszKey=new TCHAR[_tcslen(pszKey)+1]; + _tcscpy(pentry->pszKey, pszKey); + pentry->pszValue=NULL; + psect->vEntries.push_back(pentry); + } + + // copy value to entry->pszValue + if (pentry->pszValue != NULL) + delete [] pentry->pszValue; + + pentry->pszValue=new TCHAR[_tcslen(pszValue)+1]; + _tcscpy(pentry->pszValue, pszValue); + + m_bModified=true; +} + +/////////////////////////////////////////////////////////////// +// Sets the int value in the .ini file (memory) +// pszConfig, pszSection, pszKey [in] - position in .ini file +// iValue [in] - value to set +/////////////////////////////////////////////////////////////// +void CIniFile::SetInt(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, int iValue) +{ + TCHAR szBuffer[11]; + SetString(pszConfig, pszSection, pszKey, _itot(iValue, szBuffer, 10)); +} + +/////////////////////////////////////////////////////////////// +// Gets the int value from .ini file (memory) +// pszConfig, pszSection, pszKey [in] - position in .ini file +// iDefault [in] - default value - used if the file doesn't +// contain neede value +// pszBuffer [in] - buffer for internal processing (must +// contain at last 5 TCHARs). +// Ret Value [out] - value associated with the given position +/////////////////////////////////////////////////////////////// +int CIniFile::GetInt(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, int iDefault, LPTSTR pszBuffer) +{ + // get string and process it + if (GetStr(pszConfig, pszSection, pszKey, pszBuffer, _T(""))) + return _ttoi(pszBuffer); + else + return iDefault; +} + +/////////////////////////////////////////////////////////////// +// Sets the bool value in the .ini file (memory) +// pszConfig, pszSection, pszKey [in] - position in .ini file +// bValue [in] - value to set +/////////////////////////////////////////////////////////////// +void CIniFile::SetBool(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, bool bValue) +{ + TCHAR szBuffer[2]={ (TCHAR)(48+(bValue ? 1 : 0)), 0 }; + SetString(pszConfig, pszSection, pszKey, szBuffer); +} + +/////////////////////////////////////////////////////////////// +// Gets the bool value from .ini file (memory) +// pszConfig, pszSection, pszKey [in] - position in .ini file +// bDefault [in] - default value - used if the file doesn't +// contain needed value +// pszBuffer [in] - buffer for internal processing (must +// contain at last 2 TCHARs-better/safer is 1024). +// Ret Value [out] - value associated with the given position +/////////////////////////////////////////////////////////////// +bool CIniFile::GetBool(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, bool bDefault, LPTSTR pszBuffer) +{ + // get string and process it + if (GetStr(pszConfig, pszSection, pszKey, pszBuffer, _T(""))) + return pszBuffer[0] != _T('0'); + else + return bDefault; +} + +/////////////////////////////////////////////////////////////// +// Sets the int64 value in the .ini file (memory) +// pszConfig, pszSection, pszKey [in] - position in .ini file +// llValue [in] - value to set +/////////////////////////////////////////////////////////////// +void CIniFile::SetInt64(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, __int64 llValue) +{ + TCHAR szBuffer[21]; + SetString(pszConfig, pszSection, pszKey, _i64tot(llValue, szBuffer, 10)); +} + +/////////////////////////////////////////////////////////////// +// Gets the int64 value from .ini file (memory) +// pszConfig, pszSection, pszKey [in] - position in .ini file +// llDefault [in] - default value - used if the file doesn't +// contain needed value +// pszBuffer [in] - buffer for internal processing (must +// contain at last 9 TCHARs-better/safer is 1024). +// Ret Value [out] - value associated with the given position +/////////////////////////////////////////////////////////////// +__int64 CIniFile::GetInt64(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, __int64 llDefault, LPTSTR pszBuffer) +{ + // get string and process it + if (GetStr(pszConfig, pszSection, pszKey, pszBuffer, _T(""))) + return _ttoi64(pszBuffer); + else + return llDefault; +} + +/////////////////////////////////////////////////////////////// +// Gets the profile name at a given index in a file +// uiIndex [in] - index of profile to retrieve +// pszName [out] - name of the profile +/////////////////////////////////////////////////////////////// +void CIniFile::GetProfileName(UINT uiIndex, LPTSTR pszName) +{ + _tcscpy(pszName, m_vConfigProfiles.at(uiIndex)->pszProfileName); +} + +/////////////////////////////////////////////////////////////// +// Sets profile name at a given index +// uiIndex [in] - profile index +// pszName [in] - new profile name +/////////////////////////////////////////////////////////////// +void CIniFile::SetProfileName(UINT uiIndex, LPCTSTR pszName) +{ + delete [] m_vConfigProfiles.at(uiIndex)->pszProfileName; + m_vConfigProfiles.at(uiIndex)->pszProfileName=new TCHAR[_tcslen(pszName)+1]; + _tcscpy(m_vConfigProfiles.at(uiIndex)->pszProfileName, pszName); +} + +/////////////////////////////////////////////////////////////// +// Deletes one of the configurations (completely) +// uiIndex [in] - profile index to delete +/////////////////////////////////////////////////////////////// +void CIniFile::DeleteProfile(UINT uiIndex) +{ + m_vConfigProfiles.erase(m_vConfigProfiles.begin()+uiIndex); +} + +/////////////////////////////////////////////////////////////// +// Creates new profile in .ini file +// pszName [in] - new profile's name +/////////////////////////////////////////////////////////////// +void CIniFile::CreateProfile(LPCTSTR pszName) +{ + _PROFILE* pcfg=new _PROFILE; + pcfg->pszProfileName=new _TCHAR[_tcslen(pszName)+1]; + _tcscpy(pcfg->pszProfileName, pszName); +} + +/////////////////////////////////////////////////////////////// +// (Internal) Frees all data associated with this class +/////////////////////////////////////////////////////////////// +void CIniFile::FreeData() +{ + // free name string + delete [] m_pszFilename; + m_pszFilename=NULL; + + // other data + _PROFILE* pcfg=NULL; // current config object + _SECTION* psect=NULL; // current section + _ENTRY* pentry=NULL; // current entry + size_t uiIndex1=m_vConfigProfiles.size(), uiIndex2, uiIndex3; + while (uiIndex1--) + { + // delete profile name + pcfg=m_vConfigProfiles.at(uiIndex1); + delete [] pcfg->pszProfileName; + + // delete all sections + uiIndex2=pcfg->vSections.size(); + while (uiIndex2--) + { + // delete section name + psect=pcfg->vSections.at(uiIndex2); + delete [] psect->pszSectionName; + + // free all key=value strings + uiIndex3=psect->vEntries.size(); + while (uiIndex3--) + { + pentry=psect->vEntries.at(uiIndex3); + + // delete all values and this entry + delete [] pentry->pszKey; + delete [] pentry->pszValue; + delete pentry; + } + + // free this section + delete psect; + } + + // delete this profile + delete pcfg; + } + + m_vConfigProfiles.clear(); + m_bModified=false; + m_bDefault=false; +} + +void CIniFile::RemoveSection(LPCTSTR pszConfig, LPCTSTR pszSection) +{ + // localize section + _PROFILE *pcfg=NULL; + _SECTION *psect=NULL; + + vector<_PROFILE*>::iterator it=m_vConfigProfiles.begin(); + while (it != m_vConfigProfiles.end()) + { + pcfg=(*it); + if (_tcscmp(pcfg->pszProfileName, pszConfig) == 0) + break; + pcfg=NULL; + it++; + } + + if (pcfg == NULL) + return; + + // find the section + vector<_SECTION*>::iterator sit=pcfg->vSections.begin(); + while(sit != pcfg->vSections.end()) + { + psect=(*sit); + if (_tcscmp(psect->pszSectionName, pszSection) == 0) + break; + psect=NULL; + sit++; + } + + if (psect == NULL) + return; + + // delete + delete [] psect->pszSectionName; + + // free all key=value strings + size_t tIndex=psect->vEntries.size(); + _ENTRY* pentry; + while (tIndex--) + { + pentry=psect->vEntries.at(tIndex); + + // delete all values and this entry + delete [] pentry->pszKey; + delete [] pentry->pszValue; + delete pentry; + } + + // free this section + delete psect; + pcfg->vSections.erase(sit); +} + +void CIniFile::RemoveKey(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, bool bAllAfter) +{ + // localize section + _PROFILE *pcfg=NULL; + _SECTION *psect=NULL; + + vector<_PROFILE*>::iterator it=m_vConfigProfiles.begin(); + while (it != m_vConfigProfiles.end()) + { + pcfg=(*it); + if (_tcscmp(pcfg->pszProfileName, pszConfig) == 0) + break; + pcfg=NULL; + it++; + } + + if (pcfg == NULL) + return; + + // find the section + vector<_SECTION*>::iterator sit=pcfg->vSections.begin(); + while(sit != pcfg->vSections.end()) + { + psect=(*sit); + if (_tcscmp(psect->pszSectionName, pszSection) == 0) + break; + psect=NULL; + sit++; + } + + if (psect == NULL) + return; + + // localize the key(s) + _ENTRY* pentry=NULL; + vector<_ENTRY*>::iterator eit=psect->vEntries.begin(); + while (eit != psect->vEntries.end()) + { + pentry=(*eit); + if (_tcscmp(pentry->pszKey, pszKey) == 0) + break; + pentry=NULL; + eit++; + } + + if (pentry == NULL) + return; + + vector<_ENTRY*>::iterator eit2=eit; + if (bAllAfter) + { + while(eit != psect->vEntries.end()) + { + pentry=(*eit); + delete [] pentry->pszKey; + delete [] pentry->pszValue; + delete pentry; + eit++; + } + + psect->vEntries.erase(eit2, psect->vEntries.end()); + } + else + { + delete [] pentry->pszKey; + delete [] pentry->pszValue; + delete pentry; + psect->vEntries.erase(eit); + } +} + +const _PROFILE* CIniFile::GetProfile(PCTSTR pszConfig) +{ + _PROFILE *pcfg=NULL; + + vector<_PROFILE*>::iterator it=m_vConfigProfiles.begin(); + while (it != m_vConfigProfiles.end()) + { + pcfg=(*it); + if (_tcscmp(pcfg->pszProfileName, pszConfig) == 0) + break; + pcfg=NULL; + it++; + } + + if (pcfg == NULL) + return NULL; + else + return pcfg; +} + +const _SECTION* CIniFile::GetSection(PCTSTR pszConfig, PCTSTR pszSection) +{ + // localize section + _PROFILE *pcfg=NULL; + _SECTION *psect=NULL; + + vector<_PROFILE*>::iterator it=m_vConfigProfiles.begin(); + while (it != m_vConfigProfiles.end()) + { + pcfg=(*it); + if (_tcscmp(pcfg->pszProfileName, pszConfig) == 0) + break; + pcfg=NULL; + it++; + } + + if (pcfg == NULL) + return NULL; + + // find the section + vector<_SECTION*>::iterator sit=pcfg->vSections.begin(); + while(sit != pcfg->vSections.end()) + { + psect=(*sit); + if (_tcscmp(psect->pszSectionName, pszSection) == 0) + break; + psect=NULL; + sit++; + } + + if (psect == NULL) + return NULL; + else + return psect; +} Index: modules/App Framework/IniFile.cpp =================================================================== diff -u -N --- modules/App Framework/IniFile.cpp (revision 7d997aef1e72f049ed1bc199e1b765d737d9963a) +++ modules/App Framework/IniFile.cpp (revision 0) @@ -1,817 +0,0 @@ -/************************************************************************ - Copy Handler 1.x - program for copying data in Microsoft Windows - systems. - Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. -*************************************************************************/ - -#include "stdafx.h" -#include "IniFile.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -#define MAX_LINE 8192 - -/////////////////////////////////////////////////////////////// -// Opens .ini file, reads all lines from it and keep in memory -// pszFilename [in] - path to .ini file -// pszOneSection [in] - ptr to a string with section's name -// which we want to read -/////////////////////////////////////////////////////////////// -void CIniFile::Open(LPCTSTR pszFilename, PCTSTR pszOneSection, bool bEscapeConversion) -{ - // remember file name - m_pszFilename=new TCHAR[_tcslen(pszFilename)+1]; - _tcscpy(m_pszFilename, pszFilename); - - // count the length of a section member - size_t tSectionLen=(size_t)-1; - if (pszOneSection) - tSectionLen=_tcslen(pszOneSection); - - // open file - CFileEx file; - file.Open(pszFilename, FA_READ | FA_BUFFERED); // may throw an exception - - // read all lines from file and process it - TCHAR szLine[MAX_LINE]; - size_t ulLen; - - // config object - zero members - _PROFILE* pcfg=NULL; // current config object - _SECTION* psect=NULL; // current section - _ENTRY* pentry=NULL; // current entry - TCHAR* pszSeparator; // used for separating keys from values - - while(file.ReadLine(szLine, MAX_LINE)) - { - // process - ulLen=_tcslen(szLine); // length of read string - - if (ulLen == 0 || szLine[0] == '#') - continue; - - // if it's config-selector <...> - if (ulLen > 1 && szLine[0] == _T('<') && szLine[ulLen-1] == _T('>')) - { - // config-selector - // create new profile - pcfg=new _PROFILE; - pcfg->pszProfileName=new TCHAR[ulLen-1]; - _tcsncpy(pcfg->pszProfileName, szLine+1, ulLen-2); - pcfg->pszProfileName[ulLen-2]=_T('\0'); - m_vConfigProfiles.push_back(pcfg); - } - else if (ulLen > 1 && szLine[0] == _T('[') && szLine[ulLen-1] == _T(']')) - { - if (pszOneSection && psect != NULL) // break if the needed section has been read already - break; - - if (!pszOneSection || (ulLen-2 == tSectionLen && _tcsncmp(pszOneSection, szLine+1, ulLen-2) == 0)) - { - // section-selector - if (pcfg == NULL) - { - // encountered section without config-selector - create default one - pcfg=new _PROFILE; - pcfg->pszProfileName=new TCHAR[4]; - _tcscpy(pcfg->pszProfileName, _T("000")); - m_vConfigProfiles.push_back(pcfg); - } - - // new section - psect=new _SECTION; - psect->pszSectionName=new TCHAR[ulLen-1]; - _tcsncpy(psect->pszSectionName, szLine+1, ulLen-2); - psect->pszSectionName[ulLen-2]=_T('\0'); - pcfg->vSections.push_back(psect); - } - } - else - { - if (!pszOneSection || psect != NULL) - { - // normal line (not empty) - if (pcfg == NULL) - { - // config-selector doesn't exist - create default - pcfg=new _PROFILE; - pcfg->pszProfileName=new TCHAR[4]; - _tcscpy(pcfg->pszProfileName, _T("000")); - m_vConfigProfiles.push_back(pcfg); - } - - if (psect == NULL) - { - // section doesn't exist -create default - psect=new _SECTION; - psect->pszSectionName=new TCHAR[4]; - _tcscpy(psect->pszSectionName, _T("000")); - pcfg->vSections.push_back(psect); - } - - // analyze string and copy data - pentry=new _ENTRY; - pszSeparator=_tcschr(szLine, _T('=')); - if (pszSeparator != NULL) - { - pszSeparator[0]=_T('\0'); - pszSeparator++; - - pentry->pszKey=new TCHAR[_tcslen(szLine)+1]; - _tcscpy(pentry->pszKey, szLine); - - // now the value - correct the ansi escape sequences if needed - if (bEscapeConversion) - { -// int iLen=_tcslen(pszSeparator); - UnescapeString(pszSeparator); - } - pentry->pszValue=new TCHAR[_tcslen(pszSeparator)+1]; - _tcscpy(pentry->pszValue, pszSeparator); - } - else - { - // no '=' sign in the line - pentry->pszKey=NULL; - if (bEscapeConversion) - UnescapeString(szLine); - pentry->pszValue=new TCHAR[_tcslen(szLine)+1]; - _tcscpy(pentry->pszValue, szLine); - } - - psect->vEntries.push_back(pentry); - } - } - } - - file.Close(); -} - -void CIniFile::UnescapeString(PTSTR pszData) -{ - PTSTR pszOut=pszData; - while (*pszData != 0) - { - if (*pszData == _T('\\')) - { - pszData++; - switch(*pszData++) - { - case _T('t'): - *pszOut++=_T('\t'); - break; - case _T('r'): - *pszOut++=_T('\r'); - break; - case _T('n'): - *pszOut++=_T('\n'); - break; - default: - *pszOut++=_T('\\'); - } - } - else - *pszOut++=*pszData++; - } - *pszOut=_T('\0'); -} - -/////////////////////////////////////////////////////////////// -// Saves data from memory to an .ini file -/////////////////////////////////////////////////////////////// -void CIniFile::Save() -{ - // if saving data is needed - if (!m_bModified) - return; - - _ASSERT(m_pszFilename); // is there a filename - - // open file for writing - CFileEx file; - file.Open(m_pszFilename, FA_WRITE | FA_BUFFERED); // may throw an exception - - // enumerate through all data and store it to the file - TCHAR szLine[MAX_LINE]; - int iLen; - vector<_PROFILE*>::const_iterator cit=m_vConfigProfiles.begin(); - vector<_SECTION*>::const_iterator sit; - vector<_ENTRY*>::const_iterator eit; - while (cit != m_vConfigProfiles.end()) - { - // store profile name - iLen=_stprintf(szLine, _T("<%s>"), (*cit)->pszProfileName); - file.WriteLine(szLine); - - // enumerate through sections - sit=(*cit)->vSections.begin(); - while (sit != (*cit)->vSections.end()) - { - // write section name - iLen=_stprintf(szLine, _T("[%s]"), (*sit)->pszSectionName); - file.WriteLine(szLine); - - // enumerate through attributes - eit=(*sit)->vEntries.begin(); - while(eit != (*sit)->vEntries.end()) - { - // store data - iLen=_stprintf(szLine, _T("%s=%s"), (*eit)->pszKey, (*eit)->pszValue); - file.WriteLine(szLine); - - // analyze next element - eit++; - } - - // cosmetics - file.WriteLine(_T("")); - - // analyze next section - sit++; - } - - // analyze next profile - cit++; - } - - // close file - file.Close(); - - m_bModified=false; -} - -/////////////////////////////////////////////////////////////// -// Closes the .ini file. Causes data from memory to be saved, -// and frees all the memory. -/////////////////////////////////////////////////////////////// -void CIniFile::Close() -{ - // save file and free all data (doesn't matter if save succeeded) - try - { - Save(); - } - catch(...) - { - FreeData(); - throw; - } - FreeData(); -} - -/////////////////////////////////////////////////////////////// -// Gets a string from .ini file (more precisely from the data -// from memory). -// pszConfig [in] - profile name -// pszSection [in] - section name -// pszKey [in] - key name -// pszValue [out] - value name (read from file or default) -// pszDefault [in/out] - default value if there wasn't pszKey -// in .ini file. -// Ret Value [out] - if the pszValue was read from file (=true) -// or is the default one (=false) -/////////////////////////////////////////////////////////////// -bool CIniFile::GetStr(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, LPTSTR pszValue, LPCTSTR pszDefault) -{ - // localize config - vector<_PROFILE*>::const_iterator cit=m_vConfigProfiles.begin(); - while (cit != m_vConfigProfiles.end()) - { - // if this is not a config name - enumerate next - if (_tcsicmp((*cit)->pszProfileName, pszConfig) != 0) - { - cit++; - continue; - } - - // config found - check for section - vector<_SECTION*>::const_iterator sit=(*cit)->vSections.begin(); - while (sit != (*cit)->vSections.end()) - { - // continue if this is not the needed section - if (_tcsicmp((*sit)->pszSectionName, pszSection) != 0) - { - sit++; - continue; - } - - // now - localize key in section - vector<_ENTRY*>::const_iterator eit=(*sit)->vEntries.begin(); - while (eit != (*sit)->vEntries.end()) - { - // continue if needed - if (_tcsicmp((*eit)->pszKey, pszKey) != 0) - { - eit++; - continue; - } - - // read associated value - from file - _tcscpy(pszValue, (*eit)->pszValue); - m_bDefault=false; - return true; - } - - // section was found, but key in it wasn't - _tcscpy(pszValue, pszDefault); - m_bDefault=true; - return false; - } - - // section not found - _tcscpy(pszValue, pszDefault); - m_bDefault=true; - return false; - } - - // nothing - _tcscpy(pszValue, pszDefault); - m_bDefault=true; - return false; -} - -/////////////////////////////////////////////////////////////// -// Reads string from .ini file -// Look @ CIniFile::GetStr for param desc -// Ret Value [out] - string that was read (or the default one) -/////////////////////////////////////////////////////////////// -LPTSTR CIniFile::GetString(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, LPTSTR pszValue, LPCTSTR pszDefault) -{ - GetStr(pszConfig, pszSection, pszKey, pszValue, pszDefault); - return pszValue; -} - -/////////////////////////////////////////////////////////////// -// Writes string to .ini file (to memory) -// For param desc's look @GetStr -// pszValue [in] - string to store under pszKey -/////////////////////////////////////////////////////////////// -void CIniFile::SetString(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, LPCTSTR pszValue) -{ - // localize config - vector<_PROFILE*>::const_iterator cit=m_vConfigProfiles.begin(); - _PROFILE* pcfg=NULL; - while (cit != m_vConfigProfiles.end()) - { - // if this is not a config name - enumerate next - if (_tcsicmp((*cit)->pszProfileName, pszConfig) != 0) - { - cit++; - continue; - } - - // found - pcfg=*cit; - break; - } - - // if section doesn't exist - create it - if (pcfg == NULL) - { - pcfg=new _PROFILE; - pcfg->pszProfileName=new TCHAR[_tcslen(pszConfig)+1]; - _tcscpy(pcfg->pszProfileName, pszConfig); - m_vConfigProfiles.push_back(pcfg); - } - - // config is ready - now search for section - vector<_SECTION*>::const_iterator sit=pcfg->vSections.begin(); - _SECTION* psect=NULL; - while (sit != pcfg->vSections.end()) - { - // continue if this is not the needed section - if (_tcsicmp((*sit)->pszSectionName, pszSection) != 0) - { - sit++; - continue; - } - - // found - psect=*sit; - break; - } - - // create section if doesn't exist - if (psect == NULL) - { - psect=new _SECTION; - psect->pszSectionName=new TCHAR[_tcslen(pszSection)+1]; - _tcscpy(psect->pszSectionName, pszSection); - pcfg->vSections.push_back(psect); - } - - // now entry... - vector<_ENTRY*>::const_iterator eit=psect->vEntries.begin(); - _ENTRY* pentry=NULL; - while (eit != psect->vEntries.end()) - { - // continue if needed - if (_tcsicmp((*eit)->pszKey, pszKey) != 0) - { - eit++; - continue; - } - - // found - pentry=*eit; - break; - } - - // create entry if needed - if (pentry == NULL) - { - pentry=new _ENTRY; - pentry->pszKey=new TCHAR[_tcslen(pszKey)+1]; - _tcscpy(pentry->pszKey, pszKey); - pentry->pszValue=NULL; - psect->vEntries.push_back(pentry); - } - - // copy value to entry->pszValue - if (pentry->pszValue != NULL) - delete [] pentry->pszValue; - - pentry->pszValue=new TCHAR[_tcslen(pszValue)+1]; - _tcscpy(pentry->pszValue, pszValue); - - m_bModified=true; -} - -/////////////////////////////////////////////////////////////// -// Sets the int value in the .ini file (memory) -// pszConfig, pszSection, pszKey [in] - position in .ini file -// iValue [in] - value to set -/////////////////////////////////////////////////////////////// -void CIniFile::SetInt(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, int iValue) -{ - TCHAR szBuffer[11]; - SetString(pszConfig, pszSection, pszKey, _itot(iValue, szBuffer, 10)); -} - -/////////////////////////////////////////////////////////////// -// Gets the int value from .ini file (memory) -// pszConfig, pszSection, pszKey [in] - position in .ini file -// iDefault [in] - default value - used if the file doesn't -// contain neede value -// pszBuffer [in] - buffer for internal processing (must -// contain at last 5 TCHARs). -// Ret Value [out] - value associated with the given position -/////////////////////////////////////////////////////////////// -int CIniFile::GetInt(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, int iDefault, LPTSTR pszBuffer) -{ - // get string and process it - if (GetStr(pszConfig, pszSection, pszKey, pszBuffer, _T(""))) - return _ttoi(pszBuffer); - else - return iDefault; -} - -/////////////////////////////////////////////////////////////// -// Sets the bool value in the .ini file (memory) -// pszConfig, pszSection, pszKey [in] - position in .ini file -// bValue [in] - value to set -/////////////////////////////////////////////////////////////// -void CIniFile::SetBool(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, bool bValue) -{ - TCHAR szBuffer[2]={ (TCHAR)(48+(bValue ? 1 : 0)), 0 }; - SetString(pszConfig, pszSection, pszKey, szBuffer); -} - -/////////////////////////////////////////////////////////////// -// Gets the bool value from .ini file (memory) -// pszConfig, pszSection, pszKey [in] - position in .ini file -// bDefault [in] - default value - used if the file doesn't -// contain needed value -// pszBuffer [in] - buffer for internal processing (must -// contain at last 2 TCHARs-better/safer is 1024). -// Ret Value [out] - value associated with the given position -/////////////////////////////////////////////////////////////// -bool CIniFile::GetBool(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, bool bDefault, LPTSTR pszBuffer) -{ - // get string and process it - if (GetStr(pszConfig, pszSection, pszKey, pszBuffer, _T(""))) - return pszBuffer[0] != _T('0'); - else - return bDefault; -} - -/////////////////////////////////////////////////////////////// -// Sets the int64 value in the .ini file (memory) -// pszConfig, pszSection, pszKey [in] - position in .ini file -// llValue [in] - value to set -/////////////////////////////////////////////////////////////// -void CIniFile::SetInt64(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, __int64 llValue) -{ - TCHAR szBuffer[21]; - SetString(pszConfig, pszSection, pszKey, _i64tot(llValue, szBuffer, 10)); -} - -/////////////////////////////////////////////////////////////// -// Gets the int64 value from .ini file (memory) -// pszConfig, pszSection, pszKey [in] - position in .ini file -// llDefault [in] - default value - used if the file doesn't -// contain needed value -// pszBuffer [in] - buffer for internal processing (must -// contain at last 9 TCHARs-better/safer is 1024). -// Ret Value [out] - value associated with the given position -/////////////////////////////////////////////////////////////// -__int64 CIniFile::GetInt64(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, __int64 llDefault, LPTSTR pszBuffer) -{ - // get string and process it - if (GetStr(pszConfig, pszSection, pszKey, pszBuffer, _T(""))) - return _ttoi64(pszBuffer); - else - return llDefault; -} - -/////////////////////////////////////////////////////////////// -// Gets the profile name at a given index in a file -// uiIndex [in] - index of profile to retrieve -// pszName [out] - name of the profile -/////////////////////////////////////////////////////////////// -void CIniFile::GetProfileName(UINT uiIndex, LPTSTR pszName) -{ - _tcscpy(pszName, m_vConfigProfiles.at(uiIndex)->pszProfileName); -} - -/////////////////////////////////////////////////////////////// -// Sets profile name at a given index -// uiIndex [in] - profile index -// pszName [in] - new profile name -/////////////////////////////////////////////////////////////// -void CIniFile::SetProfileName(UINT uiIndex, LPCTSTR pszName) -{ - delete [] m_vConfigProfiles.at(uiIndex)->pszProfileName; - m_vConfigProfiles.at(uiIndex)->pszProfileName=new TCHAR[_tcslen(pszName)+1]; - _tcscpy(m_vConfigProfiles.at(uiIndex)->pszProfileName, pszName); -} - -/////////////////////////////////////////////////////////////// -// Deletes one of the configurations (completely) -// uiIndex [in] - profile index to delete -/////////////////////////////////////////////////////////////// -void CIniFile::DeleteProfile(UINT uiIndex) -{ - m_vConfigProfiles.erase(m_vConfigProfiles.begin()+uiIndex); -} - -/////////////////////////////////////////////////////////////// -// Creates new profile in .ini file -// pszName [in] - new profile's name -/////////////////////////////////////////////////////////////// -void CIniFile::CreateProfile(LPCTSTR pszName) -{ - _PROFILE* pcfg=new _PROFILE; - pcfg->pszProfileName=new _TCHAR[_tcslen(pszName)+1]; - _tcscpy(pcfg->pszProfileName, pszName); -} - -/////////////////////////////////////////////////////////////// -// (Internal) Frees all data associated with this class -/////////////////////////////////////////////////////////////// -void CIniFile::FreeData() -{ - // free name string - delete [] m_pszFilename; - m_pszFilename=NULL; - - // other data - _PROFILE* pcfg=NULL; // current config object - _SECTION* psect=NULL; // current section - _ENTRY* pentry=NULL; // current entry - size_t uiIndex1=m_vConfigProfiles.size(), uiIndex2, uiIndex3; - while (uiIndex1--) - { - // delete profile name - pcfg=m_vConfigProfiles.at(uiIndex1); - delete [] pcfg->pszProfileName; - - // delete all sections - uiIndex2=pcfg->vSections.size(); - while (uiIndex2--) - { - // delete section name - psect=pcfg->vSections.at(uiIndex2); - delete [] psect->pszSectionName; - - // free all key=value strings - uiIndex3=psect->vEntries.size(); - while (uiIndex3--) - { - pentry=psect->vEntries.at(uiIndex3); - - // delete all values and this entry - delete [] pentry->pszKey; - delete [] pentry->pszValue; - delete pentry; - } - - // free this section - delete psect; - } - - // delete this profile - delete pcfg; - } - - m_vConfigProfiles.clear(); - m_bModified=false; - m_bDefault=false; -} - -void CIniFile::RemoveSection(LPCTSTR pszConfig, LPCTSTR pszSection) -{ - // localize section - _PROFILE *pcfg=NULL; - _SECTION *psect=NULL; - - vector<_PROFILE*>::iterator it=m_vConfigProfiles.begin(); - while (it != m_vConfigProfiles.end()) - { - pcfg=(*it); - if (_tcscmp(pcfg->pszProfileName, pszConfig) == 0) - break; - pcfg=NULL; - it++; - } - - if (pcfg == NULL) - return; - - // find the section - vector<_SECTION*>::iterator sit=pcfg->vSections.begin(); - while(sit != pcfg->vSections.end()) - { - psect=(*sit); - if (_tcscmp(psect->pszSectionName, pszSection) == 0) - break; - psect=NULL; - sit++; - } - - if (psect == NULL) - return; - - // delete - delete [] psect->pszSectionName; - - // free all key=value strings - size_t tIndex=psect->vEntries.size(); - _ENTRY* pentry; - while (tIndex--) - { - pentry=psect->vEntries.at(tIndex); - - // delete all values and this entry - delete [] pentry->pszKey; - delete [] pentry->pszValue; - delete pentry; - } - - // free this section - delete psect; - pcfg->vSections.erase(sit); -} - -void CIniFile::RemoveKey(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, bool bAllAfter) -{ - // localize section - _PROFILE *pcfg=NULL; - _SECTION *psect=NULL; - - vector<_PROFILE*>::iterator it=m_vConfigProfiles.begin(); - while (it != m_vConfigProfiles.end()) - { - pcfg=(*it); - if (_tcscmp(pcfg->pszProfileName, pszConfig) == 0) - break; - pcfg=NULL; - it++; - } - - if (pcfg == NULL) - return; - - // find the section - vector<_SECTION*>::iterator sit=pcfg->vSections.begin(); - while(sit != pcfg->vSections.end()) - { - psect=(*sit); - if (_tcscmp(psect->pszSectionName, pszSection) == 0) - break; - psect=NULL; - sit++; - } - - if (psect == NULL) - return; - - // localize the key(s) - _ENTRY* pentry=NULL; - vector<_ENTRY*>::iterator eit=psect->vEntries.begin(); - while (eit != psect->vEntries.end()) - { - pentry=(*eit); - if (_tcscmp(pentry->pszKey, pszKey) == 0) - break; - pentry=NULL; - eit++; - } - - if (pentry == NULL) - return; - - vector<_ENTRY*>::iterator eit2=eit; - if (bAllAfter) - { - while(eit != psect->vEntries.end()) - { - pentry=(*eit); - delete [] pentry->pszKey; - delete [] pentry->pszValue; - delete pentry; - eit++; - } - - psect->vEntries.erase(eit2, psect->vEntries.end()); - } - else - { - delete [] pentry->pszKey; - delete [] pentry->pszValue; - delete pentry; - psect->vEntries.erase(eit); - } -} - -const _PROFILE* CIniFile::GetProfile(PCTSTR pszConfig) -{ - _PROFILE *pcfg=NULL; - - vector<_PROFILE*>::iterator it=m_vConfigProfiles.begin(); - while (it != m_vConfigProfiles.end()) - { - pcfg=(*it); - if (_tcscmp(pcfg->pszProfileName, pszConfig) == 0) - break; - pcfg=NULL; - it++; - } - - if (pcfg == NULL) - return NULL; - else - return pcfg; -} - -const _SECTION* CIniFile::GetSection(PCTSTR pszConfig, PCTSTR pszSection) -{ - // localize section - _PROFILE *pcfg=NULL; - _SECTION *psect=NULL; - - vector<_PROFILE*>::iterator it=m_vConfigProfiles.begin(); - while (it != m_vConfigProfiles.end()) - { - pcfg=(*it); - if (_tcscmp(pcfg->pszProfileName, pszConfig) == 0) - break; - pcfg=NULL; - it++; - } - - if (pcfg == NULL) - return NULL; - - // find the section - vector<_SECTION*>::iterator sit=pcfg->vSections.begin(); - while(sit != pcfg->vSections.end()) - { - psect=(*sit); - if (_tcscmp(psect->pszSectionName, pszSection) == 0) - break; - psect=NULL; - sit++; - } - - if (psect == NULL) - return NULL; - else - return psect; -} Index: ch/IniFile.h =================================================================== diff -u -N --- ch/IniFile.h (revision 0) +++ ch/IniFile.h (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,130 @@ +/************************************************************************ + Copy Handler 1.x - program for copying data in Microsoft Windows + systems. + Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. +*************************************************************************/ +/************************************************************************* + File: IniFile.h + Version: 1.0 + Author: Ixen Gerthannes (ixen@interia.pl) + File description: + Contains classes/structures providing functionality of ini + file. Ini file in this case is a bit modified, because it + provides something called profile. It could be used to + maintain more than one set of options in an ini file. + Classes: + CIniFile + - handles ini files in format: + - + - [section name] + - key=value + - work with/without mfc. + - NOT thread-safe + Structures: + _PROFILE - contains profile name and array of sections + _SECTION - contains section name and array of entries + _ENTRY - contains key name, value in string format +*************************************************************************/ + +#ifndef __INIFILE_H__ +#define __INIFILE_H__ + +#include "FileEx.h" +#include + +using namespace std; + +// internal structures used in managing profiles, keys, ... +struct _ENTRY +{ + TCHAR* pszKey; // key name - common for all config profiles + TCHAR* pszValue; // set of values bound to above key - differs between config-profiles +}; + +struct _SECTION +{ + TCHAR* pszSectionName; + vector<_ENTRY*> vEntries; +}; + +struct _PROFILE +{ + TCHAR* pszProfileName; + vector<_SECTION*> vSections; +}; + +// class +class CIniFile +{ +public: + // construction/destruction + CIniFile() { m_pszFilename=NULL; m_bModified=false; m_bDefault=false; }; + ~CIniFile() { Close(); }; + + // opening/closing + void Open(LPCTSTR pszFilename, PCTSTR pszOneSection=NULL, bool bEscapeConversion=false); // loads data from file and interpretes it + void Save(); // saves data to file (without closing it) + void Close(); // saves file and closes it + + // reading/writing some data from/to .ini file + bool GetStr(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, LPTSTR pszValue, LPCTSTR pszDefault); // gets string from .ini file + LPTSTR GetString(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, LPTSTR pszValue, LPCTSTR pszDefault); // gets string from .ini file + void SetString(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, LPCTSTR pszValue); // sets string in .ini file + + void SetInt(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, int iValue); + int GetInt(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, int iDefault, LPTSTR pszBuffer); + + void SetBool(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, bool bValue); + bool GetBool(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, bool bDefault, LPTSTR pszBuffer); + + void SetInt64(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, __int64 llValue); + __int64 GetInt64(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, __int64 llDefault, LPTSTR pszBuffer); + + // remove functions + void RemoveSection(LPCTSTR pszConfig, LPCTSTR pszSection); + void RemoveKey(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, bool bAllAfter); + + // Get functions + const _PROFILE* GetProfile(PCTSTR pszConfig); + const _SECTION* GetSection(PCTSTR pszConfig, PCTSTR pszSection); + + // config-selection funcs + UINT GetProfilesCount() { return (UINT)m_vConfigProfiles.size(); }; // returns count of profiles + void GetProfileName(UINT uiIndex, LPTSTR pszName); // return profile name + void SetProfileName(UINT uiIndex, LPCTSTR pszName); // sets the profile name + void DeleteProfile(UINT uiIndex); // deletes whole profile + void CreateProfile(LPCTSTR pszName); // creates new profile + + // def + bool IsDefault() const { return m_bDefault; }; + +protected: + // helpers + void FreeData(); // frees data from m_vConfigProfiles + void UnescapeString(PTSTR pszData); + +protected: + TCHAR* m_pszFilename; // this configuration's file filename + bool m_bModified; // global modification flag + bool m_bDefault; // every GetXXX refreshed member - if returned value was the default one or + // read from file + + vector<_PROFILE*> m_vConfigProfiles; // contains configuration profiles's names (user names) + // each config profile contains the same set of sections and keys +}; + +#endif \ No newline at end of file Index: modules/App Framework/IniFile.h =================================================================== diff -u -N --- modules/App Framework/IniFile.h (revision 3e1186252ab31f63d86d86c4b0ff593cfffbefde) +++ modules/App Framework/IniFile.h (revision 0) @@ -1,130 +0,0 @@ -/************************************************************************ - Copy Handler 1.x - program for copying data in Microsoft Windows - systems. - Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. -*************************************************************************/ -/************************************************************************* - File: IniFile.h - Version: 1.0 - Author: Ixen Gerthannes (ixen@interia.pl) - File description: - Contains classes/structures providing functionality of ini - file. Ini file in this case is a bit modified, because it - provides something called profile. It could be used to - maintain more than one set of options in an ini file. - Classes: - CIniFile - - handles ini files in format: - - - - [section name] - - key=value - - work with/without mfc. - - NOT thread-safe - Structures: - _PROFILE - contains profile name and array of sections - _SECTION - contains section name and array of entries - _ENTRY - contains key name, value in string format -*************************************************************************/ - -#ifndef __INIFILE_H__ -#define __INIFILE_H__ - -#include "FileEx.h" -#include - -using namespace std; - -// internal structures used in managing profiles, keys, ... -struct _ENTRY -{ - TCHAR* pszKey; // key name - common for all config profiles - TCHAR* pszValue; // set of values bound to above key - differs between config-profiles -}; - -struct _SECTION -{ - TCHAR* pszSectionName; - vector<_ENTRY*> vEntries; -}; - -struct _PROFILE -{ - TCHAR* pszProfileName; - vector<_SECTION*> vSections; -}; - -// class -class CIniFile -{ -public: - // construction/destruction - CIniFile() { m_pszFilename=NULL; m_bModified=false; m_bDefault=false; }; - ~CIniFile() { Close(); }; - - // opening/closing - void Open(LPCTSTR pszFilename, PCTSTR pszOneSection=NULL, bool bEscapeConversion=false); // loads data from file and interpretes it - void Save(); // saves data to file (without closing it) - void Close(); // saves file and closes it - - // reading/writing some data from/to .ini file - bool GetStr(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, LPTSTR pszValue, LPCTSTR pszDefault); // gets string from .ini file - LPTSTR GetString(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, LPTSTR pszValue, LPCTSTR pszDefault); // gets string from .ini file - void SetString(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, LPCTSTR pszValue); // sets string in .ini file - - void SetInt(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, int iValue); - int GetInt(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, int iDefault, LPTSTR pszBuffer); - - void SetBool(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, bool bValue); - bool GetBool(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, bool bDefault, LPTSTR pszBuffer); - - void SetInt64(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, __int64 llValue); - __int64 GetInt64(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, __int64 llDefault, LPTSTR pszBuffer); - - // remove functions - void RemoveSection(LPCTSTR pszConfig, LPCTSTR pszSection); - void RemoveKey(LPCTSTR pszConfig, LPCTSTR pszSection, LPCTSTR pszKey, bool bAllAfter); - - // Get functions - const _PROFILE* GetProfile(PCTSTR pszConfig); - const _SECTION* GetSection(PCTSTR pszConfig, PCTSTR pszSection); - - // config-selection funcs - UINT GetProfilesCount() { return (UINT)m_vConfigProfiles.size(); }; // returns count of profiles - void GetProfileName(UINT uiIndex, LPTSTR pszName); // return profile name - void SetProfileName(UINT uiIndex, LPCTSTR pszName); // sets the profile name - void DeleteProfile(UINT uiIndex); // deletes whole profile - void CreateProfile(LPCTSTR pszName); // creates new profile - - // def - bool IsDefault() const { return m_bDefault; }; - -protected: - // helpers - void FreeData(); // frees data from m_vConfigProfiles - void UnescapeString(PTSTR pszData); - -protected: - TCHAR* m_pszFilename; // this configuration's file filename - bool m_bModified; // global modification flag - bool m_bDefault; // every GetXXX refreshed member - if returned value was the default one or - // read from file - - vector<_PROFILE*> m_vConfigProfiles; // contains configuration profiles's names (user names) - // each config profile contains the same set of sections and keys -}; - -#endif \ No newline at end of file Index: ch/LanguageDialog.cpp =================================================================== diff -u -N --- ch/LanguageDialog.cpp (revision 0) +++ ch/LanguageDialog.cpp (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,675 @@ +/************************************************************************ + 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. +*************************************************************************/ + +#include "stdafx.h" +#include "LanguageDialog.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +///////////////////////////////////////////////////////////////////////////// +// CDlgTemplate +CDlgTemplate::CDlgTemplate(const DLGTEMPLATE* pDlgTemplate) +{ + Open(pDlgTemplate); +} + +CDlgTemplate::CDlgTemplate(const DLGTEMPLATEEX* pDlgTemplate) +{ + Open((DLGTEMPLATE*)pDlgTemplate); +} + +CDlgTemplate::~CDlgTemplate() +{ + delete [] m_pszMenu; + delete [] m_pszClass; + delete [] m_pszTitle; + delete [] m_pszFace; + + // items + vector<_ITEM>::iterator it; + for (it=m_vItems.begin();it != m_vItems.end();it++) + { + delete [] (*it).m_pbyCreationData; + delete [] (*it).m_pszClass; + delete [] (*it).m_pszTitle; + } +} + +bool CDlgTemplate::Open(const DLGTEMPLATE* pDlgTemplate) +{ + if (pDlgTemplate == NULL) + return false; + bool bExt=((DLGTEMPLATEEX*)pDlgTemplate)->signature == 0xffff; + const BYTE* pData=((BYTE*)pDlgTemplate); + if (bExt) + { + m_dlgTemplate=*((DLGTEMPLATEEX*)pDlgTemplate); + pData+=sizeof(DLGTEMPLATEEX); + } + else + { + ConvertDlgToEx(pDlgTemplate, &m_dlgTemplate); + pData+=sizeof(DLGTEMPLATE); + } + + // here is the menu, class and title + pData=ReadCompoundData(pData, &m_wMenu, &m_pszMenu); + pData=ReadCompoundData(pData, &m_wClass, &m_pszClass); + pData=ReadCompoundData(pData, &m_wTitle, &m_pszTitle); + + // font + if (m_dlgTemplate.style & DS_SETFONT || m_dlgTemplate.style & DS_SHELLFONT) + { + m_wFontSize=*((WORD*)pData); + pData+=sizeof(WORD); + if (bExt) + { + m_wWeight=*((WORD*)pData); + pData+=sizeof(WORD); + m_byItalic=*((BYTE*)pData); + pData+=sizeof(BYTE); + m_byCharset=*((BYTE*)pData); + pData+=sizeof(BYTE); + } + else + { + m_wWeight=FW_NORMAL; + m_byItalic=FALSE; + m_byCharset=DEFAULT_CHARSET; + } + DWORD dwLen=(DWORD)wcslen((wchar_t*)pData); + m_pszFace=new TCHAR[dwLen+1]; +#ifdef _UNICODE + _tcscpy(m_pszFace, (wchar_t*)pData); +#else + WideCharToMultiByte(CP_ACP, 0, (wchar_t*)pData, dwLen+1, m_pszFace, dwLen+1, NULL, NULL); +#endif + pData+=(dwLen+1)*sizeof(wchar_t); + } + else + { + m_wFontSize=0xffff; + m_pszFace=NULL; + } + + // items + _ITEM item; + for (int i=0;i 0) + { + item.m_wCreationDataSize-=sizeof(WORD); + item.m_pbyCreationData=new BYTE[item.m_wCreationDataSize]; + memcpy(item.m_pbyCreationData, pData, item.m_wCreationDataSize); + } + else + item.m_pbyCreationData=NULL; + + m_vItems.push_back(item); + } + + return true; +} + +void CDlgTemplate::ConvertItemToEx(const DLGITEMTEMPLATE* pSrc, DLGITEMTEMPLATEEX* pDst) +{ + pDst->helpID=0; + pDst->exStyle=pSrc->dwExtendedStyle; + pDst->style=pSrc->style; + pDst->x=pSrc->x; + pDst->y=pSrc->y; + pDst->cx=pSrc->cx; + pDst->cy=pSrc->cy; + pDst->id=pSrc->id; +} + +void CDlgTemplate::ConvertDlgToEx(const DLGTEMPLATE* pSrc, DLGTEMPLATEEX* pDst) +{ + pDst->dlgVer=1; + pDst->signature=0x0000; + pDst->helpID=(ULONG)0; + pDst->exStyle=pSrc->dwExtendedStyle; + pDst->style=pSrc->style; + pDst->cDlgItems=pSrc->cdit; + pDst->x=pSrc->x; + pDst->y=pSrc->y; + pDst->cx=pSrc->cx; + pDst->cy=pSrc->cy; +} + +const BYTE* CDlgTemplate::ReadCompoundData(const BYTE* pBuffer, WORD* pwData, PTSTR* ppszStr) +{ + if (*((WORD*)pBuffer) == 0xffff) + { + *pwData=*((WORD*)(pBuffer+2)); + *ppszStr=NULL; + + return pBuffer+4; + } + else + { + *pwData=0xffff; + DWORD dwLen=(DWORD)wcslen((wchar_t*)pBuffer); + *ppszStr=new TCHAR[dwLen+1]; +#ifdef _UNICODE + _tcscpy(*ppszStr, (wchar_t*)pBuffer); +#else + WideCharToMultiByte(CP_ACP, 0, (wchar_t*)pBuffer, dwLen+1, *ppszStr, dwLen+1, NULL, NULL); +#endif + return pBuffer+(dwLen+1)*sizeof(wchar_t); + } + +} + +///////////////////////////////////////////////////////////////////////////// +// CLanguageDialog dialog + +CResourceManager *CLanguageDialog::m_prm=NULL; + +/////////////////////////////////////////////////////////////// +// Standard constructor +// pLock [in] - specifies address of a bool value that'll be +// used to check if another instance of this window has +// already been shown. Should be declared in derived class +// as 'static bool m_xxx;' and initialized to 0. +/////////////////////////////////////////////////////////////// +CLanguageDialog::CLanguageDialog(bool* pLock) : CDialog() +{ + m_pszResName=NULL; + m_uiResID=0; + m_pParent=NULL; + m_cType=-1; + m_bAutoDelete=false; + m_pFont=NULL; + m_pbLock=pLock; + m_bLockChanged=false; + m_bLockInstance=false; + m_iBaseX=m_iBaseY=0; + _ASSERT(m_prm); // make sure the CLanguageDialog::SetResManager() has been called aready + m_prm->m_lhDialogs.push_back(this); +} + +/////////////////////////////////////////////////////////////// +// Constructor that takes string based template name +// lpszTemplateName [in] - specifies the template name to load +// and show as this dialog. +// pParent [in] - logical (everyone knows) +// pLock [in] - address of a bool for dialog instance checks +/////////////////////////////////////////////////////////////// +CLanguageDialog::CLanguageDialog(PCTSTR lpszTemplateName, CWnd* pParent, bool* pLock) : CDialog() +{ + m_pszResName=lpszTemplateName; + if (IS_INTRESOURCE(lpszTemplateName)) + m_uiResID=(WORD)lpszTemplateName; + else + m_uiResID=0; + m_pParent=pParent; + m_cType=-1; + m_bAutoDelete=false; + m_pFont=NULL; + m_pbLock=pLock; + m_bLockChanged=false; + m_bLockInstance=false; + m_iBaseX=m_iBaseY=0; + _ASSERT(m_prm); // make sure the CLanguageDialog::SetResManager() has been called aready + m_prm->m_lhDialogs.push_back(this); +} + +/////////////////////////////////////////////////////////////// +// Constructor that takes UINT based template name +// uiIDTemplate [in] - specifies the template ID to load +// and show as this dialog. +// pParent [in] - logical (everyone knows) +// pLock [in] - address of a bool for dialog instance checks +/////////////////////////////////////////////////////////////// +CLanguageDialog::CLanguageDialog(UINT uiIDTemplate, CWnd* pParent, bool* pLock) : CDialog() +{ + m_pszResName=MAKEINTRESOURCE(uiIDTemplate); + m_uiResID=uiIDTemplate; + m_pParent=pParent; + m_cType=-1; + m_bAutoDelete=false; + m_pFont=NULL; + m_pbLock=pLock; + m_bLockChanged=false; + m_bLockInstance=false; + m_iBaseX=m_iBaseY=0; + _ASSERT(m_prm); // make sure the CLanguageDialog::SetResManager() has been called aready + m_prm->m_lhDialogs.push_back(this); +} + +/////////////////////////////////////////////////////////////// +// Standard destructor +// Removes itself from a list in CWinApp (not to get any window +// messages anymore). +/////////////////////////////////////////////////////////////// +CLanguageDialog::~CLanguageDialog() +{ + list::iterator it=m_prm->m_lhDialogs.begin(); + while (it != m_prm->m_lhDialogs.end()) + { + if (*it == this) + { + m_prm->m_lhDialogs.erase(it); + break; + } + + it++; + } +} + +///////////////////////////////////////////////////////////////////////////// +// CLanguageDialog message handlers + +/////////////////////////////////////////////////////////////// +// Makes properly constructed dialog modal. +// RetVal [out] - value returned by dialog proc +/////////////////////////////////////////////////////////////// +INT_PTR CLanguageDialog::DoModal() +{ + if (m_pszResName) + { + HGLOBAL hDialog=m_prm->LoadResource(RT_DIALOG, m_pszResName); + if (!InitModalIndirect(hDialog)) + return -1; + } + m_cType=0; + return CDialog::DoModal(); +} + +/////////////////////////////////////////////////////////////// +// Creates (and shows probably) this constructed dialog. +// RetVal [out] - if creation succeeded +/////////////////////////////////////////////////////////////// +BOOL CLanguageDialog::Create() +{ + _ASSERT(m_pszResName); // nothing was set as a dialog template + + if (!m_bLockInstance || m_pbLock == NULL || !(*m_pbLock)) + { + HGLOBAL hDialog=m_prm->LoadResource(RT_DIALOG, m_pszResName); + + // modeless dialog + if (!CreateIndirect(hDialog, m_pParent)) + return FALSE; + + m_cType=1; + if (m_pbLock) + { + *m_pbLock=true; + m_bLockChanged=true; + } + + return TRUE; + } + else + { + m_bLockChanged=false; + Cleanup(); + return FALSE; + } +} + +/////////////////////////////////////////////////////////////// +// Changes values based on dialog units into the values in +// pixels. Change is based on std MapDialogRect if the language +// hasn't been changed otf or takes current font into +// consideration. +// pRect [in/out] - on [in] - dialog units, on [out] - pixels +/////////////////////////////////////////////////////////////// +void CLanguageDialog::MapRect(RECT* pRect) +{ + if (m_pFont) + { + pRect->left=MulDiv(pRect->left, m_iBaseX, 4); + pRect->right=MulDiv(pRect->right, m_iBaseX, 4); + pRect->top=MulDiv(pRect->top, m_iBaseY, 8); + pRect->bottom=MulDiv(pRect->bottom, m_iBaseY, 8); + } + else + MapDialogRect(pRect); +} + +/////////////////////////////////////////////////////////////// +// Helper function - called when this dialog receives message +// WM_RMNOTIFY (with WPARAM == RMNT_LANGCHANGE). Updates the +// dialog with data from a new template. Passes params to +// virtual function OnLanguageChanged. +// wOldLang [in] - specifies the old language code +// wNewLang [in] - specifies the new language code. +/////////////////////////////////////////////////////////////// +void CLanguageDialog::UpdateLanguage(WORD /*wOldLang*/, WORD /*wNewLang*/) +{ + // cannot update for string based template + if (m_uiResID == 0) + return; + + // set the title + SetWindowText(m_prm->LoadString((WORD)m_uiResID, 0)); + + // load the dialog template + CDlgTemplate dt; + if (!dt.Open(m_prm->LoadDialog(MAKEINTRESOURCE(m_uiResID)))) + { + TRACE("Cannot open dialog template in UpdateLanguage\n"); + return; + } + + // update the menu + if (GetMenu()) + m_prm->UpdateMenu(GetMenu()->m_hMenu, dt.m_wMenu); + + // font + if (!(GetLanguageUpdateOptions() & LDF_NODIALOGFONT)) + { + // dialog font + LOGFONT lf; + memset(&lf, 0, sizeof(LOGFONT)); + HDC hdc=::GetDC(NULL); + lf.lfHeight = -MulDiv(m_prm->m_ld.GetPointSize(), GetDeviceCaps(hdc, LOGPIXELSY), 72); + ::ReleaseDC(NULL, hdc); + lf.lfWeight = FW_NORMAL; + lf.lfCharSet = m_prm->m_ld.GetCharset(); + _tcscpy(lf.lfFaceName, m_prm->m_ld.GetFontFace()); + + delete m_pFont; + m_pFont=new CFont(); + m_pFont->CreateFontIndirect(&lf); + + // change base dlg units + CalcBaseUnits(dt.m_pszFace, dt.m_wFontSize); + } + + if (!(GetLanguageUpdateOptions() & LDF_NODIALOGSIZE)) + { + // dialog size + CRect rcWin; + GetWindowRect(&rcWin); + + CRect rcDialog(0, 0, dt.m_dlgTemplate.cx, dt.m_dlgTemplate.cy); + MapRect(&rcDialog); + rcDialog.bottom+=2*GetSystemMetrics(SM_CYDLGFRAME)+GetSystemMetrics(SM_CYCAPTION); + + // correct the height by a menu height + if ((dt.m_wMenu != 0xffff) || ((dt.m_pszMenu != NULL) && _tcslen(dt.m_pszMenu) != 0)) + rcDialog.bottom+=GetSystemMetrics(SM_CYMENU); + + rcDialog.right+=2*GetSystemMetrics(SM_CXDLGFRAME); + rcDialog.OffsetRect(rcWin.CenterPoint().x-rcDialog.Width()/2, rcWin.CenterPoint().y-rcDialog.Height()/2); + + //TEMP + TRACE("Old dlg pos/size: x=%lu, y=%lu, cx=%lu, cy=%lu; \n\tNew dlg pos/size: x=%lu, y=%lu, cx=%lu, cy=%lu\n", rcWin.left, rcWin.top, rcWin.Width(), rcWin.Height(), rcDialog.left, rcDialog.top, rcDialog.Width(), rcDialog.Height()); + SetWindowPos(NULL, rcDialog.left, rcDialog.top, rcDialog.Width(), rcDialog.Height(), SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE); + } + + // the controls + CWnd* pWnd; + vector::iterator it; + for (it=dt.m_vItems.begin();it != dt.m_vItems.end();it++) + { + // skip controls that cannot be modified + if ( (*it).m_itemTemplate.id == 0xffff || (pWnd=GetDlgItem((*it).m_itemTemplate.id)) == NULL) + continue; + + // the font + if (!(GetLanguageUpdateOptions() & LDF_NODIALOGFONT)) + pWnd->SetFont(m_pFont, FALSE); + + // style&ex style + // modify only the rtl/ltr reading order + LONG lStyleEx=::GetWindowLong(pWnd->m_hWnd, GWL_EXSTYLE); + if (lStyleEx & WS_EX_RTLREADING) + { + if (!m_prm->m_ld.GetDirection()) + lStyleEx &= ~WS_EX_RTLREADING; + } + else + { + if (m_prm->m_ld.GetDirection()) + lStyleEx |= WS_EX_RTLREADING; + } + + ::SetWindowLong(pWnd->m_hWnd, GWL_EXSTYLE, lStyleEx); + + // size + CRect rc((*it).m_itemTemplate.x, (*it).m_itemTemplate.y, (*it).m_itemTemplate.x+(*it).m_itemTemplate.cx, (*it).m_itemTemplate.y+(*it).m_itemTemplate.cy); + MapRect(&rc); + pWnd->SetWindowPos(NULL, rc.left, rc.top, rc.Width(), rc.Height(), SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE); + + // text/caption + if ( (*it).m_wClass == 0x0080 || (*it).m_wClass == 0x0082 || (*it).m_wClass == 0x0086 || ((*it).m_pszClass != NULL && _tcscmp((*it).m_pszClass, _T("STATICEX")) == 0) ) + pWnd->SetWindowText(m_prm->LoadString((WORD)m_uiResID, (*it).m_itemTemplate.id)); + } +} + +/////////////////////////////////////////////////////////////// +// Helper function - does the cleanup after destroying the +// dialog (that means releasing the instance lock, deleting +// unused fonts and in some cases deleting itself). +/////////////////////////////////////////////////////////////// +void CLanguageDialog::Cleanup() +{ + TRACE("CLanguageDialog::Cleanup()\n"); + + if (m_bLockChanged && m_pbLock) + *m_pbLock=false; + + delete m_pFont; + + if (m_bAutoDelete) + delete this; +} + +/////////////////////////////////////////////////////////////// +// Standard msg - initializes tool tip handling +/////////////////////////////////////////////////////////////// +BOOL CLanguageDialog::OnInitDialog() +{ + CDialog::OnInitDialog(); + + UpdateLanguage(0,0); // because initially all the texts are empty + + EnableToolTips(TRUE); + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + +/////////////////////////////////////////////////////////////// +// Standard handler for pressing cancel button in a dialog. +// For modeless dialog causes dialog to be destroyed. +/////////////////////////////////////////////////////////////// +void CLanguageDialog::OnCancel() +{ + switch (m_cType) + { + case 0: + CDialog::OnCancel(); + break; + case 1: + DestroyWindow(); + break; + } +} + +/////////////////////////////////////////////////////////////// +// Standard handler for pressing OK button in a dialog. +// For modeless dialog causes destruction of a dialog. +/////////////////////////////////////////////////////////////// +void CLanguageDialog::OnOK() +{ + switch(m_cType) + { + case 0: + CDialog::OnOK(); + break; + case 1: + DestroyWindow(); + break; + } +} + +/////////////////////////////////////////////////////////////// +// Standard override - calls cleanup. +/////////////////////////////////////////////////////////////// +void CLanguageDialog::PostNcDestroy() +{ + CDialog::PostNcDestroy(); + Cleanup(); +} + +/////////////////////////////////////////////////////////////// +// This dialog's window procedure handler - look at ms docs. +/////////////////////////////////////////////////////////////// +LRESULT CLanguageDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch(message) + { + case WM_RMNOTIFY: + if ((UINT)wParam == RMNT_LANGCHANGE) + { + UpdateLanguage(HIWORD(lParam), LOWORD(lParam)); + + // now update user controls (everybody has to do it him(her)self) + OnLanguageChanged(HIWORD(lParam), LOWORD(lParam)); + break; + } + case WM_NOTIFY: + { + NMHDR* pnmh=(NMHDR*)lParam; + if (pnmh->code == TTN_NEEDTEXT) + { + // establish the ID of a control + TOOLTIPTEXT *ppt=(TOOLTIPTEXT*)pnmh; + UINT nID; + if (ppt->uFlags & TTF_IDISHWND) + nID=(UINT)::GetDlgCtrlID((HWND)pnmh->idFrom); + else + nID=(UINT)pnmh->idFrom; + + return OnTooltipText(nID, ppt); + } + break; + } + } + + return CDialog::WindowProc(message, wParam, lParam); +} + +/////////////////////////////////////////////////////////////// +// Helper function. Recalculates current sizes of a dialog base +// units (font dependent) and stores in the internal members. +// pszFacename [in] - font's face name. +// wPointSize [in] - size of the font in points. +/////////////////////////////////////////////////////////////// +void CLanguageDialog::CalcBaseUnits(PCTSTR pszFacename, WORD wPointSize) +{ + LOGFONT lf; + HDC hDC = ::GetDC(NULL); + memset(&lf, 0, sizeof(LOGFONT)); + lf.lfHeight = -MulDiv(wPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72); + lf.lfWeight = FW_NORMAL; + lf.lfCharSet = DEFAULT_CHARSET; + lstrcpy(lf.lfFaceName, pszFacename); + + HFONT hNewFont = CreateFontIndirect(&lf); + if (hNewFont != NULL) + { + HFONT hFontOld = (HFONT)SelectObject(hDC, hNewFont); + TEXTMETRIC tm; + GetTextMetrics(hDC, &tm); + m_iBaseY = tm.tmHeight + tm.tmExternalLeading; + SIZE size; + ::GetTextExtentPoint32(hDC, _T("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"), 52, &size); + m_iBaseX = (size.cx + 26) / 52; + SelectObject(hDC, hFontOld); + DeleteObject(hNewFont); + } + else + { + // Could not create the font so just use the system's values + m_iBaseX = LOWORD(GetDialogBaseUnits()); + m_iBaseY = HIWORD(GetDialogBaseUnits()); + } + ::ReleaseDC(NULL, hDC); +} \ No newline at end of file Index: modules/App Framework/LanguageDialog.cpp =================================================================== diff -u -N --- modules/App Framework/LanguageDialog.cpp (revision 7d997aef1e72f049ed1bc199e1b765d737d9963a) +++ modules/App Framework/LanguageDialog.cpp (revision 0) @@ -1,675 +0,0 @@ -/************************************************************************ - 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. -*************************************************************************/ - -#include "stdafx.h" -#include "LanguageDialog.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -///////////////////////////////////////////////////////////////////////////// -// CDlgTemplate -CDlgTemplate::CDlgTemplate(const DLGTEMPLATE* pDlgTemplate) -{ - Open(pDlgTemplate); -} - -CDlgTemplate::CDlgTemplate(const DLGTEMPLATEEX* pDlgTemplate) -{ - Open((DLGTEMPLATE*)pDlgTemplate); -} - -CDlgTemplate::~CDlgTemplate() -{ - delete [] m_pszMenu; - delete [] m_pszClass; - delete [] m_pszTitle; - delete [] m_pszFace; - - // items - vector<_ITEM>::iterator it; - for (it=m_vItems.begin();it != m_vItems.end();it++) - { - delete [] (*it).m_pbyCreationData; - delete [] (*it).m_pszClass; - delete [] (*it).m_pszTitle; - } -} - -bool CDlgTemplate::Open(const DLGTEMPLATE* pDlgTemplate) -{ - if (pDlgTemplate == NULL) - return false; - bool bExt=((DLGTEMPLATEEX*)pDlgTemplate)->signature == 0xffff; - const BYTE* pData=((BYTE*)pDlgTemplate); - if (bExt) - { - m_dlgTemplate=*((DLGTEMPLATEEX*)pDlgTemplate); - pData+=sizeof(DLGTEMPLATEEX); - } - else - { - ConvertDlgToEx(pDlgTemplate, &m_dlgTemplate); - pData+=sizeof(DLGTEMPLATE); - } - - // here is the menu, class and title - pData=ReadCompoundData(pData, &m_wMenu, &m_pszMenu); - pData=ReadCompoundData(pData, &m_wClass, &m_pszClass); - pData=ReadCompoundData(pData, &m_wTitle, &m_pszTitle); - - // font - if (m_dlgTemplate.style & DS_SETFONT || m_dlgTemplate.style & DS_SHELLFONT) - { - m_wFontSize=*((WORD*)pData); - pData+=sizeof(WORD); - if (bExt) - { - m_wWeight=*((WORD*)pData); - pData+=sizeof(WORD); - m_byItalic=*((BYTE*)pData); - pData+=sizeof(BYTE); - m_byCharset=*((BYTE*)pData); - pData+=sizeof(BYTE); - } - else - { - m_wWeight=FW_NORMAL; - m_byItalic=FALSE; - m_byCharset=DEFAULT_CHARSET; - } - DWORD dwLen=(DWORD)wcslen((wchar_t*)pData); - m_pszFace=new TCHAR[dwLen+1]; -#ifdef _UNICODE - _tcscpy(m_pszFace, (wchar_t*)pData); -#else - WideCharToMultiByte(CP_ACP, 0, (wchar_t*)pData, dwLen+1, m_pszFace, dwLen+1, NULL, NULL); -#endif - pData+=(dwLen+1)*sizeof(wchar_t); - } - else - { - m_wFontSize=0xffff; - m_pszFace=NULL; - } - - // items - _ITEM item; - for (int i=0;i 0) - { - item.m_wCreationDataSize-=sizeof(WORD); - item.m_pbyCreationData=new BYTE[item.m_wCreationDataSize]; - memcpy(item.m_pbyCreationData, pData, item.m_wCreationDataSize); - } - else - item.m_pbyCreationData=NULL; - - m_vItems.push_back(item); - } - - return true; -} - -void CDlgTemplate::ConvertItemToEx(const DLGITEMTEMPLATE* pSrc, DLGITEMTEMPLATEEX* pDst) -{ - pDst->helpID=0; - pDst->exStyle=pSrc->dwExtendedStyle; - pDst->style=pSrc->style; - pDst->x=pSrc->x; - pDst->y=pSrc->y; - pDst->cx=pSrc->cx; - pDst->cy=pSrc->cy; - pDst->id=pSrc->id; -} - -void CDlgTemplate::ConvertDlgToEx(const DLGTEMPLATE* pSrc, DLGTEMPLATEEX* pDst) -{ - pDst->dlgVer=1; - pDst->signature=0x0000; - pDst->helpID=(ULONG)0; - pDst->exStyle=pSrc->dwExtendedStyle; - pDst->style=pSrc->style; - pDst->cDlgItems=pSrc->cdit; - pDst->x=pSrc->x; - pDst->y=pSrc->y; - pDst->cx=pSrc->cx; - pDst->cy=pSrc->cy; -} - -const BYTE* CDlgTemplate::ReadCompoundData(const BYTE* pBuffer, WORD* pwData, PTSTR* ppszStr) -{ - if (*((WORD*)pBuffer) == 0xffff) - { - *pwData=*((WORD*)(pBuffer+2)); - *ppszStr=NULL; - - return pBuffer+4; - } - else - { - *pwData=0xffff; - DWORD dwLen=(DWORD)wcslen((wchar_t*)pBuffer); - *ppszStr=new TCHAR[dwLen+1]; -#ifdef _UNICODE - _tcscpy(*ppszStr, (wchar_t*)pBuffer); -#else - WideCharToMultiByte(CP_ACP, 0, (wchar_t*)pBuffer, dwLen+1, *ppszStr, dwLen+1, NULL, NULL); -#endif - return pBuffer+(dwLen+1)*sizeof(wchar_t); - } - -} - -///////////////////////////////////////////////////////////////////////////// -// CLanguageDialog dialog - -CResourceManager *CLanguageDialog::m_prm=NULL; - -/////////////////////////////////////////////////////////////// -// Standard constructor -// pLock [in] - specifies address of a bool value that'll be -// used to check if another instance of this window has -// already been shown. Should be declared in derived class -// as 'static bool m_xxx;' and initialized to 0. -/////////////////////////////////////////////////////////////// -CLanguageDialog::CLanguageDialog(bool* pLock) : CDialog() -{ - m_pszResName=NULL; - m_uiResID=0; - m_pParent=NULL; - m_cType=-1; - m_bAutoDelete=false; - m_pFont=NULL; - m_pbLock=pLock; - m_bLockChanged=false; - m_bLockInstance=false; - m_iBaseX=m_iBaseY=0; - _ASSERT(m_prm); // make sure the CLanguageDialog::SetResManager() has been called aready - m_prm->m_lhDialogs.push_back(this); -} - -/////////////////////////////////////////////////////////////// -// Constructor that takes string based template name -// lpszTemplateName [in] - specifies the template name to load -// and show as this dialog. -// pParent [in] - logical (everyone knows) -// pLock [in] - address of a bool for dialog instance checks -/////////////////////////////////////////////////////////////// -CLanguageDialog::CLanguageDialog(PCTSTR lpszTemplateName, CWnd* pParent, bool* pLock) : CDialog() -{ - m_pszResName=lpszTemplateName; - if (IS_INTRESOURCE(lpszTemplateName)) - m_uiResID=(WORD)lpszTemplateName; - else - m_uiResID=0; - m_pParent=pParent; - m_cType=-1; - m_bAutoDelete=false; - m_pFont=NULL; - m_pbLock=pLock; - m_bLockChanged=false; - m_bLockInstance=false; - m_iBaseX=m_iBaseY=0; - _ASSERT(m_prm); // make sure the CLanguageDialog::SetResManager() has been called aready - m_prm->m_lhDialogs.push_back(this); -} - -/////////////////////////////////////////////////////////////// -// Constructor that takes UINT based template name -// uiIDTemplate [in] - specifies the template ID to load -// and show as this dialog. -// pParent [in] - logical (everyone knows) -// pLock [in] - address of a bool for dialog instance checks -/////////////////////////////////////////////////////////////// -CLanguageDialog::CLanguageDialog(UINT uiIDTemplate, CWnd* pParent, bool* pLock) : CDialog() -{ - m_pszResName=MAKEINTRESOURCE(uiIDTemplate); - m_uiResID=uiIDTemplate; - m_pParent=pParent; - m_cType=-1; - m_bAutoDelete=false; - m_pFont=NULL; - m_pbLock=pLock; - m_bLockChanged=false; - m_bLockInstance=false; - m_iBaseX=m_iBaseY=0; - _ASSERT(m_prm); // make sure the CLanguageDialog::SetResManager() has been called aready - m_prm->m_lhDialogs.push_back(this); -} - -/////////////////////////////////////////////////////////////// -// Standard destructor -// Removes itself from a list in CWinApp (not to get any window -// messages anymore). -/////////////////////////////////////////////////////////////// -CLanguageDialog::~CLanguageDialog() -{ - list::iterator it=m_prm->m_lhDialogs.begin(); - while (it != m_prm->m_lhDialogs.end()) - { - if (*it == this) - { - m_prm->m_lhDialogs.erase(it); - break; - } - - it++; - } -} - -///////////////////////////////////////////////////////////////////////////// -// CLanguageDialog message handlers - -/////////////////////////////////////////////////////////////// -// Makes properly constructed dialog modal. -// RetVal [out] - value returned by dialog proc -/////////////////////////////////////////////////////////////// -INT_PTR CLanguageDialog::DoModal() -{ - if (m_pszResName) - { - HGLOBAL hDialog=m_prm->LoadResource(RT_DIALOG, m_pszResName); - if (!InitModalIndirect(hDialog)) - return -1; - } - m_cType=0; - return CDialog::DoModal(); -} - -/////////////////////////////////////////////////////////////// -// Creates (and shows probably) this constructed dialog. -// RetVal [out] - if creation succeeded -/////////////////////////////////////////////////////////////// -BOOL CLanguageDialog::Create() -{ - _ASSERT(m_pszResName); // nothing was set as a dialog template - - if (!m_bLockInstance || m_pbLock == NULL || !(*m_pbLock)) - { - HGLOBAL hDialog=m_prm->LoadResource(RT_DIALOG, m_pszResName); - - // modeless dialog - if (!CreateIndirect(hDialog, m_pParent)) - return FALSE; - - m_cType=1; - if (m_pbLock) - { - *m_pbLock=true; - m_bLockChanged=true; - } - - return TRUE; - } - else - { - m_bLockChanged=false; - Cleanup(); - return FALSE; - } -} - -/////////////////////////////////////////////////////////////// -// Changes values based on dialog units into the values in -// pixels. Change is based on std MapDialogRect if the language -// hasn't been changed otf or takes current font into -// consideration. -// pRect [in/out] - on [in] - dialog units, on [out] - pixels -/////////////////////////////////////////////////////////////// -void CLanguageDialog::MapRect(RECT* pRect) -{ - if (m_pFont) - { - pRect->left=MulDiv(pRect->left, m_iBaseX, 4); - pRect->right=MulDiv(pRect->right, m_iBaseX, 4); - pRect->top=MulDiv(pRect->top, m_iBaseY, 8); - pRect->bottom=MulDiv(pRect->bottom, m_iBaseY, 8); - } - else - MapDialogRect(pRect); -} - -/////////////////////////////////////////////////////////////// -// Helper function - called when this dialog receives message -// WM_RMNOTIFY (with WPARAM == RMNT_LANGCHANGE). Updates the -// dialog with data from a new template. Passes params to -// virtual function OnLanguageChanged. -// wOldLang [in] - specifies the old language code -// wNewLang [in] - specifies the new language code. -/////////////////////////////////////////////////////////////// -void CLanguageDialog::UpdateLanguage(WORD /*wOldLang*/, WORD /*wNewLang*/) -{ - // cannot update for string based template - if (m_uiResID == 0) - return; - - // set the title - SetWindowText(m_prm->LoadString((WORD)m_uiResID, 0)); - - // load the dialog template - CDlgTemplate dt; - if (!dt.Open(m_prm->LoadDialog(MAKEINTRESOURCE(m_uiResID)))) - { - TRACE("Cannot open dialog template in UpdateLanguage\n"); - return; - } - - // update the menu - if (GetMenu()) - m_prm->UpdateMenu(GetMenu()->m_hMenu, dt.m_wMenu); - - // font - if (!(GetLanguageUpdateOptions() & LDF_NODIALOGFONT)) - { - // dialog font - LOGFONT lf; - memset(&lf, 0, sizeof(LOGFONT)); - HDC hdc=::GetDC(NULL); - lf.lfHeight = -MulDiv(m_prm->m_ld.GetPointSize(), GetDeviceCaps(hdc, LOGPIXELSY), 72); - ::ReleaseDC(NULL, hdc); - lf.lfWeight = FW_NORMAL; - lf.lfCharSet = m_prm->m_ld.GetCharset(); - _tcscpy(lf.lfFaceName, m_prm->m_ld.GetFontFace()); - - delete m_pFont; - m_pFont=new CFont(); - m_pFont->CreateFontIndirect(&lf); - - // change base dlg units - CalcBaseUnits(dt.m_pszFace, dt.m_wFontSize); - } - - if (!(GetLanguageUpdateOptions() & LDF_NODIALOGSIZE)) - { - // dialog size - CRect rcWin; - GetWindowRect(&rcWin); - - CRect rcDialog(0, 0, dt.m_dlgTemplate.cx, dt.m_dlgTemplate.cy); - MapRect(&rcDialog); - rcDialog.bottom+=2*GetSystemMetrics(SM_CYDLGFRAME)+GetSystemMetrics(SM_CYCAPTION); - - // correct the height by a menu height - if ((dt.m_wMenu != 0xffff) || ((dt.m_pszMenu != NULL) && _tcslen(dt.m_pszMenu) != 0)) - rcDialog.bottom+=GetSystemMetrics(SM_CYMENU); - - rcDialog.right+=2*GetSystemMetrics(SM_CXDLGFRAME); - rcDialog.OffsetRect(rcWin.CenterPoint().x-rcDialog.Width()/2, rcWin.CenterPoint().y-rcDialog.Height()/2); - - //TEMP - TRACE("Old dlg pos/size: x=%lu, y=%lu, cx=%lu, cy=%lu; \n\tNew dlg pos/size: x=%lu, y=%lu, cx=%lu, cy=%lu\n", rcWin.left, rcWin.top, rcWin.Width(), rcWin.Height(), rcDialog.left, rcDialog.top, rcDialog.Width(), rcDialog.Height()); - SetWindowPos(NULL, rcDialog.left, rcDialog.top, rcDialog.Width(), rcDialog.Height(), SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE); - } - - // the controls - CWnd* pWnd; - vector::iterator it; - for (it=dt.m_vItems.begin();it != dt.m_vItems.end();it++) - { - // skip controls that cannot be modified - if ( (*it).m_itemTemplate.id == 0xffff || (pWnd=GetDlgItem((*it).m_itemTemplate.id)) == NULL) - continue; - - // the font - if (!(GetLanguageUpdateOptions() & LDF_NODIALOGFONT)) - pWnd->SetFont(m_pFont, FALSE); - - // style&ex style - // modify only the rtl/ltr reading order - LONG lStyleEx=::GetWindowLong(pWnd->m_hWnd, GWL_EXSTYLE); - if (lStyleEx & WS_EX_RTLREADING) - { - if (!m_prm->m_ld.GetDirection()) - lStyleEx &= ~WS_EX_RTLREADING; - } - else - { - if (m_prm->m_ld.GetDirection()) - lStyleEx |= WS_EX_RTLREADING; - } - - ::SetWindowLong(pWnd->m_hWnd, GWL_EXSTYLE, lStyleEx); - - // size - CRect rc((*it).m_itemTemplate.x, (*it).m_itemTemplate.y, (*it).m_itemTemplate.x+(*it).m_itemTemplate.cx, (*it).m_itemTemplate.y+(*it).m_itemTemplate.cy); - MapRect(&rc); - pWnd->SetWindowPos(NULL, rc.left, rc.top, rc.Width(), rc.Height(), SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE); - - // text/caption - if ( (*it).m_wClass == 0x0080 || (*it).m_wClass == 0x0082 || (*it).m_wClass == 0x0086 || ((*it).m_pszClass != NULL && _tcscmp((*it).m_pszClass, _T("STATICEX")) == 0) ) - pWnd->SetWindowText(m_prm->LoadString((WORD)m_uiResID, (*it).m_itemTemplate.id)); - } -} - -/////////////////////////////////////////////////////////////// -// Helper function - does the cleanup after destroying the -// dialog (that means releasing the instance lock, deleting -// unused fonts and in some cases deleting itself). -/////////////////////////////////////////////////////////////// -void CLanguageDialog::Cleanup() -{ - TRACE("CLanguageDialog::Cleanup()\n"); - - if (m_bLockChanged && m_pbLock) - *m_pbLock=false; - - delete m_pFont; - - if (m_bAutoDelete) - delete this; -} - -/////////////////////////////////////////////////////////////// -// Standard msg - initializes tool tip handling -/////////////////////////////////////////////////////////////// -BOOL CLanguageDialog::OnInitDialog() -{ - CDialog::OnInitDialog(); - - UpdateLanguage(0,0); // because initially all the texts are empty - - EnableToolTips(TRUE); - - return TRUE; // return TRUE unless you set the focus to a control - // EXCEPTION: OCX Property Pages should return FALSE -} - -/////////////////////////////////////////////////////////////// -// Standard handler for pressing cancel button in a dialog. -// For modeless dialog causes dialog to be destroyed. -/////////////////////////////////////////////////////////////// -void CLanguageDialog::OnCancel() -{ - switch (m_cType) - { - case 0: - CDialog::OnCancel(); - break; - case 1: - DestroyWindow(); - break; - } -} - -/////////////////////////////////////////////////////////////// -// Standard handler for pressing OK button in a dialog. -// For modeless dialog causes destruction of a dialog. -/////////////////////////////////////////////////////////////// -void CLanguageDialog::OnOK() -{ - switch(m_cType) - { - case 0: - CDialog::OnOK(); - break; - case 1: - DestroyWindow(); - break; - } -} - -/////////////////////////////////////////////////////////////// -// Standard override - calls cleanup. -/////////////////////////////////////////////////////////////// -void CLanguageDialog::PostNcDestroy() -{ - CDialog::PostNcDestroy(); - Cleanup(); -} - -/////////////////////////////////////////////////////////////// -// This dialog's window procedure handler - look at ms docs. -/////////////////////////////////////////////////////////////// -LRESULT CLanguageDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) -{ - switch(message) - { - case WM_RMNOTIFY: - if ((UINT)wParam == RMNT_LANGCHANGE) - { - UpdateLanguage(HIWORD(lParam), LOWORD(lParam)); - - // now update user controls (everybody has to do it him(her)self) - OnLanguageChanged(HIWORD(lParam), LOWORD(lParam)); - break; - } - case WM_NOTIFY: - { - NMHDR* pnmh=(NMHDR*)lParam; - if (pnmh->code == TTN_NEEDTEXT) - { - // establish the ID of a control - TOOLTIPTEXT *ppt=(TOOLTIPTEXT*)pnmh; - UINT nID; - if (ppt->uFlags & TTF_IDISHWND) - nID=(UINT)::GetDlgCtrlID((HWND)pnmh->idFrom); - else - nID=(UINT)pnmh->idFrom; - - return OnTooltipText(nID, ppt); - } - break; - } - } - - return CDialog::WindowProc(message, wParam, lParam); -} - -/////////////////////////////////////////////////////////////// -// Helper function. Recalculates current sizes of a dialog base -// units (font dependent) and stores in the internal members. -// pszFacename [in] - font's face name. -// wPointSize [in] - size of the font in points. -/////////////////////////////////////////////////////////////// -void CLanguageDialog::CalcBaseUnits(PCTSTR pszFacename, WORD wPointSize) -{ - LOGFONT lf; - HDC hDC = ::GetDC(NULL); - memset(&lf, 0, sizeof(LOGFONT)); - lf.lfHeight = -MulDiv(wPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72); - lf.lfWeight = FW_NORMAL; - lf.lfCharSet = DEFAULT_CHARSET; - lstrcpy(lf.lfFaceName, pszFacename); - - HFONT hNewFont = CreateFontIndirect(&lf); - if (hNewFont != NULL) - { - HFONT hFontOld = (HFONT)SelectObject(hDC, hNewFont); - TEXTMETRIC tm; - GetTextMetrics(hDC, &tm); - m_iBaseY = tm.tmHeight + tm.tmExternalLeading; - SIZE size; - ::GetTextExtentPoint32(hDC, _T("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"), 52, &size); - m_iBaseX = (size.cx + 26) / 52; - SelectObject(hDC, hFontOld); - DeleteObject(hNewFont); - } - else - { - // Could not create the font so just use the system's values - m_iBaseX = LOWORD(GetDialogBaseUnits()); - m_iBaseY = HIWORD(GetDialogBaseUnits()); - } - ::ReleaseDC(NULL, hDC); -} \ No newline at end of file Index: ch/LanguageDialog.h =================================================================== diff -u -N --- ch/LanguageDialog.h (revision 0) +++ ch/LanguageDialog.h (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,202 @@ +/************************************************************************ + 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. +*************************************************************************/ +/************************************************************************* + CLanguageDialog template + + Files: LanguageDialog.h, LanguageDialog.cpp + Author: Ixen Gerthannes + Usage: + Derive your class from CLanguageDialog instead of CDialog, change all + calls from CDialog to CLanguageDialog, change call to base constructor + so it can take language as parameter. + Creating dialog class: + - derive class from CLanguageDialog + - change all occurences of CDialog to CLanguageDialog + - change parameters list of your default constructor so it can take + language as parameter (WORD wLang) + - modify call to base class constructor by putting into it declared + wLang from your constructor + Displaying dialog box: + - declare object as your dialog class + - eventually set public member m_bAutoDelete to true if you're + creating dialog with operator new, and it should be + automatically deleted when closed + - call DoModal/Create/CreateModeless member function for + modal/modeless/mixed mode dialog + Members: + Constructors - as described in CDialog constructors - language + specifies resource language to load + CLanguageDialog(); + CLanguageDialog(PCTSTR lpszTemplateName, CWnd* pParent = NULL); + CLanguageDialog(UINT uiIDTemplate, CWnd* pParent = NULL); + Functions: + int DoModal(); - like in CDialog + BOOL Create(); - creates modeless dialog box; this class + automatically handles DestroyWindow, and like + void Cleanup(); - function cleans unused data - use only when + window object wasn't created yet (in Create() and earlier) + WORD GetCurrentLanguage() const; - retrieves current language + setting for this dialog + Attributes: + bool m_bAutoDelete; - specifies whether this dialog should be + deleted (by 'delete this') when closed. +*************************************************************************/ +#pragma once + +#include "ResourceManager.h" + +#pragma pack(push, 1) +struct DLGTEMPLATEEX +{ + WORD dlgVer; + WORD signature; + DWORD helpID; + DWORD exStyle; + DWORD style; + WORD cDlgItems; + short x; + short y; + short cx; + short cy; +}; + +struct DLGITEMTEMPLATEEX +{ + DWORD helpID; + DWORD exStyle; + DWORD style; + short x; + short y; + short cx; + short cy; + WORD id; + WORD __DUMMY__; +}; +#pragma pack(pop) + +class CDlgTemplate +{ +public: + CDlgTemplate() { m_wMenu=(WORD)-1; m_pszMenu=NULL; m_wClass=(WORD)-1; m_pszClass=NULL, m_wTitle=(WORD)-1; m_pszTitle=NULL; m_wFontSize=0; m_wWeight=0; m_byItalic=0; m_byCharset=0; m_pszFace=NULL; }; + CDlgTemplate(const DLGTEMPLATE* pDlgTemplate); + CDlgTemplate(const DLGTEMPLATEEX* pDlgTemplate); + ~CDlgTemplate(); + + bool Open(const DLGTEMPLATE* pDlgTemplate); + +protected: + void ConvertItemToEx(const DLGITEMTEMPLATE* pSrc, DLGITEMTEMPLATEEX* pDst); // converts DLGITEMTEMPLATE to DLGITEMTEMPLATEEX + void ConvertDlgToEx(const DLGTEMPLATE* pSrc, DLGTEMPLATEEX* pDst); + + const BYTE* ReadCompoundData(const BYTE* pBuffer, WORD* pwData, PTSTR* ppszStr); + +public: + struct _ITEM + { + DLGITEMTEMPLATEEX m_itemTemplate; + + WORD m_wClass; + TCHAR *m_pszClass; + + WORD m_wTitle; + TCHAR *m_pszTitle; + + WORD m_wCreationDataSize; + BYTE *m_pbyCreationData; + }; + vector<_ITEM> m_vItems; + + DLGTEMPLATEEX m_dlgTemplate; + + WORD m_wMenu; + TCHAR *m_pszMenu; + + WORD m_wClass; + TCHAR *m_pszClass; + + WORD m_wTitle; // always -1 + TCHAR *m_pszTitle; + + // font + WORD m_wFontSize; + WORD m_wWeight; + BYTE m_byItalic; + BYTE m_byCharset; + TCHAR *m_pszFace; +}; + +///////////////////////////////////////////////////////////////////////////// +// CLanguageDialog dialog +#define LDF_NODIALOGSIZE 0x01 +#define LDF_NODIALOGFONT 0x02 + +class CLanguageDialog : public CDialog +{ +public: +// Construction/destruction + CLanguageDialog(bool* pLock=NULL); + CLanguageDialog(PCTSTR lpszTemplateName, CWnd* pParent = NULL, bool* pLock=NULL); // standard constructor + CLanguageDialog(UINT uiIDTemplate, CWnd* pParent = NULL, bool* pLock=NULL); // standard constructor + + ~CLanguageDialog(); + + // static members - initialize global pointer to a resource manager + static void SetResManager(CResourceManager* prm) { m_prm=prm; }; + + // creation + virtual INT_PTR DoModal(); + virtual BOOL Create(); + + void MapRect(RECT* pRect); + CFont* GetFont() { return m_pFont ? m_pFont : ((CDialog*)this)->GetFont(); }; + +protected: + void UpdateLanguage(WORD wOldLang, WORD wNewLang); + virtual UINT GetLanguageUpdateOptions() { return 0; }; + virtual void OnLanguageChanged(WORD /*wOld*/, WORD /*wNew*/) { }; + void Cleanup(); + + virtual BOOL OnTooltipText(UINT /*uiID*/, TOOLTIPTEXT* /*pTip*/) { return FALSE; }; + virtual BOOL OnInitDialog(); + virtual void OnCancel(); + virtual void OnOK(); + virtual void PostNcDestroy(); + virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); + +private: + void CalcBaseUnits(PCTSTR pszFacename, WORD wPointSize); + +// Attributes +public: + bool m_bAutoDelete; // deletes this dialog when exiting + bool m_bLockInstance; // allows only one instance of this dialog if set + +protected: + static CResourceManager* m_prm; // points to the resource manager instance + + bool *m_pbLock; // dialog box instance lock system + bool m_bLockChanged; // if this dialog changed the lock + PCTSTR m_pszResName; // resource (string) name of the dialog template + UINT m_uiResID; // resource ID if any of the dialog template + CWnd* m_pParent; // parent window ptr + char m_cType; // type of this dialog box + CFont* m_pFont; // currently used font + int m_iBaseX, m_iBaseY; +}; \ No newline at end of file Index: modules/App Framework/LanguageDialog.h =================================================================== diff -u -N --- modules/App Framework/LanguageDialog.h (revision 3e1186252ab31f63d86d86c4b0ff593cfffbefde) +++ modules/App Framework/LanguageDialog.h (revision 0) @@ -1,202 +0,0 @@ -/************************************************************************ - 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. -*************************************************************************/ -/************************************************************************* - CLanguageDialog template - - Files: LanguageDialog.h, LanguageDialog.cpp - Author: Ixen Gerthannes - Usage: - Derive your class from CLanguageDialog instead of CDialog, change all - calls from CDialog to CLanguageDialog, change call to base constructor - so it can take language as parameter. - Creating dialog class: - - derive class from CLanguageDialog - - change all occurences of CDialog to CLanguageDialog - - change parameters list of your default constructor so it can take - language as parameter (WORD wLang) - - modify call to base class constructor by putting into it declared - wLang from your constructor - Displaying dialog box: - - declare object as your dialog class - - eventually set public member m_bAutoDelete to true if you're - creating dialog with operator new, and it should be - automatically deleted when closed - - call DoModal/Create/CreateModeless member function for - modal/modeless/mixed mode dialog - Members: - Constructors - as described in CDialog constructors - language - specifies resource language to load - CLanguageDialog(); - CLanguageDialog(PCTSTR lpszTemplateName, CWnd* pParent = NULL); - CLanguageDialog(UINT uiIDTemplate, CWnd* pParent = NULL); - Functions: - int DoModal(); - like in CDialog - BOOL Create(); - creates modeless dialog box; this class - automatically handles DestroyWindow, and like - void Cleanup(); - function cleans unused data - use only when - window object wasn't created yet (in Create() and earlier) - WORD GetCurrentLanguage() const; - retrieves current language - setting for this dialog - Attributes: - bool m_bAutoDelete; - specifies whether this dialog should be - deleted (by 'delete this') when closed. -*************************************************************************/ -#pragma once - -#include "ResourceManager.h" - -#pragma pack(push, 1) -struct DLGTEMPLATEEX -{ - WORD dlgVer; - WORD signature; - DWORD helpID; - DWORD exStyle; - DWORD style; - WORD cDlgItems; - short x; - short y; - short cx; - short cy; -}; - -struct DLGITEMTEMPLATEEX -{ - DWORD helpID; - DWORD exStyle; - DWORD style; - short x; - short y; - short cx; - short cy; - WORD id; - WORD __DUMMY__; -}; -#pragma pack(pop) - -class CDlgTemplate -{ -public: - CDlgTemplate() { m_wMenu=(WORD)-1; m_pszMenu=NULL; m_wClass=(WORD)-1; m_pszClass=NULL, m_wTitle=(WORD)-1; m_pszTitle=NULL; m_wFontSize=0; m_wWeight=0; m_byItalic=0; m_byCharset=0; m_pszFace=NULL; }; - CDlgTemplate(const DLGTEMPLATE* pDlgTemplate); - CDlgTemplate(const DLGTEMPLATEEX* pDlgTemplate); - ~CDlgTemplate(); - - bool Open(const DLGTEMPLATE* pDlgTemplate); - -protected: - void ConvertItemToEx(const DLGITEMTEMPLATE* pSrc, DLGITEMTEMPLATEEX* pDst); // converts DLGITEMTEMPLATE to DLGITEMTEMPLATEEX - void ConvertDlgToEx(const DLGTEMPLATE* pSrc, DLGTEMPLATEEX* pDst); - - const BYTE* ReadCompoundData(const BYTE* pBuffer, WORD* pwData, PTSTR* ppszStr); - -public: - struct _ITEM - { - DLGITEMTEMPLATEEX m_itemTemplate; - - WORD m_wClass; - TCHAR *m_pszClass; - - WORD m_wTitle; - TCHAR *m_pszTitle; - - WORD m_wCreationDataSize; - BYTE *m_pbyCreationData; - }; - vector<_ITEM> m_vItems; - - DLGTEMPLATEEX m_dlgTemplate; - - WORD m_wMenu; - TCHAR *m_pszMenu; - - WORD m_wClass; - TCHAR *m_pszClass; - - WORD m_wTitle; // always -1 - TCHAR *m_pszTitle; - - // font - WORD m_wFontSize; - WORD m_wWeight; - BYTE m_byItalic; - BYTE m_byCharset; - TCHAR *m_pszFace; -}; - -///////////////////////////////////////////////////////////////////////////// -// CLanguageDialog dialog -#define LDF_NODIALOGSIZE 0x01 -#define LDF_NODIALOGFONT 0x02 - -class CLanguageDialog : public CDialog -{ -public: -// Construction/destruction - CLanguageDialog(bool* pLock=NULL); - CLanguageDialog(PCTSTR lpszTemplateName, CWnd* pParent = NULL, bool* pLock=NULL); // standard constructor - CLanguageDialog(UINT uiIDTemplate, CWnd* pParent = NULL, bool* pLock=NULL); // standard constructor - - ~CLanguageDialog(); - - // static members - initialize global pointer to a resource manager - static void SetResManager(CResourceManager* prm) { m_prm=prm; }; - - // creation - virtual INT_PTR DoModal(); - virtual BOOL Create(); - - void MapRect(RECT* pRect); - CFont* GetFont() { return m_pFont ? m_pFont : ((CDialog*)this)->GetFont(); }; - -protected: - void UpdateLanguage(WORD wOldLang, WORD wNewLang); - virtual UINT GetLanguageUpdateOptions() { return 0; }; - virtual void OnLanguageChanged(WORD /*wOld*/, WORD /*wNew*/) { }; - void Cleanup(); - - virtual BOOL OnTooltipText(UINT /*uiID*/, TOOLTIPTEXT* /*pTip*/) { return FALSE; }; - virtual BOOL OnInitDialog(); - virtual void OnCancel(); - virtual void OnOK(); - virtual void PostNcDestroy(); - virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); - -private: - void CalcBaseUnits(PCTSTR pszFacename, WORD wPointSize); - -// Attributes -public: - bool m_bAutoDelete; // deletes this dialog when exiting - bool m_bLockInstance; // allows only one instance of this dialog if set - -protected: - static CResourceManager* m_prm; // points to the resource manager instance - - bool *m_pbLock; // dialog box instance lock system - bool m_bLockChanged; // if this dialog changed the lock - PCTSTR m_pszResName; // resource (string) name of the dialog template - UINT m_uiResID; // resource ID if any of the dialog template - CWnd* m_pParent; // parent window ptr - char m_cType; // type of this dialog box - CFont* m_pFont; // currently used font - int m_iBaseX, m_iBaseY; -}; \ No newline at end of file Index: ch/MemDC.h =================================================================== diff -u -N --- ch/MemDC.h (revision 0) +++ ch/MemDC.h (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,106 @@ +/************************************************************************ + Copy Handler 1.x - program for copying data in Microsoft Windows + systems. + Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. +*************************************************************************/ +/////////////////////////////////////////////////////////////// +// CMemDC - memory DC +// +// Author: Keith Rule +// Email: keithr@europa.com +// Copyright 1996-1997, Keith Rule +// +// You may freely use or modify this code provided this +// Copyright is included in all derived versions. +// +/////////////////////////////////////////////////////////////// +#ifndef _MEMDC_H_ +#define _MEMDC_H_ + +/////////////////////////////////////////////////////////////// +// BCMenuMemDC - memory DC +// +// Author: Keith Rule +// Email: keithr@europa.com +// Copyright 1996-1997, Keith Rule +// +// You may freely use or modify this code provided this +// Copyright is included in all derived versions. +// +// History - 10/3/97 Fixed scrolling bug. +// Added print support. +// 25 feb 98 - fixed minor assertion bug +// +// This class implements a memory Device Context +/////////////////////////////////////////////////////////////// +class CMemDC : public CDC +{ +public: + + // constructor sets up the memory DC + CMemDC(CDC* pDC, LPCRECT lpSrcRect) : CDC() + { + ASSERT(pDC != NULL); + + m_rect.CopyRect(lpSrcRect); + m_pDC = pDC; + m_pOldBitmap = NULL; + m_bMemDC = !pDC->IsPrinting(); + + if (m_bMemDC) // Create a Memory DC + { + CreateCompatibleDC(pDC); + m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height()); + m_pOldBitmap = SelectObject(&m_bitmap); + SetWindowOrg(m_rect.left, m_rect.top); + } + else // Make a copy of the relevent parts of the current DC for printing + { + m_bPrinting = pDC->m_bPrinting; + m_hDC = pDC->m_hDC; + m_hAttribDC = pDC->m_hAttribDC; + } + } + + // Destructor copies the contents of the mem DC to the original DC + ~CMemDC() + { + if (m_bMemDC) + { + // Copy the offscreen bitmap onto the screen. + m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), + this, m_rect.left, m_rect.top, SRCCOPY); + + //Swap back the original bitmap. + SelectObject(m_pOldBitmap); + } else { + // All we need to do is replace the DC with an illegal value, + // this keeps us from accidently deleting the handles associated with + // the CDC that was passed to the constructor. + m_hDC = m_hAttribDC = NULL; + } + } + +private: + CBitmap m_bitmap; // Offscreen bitmap + CBitmap* m_pOldBitmap; // bitmap originally found in BCMenuMemDC + CDC* m_pDC; // Saves CDC passed in constructor + CRect m_rect; // Rectangle of drawing area. + BOOL m_bMemDC; // TRUE if CDC really is a Memory DC. +}; + +#endif \ No newline at end of file Index: modules/App Framework/MemDC.h =================================================================== diff -u -N --- modules/App Framework/MemDC.h (revision 3e1186252ab31f63d86d86c4b0ff593cfffbefde) +++ modules/App Framework/MemDC.h (revision 0) @@ -1,106 +0,0 @@ -/************************************************************************ - Copy Handler 1.x - program for copying data in Microsoft Windows - systems. - Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. -*************************************************************************/ -/////////////////////////////////////////////////////////////// -// CMemDC - memory DC -// -// Author: Keith Rule -// Email: keithr@europa.com -// Copyright 1996-1997, Keith Rule -// -// You may freely use or modify this code provided this -// Copyright is included in all derived versions. -// -/////////////////////////////////////////////////////////////// -#ifndef _MEMDC_H_ -#define _MEMDC_H_ - -/////////////////////////////////////////////////////////////// -// BCMenuMemDC - memory DC -// -// Author: Keith Rule -// Email: keithr@europa.com -// Copyright 1996-1997, Keith Rule -// -// You may freely use or modify this code provided this -// Copyright is included in all derived versions. -// -// History - 10/3/97 Fixed scrolling bug. -// Added print support. -// 25 feb 98 - fixed minor assertion bug -// -// This class implements a memory Device Context -/////////////////////////////////////////////////////////////// -class CMemDC : public CDC -{ -public: - - // constructor sets up the memory DC - CMemDC(CDC* pDC, LPCRECT lpSrcRect) : CDC() - { - ASSERT(pDC != NULL); - - m_rect.CopyRect(lpSrcRect); - m_pDC = pDC; - m_pOldBitmap = NULL; - m_bMemDC = !pDC->IsPrinting(); - - if (m_bMemDC) // Create a Memory DC - { - CreateCompatibleDC(pDC); - m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height()); - m_pOldBitmap = SelectObject(&m_bitmap); - SetWindowOrg(m_rect.left, m_rect.top); - } - else // Make a copy of the relevent parts of the current DC for printing - { - m_bPrinting = pDC->m_bPrinting; - m_hDC = pDC->m_hDC; - m_hAttribDC = pDC->m_hAttribDC; - } - } - - // Destructor copies the contents of the mem DC to the original DC - ~CMemDC() - { - if (m_bMemDC) - { - // Copy the offscreen bitmap onto the screen. - m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), - this, m_rect.left, m_rect.top, SRCCOPY); - - //Swap back the original bitmap. - SelectObject(m_pOldBitmap); - } else { - // All we need to do is replace the DC with an illegal value, - // this keeps us from accidently deleting the handles associated with - // the CDC that was passed to the constructor. - m_hDC = m_hAttribDC = NULL; - } - } - -private: - CBitmap m_bitmap; // Offscreen bitmap - CBitmap* m_pOldBitmap; // bitmap originally found in BCMenuMemDC - CDC* m_pDC; // Saves CDC passed in constructor - CRect m_rect; // Rectangle of drawing area. - BOOL m_bMemDC; // TRUE if CDC really is a Memory DC. -}; - -#endif \ No newline at end of file Index: ch/ResourceManager.cpp =================================================================== diff -u -N --- ch/ResourceManager.cpp (revision 0) +++ ch/ResourceManager.cpp (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,501 @@ +/************************************************************************ + Copy Handler 1.x - program for copying data in Microsoft Windows + systems. + Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. +*************************************************************************/ +#include "stdafx.h" +#include "IniFile.h" +#include "ResourceManager.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +CLangData::CLangData(const CLangData& ld) +{ + szDefString=0; + pszFilename=NULL; + pszLngName=NULL; + pszBaseFile=NULL; + pszFontFace=NULL; + pszHelpName=NULL; + pszAuthor=NULL; + pszVersion=NULL; + pszStrings=NULL; + tCount=0; + + SetFilename(ld.GetFilename(true)); + SetLangName(ld.GetLangName()); + SetLangCode(ld.GetLangCode()); + SetFontFace(ld.GetFontFace()); + SetCharset(ld.GetCharset()); + SetPointSize(ld.GetPointSize()); + SetDirection(ld.GetDirection()); + SetHelpName(ld.GetHelpName()); + SetAuthor(ld.GetAuthor()); + SetVersion(ld.GetVersion()); + + SetStringData(ld.pszStrings, ld.tCount); +} + +bool CLangData::ReadInfo(PCTSTR pszFile) +{ + try + { + CIniFile file; + file.Open(pszFile, _T("Info"), true); + + TCHAR szData[512]; + SetLangName(file.GetString(_T("000"), _T("Info"), _T("Lang Name"), szData, _T(""))); + if (file.IsDefault()) + return false; + SetLangCode((WORD)file.GetInt(_T("000"), _T("Info"), _T("Lang Code"), 0, szData)); + if (file.IsDefault()) + return false; + SetBaseFile(file.GetString(_T("000"), _T("Info"), _T("Base Language"), szData, _T(""))); + if (file.IsDefault()) + return false; + SetFontFace(file.GetString(_T("000"), _T("Info"), _T("Font Face"), szData, _T(""))); + if (file.IsDefault()) + return false; + SetCharset((BYTE)file.GetInt(_T("000"), _T("Info"), _T("Charset"), 0, szData)); + if (file.IsDefault()) + return false; + SetPointSize((WORD)file.GetInt(_T("000"), _T("Info"), _T("Size"), 0, szData)); + if (file.IsDefault()) + return false; + SetDirection(file.GetBool(_T("000"), _T("Info"), _T("RTL reading order"), false, szData)); + if (file.IsDefault()) + return false; + SetHelpName(file.GetString(_T("000"), _T("Info"), _T("Help name"), szData, _T(""))); + if (file.IsDefault()) + return false; + SetAuthor(file.GetString(_T("000"), _T("Info"), _T("Author"), szData, _T(""))); + if (file.IsDefault()) + return false; + SetVersion(file.GetString(_T("000"), _T("Info"), _T("Version"), szData, _T(""))); + if (file.IsDefault()) + return false; + + SetFilename(pszFile); + + return true; + } + catch(...) + { + return false; + } +} + +bool CLangData::ReadTranslation(PCTSTR pszFile, bool bUpdate) +{ + try + { + // load data from file + CIniFile file; + file.Open(pszFile, NULL, true); + + TCHAR szData[512]; + if (!bUpdate) + { + // std data + SetLangName(file.GetString(_T("000"), _T("Info"), _T("Lang Name"), szData, _T(""))); + if (file.IsDefault()) + return false; + SetLangCode((WORD)file.GetInt(_T("000"), _T("Info"), _T("Lang Code"), 0, szData)); + if (file.IsDefault()) + return false; + SetBaseFile(file.GetString(_T("000"), _T("Info"), _T("Base Language"), szData, _T(""))); + if (file.IsDefault()) + return false; + SetFontFace(file.GetString(_T("000"), _T("Info"), _T("Font Face"), szData, _T(""))); + if (file.IsDefault()) + return false; + SetCharset((BYTE)file.GetInt(_T("000"), _T("Info"), _T("Charset"), 0, szData)); + if (file.IsDefault()) + return false; + SetPointSize((WORD)file.GetInt(_T("000"), _T("Info"), _T("Size"), 0, szData)); + if (file.IsDefault()) + return false; + SetDirection(file.GetBool(_T("000"), _T("Info"), _T("RTL reading order"), false, szData)); + if (file.IsDefault()) + return false; + SetHelpName(file.GetString(_T("000"), _T("Info"), _T("Help name"), szData, _T(""))); + if (file.IsDefault()) + return false; + SetAuthor(file.GetString(_T("000"), _T("Info"), _T("Author"), szData, _T(""))); + if (file.IsDefault()) + return false; + SetVersion(file.GetString(_T("000"), _T("Info"), _T("Version"), szData, _T(""))); + if (file.IsDefault()) + return false; + } + + // read strings section + const _PROFILE* pcfg=file.GetProfile(_T("000")); + if (pcfg) + { + // enum through the sections + size_t tSkipped=(size_t)-1; + WORD wHiID, wLoID; + size_t tDataCount=0; + + // 1st phase - count data length + vector<_SECTION*>::const_iterator sit; + for (sit=pcfg->vSections.begin();sit != pcfg->vSections.end();sit++) + { + // skip "Info" section + if (tSkipped == -1 && _tcscmp((*sit)->pszSectionName, _T("Info")) == 0) + { + tSkipped=sit-pcfg->vSections.begin(); + continue; + } + + // now translate all the section of form [000] to the ID's, enum through the entries + for (vector<_ENTRY*>::iterator it=(*sit)->vEntries.begin();it != (*sit)->vEntries.end();it++) + { + if (!bUpdate || m_mStrings.find((_ttoi((*sit)->pszSectionName) << 16) | (_ttoi((*it)->pszKey))) == m_mStrings.end()) + tDataCount+=_tcslen((*it)->pszValue)+1; + } + } + + // allocate the buffer for all data + size_t tOffset=0; + if (bUpdate) + { + if (tDataCount == 0) + return true; + + // we need to reallocate the buffer + TCHAR* pszData=new TCHAR[tCount+tDataCount]; + memcpy(pszData, pszStrings, tCount*sizeof(TCHAR)); + + delete [] pszStrings; + pszStrings=pszData; + + tOffset=tCount; + tCount+=tDataCount; + } + else + { + // delete old settings + delete [] pszStrings; + m_mStrings.clear(); + + tCount=tDataCount; + pszStrings=new TCHAR[tDataCount]; + } + + // 2nd phase - copy all the data + for (sit=pcfg->vSections.begin();sit != pcfg->vSections.end();sit++) + { + // skip "Info" section + if (tSkipped == (size_t)(sit-pcfg->vSections.begin())) + continue; + + // now translate all the section of form [000] to the ID's, enum through the entries + wHiID=(WORD)_ttoi((*sit)->pszSectionName); + for (vector<_ENTRY*>::iterator it=(*sit)->vEntries.begin();it != (*sit)->vEntries.end();it++) + { + // add to the map + wLoID=(WORD)_ttoi((*it)->pszKey); + if (!bUpdate || m_mStrings.find((wHiID << 16) | wLoID) == m_mStrings.end()) + { + m_mStrings.insert(strings_map::value_type((((DWORD)wHiID) << 16 | wLoID), tOffset)); + + // copy string + _tcscpy(pszStrings+tOffset, (*it)->pszValue); + tOffset+=_tcslen(pszStrings+tOffset)+1; + } + } + } + } + + // free unneded data + file.Close(); + + if (!bUpdate) + { + // remember the filename + SetFilename(pszFile); + + // establish path to the base file + if (_tcslen(GetBaseFile()) != 0) + { + TCHAR* pszName=_tcsrchr(pszFile, _T('\\')); + if (pszName) + { + _tcsncpy(szData, pszFile, pszName-pszFile+1); + _tcscpy(szData+(pszName-pszFile+1), GetBaseFile()); + TRACE("Base (update) path=%s\n", szData); + ReadTranslation(szData, true); + } + } + } + + return true; + } + catch(...) + { + return false; + } +} + +PCTSTR CLangData::GetString(WORD wHiID, WORD wLoID) +{ + strings_map::iterator it=m_mStrings.find((wHiID << 16) | wLoID); + if (it != m_mStrings.end()) + return pszStrings+(*it).second; + else + return &szDefString; +} + +void CLangData::SetFilename(PCTSTR psz) +{ + if (pszFilename) + delete [] pszFilename; + + // copy + pszFilename=new TCHAR[_tcslen(psz)+1]; + _tcscpy(pszFilename, psz); +} + +PCTSTR CLangData::GetFilename(bool bFullPath) const +{ + if (bFullPath) + return pszFilename; + else + { + TCHAR *pszFnd=_tcsrchr(pszFilename, _T('\\')); + if (pszFnd) + return pszFnd+1; + else + return pszFilename; + } +} + +void CLangData::SetFnameData(PTSTR *ppszDst, PCTSTR pszSrc) +{ + if (*ppszDst) + delete [] (*ppszDst); + const TCHAR* pszLast=NULL; + if ( (pszLast=_tcsrchr(pszSrc, _T('\\'))) != NULL) + pszLast++; + else + pszLast=pszSrc; + + // copy + *ppszDst=new TCHAR[_tcslen(pszLast)+1]; + _tcscpy(*ppszDst, pszLast); +} + +// requires the param with ending '\\' +void CResourceManager::Scan(LPCTSTR pszFolder, vector* pvData) +{ + TCHAR szPath[_MAX_PATH]; + _tcscpy(szPath, pszFolder); + _tcscat(szPath, _T("*.lng")); + + WIN32_FIND_DATA wfd; + HANDLE hFind=::FindFirstFile(szPath, &wfd); + BOOL bFound=TRUE; + CLangData ld; + while (bFound && hFind != INVALID_HANDLE_VALUE) + { + if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + _tcscpy(szPath, pszFolder); + _tcscat(szPath, wfd.cFileName); + if (ld.ReadInfo(szPath)) + pvData->push_back(ld); + } + + bFound=::FindNextFile(hFind, &wfd); + } + + if (hFind != INVALID_HANDLE_VALUE) + ::FindClose(hFind); +} + +bool CResourceManager::SetLanguage(PCTSTR pszPath) +{ + EnterCriticalSection(&m_cs); + WORD wOldLang=m_ld.GetLangCode(); + bool bRet=m_ld.ReadTranslation(pszPath); + WORD wNewLang=m_ld.GetLangCode(); + LeaveCriticalSection(&m_cs); + if (!bRet) + return false; + + // update registered dialog boxes + list::iterator it=m_lhDialogs.begin(); + while (it != m_lhDialogs.end()) + { + if (::IsWindow((*it)->m_hWnd)) + (*it)->PostMessage(WM_RMNOTIFY, RMNT_LANGCHANGE, (LPARAM)(wOldLang << 16 | wNewLang)); + it++; + } + + // send the notification stuff to the others + if (m_pfnCallback) + (*m_pfnCallback)(ROT_EVERYWHERE, WM_RMNOTIFY, RMNT_LANGCHANGE, (LPARAM)(wOldLang << 16 | wNewLang)); + + return bRet; +} + +HGLOBAL CResourceManager::LoadResource(LPCTSTR pszType, LPCTSTR pszName) +{ + EnterCriticalSection(&m_cs); + + // find resource + HGLOBAL hRet=NULL; + HRSRC hr=FindResource(m_hRes, pszName, pszType); + if (hr) + hRet=::LoadResource(m_hRes, hr); + + LeaveCriticalSection(&m_cs); + return hRet; +} + +HACCEL CResourceManager::LoadAccelerators(LPCTSTR pszName) +{ + return ::LoadAccelerators(m_hRes, pszName); +} + +HBITMAP CResourceManager::LoadBitmap(LPCTSTR pszName) +{ + return ::LoadBitmap(m_hRes, pszName); +} + +HCURSOR CResourceManager::LoadCursor(LPCTSTR pszName) +{ + return ::LoadCursor(m_hRes, pszName); +} + +HICON CResourceManager::LoadIcon(LPCTSTR pszName) +{ + return ::LoadIcon(m_hRes, pszName); +} + +void CResourceManager::UpdateMenu(HMENU hMenu, WORD wMenuID) +{ + // change the strings inside the menu to the one from txt res file + int iCount=::GetMenuItemCount(hMenu); + MENUITEMINFO mif; + WORD wLoID; + TCHAR szItem[1024]; + for (int i=0;i::const_iterator sit; - for (sit=pcfg->vSections.begin();sit != pcfg->vSections.end();sit++) - { - // skip "Info" section - if (tSkipped == -1 && _tcscmp((*sit)->pszSectionName, _T("Info")) == 0) - { - tSkipped=sit-pcfg->vSections.begin(); - continue; - } - - // now translate all the section of form [000] to the ID's, enum through the entries - for (vector<_ENTRY*>::iterator it=(*sit)->vEntries.begin();it != (*sit)->vEntries.end();it++) - { - if (!bUpdate || m_mStrings.find((_ttoi((*sit)->pszSectionName) << 16) | (_ttoi((*it)->pszKey))) == m_mStrings.end()) - tDataCount+=_tcslen((*it)->pszValue)+1; - } - } - - // allocate the buffer for all data - size_t tOffset=0; - if (bUpdate) - { - if (tDataCount == 0) - return true; - - // we need to reallocate the buffer - TCHAR* pszData=new TCHAR[tCount+tDataCount]; - memcpy(pszData, pszStrings, tCount*sizeof(TCHAR)); - - delete [] pszStrings; - pszStrings=pszData; - - tOffset=tCount; - tCount+=tDataCount; - } - else - { - // delete old settings - delete [] pszStrings; - m_mStrings.clear(); - - tCount=tDataCount; - pszStrings=new TCHAR[tDataCount]; - } - - // 2nd phase - copy all the data - for (sit=pcfg->vSections.begin();sit != pcfg->vSections.end();sit++) - { - // skip "Info" section - if (tSkipped == (size_t)(sit-pcfg->vSections.begin())) - continue; - - // now translate all the section of form [000] to the ID's, enum through the entries - wHiID=(WORD)_ttoi((*sit)->pszSectionName); - for (vector<_ENTRY*>::iterator it=(*sit)->vEntries.begin();it != (*sit)->vEntries.end();it++) - { - // add to the map - wLoID=(WORD)_ttoi((*it)->pszKey); - if (!bUpdate || m_mStrings.find((wHiID << 16) | wLoID) == m_mStrings.end()) - { - m_mStrings.insert(strings_map::value_type((((DWORD)wHiID) << 16 | wLoID), tOffset)); - - // copy string - _tcscpy(pszStrings+tOffset, (*it)->pszValue); - tOffset+=_tcslen(pszStrings+tOffset)+1; - } - } - } - } - - // free unneded data - file.Close(); - - if (!bUpdate) - { - // remember the filename - SetFilename(pszFile); - - // establish path to the base file - if (_tcslen(GetBaseFile()) != 0) - { - TCHAR* pszName=_tcsrchr(pszFile, _T('\\')); - if (pszName) - { - _tcsncpy(szData, pszFile, pszName-pszFile+1); - _tcscpy(szData+(pszName-pszFile+1), GetBaseFile()); - TRACE("Base (update) path=%s\n", szData); - ReadTranslation(szData, true); - } - } - } - - return true; - } - catch(...) - { - return false; - } -} - -PCTSTR CLangData::GetString(WORD wHiID, WORD wLoID) -{ - strings_map::iterator it=m_mStrings.find((wHiID << 16) | wLoID); - if (it != m_mStrings.end()) - return pszStrings+(*it).second; - else - return &szDefString; -} - -void CLangData::SetFilename(PCTSTR psz) -{ - if (pszFilename) - delete [] pszFilename; - - // copy - pszFilename=new TCHAR[_tcslen(psz)+1]; - _tcscpy(pszFilename, psz); -} - -PCTSTR CLangData::GetFilename(bool bFullPath) const -{ - if (bFullPath) - return pszFilename; - else - { - TCHAR *pszFnd=_tcsrchr(pszFilename, _T('\\')); - if (pszFnd) - return pszFnd+1; - else - return pszFilename; - } -} - -void CLangData::SetFnameData(PTSTR *ppszDst, PCTSTR pszSrc) -{ - if (*ppszDst) - delete [] (*ppszDst); - const TCHAR* pszLast=NULL; - if ( (pszLast=_tcsrchr(pszSrc, _T('\\'))) != NULL) - pszLast++; - else - pszLast=pszSrc; - - // copy - *ppszDst=new TCHAR[_tcslen(pszLast)+1]; - _tcscpy(*ppszDst, pszLast); -} - -// requires the param with ending '\\' -void CResourceManager::Scan(LPCTSTR pszFolder, vector* pvData) -{ - TCHAR szPath[_MAX_PATH]; - _tcscpy(szPath, pszFolder); - _tcscat(szPath, _T("*.lng")); - - WIN32_FIND_DATA wfd; - HANDLE hFind=::FindFirstFile(szPath, &wfd); - BOOL bFound=TRUE; - CLangData ld; - while (bFound && hFind != INVALID_HANDLE_VALUE) - { - if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) - { - _tcscpy(szPath, pszFolder); - _tcscat(szPath, wfd.cFileName); - if (ld.ReadInfo(szPath)) - pvData->push_back(ld); - } - - bFound=::FindNextFile(hFind, &wfd); - } - - if (hFind != INVALID_HANDLE_VALUE) - ::FindClose(hFind); -} - -bool CResourceManager::SetLanguage(PCTSTR pszPath) -{ - EnterCriticalSection(&m_cs); - WORD wOldLang=m_ld.GetLangCode(); - bool bRet=m_ld.ReadTranslation(pszPath); - WORD wNewLang=m_ld.GetLangCode(); - LeaveCriticalSection(&m_cs); - if (!bRet) - return false; - - // update registered dialog boxes - list::iterator it=m_lhDialogs.begin(); - while (it != m_lhDialogs.end()) - { - if (::IsWindow((*it)->m_hWnd)) - (*it)->PostMessage(WM_RMNOTIFY, RMNT_LANGCHANGE, (LPARAM)(wOldLang << 16 | wNewLang)); - it++; - } - - // send the notification stuff to the others - if (m_pfnCallback) - (*m_pfnCallback)(ROT_EVERYWHERE, WM_RMNOTIFY, RMNT_LANGCHANGE, (LPARAM)(wOldLang << 16 | wNewLang)); - - return bRet; -} - -HGLOBAL CResourceManager::LoadResource(LPCTSTR pszType, LPCTSTR pszName) -{ - EnterCriticalSection(&m_cs); - - // find resource - HGLOBAL hRet=NULL; - HRSRC hr=FindResource(m_hRes, pszName, pszType); - if (hr) - hRet=::LoadResource(m_hRes, hr); - - LeaveCriticalSection(&m_cs); - return hRet; -} - -HACCEL CResourceManager::LoadAccelerators(LPCTSTR pszName) -{ - return ::LoadAccelerators(m_hRes, pszName); -} - -HBITMAP CResourceManager::LoadBitmap(LPCTSTR pszName) -{ - return ::LoadBitmap(m_hRes, pszName); -} - -HCURSOR CResourceManager::LoadCursor(LPCTSTR pszName) -{ - return ::LoadCursor(m_hRes, pszName); -} - -HICON CResourceManager::LoadIcon(LPCTSTR pszName) -{ - return ::LoadIcon(m_hRes, pszName); -} - -void CResourceManager::UpdateMenu(HMENU hMenu, WORD wMenuID) -{ - // change the strings inside the menu to the one from txt res file - int iCount=::GetMenuItemCount(hMenu); - MENUITEMINFO mif; - WORD wLoID; - TCHAR szItem[1024]; - for (int i=0;i +#include +#include +#include "af_defs.h" + +using namespace std; + +///////////////////////////////////////////////////////////////////////// +// types of notifications +// RMNT_LANGCHANGE, LPARAM - HIWORD - old language, LOWORD - new language +#define RMNT_LANGCHANGE 0x0001 + +/////////////////////////////////////////////////////////// +// language description structure +typedef map strings_map; + +class CLangData +{ +public: +// construction/destruction + CLangData() { szDefString=0; pszFilename=NULL; pszLngName=NULL; pszBaseFile=NULL; pszFontFace=NULL; pszHelpName=NULL; pszAuthor=NULL; pszVersion=NULL; pszStrings=NULL; tCount=0; } + ~CLangData() { delete [] pszFilename; delete [] pszLngName; delete [] pszBaseFile; delete [] pszFontFace; delete [] pszHelpName; delete [] pszAuthor; delete [] pszVersion; delete [] pszStrings; }; + CLangData(const CLangData& ld); + +protected: + void SetFnameData(PTSTR *ppszDst, PCTSTR pszSrc); + +public: +// operations + bool ReadInfo(PCTSTR pszFile); + bool ReadTranslation(PCTSTR pszFile, bool bUpdate=false); + + PCTSTR GetString(WORD wHiID, WORD wLoID); + +// attributes + void SetFilename(PCTSTR psz); + PCTSTR GetFilename(bool bFullPath) const; + + void SetLangName(PCTSTR psz) { if (pszLngName) delete [] pszLngName; pszLngName=new TCHAR[_tcslen(psz)+1]; _tcscpy(pszLngName, psz); }; + PCTSTR GetLangName() const { return pszLngName; }; + + void SetBaseFile(PCTSTR psz) { SetFnameData(&pszBaseFile, psz); }; + PCTSTR GetBaseFile() const { return pszBaseFile; }; + + void SetLangCode(WORD wLang) { wLangCode=wLang; }; + WORD GetLangCode() const { return wLangCode; }; + + void SetFontFace(PCTSTR psz) { if (pszFontFace) delete [] pszFontFace; pszFontFace=new TCHAR[_tcslen(psz)+1]; _tcscpy(pszFontFace, psz); }; + PCTSTR GetFontFace() const { return pszFontFace; }; + + void SetCharset(BYTE byChar) { byCharset=byChar; }; + BYTE GetCharset() const { return byCharset; }; + + void SetPointSize(WORD wSize) { wPointSize=wSize; }; + WORD GetPointSize() const { return wPointSize; }; + + void SetDirection(bool brtl) { bRTL=brtl; }; + bool GetDirection() const { return bRTL; }; + + void SetHelpName(PCTSTR psz) { SetFnameData(&pszHelpName, psz); }; + PCTSTR GetHelpName() const { return pszHelpName; }; + + void SetAuthor(PCTSTR psz) { if (pszAuthor) delete [] pszAuthor; pszAuthor=new TCHAR[_tcslen(psz)+1]; _tcscpy(pszAuthor, psz); }; + PCTSTR GetAuthor() const { return pszAuthor; }; + + void SetVersion(PCTSTR psz) { if (pszVersion) delete [] pszVersion; pszVersion=new TCHAR[_tcslen(psz)+1]; _tcscpy(pszVersion, psz); }; + PCTSTR GetVersion() const { return pszVersion; }; + + void SetStringData(PCTSTR psz, size_t tCnt) { tCount=tCnt; if (pszStrings) delete [] pszStrings; if (tCount > 0) { pszStrings=new TCHAR[tCnt]; memcpy(pszStrings, psz, tCnt*sizeof(TCHAR)); } }; + +public: + TCHAR *pszFilename; // file name of the language data (with path) + TCHAR *pszLngName; // name of the language (ie. Chinese (PRC)) + TCHAR *pszBaseFile; // file with base language data (wo path) + TCHAR *pszFontFace; // face name of the font that will be used in dialogs + WORD wLangCode; // language code + WORD wPointSize; // font point size + TCHAR *pszHelpName; // help name (wo the directory) for this language + TCHAR *pszAuthor; // author name + TCHAR *pszVersion; // version of this file + BYTE byCharset; // charset for use with the font + bool bRTL; // does the language require right-to-left reading order ? + + // strings (for controls in dialog boxes the ID contains hi:dlg ID, lo:ctrl ID, for strings hi part is 0) + strings_map m_mStrings; // maps string ID to the offset in pszStrings + TCHAR *pszStrings; // contains all the strings - NULL separated + size_t tCount; // length of the string table + TCHAR szDefString; // default empty string +}; + +///////////////////////////////////////////////////////////////////////////////////// + +class CResourceManager +{ +public: + CResourceManager() { m_pfnCallback=NULL; m_hRes=NULL; InitializeCriticalSection(&m_cs); }; + ~CResourceManager() { DeleteCriticalSection(&m_cs); }; + + void Init(HMODULE hrc) { m_hRes=hrc; }; + + void SetCallback(PFNNOTIFYCALLBACK pfn) { m_pfnCallback=pfn; }; + + void Scan(LPCTSTR pszFolder, vector* pvData); + bool SetLanguage(PCTSTR pszPath); + + // loading functions + HGLOBAL LoadResource(LPCTSTR pszType, LPCTSTR pszName); + HACCEL LoadAccelerators(LPCTSTR pszName); + HBITMAP LoadBitmap(LPCTSTR pszName); + HCURSOR LoadCursor(LPCTSTR pszName); + HICON LoadIcon(LPCTSTR pszName); + HANDLE LoadImage(LPCTSTR lpszName, UINT uType, int cxDesired, int cyDesired, UINT fuLoad); + HMENU LoadMenu(LPCTSTR pszName); + LPDLGTEMPLATE LoadDialog(LPCTSTR pszName); + + PCTSTR LoadString(UINT uiID); + PCTSTR LoadString(WORD wGroup, WORD wID); + PTSTR LoadStringCopy(UINT uiID, PTSTR pszStr, UINT uiMax); + + // res updating functions + void UpdateMenu(HMENU hMenu, WORD wMenuID); + +public: + CLangData m_ld; // current language data + list m_lhDialogs; // currently displayed dialog boxes (even hidden) + + HMODULE m_hRes; + PFNNOTIFYCALLBACK m_pfnCallback; +// UINT m_uiMsg; + CRITICAL_SECTION m_cs; +}; + +#endif \ No newline at end of file Index: modules/App Framework/ResourceManager.h =================================================================== diff -u -N --- modules/App Framework/ResourceManager.h (revision 3e1186252ab31f63d86d86c4b0ff593cfffbefde) +++ modules/App Framework/ResourceManager.h (revision 0) @@ -1,155 +0,0 @@ -/************************************************************************ - Copy Handler 1.x - program for copying data in Microsoft Windows - systems. - Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. -*************************************************************************/ -#ifndef __RESOURCEMANAGER_H__ -#define __RESOURCEMANAGER_H__ - -#include -#include -#include -#include "af_defs.h" - -using namespace std; - -///////////////////////////////////////////////////////////////////////// -// types of notifications -// RMNT_LANGCHANGE, LPARAM - HIWORD - old language, LOWORD - new language -#define RMNT_LANGCHANGE 0x0001 - -/////////////////////////////////////////////////////////// -// language description structure -typedef map strings_map; - -class CLangData -{ -public: -// construction/destruction - CLangData() { szDefString=0; pszFilename=NULL; pszLngName=NULL; pszBaseFile=NULL; pszFontFace=NULL; pszHelpName=NULL; pszAuthor=NULL; pszVersion=NULL; pszStrings=NULL; tCount=0; } - ~CLangData() { delete [] pszFilename; delete [] pszLngName; delete [] pszBaseFile; delete [] pszFontFace; delete [] pszHelpName; delete [] pszAuthor; delete [] pszVersion; delete [] pszStrings; }; - CLangData(const CLangData& ld); - -protected: - void SetFnameData(PTSTR *ppszDst, PCTSTR pszSrc); - -public: -// operations - bool ReadInfo(PCTSTR pszFile); - bool ReadTranslation(PCTSTR pszFile, bool bUpdate=false); - - PCTSTR GetString(WORD wHiID, WORD wLoID); - -// attributes - void SetFilename(PCTSTR psz); - PCTSTR GetFilename(bool bFullPath) const; - - void SetLangName(PCTSTR psz) { if (pszLngName) delete [] pszLngName; pszLngName=new TCHAR[_tcslen(psz)+1]; _tcscpy(pszLngName, psz); }; - PCTSTR GetLangName() const { return pszLngName; }; - - void SetBaseFile(PCTSTR psz) { SetFnameData(&pszBaseFile, psz); }; - PCTSTR GetBaseFile() const { return pszBaseFile; }; - - void SetLangCode(WORD wLang) { wLangCode=wLang; }; - WORD GetLangCode() const { return wLangCode; }; - - void SetFontFace(PCTSTR psz) { if (pszFontFace) delete [] pszFontFace; pszFontFace=new TCHAR[_tcslen(psz)+1]; _tcscpy(pszFontFace, psz); }; - PCTSTR GetFontFace() const { return pszFontFace; }; - - void SetCharset(BYTE byChar) { byCharset=byChar; }; - BYTE GetCharset() const { return byCharset; }; - - void SetPointSize(WORD wSize) { wPointSize=wSize; }; - WORD GetPointSize() const { return wPointSize; }; - - void SetDirection(bool brtl) { bRTL=brtl; }; - bool GetDirection() const { return bRTL; }; - - void SetHelpName(PCTSTR psz) { SetFnameData(&pszHelpName, psz); }; - PCTSTR GetHelpName() const { return pszHelpName; }; - - void SetAuthor(PCTSTR psz) { if (pszAuthor) delete [] pszAuthor; pszAuthor=new TCHAR[_tcslen(psz)+1]; _tcscpy(pszAuthor, psz); }; - PCTSTR GetAuthor() const { return pszAuthor; }; - - void SetVersion(PCTSTR psz) { if (pszVersion) delete [] pszVersion; pszVersion=new TCHAR[_tcslen(psz)+1]; _tcscpy(pszVersion, psz); }; - PCTSTR GetVersion() const { return pszVersion; }; - - void SetStringData(PCTSTR psz, size_t tCnt) { tCount=tCnt; if (pszStrings) delete [] pszStrings; if (tCount > 0) { pszStrings=new TCHAR[tCnt]; memcpy(pszStrings, psz, tCnt*sizeof(TCHAR)); } }; - -public: - TCHAR *pszFilename; // file name of the language data (with path) - TCHAR *pszLngName; // name of the language (ie. Chinese (PRC)) - TCHAR *pszBaseFile; // file with base language data (wo path) - TCHAR *pszFontFace; // face name of the font that will be used in dialogs - WORD wLangCode; // language code - WORD wPointSize; // font point size - TCHAR *pszHelpName; // help name (wo the directory) for this language - TCHAR *pszAuthor; // author name - TCHAR *pszVersion; // version of this file - BYTE byCharset; // charset for use with the font - bool bRTL; // does the language require right-to-left reading order ? - - // strings (for controls in dialog boxes the ID contains hi:dlg ID, lo:ctrl ID, for strings hi part is 0) - strings_map m_mStrings; // maps string ID to the offset in pszStrings - TCHAR *pszStrings; // contains all the strings - NULL separated - size_t tCount; // length of the string table - TCHAR szDefString; // default empty string -}; - -///////////////////////////////////////////////////////////////////////////////////// - -class CResourceManager -{ -public: - CResourceManager() { m_pfnCallback=NULL; m_hRes=NULL; InitializeCriticalSection(&m_cs); }; - ~CResourceManager() { DeleteCriticalSection(&m_cs); }; - - void Init(HMODULE hrc) { m_hRes=hrc; }; - - void SetCallback(PFNNOTIFYCALLBACK pfn) { m_pfnCallback=pfn; }; - - void Scan(LPCTSTR pszFolder, vector* pvData); - bool SetLanguage(PCTSTR pszPath); - - // loading functions - HGLOBAL LoadResource(LPCTSTR pszType, LPCTSTR pszName); - HACCEL LoadAccelerators(LPCTSTR pszName); - HBITMAP LoadBitmap(LPCTSTR pszName); - HCURSOR LoadCursor(LPCTSTR pszName); - HICON LoadIcon(LPCTSTR pszName); - HANDLE LoadImage(LPCTSTR lpszName, UINT uType, int cxDesired, int cyDesired, UINT fuLoad); - HMENU LoadMenu(LPCTSTR pszName); - LPDLGTEMPLATE LoadDialog(LPCTSTR pszName); - - PCTSTR LoadString(UINT uiID); - PCTSTR LoadString(WORD wGroup, WORD wID); - PTSTR LoadStringCopy(UINT uiID, PTSTR pszStr, UINT uiMax); - - // res updating functions - void UpdateMenu(HMENU hMenu, WORD wMenuID); - -public: - CLangData m_ld; // current language data - list m_lhDialogs; // currently displayed dialog boxes (even hidden) - - HMODULE m_hRes; - PFNNOTIFYCALLBACK m_pfnCallback; -// UINT m_uiMsg; - CRITICAL_SECTION m_cs; -}; - -#endif \ No newline at end of file Index: ch/TrayIcon.cpp =================================================================== diff -u -N --- ch/TrayIcon.cpp (revision 0) +++ ch/TrayIcon.cpp (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,162 @@ +/************************************************************************ + Copy Handler 1.x - program for copying data in Microsoft Windows + systems. + Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. +*************************************************************************/ +#include "stdafx.h" +#include "TrayIcon.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +///////////////////////////////////////////////////////////////////////////// +// CTrayIcon construction/creation/destruction + +CTrayIcon::CTrayIcon() +{ + memset(&m_tnd, 0, sizeof(m_tnd)); + m_bHidden=false; +} + +CTrayIcon::CTrayIcon(HWND hWnd, UINT uClbMsg, LPCTSTR szText, HICON hIcon, UINT uiID) +{ + CreateIcon(hWnd, uClbMsg, szText, hIcon, uiID); + m_bHidden=false; +} + +bool CTrayIcon::CreateIcon(HWND hWnd, UINT uClbMsg, LPCTSTR szText, HICON hIcon, UINT uiID) +{ + _ASSERT(hWnd); + + // load up the NOTIFYICONDATA structure + m_tnd.cbSize=sizeof(NOTIFYICONDATA); + m_tnd.hWnd=hWnd; + m_tnd.uID=uiID; + m_tnd.hIcon=hIcon; + m_tnd.uFlags=NIF_MESSAGE | NIF_ICON | NIF_TIP; + m_tnd.uCallbackMessage=uClbMsg; + _tcsncpy(m_tnd.szTip, szText, 64); + size_t tLen=_tcslen(szText); + if (tLen < 64) + m_tnd.szTip[tLen]=_T('\0'); + else + m_tnd.szTip[63]=_T('\0'); + + // Set the tray icon + return Shell_NotifyIcon(NIM_ADD, &m_tnd) != FALSE; +} + +CTrayIcon::~CTrayIcon() +{ + RemoveIcon(); +} + + +///////////////////////////////////////////////////////////////////////////// +// CTrayIcon icon manipulation + +void CTrayIcon::MoveToRight() +{ + HideIcon(); + ShowIcon(); +} + +void CTrayIcon::RemoveIcon() +{ + m_tnd.uFlags=0; + Shell_NotifyIcon(NIM_DELETE, &m_tnd); +} + +void CTrayIcon::HideIcon() +{ + if (!m_bHidden) + { + m_tnd.uFlags=NIF_ICON; + Shell_NotifyIcon (NIM_DELETE, &m_tnd); + m_bHidden=true; + } +} + +bool CTrayIcon::ShowIcon() +{ + if (m_bHidden) + { + m_tnd.uFlags=NIF_MESSAGE | NIF_ICON | NIF_TIP; + m_bHidden=false; + return Shell_NotifyIcon(NIM_ADD, &m_tnd) != FALSE; + } + return true; +} + +bool CTrayIcon::SetIcon(HICON hIcon) +{ + m_tnd.uFlags=NIF_ICON; + m_tnd.hIcon=hIcon; + + return Shell_NotifyIcon(NIM_MODIFY, &m_tnd) != 0; +} + +bool CTrayIcon::SetStandardIcon(LPCTSTR lpIconName) +{ + HICON hIcon=::LoadIcon(NULL, lpIconName); + return SetIcon(hIcon); +} + +HICON CTrayIcon::GetIcon() const +{ + return m_tnd.hIcon; +} + +///////////////////////////////////////////////////////////////////////////// +// CTrayIcon tooltip text manipulation + +bool CTrayIcon::SetTooltipText(LPCTSTR pszTip) +{ + m_tnd.uFlags = NIF_TIP; + _tcsncpy(m_tnd.szTip, pszTip, 64); + size_t tLen=_tcslen(pszTip); + if (tLen < 64) + m_tnd.szTip[tLen]=_T('\0'); + else + m_tnd.szTip[63]=_T('\0'); + + return Shell_NotifyIcon(NIM_MODIFY, &m_tnd) != FALSE; +} + +void CTrayIcon::GetTooltipText(LPTSTR pszText) const +{ + _tcscpy(pszText, m_tnd.szTip); +} + +///////////////////////////////////////////////////////////////////////////// +// CTrayIcon notification window stuff + +bool CTrayIcon::SetNotificationWnd(HWND hWnd) +{ + _ASSERT(hWnd); + + m_tnd.hWnd=hWnd; + m_tnd.uFlags=0; + + return Shell_NotifyIcon(NIM_MODIFY, &m_tnd) != FALSE; +} + +HWND CTrayIcon::GetNotificationWnd() const +{ + return m_tnd.hWnd; +} \ No newline at end of file Index: modules/App Framework/TrayIcon.cpp =================================================================== diff -u -N --- modules/App Framework/TrayIcon.cpp (revision 7d997aef1e72f049ed1bc199e1b765d737d9963a) +++ modules/App Framework/TrayIcon.cpp (revision 0) @@ -1,162 +0,0 @@ -/************************************************************************ - Copy Handler 1.x - program for copying data in Microsoft Windows - systems. - Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. -*************************************************************************/ -#include "stdafx.h" -#include "TrayIcon.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -///////////////////////////////////////////////////////////////////////////// -// CTrayIcon construction/creation/destruction - -CTrayIcon::CTrayIcon() -{ - memset(&m_tnd, 0, sizeof(m_tnd)); - m_bHidden=false; -} - -CTrayIcon::CTrayIcon(HWND hWnd, UINT uClbMsg, LPCTSTR szText, HICON hIcon, UINT uiID) -{ - CreateIcon(hWnd, uClbMsg, szText, hIcon, uiID); - m_bHidden=false; -} - -bool CTrayIcon::CreateIcon(HWND hWnd, UINT uClbMsg, LPCTSTR szText, HICON hIcon, UINT uiID) -{ - _ASSERT(hWnd); - - // load up the NOTIFYICONDATA structure - m_tnd.cbSize=sizeof(NOTIFYICONDATA); - m_tnd.hWnd=hWnd; - m_tnd.uID=uiID; - m_tnd.hIcon=hIcon; - m_tnd.uFlags=NIF_MESSAGE | NIF_ICON | NIF_TIP; - m_tnd.uCallbackMessage=uClbMsg; - _tcsncpy(m_tnd.szTip, szText, 64); - size_t tLen=_tcslen(szText); - if (tLen < 64) - m_tnd.szTip[tLen]=_T('\0'); - else - m_tnd.szTip[63]=_T('\0'); - - // Set the tray icon - return Shell_NotifyIcon(NIM_ADD, &m_tnd) != FALSE; -} - -CTrayIcon::~CTrayIcon() -{ - RemoveIcon(); -} - - -///////////////////////////////////////////////////////////////////////////// -// CTrayIcon icon manipulation - -void CTrayIcon::MoveToRight() -{ - HideIcon(); - ShowIcon(); -} - -void CTrayIcon::RemoveIcon() -{ - m_tnd.uFlags=0; - Shell_NotifyIcon(NIM_DELETE, &m_tnd); -} - -void CTrayIcon::HideIcon() -{ - if (!m_bHidden) - { - m_tnd.uFlags=NIF_ICON; - Shell_NotifyIcon (NIM_DELETE, &m_tnd); - m_bHidden=true; - } -} - -bool CTrayIcon::ShowIcon() -{ - if (m_bHidden) - { - m_tnd.uFlags=NIF_MESSAGE | NIF_ICON | NIF_TIP; - m_bHidden=false; - return Shell_NotifyIcon(NIM_ADD, &m_tnd) != FALSE; - } - return true; -} - -bool CTrayIcon::SetIcon(HICON hIcon) -{ - m_tnd.uFlags=NIF_ICON; - m_tnd.hIcon=hIcon; - - return Shell_NotifyIcon(NIM_MODIFY, &m_tnd) != 0; -} - -bool CTrayIcon::SetStandardIcon(LPCTSTR lpIconName) -{ - HICON hIcon=::LoadIcon(NULL, lpIconName); - return SetIcon(hIcon); -} - -HICON CTrayIcon::GetIcon() const -{ - return m_tnd.hIcon; -} - -///////////////////////////////////////////////////////////////////////////// -// CTrayIcon tooltip text manipulation - -bool CTrayIcon::SetTooltipText(LPCTSTR pszTip) -{ - m_tnd.uFlags = NIF_TIP; - _tcsncpy(m_tnd.szTip, pszTip, 64); - size_t tLen=_tcslen(pszTip); - if (tLen < 64) - m_tnd.szTip[tLen]=_T('\0'); - else - m_tnd.szTip[63]=_T('\0'); - - return Shell_NotifyIcon(NIM_MODIFY, &m_tnd) != FALSE; -} - -void CTrayIcon::GetTooltipText(LPTSTR pszText) const -{ - _tcscpy(pszText, m_tnd.szTip); -} - -///////////////////////////////////////////////////////////////////////////// -// CTrayIcon notification window stuff - -bool CTrayIcon::SetNotificationWnd(HWND hWnd) -{ - _ASSERT(hWnd); - - m_tnd.hWnd=hWnd; - m_tnd.uFlags=0; - - return Shell_NotifyIcon(NIM_MODIFY, &m_tnd) != FALSE; -} - -HWND CTrayIcon::GetNotificationWnd() const -{ - return m_tnd.hWnd; -} \ No newline at end of file Index: ch/TrayIcon.h =================================================================== diff -u -N --- ch/TrayIcon.h (revision 0) +++ ch/TrayIcon.h (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,61 @@ +/************************************************************************ + Copy Handler 1.x - program for copying data in Microsoft Windows + systems. + Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. +*************************************************************************/ +/* Code based on code written by Chris Maunder (Chris.Maunder@cbr.clw.csiro.au) */ + +#ifndef __TRAYICON_H__ +#define __TRAYICON_H__ + +#include "shellapi.h" + +class CTrayIcon +{ +public: +// construction/destruction + CTrayIcon(); + CTrayIcon(HWND hWnd, UINT uClbMsg, LPCTSTR szText, HICON hIcon, UINT uiID); + ~CTrayIcon(); + +//creation + bool CreateIcon(HWND hWnd, UINT uClbMsg, LPCTSTR szText, HICON hIcon, UINT uiID); + +// ToolTip text handleing + bool SetTooltipText(LPCTSTR pszTip); + void GetTooltipText(LPTSTR pszText) const; + +// Icon handling + bool SetIcon(HICON hIcon); + bool SetStandardIcon(LPCTSTR lpIconName); + HICON GetIcon() const; + void HideIcon(); + bool ShowIcon(); + void RemoveIcon(); + void MoveToRight(); + +// Notifications + bool SetNotificationWnd(HWND hWnd); + HWND GetNotificationWnd() const; + +// Attribs +public: + bool m_bHidden; // Has the icon been hidden? + NOTIFYICONDATA m_tnd; +}; + +#endif \ No newline at end of file Index: modules/App Framework/TrayIcon.h =================================================================== diff -u -N --- modules/App Framework/TrayIcon.h (revision 3e1186252ab31f63d86d86c4b0ff593cfffbefde) +++ modules/App Framework/TrayIcon.h (revision 0) @@ -1,61 +0,0 @@ -/************************************************************************ - Copy Handler 1.x - program for copying data in Microsoft Windows - systems. - Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. -*************************************************************************/ -/* Code based on code written by Chris Maunder (Chris.Maunder@cbr.clw.csiro.au) */ - -#ifndef __TRAYICON_H__ -#define __TRAYICON_H__ - -#include "shellapi.h" - -class CTrayIcon -{ -public: -// construction/destruction - CTrayIcon(); - CTrayIcon(HWND hWnd, UINT uClbMsg, LPCTSTR szText, HICON hIcon, UINT uiID); - ~CTrayIcon(); - -//creation - bool CreateIcon(HWND hWnd, UINT uClbMsg, LPCTSTR szText, HICON hIcon, UINT uiID); - -// ToolTip text handleing - bool SetTooltipText(LPCTSTR pszTip); - void GetTooltipText(LPTSTR pszText) const; - -// Icon handling - bool SetIcon(HICON hIcon); - bool SetStandardIcon(LPCTSTR lpIconName); - HICON GetIcon() const; - void HideIcon(); - bool ShowIcon(); - void RemoveIcon(); - void MoveToRight(); - -// Notifications - bool SetNotificationWnd(HWND hWnd); - HWND GetNotificationWnd() const; - -// Attribs -public: - bool m_bHidden; // Has the icon been hidden? - NOTIFYICONDATA m_tnd; -}; - -#endif \ No newline at end of file Index: ch/af_defs.h =================================================================== diff -u -N --- ch/af_defs.h (revision 0) +++ ch/af_defs.h (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,28 @@ +#ifndef __AFMESSAGES_H__ +#define __AFMESSAGES_H__ + +// messages used by the app framework's modules +#define WM_TRAYNOTIFY (WM_USER+0) +#define WM_CFGNOTIFY (WM_USER+1) +#define WM_RMNOTIFY (WM_USER+2) + +// message routing +// types of routing +// sends a message everywhere it could be sent (hwnds, registered modules, ...) +#define ROT_EVERYWHERE 0x0000000000000000 +// sends a message to all hwnds in an app +#define ROT_HWNDS 0x0100000000000000 +// sends a message to all registered modules +#define ROT_REGISTERED 0x0200000000000000 +// sends a message to one excact module +#define ROT_EXACT 0x0300000000000000 + +// internal modules +#define IMID_CONFIGMANAGER 0x0001000000000000 +#define IMID_RESOURCEMANAGER 0x0001000000000001 +#define IMID_LOGFILE 0x0001000000000002 + +// callbacks +typedef (*PFNNOTIFYCALLBACK)(ULONGLONG, UINT, WPARAM, LPARAM); + +#endif \ No newline at end of file Index: modules/App Framework/af_defs.h =================================================================== diff -u -N --- modules/App Framework/af_defs.h (revision 3e1186252ab31f63d86d86c4b0ff593cfffbefde) +++ modules/App Framework/af_defs.h (revision 0) @@ -1,28 +0,0 @@ -#ifndef __AFMESSAGES_H__ -#define __AFMESSAGES_H__ - -// messages used by the app framework's modules -#define WM_TRAYNOTIFY (WM_USER+0) -#define WM_CFGNOTIFY (WM_USER+1) -#define WM_RMNOTIFY (WM_USER+2) - -// message routing -// types of routing -// sends a message everywhere it could be sent (hwnds, registered modules, ...) -#define ROT_EVERYWHERE 0x0000000000000000 -// sends a message to all hwnds in an app -#define ROT_HWNDS 0x0100000000000000 -// sends a message to all registered modules -#define ROT_REGISTERED 0x0200000000000000 -// sends a message to one excact module -#define ROT_EXACT 0x0300000000000000 - -// internal modules -#define IMID_CONFIGMANAGER 0x0001000000000000 -#define IMID_RESOURCEMANAGER 0x0001000000000001 -#define IMID_LOGFILE 0x0001000000000002 - -// callbacks -typedef (*PFNNOTIFYCALLBACK)(ULONGLONG, UINT, WPARAM, LPARAM); - -#endif \ No newline at end of file Index: ch/ch.vcproj =================================================================== diff -u -N --- ch/ch.vcproj (revision 0) +++ ch/ch.vcproj (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,1679 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: ch/Copy Handler.vcproj =================================================================== diff -u -N --- ch/Copy Handler.vcproj (revision 6472716fec44f80b223922d89f269e365aeaba60) +++ ch/Copy Handler.vcproj (revision 0) @@ -1,1679 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Index: ch/charvect.h =================================================================== diff -u -N --- ch/charvect.h (revision 0) +++ ch/charvect.h (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,105 @@ +/************************************************************************ + Copy Handler 1.x - program for copying data in Microsoft Windows + systems. + Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. +*************************************************************************/ +#ifndef __CHARVECT_H__ +#define __CHARVECT_H__ + +#include + +using namespace std; + +class char_vector : public vector +{ +public: + char_vector() : vector() { }; + char_vector(const char_vector& cv, bool bCopy) { insert(begin(), cv.begin(), cv.end(), bCopy); }; + ~char_vector() { erase(begin(), end(), true); }; + + void assign(size_type _Count, const PTSTR& _Type, bool bDelete, bool bCopy) { erase(begin(), end(), bDelete); insert(begin(), _Count, _Type, bCopy); }; + template void assign(_It _First, _It _Last, bool bDelete, bool bCopy) { erase(begin(), end(), bDelete); insert(begin(), _First, _Last, bCopy); }; + + void clear(bool bDelete) { erase(begin(), end(), bDelete); }; + + iterator erase(iterator _Where, bool bDelete) { if (bDelete) delete [] (*_Where); return ((vector*)this)->erase(_Where); }; + iterator erase(iterator _First, iterator _Last, bool bDelete) { if (bDelete) for (iterator _Run=_First;_Run != _Last;_Run++) delete [] (*_Run); return ((vector*)this)->erase(_First, _Last); }; + + void replace(iterator _Where, const PTSTR& _Val, bool bDelete, bool bCopy) + { + if (bDelete) + delete [] (*_Where); + if (bCopy) + { + (*_Where)=new TCHAR[_tcslen(_Val)+1]; + _tcscpy(*_Where, _Val); + } + else + (*_Where)=_Val; + }; + iterator insert(iterator _Where, const PTSTR& _Val, bool bCopy) + { + size_type _O = _Where - begin(); + insert(_Where, 1, _Val, bCopy); + return (begin() + _O); + }; + void insert(iterator _Where, size_type _Count, const PTSTR& _Val, bool bCopy) + { + if (bCopy) + { + size_type _Size=_tcslen(_Val)+1; + PTSTR *ppsz=new PTSTR[_Count]; + for (size_type i=0;i<_Count;i++) + { + ppsz[i]=new TCHAR[_Size]; + _tcscpy(ppsz[i], _Val); + } + + ((vector*)this)->insert(_Where, ppsz, ppsz+_Count); + delete [] ppsz; + } + else + ((vector*)this)->insert(_Where, _Count, _Val); + }; + template void insert(iterator _Where, _It _First, _It _Last, bool bCopy) + { + if (bCopy) + { + size_type _Cnt=_Last-_First; + PTSTR *ppsz=new PTSTR[_Cnt]; + for (size_type i=0;i<_Cnt;i++) + { + ppsz[i]=new TCHAR[_tcslen(*_First)+1]; + _tcscpy(ppsz[i], *_First); + + _First++; + } + + ((vector*)this)->insert(_Where, ppsz, ppsz+_Cnt); + delete [] ppsz; + } + else + ((vector*)this)->insert(_Where, _First, _Last); + }; + + void swap_items(iterator _Item1, iterator _Item2) { PTSTR psz=(*_Item1); (*_Item1)=(*_Item2); (*_Item2)=psz; }; + + void pop_back(bool bDelete) { if (bDelete) delete [] (*(end()-1)); ((vector*)this)->pop_back(); }; + void push_back(const PTSTR& _Val, bool bCopy) { insert(end(), 1, _Val, bCopy); }; +}; + +#endif \ No newline at end of file Index: modules/App Framework/charvect.h =================================================================== diff -u -N --- modules/App Framework/charvect.h (revision 3e1186252ab31f63d86d86c4b0ff593cfffbefde) +++ modules/App Framework/charvect.h (revision 0) @@ -1,105 +0,0 @@ -/************************************************************************ - Copy Handler 1.x - program for copying data in Microsoft Windows - systems. - Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.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. -*************************************************************************/ -#ifndef __CHARVECT_H__ -#define __CHARVECT_H__ - -#include - -using namespace std; - -class char_vector : public vector -{ -public: - char_vector() : vector() { }; - char_vector(const char_vector& cv, bool bCopy) { insert(begin(), cv.begin(), cv.end(), bCopy); }; - ~char_vector() { erase(begin(), end(), true); }; - - void assign(size_type _Count, const PTSTR& _Type, bool bDelete, bool bCopy) { erase(begin(), end(), bDelete); insert(begin(), _Count, _Type, bCopy); }; - template void assign(_It _First, _It _Last, bool bDelete, bool bCopy) { erase(begin(), end(), bDelete); insert(begin(), _First, _Last, bCopy); }; - - void clear(bool bDelete) { erase(begin(), end(), bDelete); }; - - iterator erase(iterator _Where, bool bDelete) { if (bDelete) delete [] (*_Where); return ((vector*)this)->erase(_Where); }; - iterator erase(iterator _First, iterator _Last, bool bDelete) { if (bDelete) for (iterator _Run=_First;_Run != _Last;_Run++) delete [] (*_Run); return ((vector*)this)->erase(_First, _Last); }; - - void replace(iterator _Where, const PTSTR& _Val, bool bDelete, bool bCopy) - { - if (bDelete) - delete [] (*_Where); - if (bCopy) - { - (*_Where)=new TCHAR[_tcslen(_Val)+1]; - _tcscpy(*_Where, _Val); - } - else - (*_Where)=_Val; - }; - iterator insert(iterator _Where, const PTSTR& _Val, bool bCopy) - { - size_type _O = _Where - begin(); - insert(_Where, 1, _Val, bCopy); - return (begin() + _O); - }; - void insert(iterator _Where, size_type _Count, const PTSTR& _Val, bool bCopy) - { - if (bCopy) - { - size_type _Size=_tcslen(_Val)+1; - PTSTR *ppsz=new PTSTR[_Count]; - for (size_type i=0;i<_Count;i++) - { - ppsz[i]=new TCHAR[_Size]; - _tcscpy(ppsz[i], _Val); - } - - ((vector*)this)->insert(_Where, ppsz, ppsz+_Count); - delete [] ppsz; - } - else - ((vector*)this)->insert(_Where, _Count, _Val); - }; - template void insert(iterator _Where, _It _First, _It _Last, bool bCopy) - { - if (bCopy) - { - size_type _Cnt=_Last-_First; - PTSTR *ppsz=new PTSTR[_Cnt]; - for (size_type i=0;i<_Cnt;i++) - { - ppsz[i]=new TCHAR[_tcslen(*_First)+1]; - _tcscpy(ppsz[i], *_First); - - _First++; - } - - ((vector*)this)->insert(_Where, ppsz, ppsz+_Cnt); - delete [] ppsz; - } - else - ((vector*)this)->insert(_Where, _First, _Last); - }; - - void swap_items(iterator _Item1, iterator _Item2) { PTSTR psz=(*_Item1); (*_Item1)=(*_Item2); (*_Item2)=psz; }; - - void pop_back(bool bDelete) { if (bDelete) delete [] (*(end()-1)); ((vector*)this)->pop_back(); }; - void push_back(const PTSTR& _Val, bool bCopy) { insert(end(), 1, _Val, bCopy); }; -}; - -#endif \ No newline at end of file Index: ch/debug.h =================================================================== diff -u -N --- ch/debug.h (revision 0) +++ ch/debug.h (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,280 @@ +#ifndef __DEBUG_H__ +#define __DEBUG_H__ + +// time measuring macros +#ifdef _DEBUG + static long __dwst, __dwen; + #define MEASURE_TIME(lines, text) __dwst=GetTickCount(); lines __dwen=GetTickCount(); TRACE(text, __dwen-__dwst); +#else + #define MEASURE_TIME(lines, text) lines +#endif + +#ifdef _DEBUG + #define TRACELOGFONT(str, lf)\ + {\ + TRACE( str "\tlfHeight: %ld\n\tlfWidth: %ld\n\tlfEscapement: %ld\n\tlfOrientation: %ld\n\tlfWeight: %ld\n", (lf).lfHeight, (lf).lfWidth, (lf).lfEscapement, (lf).lfOrientation, (lf).lfWeight);\ + TRACE("\tlfItalic: %d\n\tlfUnderline: %d\n\tlfStrikeOut: %d\n\tlfCharSet: %d\n\tlfOutPrecision: %d\n\tlfClipPrecision: %d\n\tlfQuality: %d\n\tlfPitchAndFamily: %d\n\tlfFaceName: %s\n", (lf).lfItalic, (lf).lfUnderline, (lf).lfStrikeOut, (lf).lfCharSet, (lf).lfOutPrecision, (lf).lfClipPrecision, (lf).lfQuality, (lf).lfPitchAndFamily, (lf).lfFaceName);\ + } +#else + #define TRACELOGFONT(lf) +#endif + +// window messages +#ifdef _DEBUG +struct __dbg_msg__ +{ + UINT uiMsg; + TCHAR *pszText; +}; + +////////////////////////////////////// + +#define GEN_PAIR(str) { str, #str } + +static __dbg_msg__ __msgs__[] = { + GEN_PAIR(WM_NULL), + GEN_PAIR(WM_CREATE), + GEN_PAIR(WM_DESTROY), + GEN_PAIR(WM_MOVE), + GEN_PAIR(WM_SIZE), + GEN_PAIR(WM_ACTIVATE), + GEN_PAIR(WM_SETFOCUS), + GEN_PAIR(WM_KILLFOCUS), + GEN_PAIR(WM_ENABLE), + GEN_PAIR(WM_SETREDRAW), + GEN_PAIR(WM_SETTEXT), + GEN_PAIR(WM_GETTEXT), + GEN_PAIR(WM_GETTEXTLENGTH), + GEN_PAIR(WM_PAINT), + GEN_PAIR(WM_CLOSE), + GEN_PAIR(WM_QUERYENDSESSION), + GEN_PAIR(WM_QUERYOPEN), + GEN_PAIR(WM_ENDSESSION), + GEN_PAIR(WM_QUIT), + GEN_PAIR(WM_ERASEBKGND), + GEN_PAIR(WM_SYSCOLORCHANGE), + GEN_PAIR(WM_SHOWWINDOW), + GEN_PAIR(WM_WININICHANGE), + GEN_PAIR(WM_DEVMODECHANGE), + GEN_PAIR(WM_ACTIVATEAPP), + GEN_PAIR(WM_FONTCHANGE), + GEN_PAIR(WM_TIMECHANGE), + GEN_PAIR(WM_CANCELMODE), + GEN_PAIR(WM_SETCURSOR), + GEN_PAIR(WM_MOUSEACTIVATE), + GEN_PAIR(WM_CHILDACTIVATE), + GEN_PAIR(WM_QUEUESYNC), + GEN_PAIR(WM_GETMINMAXINFO), + GEN_PAIR(WM_PAINTICON), + GEN_PAIR(WM_ICONERASEBKGND), + GEN_PAIR(WM_NEXTDLGCTL), + GEN_PAIR(WM_SPOOLERSTATUS), + GEN_PAIR(WM_DRAWITEM), + GEN_PAIR(WM_MEASUREITEM), + GEN_PAIR(WM_DELETEITEM), + GEN_PAIR(WM_VKEYTOITEM), + GEN_PAIR(WM_CHARTOITEM), + GEN_PAIR(WM_SETFONT), + GEN_PAIR(WM_GETFONT), + GEN_PAIR(WM_SETHOTKEY), + GEN_PAIR(WM_GETHOTKEY), + GEN_PAIR(WM_QUERYDRAGICON), + GEN_PAIR(WM_COMPAREITEM), + { 0x003d, "WM_GETOBJECT" }, + GEN_PAIR(WM_COMPACTING), + GEN_PAIR(WM_COMMNOTIFY), + GEN_PAIR(WM_WINDOWPOSCHANGING), + GEN_PAIR(WM_WINDOWPOSCHANGED), + GEN_PAIR(WM_POWER), + GEN_PAIR(WM_COPYDATA), + GEN_PAIR(WM_CANCELJOURNAL), + GEN_PAIR(WM_NOTIFY), + GEN_PAIR(WM_INPUTLANGCHANGEREQUEST), + GEN_PAIR(WM_INPUTLANGCHANGE), + GEN_PAIR(WM_TCARD), + GEN_PAIR(WM_HELP), + GEN_PAIR(WM_USERCHANGED), + GEN_PAIR(WM_NOTIFYFORMAT), + GEN_PAIR(WM_CONTEXTMENU), + GEN_PAIR(WM_STYLECHANGING), + GEN_PAIR(WM_STYLECHANGED), + GEN_PAIR(WM_DISPLAYCHANGE), + GEN_PAIR(WM_GETICON), + GEN_PAIR(WM_SETICON), + GEN_PAIR(WM_NCCREATE), + GEN_PAIR(WM_NCDESTROY), + GEN_PAIR(WM_NCCALCSIZE), + GEN_PAIR(WM_NCHITTEST), + GEN_PAIR(WM_NCPAINT), + GEN_PAIR(WM_NCACTIVATE), + GEN_PAIR(WM_GETDLGCODE), + GEN_PAIR(WM_SYNCPAINT), + GEN_PAIR(WM_NCMOUSEMOVE), + GEN_PAIR(WM_NCLBUTTONDOWN), + GEN_PAIR(WM_NCLBUTTONUP), + GEN_PAIR(WM_NCLBUTTONDBLCLK), + GEN_PAIR(WM_NCRBUTTONDOWN), + GEN_PAIR(WM_NCRBUTTONUP), + GEN_PAIR(WM_NCRBUTTONDBLCLK), + GEN_PAIR(WM_NCMBUTTONDOWN), + GEN_PAIR(WM_NCMBUTTONUP), + GEN_PAIR(WM_NCMBUTTONDBLCLK), + { 0x00AB, "WM_NCXBUTTONDOWN" }, + { 0x00AC, "WM_NCXBUTTONUP" }, + { 0x00AD, "WM_NCXBUTTONDBLCLK" }, + { 0x00FF, "WM_INPUT" }, + GEN_PAIR(WM_KEYFIRST), + GEN_PAIR(WM_KEYDOWN), + GEN_PAIR(WM_KEYUP), + GEN_PAIR(WM_CHAR), + GEN_PAIR(WM_DEADCHAR), + GEN_PAIR(WM_SYSKEYDOWN), + GEN_PAIR(WM_SYSKEYUP), + GEN_PAIR(WM_SYSCHAR), + GEN_PAIR(WM_SYSDEADCHAR), + GEN_PAIR(WM_UNICHAR), + GEN_PAIR(WM_KEYLAST), + GEN_PAIR(WM_IME_STARTCOMPOSITION), + GEN_PAIR(WM_IME_ENDCOMPOSITION), + GEN_PAIR(WM_IME_COMPOSITION), + GEN_PAIR(WM_IME_KEYLAST), + GEN_PAIR(WM_INITDIALOG), + GEN_PAIR(WM_COMMAND), + GEN_PAIR(WM_SYSCOMMAND), + GEN_PAIR(WM_TIMER), + GEN_PAIR(WM_HSCROLL), + GEN_PAIR(WM_VSCROLL), + GEN_PAIR(WM_INITMENU), + GEN_PAIR(WM_INITMENUPOPUP), + GEN_PAIR(WM_MENUSELECT), + GEN_PAIR(WM_MENUCHAR), + GEN_PAIR(WM_ENTERIDLE), + { 0x0122, "WM_MENURBUTTONUP" }, + { 0x0123, "WM_MENUDRAG" }, + { 0x0124, "WM_MENUGETOBJECT" }, + { 0x0125, "WM_UNINITMENUPOPUP" }, + { 0x0126, "WM_MENUCOMMAND" }, + { 0x0127, "WM_CHANGEUISTATE" }, + { 0x0128, "WM_UPDATEUISTATE" }, + { 0x0129, "WM_QUERYUISTATE" }, + GEN_PAIR(WM_CTLCOLORMSGBOX), + GEN_PAIR(WM_CTLCOLOREDIT), + GEN_PAIR(WM_CTLCOLORLISTBOX), + GEN_PAIR(WM_CTLCOLORBTN), + GEN_PAIR(WM_CTLCOLORDLG), + GEN_PAIR(WM_CTLCOLORSCROLLBAR), + GEN_PAIR(WM_CTLCOLORSTATIC), + GEN_PAIR(WM_MOUSEFIRST), + GEN_PAIR(WM_MOUSEMOVE), + GEN_PAIR(WM_LBUTTONDOWN), + GEN_PAIR(WM_LBUTTONUP), + GEN_PAIR(WM_LBUTTONDBLCLK), + GEN_PAIR(WM_RBUTTONDOWN), + GEN_PAIR(WM_RBUTTONUP), + GEN_PAIR(WM_RBUTTONDBLCLK), + GEN_PAIR(WM_MBUTTONDOWN), + GEN_PAIR(WM_MBUTTONUP), + GEN_PAIR(WM_MBUTTONDBLCLK), + GEN_PAIR(WM_MOUSEWHEEL), + { 0x020B, "WM_XBUTTONDOWN" }, + { 0x020C, "WM_XBUTTONUP" }, + { 0x020D, "WM_XBUTTONDBLCLK" }, + GEN_PAIR(WM_MOUSELAST), + GEN_PAIR(WM_MOUSELAST), + GEN_PAIR(WM_MOUSELAST), + GEN_PAIR(WM_PARENTNOTIFY), + GEN_PAIR(WM_ENTERMENULOOP), + GEN_PAIR(WM_EXITMENULOOP), + GEN_PAIR(WM_NEXTMENU), + GEN_PAIR(WM_SIZING), + GEN_PAIR(WM_CAPTURECHANGED), + GEN_PAIR(WM_MOVING), + GEN_PAIR(WM_POWERBROADCAST), + GEN_PAIR(WM_DEVICECHANGE), + GEN_PAIR(WM_MDICREATE), + GEN_PAIR(WM_MDIDESTROY), + GEN_PAIR(WM_MDIACTIVATE), + GEN_PAIR(WM_MDIRESTORE), + GEN_PAIR(WM_MDINEXT), + GEN_PAIR(WM_MDIMAXIMIZE), + GEN_PAIR(WM_MDITILE), + GEN_PAIR(WM_MDICASCADE), + GEN_PAIR(WM_MDIICONARRANGE), + GEN_PAIR(WM_MDIGETACTIVE), + GEN_PAIR(WM_MDISETMENU), + GEN_PAIR(WM_ENTERSIZEMOVE), + GEN_PAIR(WM_EXITSIZEMOVE), + GEN_PAIR(WM_DROPFILES), + GEN_PAIR(WM_MDIREFRESHMENU), + GEN_PAIR(WM_IME_SETCONTEXT), + GEN_PAIR(WM_IME_NOTIFY), + GEN_PAIR(WM_IME_CONTROL), + GEN_PAIR(WM_IME_COMPOSITIONFULL), + GEN_PAIR(WM_IME_SELECT), + GEN_PAIR(WM_IME_CHAR), + { 0x0288, "WM_IME_REQUEST" }, + GEN_PAIR(WM_IME_KEYDOWN), + GEN_PAIR(WM_IME_KEYUP), + GEN_PAIR(WM_MOUSEHOVER), + GEN_PAIR(WM_MOUSELEAVE), + { 0x02A0, "WM_NCMOUSEHOVER" }, + { 0x02A2, "WM_NCMOUSELEAVE" }, + { 0x02B1, "WM_WTSSESSION_CHANGE" }, + { 0x02C0, "WM_TABLET_FIRST" }, + { 0x02DF, "WM_TABLET_LAST" }, + GEN_PAIR(WM_CUT), + GEN_PAIR(WM_COPY), + GEN_PAIR(WM_PASTE), + GEN_PAIR(WM_CLEAR), + GEN_PAIR(WM_UNDO), + GEN_PAIR(WM_RENDERFORMAT), + GEN_PAIR(WM_RENDERALLFORMATS), + GEN_PAIR(WM_DESTROYCLIPBOARD), + GEN_PAIR(WM_DRAWCLIPBOARD), + GEN_PAIR(WM_PAINTCLIPBOARD), + GEN_PAIR(WM_VSCROLLCLIPBOARD), + GEN_PAIR(WM_SIZECLIPBOARD), + GEN_PAIR(WM_ASKCBFORMATNAME), + GEN_PAIR(WM_CHANGECBCHAIN), + GEN_PAIR(WM_HSCROLLCLIPBOARD), + GEN_PAIR(WM_QUERYNEWPALETTE), + GEN_PAIR(WM_PALETTEISCHANGING), + GEN_PAIR(WM_PALETTECHANGED), + GEN_PAIR(WM_HOTKEY), + GEN_PAIR(WM_PRINT), + GEN_PAIR(WM_PRINTCLIENT), + { 0x0319, "WM_APPCOMMAND" }, + { 0x031A, "WM_THEMECHANGED" }, + GEN_PAIR(WM_HANDHELDFIRST), + GEN_PAIR(WM_HANDHELDLAST), + GEN_PAIR(WM_AFXFIRST), + GEN_PAIR(WM_AFXLAST), + GEN_PAIR(WM_PENWINFIRST), + GEN_PAIR(WM_PENWINLAST), + GEN_PAIR(WM_APP), + GEN_PAIR(WM_USER) + }; +///////////////////////////////// + +static char* UINTToMsg(UINT uiMsg, char* szBuffer) +{ + int iCount=sizeof(__msgs__)/(sizeof(UINT)+sizeof(char*)); + for (int i=0;i -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=CopyHandlerShellExt - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "CopyHandlerShellExt.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "CopyHandlerShellExt.mak" CFG="CopyHandlerShellExt - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "CopyHandlerShellExt - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "CopyHandlerShellExt - Win32 Release MinDependency" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "CopyHandlerShellExt - Win32 Debug" - -# PROP BASE Use_MFC 2 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /Yu"stdafx.h" /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /Yu"stdafx.h" /FD /GZ /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x415 /d "_DEBUG" /d "_AFXDLL" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 kernel32.lib shell32.lib gdi32.lib comctl32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"../BIN/Debug/chext.dll" /pdbtype:sept -# SUBTRACT LINK32 /nodefaultlib -# Begin Custom Build - Performing registration -OutDir=.\Debug -TargetPath=\PROJECTS\c++\working\Copy Handler\BIN\Debug\chext.dll -InputPath=\PROJECTS\c++\working\Copy Handler\BIN\Debug\chext.dll -SOURCE="$(InputPath)" - -"$(OutDir)\regsvr32.trg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - start regsvr32 /s /c "$(TargetPath)" - echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg" - -# End Custom Build -# Begin Special Build Tool -WkspDir=. -SOURCE="$(InputPath)" -PostBuild_Cmds="BuildManager" "Debug builds" "$(WkspDir)\chext_count.txt" -# End Special Build Tool - -!ELSEIF "$(CFG)" == "CopyHandlerShellExt - Win32 Release MinDependency" - -# PROP BASE Use_MFC 2 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "ReleaseMinDependency" -# PROP BASE Intermediate_Dir "ReleaseMinDependency" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "ReleaseMinDependency" -# PROP Intermediate_Dir "ReleaseMinDependency" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MD /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /Yu"stdafx.h" /FD /c -# ADD CPP /nologo /G5 /MT /W4 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "_ATL_STATIC_REGISTRY" /Yu"stdafx.h" /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x415 /d "NDEBUG" /d "_AFXDLL" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 /nologo /subsystem:windows /dll /machine:I386 -# ADD LINK32 kernel32.lib shell32.lib gdi32.lib comctl32.lib /nologo /subsystem:windows /dll /machine:I386 /out:"../BIN/Release/chext.dll" -# SUBTRACT LINK32 /debug /nodefaultlib -# Begin Custom Build - Performing registration -OutDir=.\ReleaseMinDependency -TargetPath=\PROJECTS\c++\working\Copy Handler\BIN\Release\chext.dll -InputPath=\PROJECTS\c++\working\Copy Handler\BIN\Release\chext.dll -SOURCE="$(InputPath)" - -"$(OutDir)\regsvr32.trg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - regsvr32 /s /c "$(TargetPath)" - echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg" - -# End Custom Build -# Begin Special Build Tool -WkspDir=. -TargetPath=\PROJECTS\c++\working\Copy Handler\BIN\Release\chext.dll -SOURCE="$(InputPath)" -PostBuild_Cmds="BuildManager" "Release builds" "$(WkspDir)\chext_count.txt" upx.exe -9 -v "$(TargetPath)" -# End Special Build Tool - -!ENDIF - -# Begin Target - -# Name "CopyHandlerShellExt - Win32 Debug" -# Name "CopyHandlerShellExt - Win32 Release MinDependency" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\clipboard.cpp -# End Source File -# Begin Source File - -SOURCE=.\CopyHandlerShellExt.cpp -# End Source File -# Begin Source File - -SOURCE=.\CopyHandlerShellExt.def -# End Source File -# Begin Source File - -SOURCE=.\CopyHandlerShellExt.idl -# ADD MTL /tlb ".\CopyHandlerShellExt.tlb" /h "CopyHandlerShellExt.h" /iid "CopyHandlerShellExt_i.c" /Oicf -# End Source File -# Begin Source File - -SOURCE=.\CopyHandlerShellExt.rc -# End Source File -# Begin Source File - -SOURCE=.\DropMenuExt.cpp -# End Source File -# Begin Source File - -SOURCE=..\Common\FileSupport.cpp -# End Source File -# Begin Source File - -SOURCE=.\MenuExt.cpp -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.cpp -# ADD CPP /Yc"stdafx.h" -# End Source File -# Begin Source File - -SOURCE=.\StringHelpers.cpp -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\clipboard.h -# End Source File -# Begin Source File - -SOURCE=.\DropMenuExt.h -# End Source File -# Begin Source File - -SOURCE=..\Common\FileSupport.h -# End Source File -# Begin Source File - -SOURCE=.\IContextMenuImpl.h -# End Source File -# Begin Source File - -SOURCE=..\Common\ipcstructs.h -# End Source File -# Begin Source File - -SOURCE=.\IShellExtInitImpl.h -# End Source File -# Begin Source File - -SOURCE=.\MenuExt.h -# End Source File -# Begin Source File - -SOURCE=.\Resource.h -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.h -# End Source File -# Begin Source File - -SOURCE=.\StringHelpers.h -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# Begin Source File - -SOURCE=.\DropMenuExt.rgs -# End Source File -# Begin Source File - -SOURCE=.\MenuExt.rgs -# End Source File -# End Group -# End Target -# End Project Index: chext/chext.vcproj =================================================================== diff -u -N --- chext/chext.vcproj (revision 0) +++ chext/chext.vcproj (revision c6290a462071d2be616e833d9f4fbf804c63a149) @@ -0,0 +1,374 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: chext/CopyHandlerShellExt.vcproj =================================================================== diff -u -N --- chext/CopyHandlerShellExt.vcproj (revision 6472716fec44f80b223922d89f269e365aeaba60) +++ chext/CopyHandlerShellExt.vcproj (revision 0) @@ -1,374 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -