summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-10-10 16:11:36 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-10-10 16:11:36 +0000
commit12be1d94b988efbaee17bc1cdf1667c870d1a53b (patch)
treea9392e334a3d88b4159efbc9eb3e66f859506ab7
parentfbe102bea6ca57970d1de4a2c6cc349d3f6ff71d (diff)
intermediate variant of Updater without problems with core
git-svn-id: http://svn.miranda-ng.org/main/trunk@1865 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--plugins/PluginUpdater/src/Common.h5
-rw-r--r--plugins/PluginUpdater/src/Notifications.cpp22
-rw-r--r--plugins/PluginUpdater/src/Scanner.cpp25
-rw-r--r--plugins/PluginUpdater/src/unzipfile.cpp43
4 files changed, 52 insertions, 43 deletions
diff --git a/plugins/PluginUpdater/src/Common.h b/plugins/PluginUpdater/src/Common.h
index eeffd250db..1e05b9b336 100644
--- a/plugins/PluginUpdater/src/Common.h
+++ b/plugins/PluginUpdater/src/Common.h
@@ -128,6 +128,9 @@ int OnFoldersChanged(WPARAM, LPARAM);
int OnPreShutdown(WPARAM, LPARAM);
int OptInit(WPARAM, LPARAM);
+void PrepareFileName(TCHAR *dest, size_t destSize, const TCHAR *ptszPath, const TCHAR *ptszFileName);
+void BackupFile(TCHAR *ptszSrcFileName, TCHAR *ptszBackFileName);
+
void DoCheck(int iFlag);
BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal);
void ShowPopup(HWND hDlg, LPCTSTR Title, LPCTSTR Text, int Number, int ActType);
@@ -141,7 +144,7 @@ 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 *ptszOldFileName, const TCHAR *ptszZipFile, TCHAR *ptszDestPath, TCHAR *ptszBackPath);
+bool unzip(const TCHAR *ptszZipFile, TCHAR *ptszDestPath, TCHAR *ptszBackPath);
void strdel(TCHAR *parBuffer, int len);
#if MIRANDA_VER < 0x0A00
diff --git a/plugins/PluginUpdater/src/Notifications.cpp b/plugins/PluginUpdater/src/Notifications.cpp
index aad66b965e..7e30ad5e85 100644
--- a/plugins/PluginUpdater/src/Notifications.cpp
+++ b/plugins/PluginUpdater/src/Notifications.cpp
@@ -278,16 +278,26 @@ static void ApplyUpdates(void *param)
if ( !todo[i].enabled)
continue;
+ TCHAR tszBackFile[MAX_PATH];
FILEINFO& p = todo[i];
- if (p.bDeleteOnly) { // delete only
+ if (p.bDeleteOnly) { // we need only to backup the old file
TCHAR *ptszRelPath = p.tszNewName + _tcslen(tszMirandaPath) + 1;
- TCHAR tszBackFile[MAX_PATH];
mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, ptszRelPath);
- DeleteFile(tszBackFile);
- MoveFile(p.tszNewName, tszBackFile);
+ BackupFile(p.tszNewName, tszBackFile);
+ continue;
+ }
+
+ // if file name differs, we also need to backup the old file here
+ // otherwise it would be replaced by unzip
+ if ( _tcsicmp(p.tszOldName, p.tszNewName)) {
+ TCHAR tszSrcPath[MAX_PATH];
+ mir_sntprintf(tszSrcPath, SIZEOF(tszSrcPath), _T("%s\\%s"), tszMirandaPath, p.tszOldName);
+ mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, p.tszOldName);
+ BackupFile(tszSrcPath, tszBackFile);
}
- else if ( unzip(p.tszOldName, p.File.tszDiskPath, tszMirandaPath, tszFileBack))
- DeleteFile(p.File.tszDiskPath);
+
+ if ( unzip(p.File.tszDiskPath, tszMirandaPath, tszFileBack))
+ DeleteFile(p.File.tszDiskPath); // remove .zip after successful update
}
DBWriteContactSettingByte(NULL, MODNAME, "RestartCount", 2);
diff --git a/plugins/PluginUpdater/src/Scanner.cpp b/plugins/PluginUpdater/src/Scanner.cpp
index 43ac20dff2..3858316005 100644
--- a/plugins/PluginUpdater/src/Scanner.cpp
+++ b/plugins/PluginUpdater/src/Scanner.cpp
@@ -81,7 +81,7 @@ static bool CheckFileRename(const TCHAR *ptszOldName, TCHAR *pNewName)
typedef OBJLIST<ServListEntry> SERVLIST;
-static void ScanFolder(const TCHAR *tszFolder, const TCHAR *tszBaseUrl, SERVLIST& hashes, OBJLIST<FILEINFO> *UpdateFiles)
+static void ScanFolder(const TCHAR *tszFolder, size_t cbBaseLen, const TCHAR *tszBaseUrl, SERVLIST& hashes, OBJLIST<FILEINFO> *UpdateFiles)
{
// skip updater's own folder
if ( !_tcsicmp(tszFolder, tszRoot))
@@ -103,7 +103,7 @@ static void ScanFolder(const TCHAR *tszFolder, const TCHAR *tszBaseUrl, SERVLIST
continue;
mir_sntprintf(tszMask, SIZEOF(tszMask), _T("%s\\%s"), tszFolder, ffd.cFileName);
- ScanFolder(tszMask, tszBaseUrl, hashes, UpdateFiles);
+ ScanFolder(tszMask, cbBaseLen, tszBaseUrl, hashes, UpdateFiles);
continue;
}
@@ -138,13 +138,10 @@ static void ScanFolder(const TCHAR *tszFolder, const TCHAR *tszBaseUrl, SERVLIST
strdel(tszNewName+iPos, 1);
}
- 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
+ PrepareFileName(key, SIZEOF(key), NULL, item->m_name);
+
+ mir_sntprintf(tszMask, SIZEOF(tszMask), _T("%s\\%s"), tszFolder, tszNewName);
+ if ( _tcsicmp(tszMask + cbBaseLen, key)) // the relative name should match
continue;
szSiteHash = item->m_szHash;
@@ -161,14 +158,14 @@ static void ScanFolder(const TCHAR *tszFolder, const TCHAR *tszBaseUrl, SERVLIST
// Compare versions
if ( strcmp(szMyHash, szSiteHash)) { // Yeah, we've got new version.
FILEINFO *FileInfo = new FILEINFO;
- _tcscpy(FileInfo->tszOldName, ffd.cFileName);
+ _tcscpy(FileInfo->tszOldName, tszMask+cbBaseLen); // copy the relative old name
if (tszNewName[0] == 0) {
FileInfo->bDeleteOnly = TRUE;
- _tcscpy(FileInfo->tszNewName, tszMask);
+ _tcscpy(FileInfo->tszNewName, tszMask); // save the full old name for deletion
}
else {
FileInfo->bDeleteOnly = FALSE;
- _tcscpy(FileInfo->tszNewName, tszNewName);
+ PrepareFileName(FileInfo->tszNewName, SIZEOF(FileInfo->tszNewName), NULL, ptszUrl);
}
*pExt = 0;
@@ -232,7 +229,7 @@ static void CheckUpdates(void *)
return;
}
- unzip(_T("hashes.txt"), pFileUrl.tszDiskPath, tszRoot, tszRoot);
+ unzip(pFileUrl.tszDiskPath, tszRoot, tszRoot);
DeleteFile(pFileUrl.tszDiskPath);
TCHAR tszTmpIni[MAX_PATH] = {0};
@@ -272,7 +269,7 @@ static void CheckUpdates(void *)
FILELIST *UpdateFiles = new FILELIST(20);
TCHAR *dirname = Utils_ReplaceVarsT(_T("%miranda_path%"));
- ScanFolder(dirname, tszBaseUrl, hashes, UpdateFiles);
+ ScanFolder(dirname, lstrlen(dirname)+1, tszBaseUrl, hashes, UpdateFiles);
mir_free(dirname);
// Show dialog
diff --git a/plugins/PluginUpdater/src/unzipfile.cpp b/plugins/PluginUpdater/src/unzipfile.cpp
index 1dd403959c..c5f39e1451 100644
--- a/plugins/PluginUpdater/src/unzipfile.cpp
+++ b/plugins/PluginUpdater/src/unzipfile.cpp
@@ -26,16 +26,26 @@ extern "C"
void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def);
}
-static void PrepareFileName(TCHAR *dest, size_t destSize, const TCHAR *ptszPath, const TCHAR *ptszFileName)
+void PrepareFileName(TCHAR *dest, size_t destSize, const TCHAR *ptszPath, const TCHAR *ptszFileName)
{
- mir_sntprintf(dest, destSize, _T("%s\\%s"), ptszPath, ptszFileName);
+ if (ptszPath)
+ mir_sntprintf(dest, destSize, _T("%s\\%s"), ptszPath, ptszFileName);
+ else
+ mir_sntprintf(dest, destSize, _T("%s"), ptszFileName);
+
for (TCHAR *p = dest; *p; ++p)
if (*p == '/')
*p = '\\';
- CreatePathToFileT(dest);
}
-bool extractCurrentFile(unzFile uf, const TCHAR *ptszOldFileName, TCHAR *ptszDestPath, TCHAR *ptszBackPath)
+void BackupFile(TCHAR *ptszSrcFileName, TCHAR *ptszBackFileName)
+{
+ CreatePathToFileT(ptszBackFileName);
+ DeleteFile(ptszBackFileName);
+ MoveFile(ptszSrcFileName, ptszBackFileName);
+}
+
+bool extractCurrentFile(unzFile uf, TCHAR *ptszDestPath, TCHAR *ptszBackPath)
{
int err = UNZ_OK;
unz_file_info64 file_info;
@@ -59,24 +69,13 @@ bool extractCurrentFile(unzFile uf, const TCHAR *ptszOldFileName, TCHAR *ptszDes
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);
-
- if (0 != _tcsicmp(tszOldName, ptszNewName))
- _tcscpy(tszOldName, ptszNewName);
-
- PrepareFileName(tszDestFile, SIZEOF(tszDestFile), ptszDestPath, tszOldName);
- PrepareFileName(tszBackFile, SIZEOF(tszBackFile), ptszBackPath, tszOldName);
-
- DeleteFile(tszBackFile);
- MoveFile(tszDestFile, tszBackFile);
+ PrepareFileName(tszDestFile, SIZEOF(tszDestFile), ptszDestPath, ptszNewName);
+ PrepareFileName(tszBackFile, SIZEOF(tszBackFile), ptszBackPath, ptszNewName);
+ BackupFile(tszDestFile, tszBackFile);
PrepareFileName(tszDestFile, SIZEOF(tszDestFile), ptszDestPath, ptszNewName);
+ CreatePathToFileT(tszDestFile);
+
HANDLE hFile = CreateFile(tszDestFile, GENERIC_WRITE, FILE_SHARE_WRITE, 0,
CREATE_ALWAYS, file_info.external_fa, 0);
@@ -107,7 +106,7 @@ bool extractCurrentFile(unzFile uf, const TCHAR *ptszOldFileName, TCHAR *ptszDes
return true;
}
-bool unzip(const TCHAR *ptszOldFileName, const TCHAR *ptszZipFile, TCHAR *ptszDestPath, TCHAR *ptszBackPath)
+bool unzip(const TCHAR *ptszZipFile, TCHAR *ptszDestPath, TCHAR *ptszBackPath)
{
bool bResult = true;
@@ -117,7 +116,7 @@ bool unzip(const TCHAR *ptszOldFileName, const TCHAR *ptszZipFile, TCHAR *ptszDe
unzFile uf = unzOpen2_64(ptszZipFile, &ffunc);
if (uf) {
do {
- if ( !extractCurrentFile(uf, ptszOldFileName, ptszDestPath, ptszBackPath))
+ if ( !extractCurrentFile(uf, ptszDestPath, ptszBackPath))
bResult = false;
}
while (unzGoToNextFile(uf) == UNZ_OK);