Version Information now rely on languages, some more updates on named uservars, maybe last one before official release :) (preview UserVars.nsi - doesn't compile yet)
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@2633 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
7adbddc567
commit
1ea2160310
14 changed files with 539 additions and 283 deletions
|
@ -28,12 +28,24 @@ CResourceVersionInfo::CResourceVersionInfo()
|
|||
// Detect local codepage and language
|
||||
WORD Lang = GetSystemDefaultLangID();
|
||||
WORD CodePage = GetACP();
|
||||
char Buff[10];
|
||||
sprintf(Buff, "%04x%04x", Lang, CodePage);
|
||||
SetVersionInfoLang(Buff);
|
||||
/*
|
||||
SetKeyValue(Lang, CodePage, "Comments", "Portuguese");
|
||||
SetKeyValue(Lang, CodePage, "FileVersion", "1.2");
|
||||
SetKeyValue(Lang, CodePage, "FileDescription", "Soft");
|
||||
SetKeyValue(Lang, CodePage, "LegalCopyright", "My");
|
||||
SetKeyValue(Lang, CodePage, "InternalName", "My");
|
||||
SetKeyValue(Lang, CodePage, "CompanyName", "rats");
|
||||
SetKeyValue(Lang, CodePage, "ProductVersion", "ProductVersion");
|
||||
|
||||
AddTranslation(CodePage, Lang);
|
||||
b_CustomTranslations = false;
|
||||
Lang = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
|
||||
SetKeyValue(Lang, CodePage, "Comments", "English");
|
||||
SetKeyValue(Lang, CodePage, "FileVersion", "1.2");
|
||||
SetKeyValue(Lang, CodePage, "FileDescription", "Soft");
|
||||
SetKeyValue(Lang, CodePage, "LegalCopyright", "My");
|
||||
SetKeyValue(Lang, CodePage, "InternalName", "My");
|
||||
SetKeyValue(Lang, CodePage, "CompanyName", "rats");
|
||||
SetKeyValue(Lang, CodePage, "ProductVersion", "ProductVersion");
|
||||
*/
|
||||
}
|
||||
|
||||
CResourceVersionInfo::~CResourceVersionInfo()
|
||||
|
@ -58,14 +70,13 @@ void CResourceVersionInfo::SetProductVersion(int HighPart, int LowPart)
|
|||
m_FixedInfo.dwProductVersionMS = HighPart;
|
||||
}
|
||||
|
||||
// Util function
|
||||
wstring StrToWstr(const string& istr)
|
||||
// Util function - must be freeded
|
||||
WCHAR* StrToWstrAlloc(const char* istr, int codepage)
|
||||
{
|
||||
wstring wstr;
|
||||
for(string::const_iterator it = istr.begin(); it != istr.end(); ++it)
|
||||
{
|
||||
wstr += (unsigned char)*it;
|
||||
} return wstr;
|
||||
int strSize = strlen(istr);
|
||||
WCHAR* wstr = new WCHAR[(strSize*2)];
|
||||
MultiByteToWideChar(codepage, 0, istr, -1, wstr, strSize*2);
|
||||
return wstr;
|
||||
}
|
||||
|
||||
int GetVersionHeader (LPSTR &p, WORD &wLength, WORD &wValueLength, WORD &wType)
|
||||
|
@ -95,7 +106,7 @@ void PadStream (GrowBuf &strm)
|
|||
strm.add (&ZEROS, 4 - (strm.getlen() % 4));
|
||||
}
|
||||
|
||||
void SaveVersionHeader (GrowBuf &strm, WORD wLength, WORD wValueLength, WORD wType, const wstring &key, void *value)
|
||||
void SaveVersionHeader (GrowBuf &strm, WORD wLength, WORD wValueLength, WORD wType, const WCHAR *key, void *value)
|
||||
{
|
||||
WORD valueLen;
|
||||
WORD keyLen;
|
||||
|
@ -104,8 +115,8 @@ void SaveVersionHeader (GrowBuf &strm, WORD wLength, WORD wValueLength, WORD wTy
|
|||
|
||||
strm.add (&wValueLength, sizeof (wValueLength));
|
||||
strm.add (&wType, sizeof (wType));
|
||||
keyLen = (key.length() + 1) * sizeof (WCHAR);
|
||||
strm.add ((void*)key.c_str(), keyLen);
|
||||
keyLen = (wcslen(key) + 1) * sizeof (WCHAR);
|
||||
strm.add ((void*)key, keyLen);
|
||||
|
||||
PadStream(strm);
|
||||
|
||||
|
@ -118,112 +129,129 @@ void SaveVersionHeader (GrowBuf &strm, WORD wLength, WORD wValueLength, WORD wTy
|
|||
}
|
||||
}
|
||||
|
||||
void CResourceVersionInfo::ExportToStream(GrowBuf &strm)
|
||||
void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index)
|
||||
{
|
||||
DWORD v;
|
||||
WORD wSize;
|
||||
int p, p1;
|
||||
wstring KeyName, KeyValue;
|
||||
|
||||
WCHAR *KeyName, *KeyValue;
|
||||
|
||||
strm.resize(0);
|
||||
SaveVersionHeader (strm, 0, sizeof (VS_FIXEDFILEINFO), 0, L"VS_VERSION_INFO", &m_FixedInfo);
|
||||
|
||||
if ( m_ChildStrings.getnum() > 0 )
|
||||
DefineList *pChildStrings = m_ChildStringLists.get_strings(Index);
|
||||
if ( pChildStrings->getnum() > 0 )
|
||||
{
|
||||
GrowBuf stringInfoStream;
|
||||
KeyName = StrToWstr(m_VersionInfoLang);
|
||||
GrowBuf stringInfoStream;
|
||||
int codepage = m_ChildStringLists.get_codepage(Index);
|
||||
LANGID langid = m_ChildStringLists.get_lang(Index);
|
||||
char Buff[16];
|
||||
sprintf(Buff, "%04x%04x", langid, codepage);
|
||||
KeyName = StrToWstrAlloc(Buff, CP_ACP);
|
||||
SaveVersionHeader (stringInfoStream, 0, 0, 0, KeyName, &ZEROS);
|
||||
delete [] KeyName;
|
||||
|
||||
for ( int i = 0; i < pChildStrings->getnum(); i++ )
|
||||
{
|
||||
PadStream (stringInfoStream);
|
||||
|
||||
SaveVersionHeader (stringInfoStream, 0, 0, 0, KeyName.c_str(), &ZEROS);
|
||||
p = stringInfoStream.getlen();
|
||||
KeyName = StrToWstrAlloc(pChildStrings->getname(i), codepage);
|
||||
KeyValue = StrToWstrAlloc(pChildStrings->getvalue(i), codepage);
|
||||
SaveVersionHeader (stringInfoStream, 0, wcslen(KeyValue) + 1, 1, KeyName, (void*)KeyValue);
|
||||
delete [] KeyName;
|
||||
delete [] KeyValue;
|
||||
wSize = stringInfoStream.getlen() - p;
|
||||
|
||||
for ( int i = 0; i < m_ChildStrings.getnum(); i++ )
|
||||
{
|
||||
PadStream (stringInfoStream);
|
||||
|
||||
p = stringInfoStream.getlen();
|
||||
KeyName = StrToWstr(m_ChildStrings.getname(i));
|
||||
KeyValue = StrToWstr(m_ChildStrings.getvalue(i));
|
||||
SaveVersionHeader (stringInfoStream, 0, KeyValue.length() + 1, 1, KeyName.c_str(), (void*)KeyValue.c_str());
|
||||
wSize = stringInfoStream.getlen() - p;
|
||||
|
||||
*(WORD*)((PBYTE)stringInfoStream.get()+p)=wSize;
|
||||
}
|
||||
|
||||
wSize = stringInfoStream.getlen();
|
||||
*(WORD*)((PBYTE)stringInfoStream.get())=wSize;
|
||||
|
||||
PadStream (strm);
|
||||
p = strm.getlen();
|
||||
SaveVersionHeader (strm, 0, 0, 0, L"StringFileInfo", &ZEROS);
|
||||
strm.add (stringInfoStream.get(), stringInfoStream.getlen());
|
||||
wSize = strm.getlen() - p;
|
||||
|
||||
*(WORD*)((PBYTE)strm.get()+p)=wSize;
|
||||
*(WORD*)((PBYTE)stringInfoStream.get()+p)=wSize;
|
||||
}
|
||||
|
||||
wSize = stringInfoStream.getlen();
|
||||
*(WORD*)((PBYTE)stringInfoStream.get())=wSize;
|
||||
|
||||
PadStream (strm);
|
||||
p = strm.getlen();
|
||||
SaveVersionHeader (strm, 0, 0, 0, L"StringFileInfo", &ZEROS);
|
||||
strm.add (stringInfoStream.get(), stringInfoStream.getlen());
|
||||
wSize = strm.getlen() - p;
|
||||
|
||||
*(WORD*)((PBYTE)strm.get()+p)=wSize;
|
||||
}
|
||||
|
||||
if ( m_Translations.size() > 0 )
|
||||
// Show all languages avaiable using Var-Translations
|
||||
if ( m_ChildStringLists.getnum() > 0 )
|
||||
{
|
||||
PadStream (strm);
|
||||
p = strm.getlen();
|
||||
SaveVersionHeader (strm, 0, 0, 0, L"VarFileInfo", &ZEROS);
|
||||
PadStream (strm);
|
||||
|
||||
p1 = strm.getlen();
|
||||
SaveVersionHeader (strm, 0, 0, 0, L"Translation", &ZEROS);
|
||||
|
||||
for ( int i = 0; i < m_Translations.size(); i++ )
|
||||
PadStream (strm);
|
||||
p = strm.getlen();
|
||||
SaveVersionHeader (strm, 0, 0, 0, L"VarFileInfo", &ZEROS);
|
||||
PadStream (strm);
|
||||
|
||||
p1 = strm.getlen();
|
||||
SaveVersionHeader (strm, 0, 0, 0, L"Translation", &ZEROS);
|
||||
|
||||
// First add selected code language translation
|
||||
v = MAKELONG(m_ChildStringLists.get_lang(Index), m_ChildStringLists.get_codepage(Index));
|
||||
strm.add (&v, sizeof (v));
|
||||
|
||||
for ( int k =0; k < m_ChildStringLists.getnum(); k++ )
|
||||
{
|
||||
if ( k != Index )
|
||||
{
|
||||
v = m_Translations[i];
|
||||
strm.add (&v, sizeof (v));
|
||||
v = MAKELONG(m_ChildStringLists.get_lang(k), m_ChildStringLists.get_codepage(k));
|
||||
strm.add (&v, sizeof (v));
|
||||
}
|
||||
|
||||
wSize = strm.getlen() - p1;
|
||||
*(WORD*)((PBYTE)strm.get()+p1)=wSize;
|
||||
wSize = sizeof (int) * m_Translations.size();
|
||||
p1+=sizeof(WORD);
|
||||
*(WORD*)((PBYTE)strm.get()+p1)=wSize;
|
||||
|
||||
wSize = strm.getlen() - p;
|
||||
*(WORD*)((PBYTE)strm.get()+p)=wSize;
|
||||
}
|
||||
|
||||
wSize = strm.getlen() - p1;
|
||||
*(WORD*)((PBYTE)strm.get()+p1)=wSize;
|
||||
wSize = sizeof (int) * m_ChildStringLists.getnum();
|
||||
p1+=sizeof(WORD);
|
||||
*(WORD*)((PBYTE)strm.get()+p1)=wSize;
|
||||
|
||||
wSize = strm.getlen() - p;
|
||||
*(WORD*)((PBYTE)strm.get()+p)=wSize;
|
||||
}
|
||||
|
||||
wSize = strm.getlen();
|
||||
*(WORD*)((PBYTE)strm.get())=wSize;
|
||||
}
|
||||
|
||||
void CResourceVersionInfo::SetKeyValue(char* AKeyName, char* AValue)
|
||||
// Returns 0 if success, 1 if already defined
|
||||
int CResourceVersionInfo::SetKeyValue(LANGID lang_id, int codepage, char* AKeyName, char* AValue)
|
||||
{
|
||||
m_ChildStrings.add(AKeyName, AValue);
|
||||
int pos = m_ChildStringLists.find(lang_id, codepage);
|
||||
if ( pos == -1 )
|
||||
{
|
||||
pos = m_ChildStringLists.add(lang_id, codepage);
|
||||
}
|
||||
DefineList *pStrings = m_ChildStringLists.get_strings(pos);
|
||||
return pStrings->add(AKeyName, AValue);
|
||||
}
|
||||
|
||||
void CResourceVersionInfo::AddTranslation(WORD CodePage, WORD LangID )
|
||||
int CResourceVersionInfo::GetStringTablesCount()
|
||||
{
|
||||
if ( !b_CustomTranslations )
|
||||
{
|
||||
b_CustomTranslations = true;
|
||||
m_Translations.clear(); // remove local system default, user want to customize
|
||||
}
|
||||
DWORD dwTrans = MAKELONG(LangID, CodePage);
|
||||
if ( find(m_Translations.begin(), m_Translations.end(), dwTrans) == m_Translations.end() )
|
||||
m_Translations.push_back(dwTrans);
|
||||
return m_ChildStringLists.getnum();
|
||||
}
|
||||
|
||||
int CResourceVersionInfo::GetKeyCount()
|
||||
LANGID CResourceVersionInfo::GetLangID(int Index)
|
||||
{
|
||||
return m_ChildStrings.getnum();
|
||||
return m_ChildStringLists.get_lang(Index);
|
||||
}
|
||||
|
||||
int CResourceVersionInfo::GetTranslationCount()
|
||||
int CResourceVersionInfo::GetCodePage(int Index)
|
||||
{
|
||||
return m_Translations.size();
|
||||
return m_ChildStringLists.get_codepage(Index);
|
||||
}
|
||||
|
||||
char *CResourceVersionInfo::FindKey(char *pKeyName)
|
||||
char *CResourceVersionInfo::FindKey(LANGID LangID, int codepage, char *pKeyName)
|
||||
{
|
||||
return m_ChildStrings.find(pKeyName);
|
||||
}
|
||||
|
||||
void CResourceVersionInfo::SetVersionInfoLang(char *pLandCp)
|
||||
{
|
||||
m_VersionInfoLang = pLandCp;
|
||||
int pos = m_ChildStringLists.find(LangID, codepage);
|
||||
if ( pos == -1 )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
DefineList *pStrings = m_ChildStringLists.get_strings(pos);
|
||||
return pStrings->find(pKeyName);
|
||||
}
|
||||
|
||||
bool CResourceVersionInfo::IsValidCodePage(WORD codePage )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue