From 61b011937f55446542eb829004d14336837f1ce7 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 12 Jan 2013 19:39:37 +0000 Subject: final variant of profile name's fix for AssocMgr git-svn-id: http://svn.miranda-ng.org/main/trunk@3077 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/AssocMgr/src/reg.cpp | 412 +++++++++++++++++++++---------------------- 1 file changed, 205 insertions(+), 207 deletions(-) (limited to 'plugins/AssocMgr/src/reg.cpp') diff --git a/plugins/AssocMgr/src/reg.cpp b/plugins/AssocMgr/src/reg.cpp index 042b0da119..41e724025d 100644 --- a/plugins/AssocMgr/src/reg.cpp +++ b/plugins/AssocMgr/src/reg.cpp @@ -21,19 +21,21 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "common.h" +extern HINSTANCE hInst; + #ifdef _DEBUG /* Debug: Ensure all registry calls do succeed and have valid parameters. * Shows a details message box otherwise. */ static __inline LONG regchk(LONG res, const char *pszFunc, const void *pszInfo, BOOL fInfoUnicode, const char *pszFile, unsigned int nLine) { - if(res != ERROR_SUCCESS && res != ERROR_FILE_NOT_FOUND && res != ERROR_NO_MORE_ITEMS) { + if (res != ERROR_SUCCESS && res != ERROR_FILE_NOT_FOUND && res != ERROR_NO_MORE_ITEMS) { TCHAR szMsg[1024], *pszInfo2; char *pszErr; pszErr = GetWinErrorDescription(res); pszInfo2 = s2t(pszInfo, fInfoUnicode, FALSE); /* does NULL check */ mir_sntprintf(szMsg, SIZEOF(szMsg), TranslateT("Access failed:\n%.64hs(%.128s)\n%.250hs(%u)\n%.256hs (%u)"), pszFunc, pszInfo2, pszFile, nLine, pszErr, res); MessageBox(NULL, szMsg, TranslateT("Registry Warning"), MB_OK | MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST | MB_TASKMODAL); - if(pszErr != NULL) LocalFree(pszErr); + if (pszErr != NULL) LocalFree(pszErr); mir_free(pszInfo2); /* does NULL check */ } return res; @@ -98,7 +100,7 @@ char *MakeFileClassName(const char *pszFileExt) { char *pszClass; pszClass=(char*)mir_alloc((lstrlenA(pszFileExt)+12)*sizeof(TCHAR)); - if(pszClass!=NULL) + if (pszClass!=NULL) /* using correctly formated PROGID */ wsprintfA(pszClass,"miranda%sfile",pszFileExt); /* includes dot, buffer safe */ return pszClass; @@ -109,7 +111,7 @@ char *MakeUrlClassName(const char *pszUrl) { char *pszClass; pszClass=mir_strdup(pszUrl); - if(pszClass!=NULL) + if (pszClass!=NULL) /* remove trailing : */ pszClass[lstrlenA(pszClass)-1]=0; return pszClass; @@ -124,41 +126,39 @@ static BOOL IsFileClassName(char *pszClassName, char **ppszFileExt) // mir_free() the return value TCHAR *MakeRunCommand(BOOL fMirExe,BOOL fFixedDbProfile) { - extern HINSTANCE hInst; - TCHAR szExe[MAX_PATH],*pszFmt,*pszRunCmd=NULL; - char szDbFile[MAX_PATH]; - int cch; - if (!fFixedDbProfile || !CallService(MS_DB_GETPROFILENAME,SIZEOF(szDbFile),(LPARAM)szDbFile)) - if(GetModuleFileNameWorkaround(fMirExe?NULL:hInst,szExe,SIZEOF(szExe))) { - /* db file */ - if (!fFixedDbProfile) - lstrcpyA(szDbFile,"%1"); /* buffer safe */ - /* size */ - cch=lstrlen(szExe)+lstrlenA(szDbFile); - if(fMirExe) { - /* run command for miranda32.exe */ - cch+=7; - pszFmt=_T("\"%s\" \"%hs\""); - } else { - DWORD len; - /* run command for rundll32.exe calling WaitForDDE */ - cch+=28; - pszFmt=_T("rundll32.exe %s,WaitForDDE \"%hs\""); - /* ensure the command line is not too long */ - GetShortPathName(szExe,szExe,SIZEOF(szExe)); - /* surround by quotes if failed */ - len=lstrlen(szExe); - if(_tcschr(szExe,_T(' '))!=NULL && (len+2)sizeof(TCHAR)) { pszVal=(TCHAR*)mir_alloc(dwSize+sizeof(TCHAR)); - if(pszVal!=NULL) { + if (pszVal!=NULL) { /* get value */ if (!RegQueryValueEx(hKey,pszValName,NULL,&dwType,(BYTE*)pszVal,&dwSize)) { pszVal[dwSize/sizeof(TCHAR)]=0; - if(dwType==REG_EXPAND_SZ) { + if (dwType==REG_EXPAND_SZ) { dwSize=MAX_PATH; pszVal2=(TCHAR*)mir_alloc(dwSize*sizeof(TCHAR)); - if(ExpandEnvironmentStrings(pszVal,pszVal2,dwSize)) { + if (ExpandEnvironmentStrings(pszVal,pszVal2,dwSize)) { mir_free(pszVal); return pszVal2; } mir_free(pszVal2); - } else if(dwType==REG_SZ) + } else if (dwType==REG_SZ) return pszVal; } mir_free(pszVal); @@ -311,7 +310,7 @@ static BOOL IsRegStrValue(HKEY hKey,const TCHAR *pszValName,const TCHAR *pszCmpV BOOL fSame=FALSE; TCHAR *pszVal; pszVal=GetRegStrValue(hKey,pszValName); - if(pszVal!=NULL) { + if (pszVal!=NULL) { fSame=!lstrcmp(pszVal,pszCmpVal); mir_free(pszVal); } @@ -325,9 +324,9 @@ static BOOL IsRegStrValueA(HKEY hKey,const TCHAR *pszValName,const char *pszCmpV TCHAR *pszVal; char *pszValA; pszVal=GetRegStrValue(hKey,pszValName); - if(pszVal!=NULL) { + if (pszVal!=NULL) { pszValA=t2a(pszVal); - if(pszValA!=NULL) + if (pszValA!=NULL) fSame=!lstrcmpA(pszValA,pszCmpVal); mir_free(pszValA); /* does NULL check */ mir_free(pszVal); @@ -348,7 +347,7 @@ static void WriteDbBackupData(const char *pszSetting,DWORD dwType,BYTE *pData,DW dbcws.value.type=DBVT_BLOB; dbcws.value.cpbVal=(WORD)(cbData+sizeof(DWORD)); dbcws.value.pbVal=(BYTE*)mir_alloc(cbData+sizeof(DWORD)); - if(dbcws.value.pbVal==NULL) return; + if (dbcws.value.pbVal==NULL) return; *(DWORD*)dbcws.value.pbVal=dwType; CopyMemory(dbcws.value.pbVal+sizeof(DWORD),pData,cbData); CallService(MS_DB_CONTACT_WRITESETTING,0,(LPARAM)&dbcws); @@ -364,7 +363,7 @@ static BOOL ReadDbBackupData(const char *pszSetting,DWORD *pdwType,BYTE **ppData dbcgs.szSetting=pszSetting; dbcgs.pValue=&dbv; if (!CallService(MS_DB_CONTACT_GETSETTING,0,(LPARAM)&dbcgs)) { - if(dbv.type==DBVT_BLOB && dbv.cpbVal>=sizeof(DWORD)) { + if (dbv.type==DBVT_BLOB && dbv.cpbVal>=sizeof(DWORD)) { *pdwType=*(DWORD*)dbv.pbVal; *ppData=dbv.pbVal; *pcbData=dbv.cpbVal-sizeof(DWORD); @@ -393,22 +392,22 @@ static void BackupRegTree_Worker(HKEY hKey,const char *pszSubKey,struct BackupRe DWORD nDbPrefixLen; if ((res=RegOpenKeyExA(hKey,pszSubKey,0,KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS,&hKey))==ERROR_SUCCESS) { if ((res=RegQueryInfoKey(hKey,NULL,NULL,NULL,NULL,&nMaxSubKeyLen,NULL,NULL,&nMaxValNameLen,&nMaxValSize,NULL,NULL))==ERROR_SUCCESS) { - if(nMaxSubKeyLen>nMaxValNameLen) nMaxValNameLen=nMaxSubKeyLen; + if (nMaxSubKeyLen>nMaxValNameLen) nMaxValNameLen=nMaxSubKeyLen; /* prepare buffer */ nDbPrefixLen=(DWORD)lstrlenA(*param->ppszDbPrefix)+lstrlenA(pszSubKey)+1; cchName=nDbPrefixLen+nMaxValNameLen+3; - if(cchName>*param->pdwDbPrefixSize) { + if (cchName>*param->pdwDbPrefixSize) { pszName=(char*)mir_realloc(*param->ppszDbPrefix,cchName); - if(pszName==NULL) return; + if (pszName==NULL) return; *param->ppszDbPrefix=pszName; *param->pdwDbPrefixSize=cchName; } lstrcatA(lstrcatA(*param->ppszDbPrefix,pszSubKey),"\\"); /* buffer safe */ /* enum values */ pszName=(char*)mir_alloc(nMaxValNameLen+1); - if(nMaxValSize==0) nMaxValSize=1; + if (nMaxValSize==0) nMaxValSize=1; pData=(BYTE*)mir_alloc(nMaxValSize); - if(pszName!=NULL && pData!=NULL) { + if (pszName!=NULL && pData!=NULL) { index=0; while(!res) { cchName=nMaxValNameLen+1; @@ -417,21 +416,21 @@ static void BackupRegTree_Worker(HKEY hKey,const char *pszSubKey,struct BackupRe (*param->ppszDbPrefix)[nDbPrefixLen]=0; lstrcatA(*param->ppszDbPrefix,pszName); /* buffer safe */ ptszName=a2t(pszName); - if(ptszName!=NULL) { + if (ptszName!=NULL) { if (!RegQueryValueEx(hKey,ptszName,NULL,&dwType,pData,&cbData)) { - + WriteDbBackupData(*param->ppszDbPrefix,dwType,pData,cbData); - + } mir_free(ptszName); } } } - if(res==ERROR_NO_MORE_ITEMS) res=ERROR_SUCCESS; + if (res==ERROR_NO_MORE_ITEMS) res=ERROR_SUCCESS; } mir_free(pData); /* does NULL check */ /* enum subkeys */ - if(param->level<32 && pszName!=NULL) { + if (param->level<32 && pszName!=NULL) { ++param->level; /* can be max 32 levels deep (after prefix), restriction of RegCreateKeyEx() */ index=0; while(!res) { @@ -442,7 +441,7 @@ static void BackupRegTree_Worker(HKEY hKey,const char *pszSubKey,struct BackupRe } } } - if(res==ERROR_NO_MORE_ITEMS) res=ERROR_SUCCESS; + if (res==ERROR_NO_MORE_ITEMS) res=ERROR_SUCCESS; mir_free(pszName); /* does NULL check */ } RegCloseKey(hKey); @@ -457,7 +456,7 @@ static void BackupRegTree(HKEY hKey,const char *pszSubKey,const char *pszDbPrefi param.pdwDbPrefixSize=&dwDbPrefixSize; param.ppszDbPrefix=(char**)&pszDbPrefix; pszDbPrefix=mir_strdup(pszDbPrefix); - if(pszDbPrefix!=NULL) { + if (pszDbPrefix!=NULL) { dwDbPrefixSize=lstrlenA(pszDbPrefix)+1; BackupRegTree_Worker(hKey,pszSubKey,¶m); mir_free((char*)pszDbPrefix); @@ -479,39 +478,39 @@ static LONG RestoreRegTree(HKEY hKey,const char *pszSubKey,const char *pszDbPref nDbPrefixLen=lstrlenA(pszDbPrefix); nPrefixWithSubKeyLen=nDbPrefixLen+lstrlenA(pszSubKey)+1; pszPrefixWithSubKey=(char*)mir_alloc(nPrefixWithSubKeyLen+1); - if(pszPrefixWithSubKey==NULL) return ERROR_OUTOFMEMORY; + if (pszPrefixWithSubKey==NULL) return ERROR_OUTOFMEMORY; lstrcatA(lstrcatA(lstrcpyA(pszPrefixWithSubKey,pszDbPrefix),pszSubKey),"\\"); /* buffer safe */ res=ERROR_NO_MORE_ITEMS; - if(pszPrefixWithSubKey!=NULL) { - if(EnumDbPrefixSettings("AssocMgr",pszPrefixWithSubKey,&ppszSettings,&nSettingsCount)) { + if (pszPrefixWithSubKey!=NULL) { + if (EnumDbPrefixSettings("AssocMgr",pszPrefixWithSubKey,&ppszSettings,&nSettingsCount)) { for(i=0;i