Index: src/ch/OptionsDlg.cpp =================================================================== diff -u -N -rcdf6a22ddf857f56ce2e27e26d8cd6f0b8034b2e -r37a273b73ad2ba80df122121bc36c7a11a5492bc --- src/ch/OptionsDlg.cpp (.../OptionsDlg.cpp) (revision cdf6a22ddf857f56ce2e27e26d8cd6f0b8034b2e) +++ src/ch/OptionsDlg.cpp (.../OptionsDlg.cpp) (revision 37a273b73ad2ba80df122121bc36c7a11a5492bc) @@ -254,7 +254,7 @@ UINT uiIndex=0; for (vector::iterator it=m_vld.begin();it != m_vld.end();it++) { - strLangs+=(*it).pszLngName; + strLangs+=(*it).m_pszLngName; strLangs+=_T("!"); if (_tcsicmp((*it).GetFilename(true), GetResManager()->m_ld.GetFilename(true)) == 0) uiIndex=it-m_vld.begin(); Index: src/ch/ResourceManager.cpp =================================================================== diff -u -N -rcdf6a22ddf857f56ce2e27e26d8cd6f0b8034b2e -r37a273b73ad2ba80df122121bc36c7a11a5492bc --- src/ch/ResourceManager.cpp (.../ResourceManager.cpp) (revision cdf6a22ddf857f56ce2e27e26d8cd6f0b8034b2e) +++ src/ch/ResourceManager.cpp (.../ResourceManager.cpp) (revision 37a273b73ad2ba80df122121bc36c7a11a5492bc) @@ -20,24 +20,52 @@ #include "stdafx.h" #include "IniFile.h" #include "ResourceManager.h" +#include "../libicpf/cfg.h" +#include #ifdef _DEBUG #define new DEBUG_NEW #endif -CLangData::CLangData(const CLangData& ld) +#define EMPTY_STRING _t("") + +CLangData::CLangData() : + m_pszFilename(NULL), + m_pszLngName(NULL), + m_pszBaseFile(NULL), + m_pszFontFace(NULL), + m_pszHelpName(NULL), + m_pszAuthor(NULL), + m_pszVersion(NULL), + m_uiSectionID(0) { - szDefString=0; - pszFilename=NULL; - pszLngName=NULL; - pszBaseFile=NULL; - pszFontFace=NULL; - pszHelpName=NULL; - pszAuthor=NULL; - pszVersion=NULL; - pszStrings=NULL; - tCount=0; +} +CLangData::~CLangData() +{ + delete [] m_pszFilename; + delete [] m_pszLngName; + delete [] m_pszBaseFile; + delete [] m_pszFontFace; + delete [] m_pszHelpName; + delete [] m_pszAuthor; + delete [] m_pszVersion; + + for(strings_map::iterator it = m_mStrings.begin(); it != m_mStrings.end(); it++) + { + delete [] (*it).second; + } +} + +CLangData::CLangData(const CLangData& ld) : + m_pszFilename(NULL), + m_pszLngName(NULL), + m_pszBaseFile(NULL), + m_pszFontFace(NULL), + m_pszHelpName(NULL), + m_pszAuthor(NULL), + m_pszVersion(NULL) +{ SetFilename(ld.GetFilename(true)); SetLangName(ld.GetLangName()); SetLangCode(ld.GetLangCode()); @@ -48,48 +76,71 @@ 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); + icpf::config cfg(icpf::config::eIni); + const uint_t uiLangName = cfg.register_string(_T("Info/Lang Name"), _t("")); + const uint_t uiLangCode = cfg.register_signed_num(_T("Info/Lang Code"), 0, 0, 0xffff); + const uint_t uiBaseLanguage = cfg.register_string(_T("Info/Base Language"), _T("")); + const uint_t uiFontFace = cfg.register_string(_T("Info/Font Face"), _T("")); + const uint_t uiCharset = cfg.register_signed_num(_T("Info/Charset"), 0, 0, 0xffff); + const uint_t uiSize = cfg.register_signed_num(_T("Info/Size"), 0, 0, 0xffff); + const uint_t uiRTL = cfg.register_bool(_T("Info/RTL reading order"), false); + const uint_t uiHelpName = cfg.register_string(_T("Info/Help name"), _T("")); + const uint_t uiAuthor = cfg.register_string(_T("Info/Author"), _T("")); + const uint_t uiVersion = cfg.register_string(_T("Info/Version"), _T("")); + cfg.read(pszFile); - TCHAR szData[512]; - SetLangName(file.GetString(_T("000"), _T("Info"), _T("Lang Name"), szData, _T(""))); - if (file.IsDefault()) + const tchar_t* psz = cfg.get_string(uiLangName); + if(!psz || psz[0] == _t('\0')) return false; - SetLangCode((WORD)file.GetInt(_T("000"), _T("Info"), _T("Lang Code"), 0, szData)); - if (file.IsDefault()) + SetLangName(psz); + + ll_t ll = cfg.get_signed_num(uiLangCode); + if(ll == 0) return false; - SetBaseFile(file.GetString(_T("000"), _T("Info"), _T("Base Language"), szData, _T(""))); - if (file.IsDefault()) + SetLangCode((WORD)ll); + + psz = cfg.get_string(uiBaseLanguage); + if(!psz || psz[0] == _t('\0')) return false; - SetFontFace(file.GetString(_T("000"), _T("Info"), _T("Font Face"), szData, _T(""))); - if (file.IsDefault()) + SetBaseFile(psz); + + psz = cfg.get_string(uiFontFace); + if(!psz || psz[0] == _t('\0')) return false; - SetCharset((BYTE)file.GetInt(_T("000"), _T("Info"), _T("Charset"), 0, szData)); - if (file.IsDefault()) + SetFontFace(psz); + + ll = cfg.get_signed_num(uiCharset); + if(ll == 0) return false; - SetPointSize((WORD)file.GetInt(_T("000"), _T("Info"), _T("Size"), 0, szData)); - if (file.IsDefault()) + SetCharset((BYTE)ll); + + ll = cfg.get_signed_num(uiSize); + if(ll == 0) return false; - SetDirection(file.GetBool(_T("000"), _T("Info"), _T("RTL reading order"), false, szData)); - if (file.IsDefault()) + SetPointSize((WORD)ll); + + SetDirection(cfg.get_bool(uiRTL)); + + psz = cfg.get_string(uiHelpName); + if(!psz || psz[0] == _t('\0')) return false; - SetHelpName(file.GetString(_T("000"), _T("Info"), _T("Help name"), szData, _T(""))); - if (file.IsDefault()) + SetHelpName(psz); + + psz = cfg.get_string(uiAuthor); + if(!psz || psz[0] == _t('\0')) return false; - SetAuthor(file.GetString(_T("000"), _T("Info"), _T("Author"), szData, _T(""))); - if (file.IsDefault()) + SetAuthor(psz); + + psz = cfg.get_string(uiVersion); + if(!psz || psz[0] == _t('\0')) return false; - SetVersion(file.GetString(_T("000"), _T("Info"), _T("Version"), szData, _T(""))); - if (file.IsDefault()) - return false; + SetVersion(psz); SetFilename(pszFile); @@ -101,134 +152,109 @@ } } +void CLangData::EnumAttributesCallback(bool bGroup, const tchar_t* pszName, const tchar_t* pszValue, ptr_t pData) +{ + CLangData* pLangData = (CLangData*)pData; + assert(pLangData); + assert(pszName); + + if(bGroup && _tcsicmp(pszName, _t("Info")) != 0) + { + // new section - remember in member + pLangData->m_uiSectionID = _ttoi(pszName); + } + else + { + uint_t uiVal = _ttoi(pszName); + if(pLangData->m_bUpdating) + { + // check if the entry already exists + strings_map::iterator it = pLangData->m_mStrings.find(pLangData->m_uiSectionID << 16 | uiVal); + if(it != pLangData->m_mStrings.end()) + return; + } + size_t stLen = _tcslen(pszValue); + tchar_t* pszStr = new tchar_t[stLen + 1]; + _tcscpy(pszStr, pszValue); + pLangData->m_mStrings.insert(strings_map::value_type(pLangData->m_uiSectionID << 16 | uiVal, pszStr)); + } +} + bool CLangData::ReadTranslation(PCTSTR pszFile, bool bUpdate) { try { // load data from file - CIniFile file; - file.Open(pszFile, NULL, true); + icpf::config cfg(icpf::config::eIni); + const uint_t uiLangName = cfg.register_string(_T("Info/Lang Name"), _t("")); + const uint_t uiLangCode = cfg.register_signed_num(_T("Info/Lang Code"), 0, 0, 0xffff); + const uint_t uiBaseLanguage = cfg.register_string(_T("Info/Base Language"), _T("")); + const uint_t uiFontFace = cfg.register_string(_T("Info/Font Face"), _T("")); + const uint_t uiCharset = cfg.register_signed_num(_T("Info/Charset"), 0, 0, 0xffff); + const uint_t uiSize = cfg.register_signed_num(_T("Info/Size"), 0, 0, 0xffff); + const uint_t uiRTL = cfg.register_bool(_T("Info/RTL reading order"), false); + const uint_t uiHelpName = cfg.register_string(_T("Info/Help name"), _T("")); + const uint_t uiAuthor = cfg.register_string(_T("Info/Author"), _T("")); + const uint_t uiVersion = cfg.register_string(_T("Info/Version"), _T("")); + cfg.read(pszFile); TCHAR szData[512]; - if (!bUpdate) + if(!bUpdate) { - // std data - SetLangName(file.GetString(_T("000"), _T("Info"), _T("Lang Name"), szData, _T(""))); - if (file.IsDefault()) + const tchar_t* psz = cfg.get_string(uiLangName); + if(!psz || psz[0] == _t('\0')) return false; - SetLangCode((WORD)file.GetInt(_T("000"), _T("Info"), _T("Lang Code"), 0, szData)); - if (file.IsDefault()) + SetLangName(psz); + + ll_t ll = cfg.get_signed_num(uiLangCode); + if(ll == 0) return false; - SetBaseFile(file.GetString(_T("000"), _T("Info"), _T("Base Language"), szData, _T(""))); - if (file.IsDefault()) + SetLangCode((WORD)ll); + + psz = cfg.get_string(uiBaseLanguage); + if(!psz || psz[0] == _t('\0')) return false; - SetFontFace(file.GetString(_T("000"), _T("Info"), _T("Font Face"), szData, _T(""))); - if (file.IsDefault()) + SetBaseFile(psz); + + psz = cfg.get_string(uiFontFace); + if(!psz || psz[0] == _t('\0')) return false; - SetCharset((BYTE)file.GetInt(_T("000"), _T("Info"), _T("Charset"), 0, szData)); - if (file.IsDefault()) + SetFontFace(psz); + + ll = cfg.get_signed_num(uiCharset); + if(ll == 0) return false; - SetPointSize((WORD)file.GetInt(_T("000"), _T("Info"), _T("Size"), 0, szData)); - if (file.IsDefault()) + SetCharset((BYTE)ll); + + ll = cfg.get_signed_num(uiSize); + if(ll == 0) 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; + SetPointSize((WORD)ll); - // we need to reallocate the buffer - TCHAR* pszData=new TCHAR[tCount+tDataCount]; - memcpy(pszData, pszStrings, tCount*sizeof(TCHAR)); + SetDirection(cfg.get_bool(uiRTL)); - delete [] pszStrings; - pszStrings=pszData; + psz = cfg.get_string(uiHelpName); + if(!psz || psz[0] == _t('\0')) + return false; + SetHelpName(psz); - tOffset=tCount; - tCount+=tDataCount; - } - else - { - // delete old settings - delete [] pszStrings; - m_mStrings.clear(); + psz = cfg.get_string(uiAuthor); + if(!psz || psz[0] == _t('\0')) + return false; + SetAuthor(psz); - 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; - } - } - } + psz = cfg.get_string(uiVersion); + if(!psz || psz[0] == _t('\0')) + return false; + SetVersion(psz); } - // free unneded data - file.Close(); - - if (!bUpdate) + m_bUpdating = bUpdate; + m_uiSectionID = 0; + if(!cfg.enum_properties(_t("*"), EnumAttributesCallback, this)) + return false; + + if(!bUpdate) { // remember the filename SetFilename(pszFile); @@ -259,32 +285,32 @@ { strings_map::iterator it=m_mStrings.find((wHiID << 16) | wLoID); if (it != m_mStrings.end()) - return pszStrings+(*it).second; + return (*it).second; else - return &szDefString; + return EMPTY_STRING; } void CLangData::SetFilename(PCTSTR psz) { - if (pszFilename) - delete [] pszFilename; + if (m_pszFilename) + delete [] m_pszFilename; // copy - pszFilename=new TCHAR[_tcslen(psz)+1]; - _tcscpy(pszFilename, psz); + m_pszFilename=new TCHAR[_tcslen(psz)+1]; + _tcscpy(m_pszFilename, psz); } PCTSTR CLangData::GetFilename(bool bFullPath) const { if (bFullPath) - return pszFilename; + return m_pszFilename; else { - TCHAR *pszFnd=_tcsrchr(pszFilename, _T('\\')); + TCHAR *pszFnd=_tcsrchr(m_pszFilename, _T('\\')); if (pszFnd) return pszFnd+1; else - return pszFilename; + return m_pszFilename; } } Index: src/ch/ResourceManager.h =================================================================== diff -u -N -r3493e9fc470285b0a0b417d50be281467a071eb7 -r37a273b73ad2ba80df122121bc36c7a11a5492bc --- src/ch/ResourceManager.h (.../ResourceManager.h) (revision 3493e9fc470285b0a0b417d50be281467a071eb7) +++ src/ch/ResourceManager.h (.../ResourceManager.h) (revision 37a273b73ad2ba80df122121bc36c7a11a5492bc) @@ -24,6 +24,7 @@ #include #include #include "af_defs.h" +#include "../libicpf/gen_types.h" using namespace std; @@ -34,20 +35,16 @@ /////////////////////////////////////////////////////////// // language description structure -typedef map strings_map; +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(); + ~CLangData(); CLangData(const CLangData& ld); -protected: - void SetFnameData(PTSTR *ppszDst, PCTSTR pszSrc); - -public: // operations bool ReadInfo(PCTSTR pszFile); bool ReadTranslation(PCTSTR pszFile, bool bUpdate=false); @@ -58,56 +55,61 @@ 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 SetLangName(PCTSTR psz) { if (m_pszLngName) delete [] m_pszLngName; m_pszLngName=new TCHAR[_tcslen(psz)+1]; _tcscpy(m_pszLngName, psz); }; + PCTSTR GetLangName() const { return m_pszLngName; }; - void SetBaseFile(PCTSTR psz) { SetFnameData(&pszBaseFile, psz); }; - PCTSTR GetBaseFile() const { return pszBaseFile; }; + void SetBaseFile(PCTSTR psz) { SetFnameData(&m_pszBaseFile, psz); }; + PCTSTR GetBaseFile() const { return m_pszBaseFile; }; - void SetLangCode(WORD wLang) { wLangCode=wLang; }; - WORD GetLangCode() const { return wLangCode; }; + void SetLangCode(WORD wLang) { m_wLangCode=wLang; }; + WORD GetLangCode() const { return m_wLangCode; }; - void SetFontFace(PCTSTR psz) { if (pszFontFace) delete [] pszFontFace; pszFontFace=new TCHAR[_tcslen(psz)+1]; _tcscpy(pszFontFace, psz); }; - PCTSTR GetFontFace() const { return pszFontFace; }; + void SetFontFace(PCTSTR psz) { if (m_pszFontFace) delete [] m_pszFontFace; m_pszFontFace=new TCHAR[_tcslen(psz)+1]; _tcscpy(m_pszFontFace, psz); }; + PCTSTR GetFontFace() const { return m_pszFontFace; }; - void SetCharset(BYTE byChar) { byCharset=byChar; }; - BYTE GetCharset() const { return byCharset; }; + void SetCharset(BYTE byChar) { m_byCharset=byChar; }; + BYTE GetCharset() const { return m_byCharset; }; - void SetPointSize(WORD wSize) { wPointSize=wSize; }; - WORD GetPointSize() const { return wPointSize; }; + void SetPointSize(WORD wSize) { m_wPointSize=wSize; }; + WORD GetPointSize() const { return m_wPointSize; }; - void SetDirection(bool brtl) { bRTL=brtl; }; - bool GetDirection() const { return bRTL; }; + void SetDirection(bool brtl) { m_bRTL=brtl; }; + bool GetDirection() const { return m_bRTL; }; - void SetHelpName(PCTSTR psz) { SetFnameData(&pszHelpName, psz); }; - PCTSTR GetHelpName() const { return pszHelpName; }; + void SetHelpName(PCTSTR psz) { SetFnameData(&m_pszHelpName, psz); }; + PCTSTR GetHelpName() const { return m_pszHelpName; }; - void SetAuthor(PCTSTR psz) { if (pszAuthor) delete [] pszAuthor; pszAuthor=new TCHAR[_tcslen(psz)+1]; _tcscpy(pszAuthor, psz); }; - PCTSTR GetAuthor() const { return pszAuthor; }; + void SetAuthor(PCTSTR psz) { if (m_pszAuthor) delete [] m_pszAuthor; m_pszAuthor=new TCHAR[_tcslen(psz)+1]; _tcscpy(m_pszAuthor, psz); }; + PCTSTR GetAuthor() const { return m_pszAuthor; }; - void SetVersion(PCTSTR psz) { if (pszVersion) delete [] pszVersion; pszVersion=new TCHAR[_tcslen(psz)+1]; _tcscpy(pszVersion, psz); }; - PCTSTR GetVersion() const { return pszVersion; }; + void SetVersion(PCTSTR psz) { if (m_pszVersion) delete [] m_pszVersion; m_pszVersion=new TCHAR[_tcslen(psz)+1]; _tcscpy(m_pszVersion, psz); }; + PCTSTR GetVersion() const { return m_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)); } }; +// 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)); } }; +protected: + void SetFnameData(PTSTR *ppszDst, PCTSTR pszSrc); + static void EnumAttributesCallback(bool bGroup, const tchar_t* pszName, const tchar_t* pszValue, ptr_t pData); + 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 ? + TCHAR *m_pszFilename; // file name of the language data (with path) + TCHAR *m_pszLngName; // name of the language (ie. Chinese (PRC)) + TCHAR *m_pszBaseFile; // file with base language data (wo path) + TCHAR *m_pszFontFace; // face name of the font that will be used in dialogs + WORD m_wLangCode; // language code + WORD m_wPointSize; // font point size + TCHAR *m_pszHelpName; // help name (wo the directory) for this language + TCHAR *m_pszAuthor; // author name + TCHAR *m_pszVersion; // version of this file + BYTE m_byCharset; // charset for use with the font + bool m_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 + +private: + uint_t m_uiSectionID; ///< ID of the currently processed section + bool m_bUpdating; ///< Are we updating the language with base language ? }; /////////////////////////////////////////////////////////////////////////////////////