summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgeorge.hazan <george.hazan@e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb>2011-12-12 15:48:12 +0000
committergeorge.hazan <george.hazan@e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb>2011-12-12 15:48:12 +0000
commitc7a77c3e13828c4907de97c0cc62ab257682d06a (patch)
tree4507c6bb49dade2700dedba568bf62ff8b8fa5d9
parent580b65fe7fd53ba85c591e14423249c0b44838a6 (diff)
fix for Unicode langpack files
git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@249 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb
-rw-r--r--LangMan/langpack.c82
-rw-r--r--LangMan/main.c58
2 files changed, 74 insertions, 66 deletions
diff --git a/LangMan/langpack.c b/LangMan/langpack.c
index be30cae..6ce827c 100644
--- a/LangMan/langpack.c
+++ b/LangMan/langpack.c
@@ -26,9 +26,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void TrimString(char *str)
{
int len,start;
- len=lstrlenA(str);
- while(str[0]!='\0' && (unsigned char)str[len-1]<=' ') str[--len]=0;
- for(start=0;str[start] && (unsigned char)str[start]<=' ';++start);
+ len = lstrlenA(str);
+ while (str[0]!='\0' && (unsigned char)str[len-1]<=' ') str[--len]=0;
+ for (start=0; str[start] && (unsigned char)str[start]<=' '; ++start);
MoveMemory(str,str+start,len-start+1);
}
@@ -153,49 +153,60 @@ static BOOL LoadPackData(LANGPACK_INFO *pack,BOOL fEnabledPacks,const char *pszF
X-Version: 1.2.3.4 (non-standard extension)
see 'LangMan-Translation.txt' for some header quidelines
*/
- if(!GetPackPath(szFileName,SIZEOF(szFileName),fEnabledPacks,pack->szFileName)) return FALSE;
- fp=_tfopen(szFileName,_T("rt"));
- if(fp==NULL) return FALSE;
- fgets(line,sizeof(line),fp);
+ if ( !GetPackPath( szFileName, SIZEOF(szFileName), fEnabledPacks, pack->szFileName))
+ return FALSE;
+
+ fp = _tfopen(szFileName,_T("rt"));
+ if (fp == NULL)
+ return FALSE;
+
+ fgets(line, sizeof(line), fp);
TrimString(line);
- if(lstrcmpA(line,pszFileVersionHeader)) {
+ buf = line;
+
+ if (strlen(line) >= 3 && line[0] == '\xef' && line[1] == '\xbb' && line[2] == '\xbf') {
+ pack->codepage = CP_UTF8;
+ buf += 3;
+ }
+
+ if ( lstrcmpA(buf, pszFileVersionHeader )) {
fclose(fp);
return FALSE;
}
- pack->flags=LPF_NOLOCALE;
- szLanguageA[0]='\0';
- while(!feof(fp)) {
- if(fgets(line,sizeof(line),fp)==NULL) break;
+ pack->flags = LPF_NOLOCALE;
+ szLanguageA[0] = '\0';
+ while( !feof( fp )) {
+ if ( fgets(line, sizeof(line), fp) == NULL) break;
TrimString(line);
- if(IsEmpty(line) || line[0]==';' || line[0]=='\0') continue;
- if(line[0]=='[') break;
- pszColon=strchr(line,':');
- if(pszColon==NULL) continue;
- *pszColon='\0';
+ if ( IsEmpty(line) || line[0]==';' || line[0]=='\0') continue;
+ if ( line[0]=='[' ) break;
+ pszColon = strchr(line,':');
+ if ( pszColon == NULL ) continue;
+ *pszColon = '\0';
TrimString(pszColon+1);
- if(!lstrcmpA(line,"Language") && !pack->szLanguage[0])
- lstrcpynA(szLanguageA,pszColon+1,sizeof(szLanguageA)); /* buffer safe */
- else if(!lstrcmpA(line,"Last-Modified-Using") && !pack->szLastModifiedUsing[0])
- lstrcpynA(pack->szLastModifiedUsing,pszColon+1,sizeof(pack->szLastModifiedUsing)); /* buffer safe */
- else if(!lstrcmpA(line, "Authors")) {
+ if ( !lstrcmpA(line,"Language") && !pack->szLanguage[0] )
+ lstrcpynA(szLanguageA, pszColon+1, sizeof(szLanguageA)); /* buffer safe */
+ else if ( !lstrcmpA(line, "Last-Modified-Using") && !pack->szLastModifiedUsing[0] )
+ lstrcpynA(pack->szLastModifiedUsing, pszColon+1, sizeof(pack->szLastModifiedUsing)); /* buffer safe */
+ else if ( !lstrcmpA(line, "Authors")) {
buf=pack->szAuthors+lstrlenA(pack->szAuthors); /* allow multiple tags */
if((sizeof(pack->szAuthors)-lstrlenA(pack->szAuthors))>0) /* buffer safe */
mir_snprintf(buf,sizeof(pack->szAuthors)-lstrlenA(pack->szAuthors),(pack->szAuthors[0]=='\0')?"%s":" %s",pszColon+1);
- } else if(!lstrcmpA(line, "Author-email") && !pack->szAuthorEmail[0])
- lstrcpynA(pack->szAuthorEmail,pszColon+1,sizeof(pack->szAuthorEmail)); /* buffer safe */
- else if(!lstrcmpA(line,"Locale") && pack->flags&LPF_NOLOCALE) {
- pack->Locale=MAKELCID((USHORT)strtol(pszColon+1,NULL,16),SORT_DEFAULT);
- if(pack->Locale) pack->flags&=~LPF_NOLOCALE;
+ } else if ( !lstrcmpA(line, "Author-email") && !pack->szAuthorEmail[0])
+ lstrcpynA(pack->szAuthorEmail, pszColon+1, sizeof(pack->szAuthorEmail)); /* buffer safe */
+ else if ( !lstrcmpA(line,"Locale") && (pack->flags & LPF_NOLOCALE)) {
+ pack->Locale = MAKELCID((USHORT)strtol(pszColon+1, NULL, 16), SORT_DEFAULT);
+ if(pack->Locale) pack->flags &= ~LPF_NOLOCALE;
}
- else if(!lstrcmpA(line,"Plugins-included")) {
- buf=pack->szPluginsIncluded+lstrlenA(pack->szPluginsIncluded); /* allow multiple tags */
- if((sizeof(pack->szPluginsIncluded)-lstrlenA(pack->szPluginsIncluded))>0) /* buffer safe */
- mir_snprintf(buf,sizeof(pack->szPluginsIncluded)-lstrlenA(pack->szPluginsIncluded),(pack->szPluginsIncluded[0]=='\0')?"%s":", %s",CharLowerA(pszColon+1));
+ else if ( !lstrcmpA(line,"Plugins-included")) {
+ buf = pack->szPluginsIncluded + lstrlenA(pack->szPluginsIncluded); /* allow multiple tags */
+ if (( sizeof(pack->szPluginsIncluded)-lstrlenA(pack->szPluginsIncluded)) > 0 ) /* buffer safe */
+ mir_snprintf(buf, sizeof(pack->szPluginsIncluded)-lstrlenA(pack->szPluginsIncluded),(pack->szPluginsIncluded[0]=='\0')?"%s":", %s",CharLowerA(pszColon+1));
}
- else if(!lstrcmpA(line,"X-Version") && !pack->szVersion[0])
- lstrcpynA(pack->szVersion,pszColon+1,sizeof(pack->szVersion)); /* buffer safe */
- else if(!lstrcmpA(line,"X-FLName") && !pack->szFLName[0])
- lstrcpynA(pack->szFLName,pszColon+1,sizeof(pack->szFLName)); /* buffer safe */
+ else if ( !lstrcmpA(line,"X-Version") && !pack->szVersion[0] )
+ lstrcpynA(pack->szVersion, pszColon+1, sizeof(pack->szVersion)); /* buffer safe */
+ else if ( !lstrcmpA(line,"X-FLName") && !pack->szFLName[0] )
+ lstrcpynA(pack->szFLName, pszColon+1, sizeof(pack->szFLName)); /* buffer safe */
}
CleanupLanguage(szLanguageA);
CleanupAuthors(pack->szAuthors);
@@ -343,7 +354,6 @@ BOOL IsPluginIncluded(const LANGPACK_INFO *pack,char *pszFileBaseName)
}
else p+=lstrlenA(pszFileBaseName)+1;
}
- return FALSE;
}
/************************* Switch *************************************/
diff --git a/LangMan/main.c b/LangMan/main.c
index a166195..9dd4bfa 100644
--- a/LangMan/main.c
+++ b/LangMan/main.c
@@ -27,6 +27,8 @@ PLUGINLINK *pluginLink;
struct MM_INTERFACE mmi;
static HANDLE hHookModulesLoaded;
+static char szEmail[100] = PLUGIN_EMAIL;
+
static PLUGININFOEX pluginInfo={
sizeof(PLUGININFOEX),
"Language Pack Manager",
@@ -37,7 +39,7 @@ static PLUGININFOEX pluginInfo={
"Helps you manage Language Packs of different languages.", /* autotranslated */
#endif
"H. Herkenrath",
- PLUGIN_EMAIL, /* @ will be set later */
+ szEmail, /* @ will be set later */
"© 2005-2007 H. Herkenrath",
PLUGIN_WEBSITE,
UNICODE_AWARE,
@@ -69,27 +71,27 @@ static void InstallFile(const TCHAR *pszFileName,const TCHAR *pszDestSubDir)
TCHAR szFileFrom[MAX_PATH+1],szFileTo[MAX_PATH+1],*p;
HANDLE hFile;
- if(!GetModuleFileName(hInst,szFileFrom,SIZEOF(szFileFrom)-lstrlen(pszFileName)))
+ if ( !GetModuleFileName(hInst, szFileFrom, SIZEOF(szFileFrom) - lstrlen(pszFileName)))
return;
- p=_tcsrchr(szFileFrom,_T('\\'));
- if(p!=NULL) *(++p)=0;
- lstrcat(szFileFrom,pszFileName); /* buffer safe */
+ p = _tcsrchr(szFileFrom,_T('\\'));
+ if ( p != NULL ) *(++p)=0;
+ lstrcat(szFileFrom, pszFileName); /* buffer safe */
- hFile=CreateFile(szFileFrom,0,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
- if(hFile==INVALID_HANDLE_VALUE) return;
+ hFile = CreateFile(szFileFrom, 0, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
+ if ( hFile == INVALID_HANDLE_VALUE ) return;
CloseHandle(hFile);
- if(!GetModuleFileName(NULL,szFileTo,SIZEOF(szFileTo)-lstrlen(pszDestSubDir)-lstrlen(pszFileName)))
+ if ( !GetModuleFileName(NULL, szFileTo, SIZEOF(szFileTo) - lstrlen(pszDestSubDir) - lstrlen(pszFileName)))
return;
- p=_tcsrchr(szFileTo,_T('\\'));
- if(p!=NULL) *(++p)=0;
- lstrcat(szFileTo,pszDestSubDir); /* buffer safe */
- CreateDirectory(szFileTo,NULL);
- lstrcat(szFileTo,pszFileName); /* buffer safe */
+ p = _tcsrchr(szFileTo, _T('\\'));
+ if ( p != NULL ) *(++p)=0;
+ lstrcat(szFileTo, pszDestSubDir); /* buffer safe */
+ CreateDirectory(szFileTo, NULL);
+ lstrcat(szFileTo, pszFileName); /* buffer safe */
- if(!MoveFile(szFileFrom,szFileTo) && GetLastError()==ERROR_ALREADY_EXISTS) {
+ if ( !MoveFile(szFileFrom, szFileTo) && GetLastError() == ERROR_ALREADY_EXISTS) {
DeleteFile(szFileTo);
- MoveFile(szFileFrom,szFileTo);
+ MoveFile(szFileFrom, szFileTo);
}
}
@@ -97,8 +99,8 @@ static int LangManModulesLoaded(WPARAM wParam,LPARAM lParam)
{
UNREFERENCED_PARAMETER(wParam);
UNREFERENCED_PARAMETER(lParam);
- if(ServiceExists("DBEditorpp/RegisterSingleModule"))
- CallService("DBEditorpp/RegisterSingleModule",(WPARAM)"LangMan",0);
+ if ( ServiceExists("DBEditorpp/RegisterSingleModule"))
+ CallService("DBEditorpp/RegisterSingleModule", (WPARAM)"LangMan", 0);
return 0;
}
@@ -109,18 +111,16 @@ extern "C" {
__declspec(dllexport) const PLUGININFO* MirandaPluginInfo(DWORD mirandaVersion)
{
if(mirandaVersion<PLUGIN_MAKE_VERSION(0,1,0,1)) return NULL;
- pluginInfo.cbSize=sizeof(PLUGININFO); /* needed as v0.6 does equality check */
- /* email obfuscated, made .rdata writable */
- pluginInfo.authorEmail[PLUGIN_EMAIL_ATT_POS-1]='@';
+ pluginInfo.cbSize = sizeof(PLUGININFO); /* needed as v0.6 does equality check */
+ szEmail[PLUGIN_EMAIL_ATT_POS-1] = '@';
return (PLUGININFO*)&pluginInfo; /* header is the same */
}
__declspec(dllexport) const PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
{
UNREFERENCED_PARAMETER(mirandaVersion);
- pluginInfo.cbSize=sizeof(PLUGININFOEX);
- /* email obfuscated, made .rdata writable */
- pluginInfo.authorEmail[PLUGIN_EMAIL_ATT_POS-1]='@';
+ pluginInfo.cbSize = sizeof(PLUGININFOEX);
+ szEmail[PLUGIN_EMAIL_ATT_POS-1] = '@';
return &pluginInfo;
}
@@ -132,37 +132,35 @@ __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void)
__declspec(dllexport) int Load(PLUGINLINK *link)
{
INITCOMMONCONTROLSEX icc;
- pluginLink=link;
+ pluginLink = link;
/* existance of MS_SYSTEM_GETVERSION and MS_LANGPACK_TRANSLATESTRING
* is checked in MirandaPluginInfo().
* Not placed in MirandaPluginInfo() to avoid MessageBoxes on plugin options.
* Using ANSI as LANG_UNICODE might not be supported. */
- if(CallService(MS_SYSTEM_GETVERSION,0,0)<NEEDED_MIRANDA_VERSION) {
+ if ( CallService(MS_SYSTEM_GETVERSION, 0, 0) < NEEDED_MIRANDA_VERSION ) {
char szText[256];
mir_snprintf(szText,sizeof(szText),Translate("The Language Pack Manager Plugin can not be loaded. It requires Miranda IM %hs or later."),NEEDED_MIRANDA_VERSION_STR);
MessageBoxA(NULL,szText,Translate("Language Pack Manager Plugin"),MB_OK|MB_ICONERROR|MB_SETFOREGROUND|MB_TOPMOST|MB_TASKMODAL);
return 1;
}
- if(mir_getMMI(&mmi)) return 1;
- icc.dwSize=sizeof(icc);
+ if ( mir_getMMI(&mmi)) return 1;
+ icc.dwSize = sizeof(icc);
icc.dwICC=ICC_TREEVIEW_CLASSES|ICC_USEREX_CLASSES;
InitCommonControlsEx(&icc);
InitOptions();
-// InitUpdate();
/* installation */
InstallFile(_T("LangMan-Readme.txt"),_T("Docs\\"));
InstallFile(_T("LangMan-License.txt"),_T("Docs\\"));
InstallFile(_T("LangMan-SDK.zip"),_T("Docs\\"));
- hHookModulesLoaded=HookEvent(ME_SYSTEM_MODULESLOADED,LangManModulesLoaded);
+ hHookModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, LangManModulesLoaded);
return 0;
}
__declspec(dllexport) int Unload(void)
{
UninitOptions();
-// UninitUpdate();
UnhookEvent(hHookModulesLoaded);
return 0;
}