From 82ea016e57d36a1e75e57529f8f5dfdd2ac39b63 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 30 Sep 2012 14:24:30 +0000 Subject: patch to correctly upgrade old Miranda IM installations git-svn-id: http://svn.miranda-ng.org/main/trunk@1728 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/PluginUpdater/src/Common.h | 50 ++++++----- plugins/PluginUpdater/src/Notifications.cpp | 19 +++-- plugins/PluginUpdater/src/Options.cpp | 6 +- plugins/PluginUpdater/src/PluginUpdater.cpp | 6 +- plugins/PluginUpdater/src/Scanner.cpp | 124 ++++++++++++++++++++-------- plugins/PluginUpdater/src/Utils.cpp | 20 ++--- plugins/PluginUpdater/src/checksum.cpp | 8 +- plugins/PluginUpdater/src/unzipfile.cpp | 47 +++++++---- 8 files changed, 176 insertions(+), 104 deletions(-) (limited to 'plugins/PluginUpdater') diff --git a/plugins/PluginUpdater/src/Common.h b/plugins/PluginUpdater/src/Common.h index 28c899e9d7..e6eb4340b7 100644 --- a/plugins/PluginUpdater/src/Common.h +++ b/plugins/PluginUpdater/src/Common.h @@ -1,4 +1,4 @@ -/* +/* Copyright (C) 2010 Mataes This is free software; you can redistribute it and/or @@ -65,9 +65,7 @@ struct FILEURL struct FILEINFO { - char curhash[32+1]; - char newhash[32+1]; - TCHAR tszDescr[256]; + TCHAR tszOldName[MAX_PATH], tszNewName[MAX_PATH]; FILEURL File; BOOL enabled; BYTE FileType; @@ -79,8 +77,8 @@ typedef OBJLIST FILELIST; struct PopupDataText { - TCHAR* Title; - TCHAR* Text; + TCHAR *Title; + TCHAR *Text; }; struct PlugOptions @@ -114,7 +112,7 @@ using namespace std; extern HINSTANCE hInst; extern TCHAR tszRoot[MAX_PATH], tszDialogMsg[2048]; -extern FILEINFO* pFileInfo; +extern FILEINFO *pFileInfo; extern HANDLE CheckThread, hPluginUpdaterFolder; extern PlugOptions opts; extern POPUP_OPTIONS PopupOptions; @@ -146,31 +144,31 @@ INT_PTR EmptyFolder(WPARAM wParam,LPARAM lParam); INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DlgMsgPop(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -bool unzip(const TCHAR* ptszZipFile, TCHAR* ptszDestPath, TCHAR* ptszBackPath); +bool unzip(const TCHAR *ptszOldFileName, const TCHAR *ptszZipFile, TCHAR *ptszDestPath, TCHAR *ptszBackPath); #if MIRANDA_VER < 0x0A00 template class mir_ptr { - T* data; + T *data; public: __inline mir_ptr() : data((T*)mir_calloc(sizeof(T))) {} - __inline mir_ptr(T* _p) : data(_p) {} + __inline mir_ptr(T *_p) : data(_p) {} __inline ~mir_ptr() { mir_free(data); } - __inline T* operator = (T* _p) { if (data) mir_free(data); data = _p; return data; } - __inline T* operator->() const { return data; } + __inline T *operator = (T *_p) { if (data) mir_free(data); data = _p; return data; } + __inline T *operator->() const { return data; } __inline operator T*() const { return data; } __inline operator INT_PTR() const { return (INT_PTR)data; } }; class _A2T { - TCHAR* buf; + TCHAR *buf; public: - __forceinline _A2T(const char* s) : buf(mir_a2t(s)) {} - __forceinline _A2T(const char* s, int cp) : buf(mir_a2t_cp(s, cp)) {} + __forceinline _A2T(const char *s) : buf(mir_a2t(s)) {} + __forceinline _A2T(const char *s, int cp) : buf(mir_a2t_cp(s, cp)) {} ~_A2T() { mir_free(buf); } __forceinline operator TCHAR*() const @@ -180,11 +178,11 @@ public: class _T2A { - char* buf; + char *buf; public: - __forceinline _T2A(const TCHAR* s) : buf(mir_t2a(s)) {} - __forceinline _T2A(const TCHAR* s, int cp) : buf(mir_t2a_cp(s, cp)) {} + __forceinline _T2A(const TCHAR *s) : buf(mir_t2a(s)) {} + __forceinline _T2A(const TCHAR *s, int cp) : buf(mir_t2a_cp(s, cp)) {} __forceinline ~_T2A() { mir_free(buf); } __forceinline operator char*() const @@ -197,21 +195,21 @@ __forceinline INT_PTR Options_Open(OPENOPTIONSDIALOG *ood) return CallService("Opt/OpenOptions", 0, (LPARAM)ood); } -__forceinline INT_PTR Options_AddPage(WPARAM wParam, OPTIONSDIALOGPAGE* odp) +__forceinline INT_PTR Options_AddPage(WPARAM wParam, OPTIONSDIALOGPAGE *odp) { return CallService("Opt/AddPage", wParam, (LPARAM)odp); } -char* rtrim(char* str); -void CreatePathToFileT(TCHAR* szFilePath); +char *rtrim(char *str); +void CreatePathToFileT(TCHAR *szFilePath); -#define NEWTSTR_ALLOCA(A) (A == NULL)?NULL:_tcscpy((TCHAR*)alloca((_tcslen(A)+1)* sizeof(TCHAR)), A) +#define NEWTSTR_ALLOCA(A) (A == NULL)?NULL:_tcscpy((TCHAR*)alloca((_tcslen(A)+1) *sizeof(TCHAR)), A) -__forceinline HANDLE Skin_GetIconHandle(const char* szIconName) +__forceinline HANDLE Skin_GetIconHandle(const char *szIconName) { return (HANDLE)CallService(MS_SKIN2_GETICONHANDLE, 0, (LPARAM)szIconName); } -__forceinline HICON Skin_GetIcon(const char* szIconName, int size=0) +__forceinline HICON Skin_GetIcon(const char *szIconName, int size=0) { return (HICON)CallService(MS_SKIN2_GETICON, size, (LPARAM)szIconName); } @@ -223,11 +221,11 @@ __forceinline INT_PTR Hotkey_Register(HOTKEYDESC *hk) { return CallService("CoreHotkeys/Register", 0, (LPARAM)hk); } -__forceinline INT_PTR CreateDirectoryTreeT(const TCHAR* ptszPath) +__forceinline INT_PTR CreateDirectoryTreeT(const TCHAR *ptszPath) { return CallService(MS_UTILS_CREATEDIRTREET, 0, (LPARAM)ptszPath); } -__forceinline HANDLE Skin_AddIcon(SKINICONDESC* si) +__forceinline HANDLE Skin_AddIcon(SKINICONDESC *si) { return (HANDLE)CallService("Skin2/Icons/AddIcon", 0, (LPARAM)si); } diff --git a/plugins/PluginUpdater/src/Notifications.cpp b/plugins/PluginUpdater/src/Notifications.cpp index 2a3c93a54a..4a07b446fb 100644 --- a/plugins/PluginUpdater/src/Notifications.cpp +++ b/plugins/PluginUpdater/src/Notifications.cpp @@ -30,7 +30,7 @@ void PopupAction(HWND hWnd, BYTE action) break; case PCA_DONOTHING: return; - }//end* switch + } PUDeletePopUp(hWnd); } @@ -220,12 +220,12 @@ void SelectAll(HWND hDlg, bool bEnable) } } -static void SetStringText(HWND hWnd, size_t i, TCHAR* ptszText) +static void SetStringText(HWND hWnd, size_t i, TCHAR *ptszText) { ListView_SetItemText(hWnd, i, 1, ptszText); } -static void ApplyUpdates(void* param) +static void ApplyUpdates(void *param) { HWND hDlg = (HWND)param; HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES); @@ -272,14 +272,21 @@ static void ApplyUpdates(void* param) return; } - TCHAR* tszMirandaPath = Utils_ReplaceVarsT(_T("%miranda_path%")); + TCHAR *tszMirandaPath = Utils_ReplaceVarsT(_T("%miranda_path%")); for (int i = 0; i < todo.getCount(); i++) { if ( !todo[i].enabled) continue; FILEINFO& p = todo[i]; - if ( unzip(p.File.tszDiskPath, tszMirandaPath, tszFileBack)) + if (p.tszNewName[0] == 0) { // delete only + TCHAR *ptszRelPath = p.tszOldName + _tcslen(tszMirandaPath) + 1; + TCHAR tszBackFile[MAX_PATH]; + mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, ptszRelPath); + DeleteFile(tszBackFile); + MoveFile(p.tszOldName, tszBackFile); + } + else if ( unzip(p.tszOldName, p.File.tszDiskPath, tszMirandaPath, tszFileBack)) DeleteFile(p.File.tszDiskPath); } @@ -341,7 +348,7 @@ INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam lvI.mask = LVIF_TEXT | LVIF_PARAM;// | LVIF_IMAGE; lvI.iSubItem = 0; lvI.lParam = (LPARAM)&todo[i]; - lvI.pszText = todo[i].tszDescr; + lvI.pszText = todo[i].tszOldName; lvI.iItem = i; ListView_InsertItem(hwndList, &lvI); diff --git a/plugins/PluginUpdater/src/Options.cpp b/plugins/PluginUpdater/src/Options.cpp index 478a8a73fa..d710de7124 100644 --- a/plugins/PluginUpdater/src/Options.cpp +++ b/plugins/PluginUpdater/src/Options.cpp @@ -130,7 +130,7 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA } break; } - }//end* switch (msg) + } return FALSE; } @@ -310,8 +310,8 @@ INT_PTR CALLBACK DlgPopUpOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) if ((HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == EN_CHANGE) && (HWND)lParam == GetFocus()) SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); break; - }//end* switch(idCtrl) - }//end* case WM_COMMAND: + } + } break; case WM_NOTIFY: diff --git a/plugins/PluginUpdater/src/PluginUpdater.cpp b/plugins/PluginUpdater/src/PluginUpdater.cpp index 8e2ffd6935..1d98bf2fff 100644 --- a/plugins/PluginUpdater/src/PluginUpdater.cpp +++ b/plugins/PluginUpdater/src/PluginUpdater.cpp @@ -1,4 +1,4 @@ -/* +/* Copyright (C) 2010 Mataes This is free software; you can redistribute it and/or @@ -22,7 +22,7 @@ Boston, MA 02111-1307, USA. #if MIRANDA_VER < 0x0A00 #define MIID_UPDATER {0x4a47b19b, 0xde5a, 0x4436, { 0xab, 0x4b, 0xe1, 0xf3, 0xa0, 0x22, 0x5d, 0xe7}} - PLUGINLINK* pluginLink; + PLUGINLINK *pluginLink; MM_INTERFACE mmi; LIST_INTERFACE li; MD5_INTERFACE md5i; @@ -73,7 +73,7 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD miranda #if MIRANDA_VER < 0x0A00 -extern "C" __declspec(dllexport) int Load(PLUGINLINK* link) +extern "C" __declspec(dllexport) int Load(PLUGINLINK *link) { pluginLink = link; mir_getMMI(&mmi); diff --git a/plugins/PluginUpdater/src/Scanner.cpp b/plugins/PluginUpdater/src/Scanner.cpp index f1696738fd..6f0a266296 100644 --- a/plugins/PluginUpdater/src/Scanner.cpp +++ b/plugins/PluginUpdater/src/Scanner.cpp @@ -19,7 +19,7 @@ Boston, MA 02111-1307, USA. #include "Common.h" -int CalculateModuleHash(const TCHAR* tszFileName, char* dest); +int CalculateModuleHash(const TCHAR *tszFileName, char *dest); static BYTE IsPluginDisabled(const char *filename) { @@ -43,14 +43,42 @@ struct ServListEntry char m_szHash[32+1]; }; -static int CompareHashes(const ServListEntry* p1, const ServListEntry* p2) +static int CompareHashes(const ServListEntry *p1, const ServListEntry *p2) { return _tcscmp(p1->m_searchName, p2->m_searchName); } +///////////////////////////////////////////////////////////////////////////////////////// + +struct +{ + TCHAR *oldName, *newName; +} +static renameTable[] = +{ + { _T("svc_dbepp.dll"), _T("dbeditorpp.dll") }, + { _T("svc_crsh.dll"), _T("crashdumper.dll") }, + { _T("svc_vi.dll"), _T("versioninfo.dll") }, + + { _T("clist_classic.dll"), _T("") }, + { _T("chat.dll"), _T("") }, + { _T("srmm.dll"), _T("") }, +}; + +static bool CheckFileRename(const TCHAR *ptszOldName, TCHAR *pNewName) +{ + for (int i=0; i < SIZEOF(renameTable); i++) + if ( !_tcsicmp(ptszOldName, renameTable[i].oldName)) { + _tcscpy(pNewName, renameTable[i].newName); + return true; + } + + return false; +} + typedef OBJLIST SERVLIST; -static void ScanFolder(const TCHAR* tszFolder, const TCHAR* tszBaseUrl, SERVLIST& hashes, OBJLIST* UpdateFiles) +static void ScanFolder(const TCHAR *tszFolder, const TCHAR *tszBaseUrl, SERVLIST& hashes, OBJLIST *UpdateFiles) { // skip updater's own folder if ( !_tcsicmp(tszFolder, tszRoot)) @@ -80,39 +108,65 @@ static void ScanFolder(const TCHAR* tszFolder, const TCHAR* tszBaseUrl, SERVLIST if (pExt == NULL) continue; if ( _tcsicmp(pExt, _T(".dll")) && _tcsicmp(pExt, _T(".exe"))) continue; - - // Read version info - TCHAR key[MAX_PATH]; - _tcscpy(key, ffd.cFileName); - _tcslwr(key); - ServListEntry tmp = {NULL, key}; - ServListEntry* item = hashes.find(&tmp); - if (item == NULL) - continue; - size_t cbLenOrig = _tcslen(item->m_name); - size_t cbLen = (size_t)mir_sntprintf(tszMask, SIZEOF(tszMask), _T("%s\\%s"), tszFolder, ffd.cFileName); - if (cbLenOrig > cbLen) // wtf? - continue; - for (TCHAR *p = _tcschr(tszMask, '\\'); p != NULL; p = _tcschr(p+1, '\\')) - *p = '/'; - if ( _tcsicmp(tszMask + cbLen - cbLenOrig, item->m_name)) // now verify the rest - continue; + TCHAR tszNewName[MAX_PATH]; + if ( !CheckFileRename(ffd.cFileName, tszNewName)) + _tcscpy(tszNewName, ffd.cFileName); + + char szMyHash[33], *szSiteHash; + TCHAR *ptszUrl; + if (tszNewName[0]) { // this file is not marked for deletion + // Read version info + TCHAR key[MAX_PATH]; + _tcscpy(key, tszNewName); + _tcslwr(key); + ServListEntry tmp = {NULL, key}; + ServListEntry *item = hashes.find(&tmp); + if (item == NULL) { + size_t cbKeyLen = _tcslen(key)-1; + if (key[cbKeyLen] != 'w') + continue; + + key[cbKeyLen] = 0; + if ((item = hashes.find(&tmp)) == NULL) + continue; + + ffd.cFileName[cbKeyLen] = 0; + } + + size_t cbLenOrig = _tcslen(item->m_name); + size_t cbLen = (size_t)mir_sntprintf(tszMask, SIZEOF(tszMask), _T("%s\\%s"), tszFolder, tszNewName); + if (cbLenOrig > cbLen) // wtf? + continue; + for (TCHAR *p = _tcschr(tszMask, '\\'); p != NULL; p = _tcschr(p+1, '\\')) + *p = '/'; + if ( _tcsicmp(tszMask + cbLen - cbLenOrig, item->m_name)) // now verify the rest + continue; + + szSiteHash = item->m_szHash; + ptszUrl = item->m_name; + } + else { + szSiteHash = "boo"; // never matches + ptszUrl = _T(""); + } - char szMyHash[33]; + mir_sntprintf(tszMask, SIZEOF(tszMask), _T("%s\\%s"), tszFolder, ffd.cFileName); CalculateModuleHash(tszMask, szMyHash); // Compare versions - if ( strcmp(szMyHash, item->m_szHash)) { // Yeah, we've got new version. - FILEINFO* FileInfo = new FILEINFO; - strncpy(FileInfo->newhash, item->m_szHash, SIZEOF(FileInfo->newhash)); - strncpy(FileInfo->curhash, szMyHash, SIZEOF(FileInfo->newhash)); - _tcscpy(FileInfo->tszDescr, ffd.cFileName); + if ( strcmp(szMyHash, szSiteHash)) { // Yeah, we've got new version. + FILEINFO *FileInfo = new FILEINFO; + _tcscpy(FileInfo->tszNewName, tszNewName); + if (tszNewName[0]) + _tcscpy(FileInfo->tszOldName, ffd.cFileName); + else + _tcscpy(FileInfo->tszOldName, tszMask); // *pExt = 0; - mir_sntprintf(FileInfo->File.tszDiskPath, SIZEOF(FileInfo->File.tszDiskPath), _T("%s\\Temp\\%s.zip"), tszRoot, ffd.cFileName); + mir_sntprintf(FileInfo->File.tszDiskPath, SIZEOF(FileInfo->File.tszDiskPath), _T("%s\\Temp\\%s.zip"), tszRoot, tszNewName); - mir_sntprintf(FileInfo->File.tszDownloadURL, SIZEOF(FileInfo->File.tszDownloadURL), _T("%s/%s"), tszBaseUrl, item->m_name); + mir_sntprintf(FileInfo->File.tszDownloadURL, SIZEOF(FileInfo->File.tszDownloadURL), _T("%s/%s"), tszBaseUrl, ptszUrl); if ((pExt = _tcsrchr(FileInfo->File.tszDownloadURL, '.')) != NULL) _tcscpy(pExt, _T(".zip")); @@ -124,7 +178,7 @@ static void ScanFolder(const TCHAR* tszFolder, const TCHAR* tszBaseUrl, SERVLIST FindClose(hFind); } -static void __stdcall LaunchDialog(void* param) +static void __stdcall LaunchDialog(void *param) { CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_UPDATE), GetDesktopWindow(), DlgUpdate, (LPARAM)param); } @@ -150,7 +204,7 @@ static void CheckUpdates(void *) } #endif } - TCHAR* tszBaseUrl = NEWTSTR_ALLOCA(dbVar.ptszVal); + TCHAR *tszBaseUrl = NEWTSTR_ALLOCA(dbVar.ptszVal); DBFreeVariant(&dbVar); // Download version info @@ -165,12 +219,12 @@ static void CheckUpdates(void *) return; } - unzip(pFileUrl.tszDiskPath, tszRoot, tszRoot); + unzip(_T("hashes.txt"), pFileUrl.tszDiskPath, tszRoot, tszRoot); DeleteFile(pFileUrl.tszDiskPath); TCHAR tszTmpIni[MAX_PATH] = {0}; mir_sntprintf(tszTmpIni, SIZEOF(tszTmpIni), _T("%s\\hashes.txt"), tszRoot); - FILE* fp = _tfopen(tszTmpIni, _T("r")); + FILE *fp = _tfopen(tszTmpIni, _T("r")); if (!fp) return; @@ -178,7 +232,7 @@ static void CheckUpdates(void *) char str[200]; while(fgets(str, SIZEOF(str), fp) != NULL) { rtrim(str); - char* p = strchr(str, ' '); + char *p = strchr(str, ' '); if (p == NULL) continue; @@ -186,7 +240,7 @@ static void CheckUpdates(void *) if ( !opts.bUpdateIcons && !_strnicmp(str, "icons\\", 6)) continue; - ServListEntry* newItem = new ServListEntry; + ServListEntry *newItem = new ServListEntry; _strlwr(p); strncpy(newItem->m_szHash, p, sizeof(newItem->m_szHash)); @@ -195,7 +249,7 @@ static void CheckUpdates(void *) newItem->m_name = mir_a2t(str); - TCHAR* szName = _tcsrchr(newItem->m_name, '/'); + TCHAR *szName = _tcsrchr(newItem->m_name, '/'); newItem->m_searchName = (szName == NULL) ? newItem->m_name : szName+1; _tcslwr(newItem->m_searchName); hashes.insert(newItem); diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp index 737df21960..91716a45c6 100644 --- a/plugins/PluginUpdater/src/Utils.cpp +++ b/plugins/PluginUpdater/src/Utils.cpp @@ -22,16 +22,16 @@ Boston, MA 02111-1307, USA. BOOL DlgDld; int Number = 0; TCHAR tszDialogMsg[2048] = {0}; -FILEINFO* pFileInfo = NULL; +FILEINFO *pFileInfo = NULL; HANDLE CheckThread = NULL, hNetlibUser = NULL; POPUP_OPTIONS PopupOptions = {0}; aPopups PopupsList[POPUPS]; struct { - char* szIconName; - char* szDescr; - int IconID; + char *szIconName; + char *szDescr; + int IconID; } static iconList[] = { @@ -133,7 +133,7 @@ BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal) #endif nlhr.requestType = REQUEST_GET; nlhr.flags = NLHRF_DUMPASTEXT | NLHRF_HTTP11; - char* szUrl = mir_t2a(tszURL); + char *szUrl = mir_t2a(tszURL); nlhr.szUrl = szUrl; nlhr.headersCount = 4; nlhr.headers=(NETLIBHTTPHEADER*)mir_alloc(sizeof(NETLIBHTTPHEADER)*nlhr.headersCount); @@ -147,7 +147,7 @@ BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal) nlhr.headers[3].szValue = "no-cache"; bool ret = false; - NETLIBHTTPREQUEST* pReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser,(LPARAM)&nlhr); + NETLIBHTTPREQUEST *pReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser,(LPARAM)&nlhr); if (pReply) { if ((200 == pReply->resultCode) && (pReply->dataLength > 0)) { hFile = CreateFile(tszLocal, GENERIC_READ | GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); @@ -227,12 +227,12 @@ void InitTimer() } #if MIRANDA_VER < 0x0A00 -char* rtrim(char* str) +char* rtrim(char *str) { if (str == NULL) return NULL; - char* p = strchr(str, 0); + char *p = strchr(str, 0); while (--p >= str) { switch (*p) { case ' ': case '\t': case '\n': case '\r': @@ -244,9 +244,9 @@ char* rtrim(char* str) return str; } -void CreatePathToFileT(TCHAR* szFilePath) +void CreatePathToFileT(TCHAR *szFilePath) { - TCHAR* pszLastBackslash = _tcsrchr(szFilePath, '\\'); + TCHAR *pszLastBackslash = _tcsrchr(szFilePath, '\\'); if (pszLastBackslash == NULL) return; diff --git a/plugins/PluginUpdater/src/checksum.cpp b/plugins/PluginUpdater/src/checksum.cpp index 657b8f6c93..5ac7160142 100644 --- a/plugins/PluginUpdater/src/checksum.cpp +++ b/plugins/PluginUpdater/src/checksum.cpp @@ -19,9 +19,9 @@ int debug = 0; -static void PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY pIRD, BYTE* pBase); +static void PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY pIRD, BYTE *pBase); -static void PatchResourceEntry(PIMAGE_RESOURCE_DIRECTORY_ENTRY pIRDE, BYTE* pBase) +static void PatchResourceEntry(PIMAGE_RESOURCE_DIRECTORY_ENTRY pIRDE, BYTE *pBase) { if ( pIRDE->DataIsDirectory ) PatchResourcesDirectory( PIMAGE_RESOURCE_DIRECTORY(pBase + pIRDE->OffsetToDirectory), pBase); @@ -40,7 +40,7 @@ static void PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY pIRD, PBYTE pBase) PatchResourceEntry(pIRDE, pBase); } -int CalculateModuleHash(const TCHAR *filename, char* szDest) +int CalculateModuleHash(const TCHAR *filename, char *szDest) { HANDLE hFile = INVALID_HANDLE_VALUE; HANDLE hMap; @@ -220,7 +220,7 @@ int CalculateModuleHash(const TCHAR *filename, char* szDest) if ( resSize > 0 && resAddr >= pISH->VirtualAddress && resAddr + resSize <= pISH->VirtualAddress + pISH->SizeOfRawData ) { DWORD shift = resAddr - pISH->VirtualAddress + pISH->PointerToRawData; - IMAGE_RESOURCE_DIRECTORY* pIRD = (IMAGE_RESOURCE_DIRECTORY*)( ptr + shift ); + IMAGE_RESOURCE_DIRECTORY *pIRD = (IMAGE_RESOURCE_DIRECTORY*)( ptr + shift ); PatchResourcesDirectory(pIRD, ptr + shift); } diff --git a/plugins/PluginUpdater/src/unzipfile.cpp b/plugins/PluginUpdater/src/unzipfile.cpp index 6d3057d12d..ed4e045e70 100644 --- a/plugins/PluginUpdater/src/unzipfile.cpp +++ b/plugins/PluginUpdater/src/unzipfile.cpp @@ -1,4 +1,4 @@ -/* +/* Copyright (C) 2012 George Hazan This is free software; you can redistribute it and/or @@ -23,10 +23,19 @@ extern "C" { #include "Minizip\unzip.h" - void fill_fopen64_filefunc(zlib_filefunc64_def* pzlib_filefunc_def); + void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def); } -bool extractCurrentFile(unzFile uf, TCHAR* ptszDestPath, TCHAR* ptszBackPath) +static void PrepareFileName(TCHAR *dest, size_t destSize, const TCHAR *ptszPath, const TCHAR *ptszFileName) +{ + mir_sntprintf(dest, destSize, _T("%s\\%s"), ptszPath, ptszFileName); + for (TCHAR *p = dest; *p; ++p) + if (*p == '/') + *p = '\\'; + CreatePathToFileT(dest); +} + +bool extractCurrentFile(unzFile uf, const TCHAR *ptszOldFileName, TCHAR *ptszDestPath, TCHAR *ptszBackPath) { int err = UNZ_OK; unz_file_info64 file_info; @@ -41,27 +50,30 @@ bool extractCurrentFile(unzFile uf, TCHAR* ptszDestPath, TCHAR* ptszBackPath) return true; TCHAR tszDestFile[MAX_PATH], tszBackFile[MAX_PATH]; - TCHAR* p = mir_utf8decodeT(filename); - if (p == NULL) - p = mir_a2t(filename); - mir_sntprintf(tszDestFile, SIZEOF(tszDestFile), _T("%s\\%s"), ptszDestPath, p); - mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), ptszBackPath, p); - mir_free(p); - - for (p = tszDestFile; *p; ++p) if (*p == '/') *p = '\\'; - for (p = tszBackFile; *p; ++p) if (*p == '/') *p = '\\'; - - CreatePathToFileT(tszDestFile); - CreatePathToFileT(tszBackFile); + TCHAR *ptszNewName = mir_utf8decodeT(filename); + if (ptszNewName == NULL) + ptszNewName = mir_a2t(filename); if ( !(file_info.external_fa & FILE_ATTRIBUTE_DIRECTORY)) { err = unzOpenCurrentFile(uf); if (err != UNZ_OK) return false; + TCHAR tszOldName[MAX_PATH], *p = _tcschr(ptszNewName, '/'); + if (p != NULL) { + *p = 0; + mir_sntprintf(tszOldName, SIZEOF(tszOldName), _T("%s\\%s"), ptszNewName, ptszOldFileName); + *p = '\\'; + } + else _tcscpy(tszOldName, ptszOldFileName); + + PrepareFileName(tszDestFile, SIZEOF(tszDestFile), ptszDestPath, tszOldName); + PrepareFileName(tszBackFile, SIZEOF(tszBackFile), ptszBackPath, tszOldName); + DeleteFile(tszBackFile); MoveFile(tszDestFile, tszBackFile); + PrepareFileName(tszDestFile, SIZEOF(tszDestFile), ptszDestPath, ptszNewName); HANDLE hFile = CreateFile(tszDestFile, GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_ALWAYS, file_info.external_fa, 0); @@ -88,10 +100,11 @@ bool extractCurrentFile(unzFile uf, TCHAR* ptszDestPath, TCHAR* ptszBackPath) unzCloseCurrentFile(uf); /* don't lose the error */ } } + mir_free(ptszNewName); return true; } -bool unzip(const TCHAR* ptszZipFile, TCHAR* ptszDestPath, TCHAR* ptszBackPath) +bool unzip(const TCHAR *ptszOldFileName, const TCHAR *ptszZipFile, TCHAR *ptszDestPath, TCHAR *ptszBackPath) { bool bResult = true; @@ -101,7 +114,7 @@ bool unzip(const TCHAR* ptszZipFile, TCHAR* ptszDestPath, TCHAR* ptszBackPath) unzFile uf = unzOpen2_64(ptszZipFile, &ffunc); if (uf) { do { - if ( !extractCurrentFile(uf, ptszDestPath, ptszBackPath)) + if ( !extractCurrentFile(uf, ptszOldFileName, ptszDestPath, ptszBackPath)) bResult = false; } while (unzGoToNextFile(uf) == UNZ_OK); -- cgit v1.2.3