summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-01-21 15:18:22 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-01-21 15:18:22 +0000
commit1b6462b532772d0d0537a760f34f82daceccb55d (patch)
treee412606ac75116000c7703c1e6d0889f4e7a8542
parentbc97d8192aa854aa675ae9cb68c79fca2c7893bc (diff)
PluginUpdater:
- fix for displaying MessageBox over modeless dialog; - auto-handle for a pipe; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@7815 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--plugins/PluginUpdater/src/Common.h14
-rw-r--r--plugins/PluginUpdater/src/DlgListNew.cpp21
-rw-r--r--plugins/PluginUpdater/src/DlgUpdate.cpp47
-rw-r--r--plugins/PluginUpdater/src/Notifications.cpp2
-rw-r--r--plugins/PluginUpdater/src/Options.cpp6
-rw-r--r--plugins/PluginUpdater/src/checksum.cpp2
-rw-r--r--plugins/PluginUpdater/src/unzipfile.cpp4
7 files changed, 59 insertions, 37 deletions
diff --git a/plugins/PluginUpdater/src/Common.h b/plugins/PluginUpdater/src/Common.h
index 0b07b9098f..7d3bdc7167 100644
--- a/plugins/PluginUpdater/src/Common.h
+++ b/plugins/PluginUpdater/src/Common.h
@@ -132,6 +132,20 @@ extern HWND hwndDialog;
void DoCheck(int iFlag);
void DoGetList(int iFlag);
+struct AutoHandle
+{
+ HANDLE &m_handle;
+
+ AutoHandle(HANDLE &_handle) : m_handle(_handle) {}
+ ~AutoHandle()
+ {
+ if (m_handle) {
+ ::CloseHandle(m_handle);
+ m_handle = 0;
+ }
+ }
+};
+
///////////////////////////////////////////////////////////////////////////////
struct ServListEntry
diff --git a/plugins/PluginUpdater/src/DlgListNew.cpp b/plugins/PluginUpdater/src/DlgListNew.cpp
index 67f6afe957..e9bca0acdb 100644
--- a/plugins/PluginUpdater/src/DlgListNew.cpp
+++ b/plugins/PluginUpdater/src/DlgListNew.cpp
@@ -37,14 +37,15 @@ static void ApplyDownloads(void *param)
//////////////////////////////////////////////////////////////////////////////////////
// if we need to escalate priviledges, launch a atub
- if ( !PrepareEscalation()) {
- EndDialog(hDlg, 0);
+ if (!PrepareEscalation()) {
+ DestroyWindow(hDlg);
return;
}
//////////////////////////////////////////////////////////////////////////////////////
// ok, let's unpack all zips
+ AutoHandle pipe(hPipe);
HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES);
OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
TCHAR tszBuff[2048], tszFileTemp[MAX_PATH], tszFileBack[MAX_PATH];
@@ -58,7 +59,7 @@ static void ApplyDownloads(void *param)
HANDLE nlc = NULL;
for (int i=0; i < todo.getCount(); ++i) {
ListView_EnsureVisible(hwndList, i, FALSE);
- if ( !todo[i].bEnabled) {
+ if (!todo[i].bEnabled) {
ListView_SetItemText(hwndList, i, 2, TranslateT("Skipped."));
continue;
}
@@ -67,7 +68,7 @@ static void ApplyDownloads(void *param)
ListView_SetItemText(hwndList, i, 2, TranslateT("Downloading..."));
FILEURL *pFileUrl = &todo[i].File;
- if ( !DownloadFile(pFileUrl->tszDownloadURL, pFileUrl->tszDiskPath, pFileUrl->CRCsum, nlc)) {
+ if (!DownloadFile(pFileUrl->tszDownloadURL, pFileUrl->tszDiskPath, pFileUrl->CRCsum, nlc)) {
ListView_SetItemText(hwndList, i, 2, TranslateT("Failed!"));
}
else
@@ -81,7 +82,7 @@ static void ApplyDownloads(void *param)
TCHAR *tszMirandaPath = Utils_ReplaceVarsT(_T("%miranda_path%"));
for (int i = 0; i < todo.getCount(); i++) {
- if ( !todo[i].bEnabled)
+ if (!todo[i].bEnabled)
continue;
TCHAR tszBackFile[MAX_PATH];
@@ -115,10 +116,8 @@ static void ApplyDownloads(void *param)
if (rc == IDYES)
CallFunctionAsync(OpenPluginOptions, 0);
- if (hPipe)
- CloseHandle(hPipe);
CloseWindow(hDlg);
- EndDialog(hDlg, 0);
+ DestroyWindow(hDlg);
hwndDialog = NULL;
return;
}
@@ -337,7 +336,7 @@ INT_PTR CALLBACK DlgList(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
break;
case WM_SIZE: // make the dlg resizeable
- if ( !IsIconic(hDlg)) {
+ if (!IsIconic(hDlg)) {
UTILRESIZEDIALOG urd = { sizeof(urd) };
urd.hInstance = hInst;
urd.hwndDlg = hDlg;
@@ -390,7 +389,7 @@ static void GetList(void *)
ptrT updateUrl( GetDefaultUrl()), baseUrl;
SERVLIST hashes(50, CompareHashes);
- if ( !ParseHashes(updateUrl, baseUrl, hashes)) {
+ if (!ParseHashes(updateUrl, baseUrl, hashes)) {
hListThread = NULL;
return;
}
@@ -434,7 +433,7 @@ static void GetList(void *)
// Show dialog
if (UpdateFiles->getCount() == 0) {
- if ( !opts.bSilent)
+ if (!opts.bSilent)
ShowPopup(0, LPGENT("Plugin Updater"), LPGENT("List is empty."), 2, 0);
delete UpdateFiles;
}
diff --git a/plugins/PluginUpdater/src/DlgUpdate.cpp b/plugins/PluginUpdater/src/DlgUpdate.cpp
index 0646dc15df..220d3441d1 100644
--- a/plugins/PluginUpdater/src/DlgUpdate.cpp
+++ b/plugins/PluginUpdater/src/DlgUpdate.cpp
@@ -19,6 +19,8 @@ Boston, MA 02111-1307, USA.
#include "common.h"
+#define UM_ERROR (WM_USER+1)
+
static bool bShowDetails;
static void SelectAll(HWND hDlg, bool bEnable)
@@ -44,14 +46,15 @@ static void ApplyUpdates(void *param)
//////////////////////////////////////////////////////////////////////////////////////
// if we need to escalate priviledges, launch a atub
- if ( !PrepareEscalation()) {
- EndDialog(hDlg, 0);
+ if (!PrepareEscalation()) {
+ DestroyWindow(hDlg);
return;
}
//////////////////////////////////////////////////////////////////////////////////////
// ok, let's unpack all zips
+ AutoHandle pipe(hPipe);
HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES);
OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
TCHAR tszBuff[2048], tszFileTemp[MAX_PATH], tszFileBack[MAX_PATH];
@@ -63,10 +66,10 @@ static void ApplyUpdates(void *param)
SafeCreateDirectory(tszFileTemp);
bool error = false;
- HANDLE nlc = NULL;
- for (int i=0; i < todo.getCount(); ++i) {
+ HANDLE nlc = NULL;
+ for (int i=0; i < todo.getCount(); i++) {
ListView_EnsureVisible(hwndList, i, FALSE);
- if ( !todo[i].bEnabled) {
+ if (!todo[i].bEnabled) {
SetStringText(hwndList, i, TranslateT("Skipped."));
continue;
}
@@ -83,19 +86,22 @@ static void ApplyUpdates(void *param)
SetStringText(hwndList, i, TranslateT("Failed!"));
// interrupt update as we require all components to be updated
- MessageBox(hDlg, TranslateT("Update failed! One of the components wasn't downloaded correctly. Try it again later."), TranslateT("Plugin Updater"), MB_OK | MB_ICONERROR);
error = true;
break;
- } else
- SetStringText(hwndList, i, TranslateT("Succeeded."));
+ }
+ SetStringText(hwndList, i, TranslateT("Succeeded."));
}
Netlib_CloseHandle(nlc);
- if (!error && todo.getCount() > 0) {
+ if (error) {
+ PostMessage(hDlg, UM_ERROR, 0, 0);
+ return;
+ }
+ if (todo.getCount() > 0) {
TCHAR *tszMirandaPath = Utils_ReplaceVarsT(_T("%miranda_path%"));
for (int i = 0; i < todo.getCount(); i++) {
- if ( !todo[i].bEnabled)
+ if (!todo[i].bEnabled)
continue;
TCHAR tszBackFile[MAX_PATH];
@@ -140,9 +146,7 @@ static void ApplyUpdates(void *param)
if (rc == IDYES)
CallFunctionAsync(RestartMe, 0);
}
- if (hPipe)
- CloseHandle(hPipe);
- EndDialog(hDlg, 0);
+ DestroyWindow(hDlg);
}
static void ResizeVert(HWND hDlg, int yy)
@@ -307,6 +311,11 @@ static INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM
}
break;
+ case UM_ERROR:
+ MessageBox(hDlg, TranslateT("Update failed! One of the components wasn't downloaded correctly. Try it again later."), TranslateT("Plugin Updater"), MB_OK | MB_ICONERROR);
+ DestroyWindow(hDlg);
+ break;
+
case WM_DESTROY:
Skin_ReleaseIcon((HICON)SendMessage(hDlg, WM_SETICON, ICON_SMALL, 0));
Utils_SaveWindowPosition(hDlg, NULL, MODNAME, "ConfirmWindow");
@@ -396,7 +405,7 @@ static renameTable[] =
static bool CheckFileRename(const TCHAR *ptszOldName, TCHAR *pNewName)
{
for (int i=0; i < SIZEOF(renameTable); i++)
- if ( !_tcsicmp(ptszOldName, renameTable[i].oldName)) {
+ if (!_tcsicmp(ptszOldName, renameTable[i].oldName)) {
_tcscpy(pNewName, renameTable[i].newName);
return true;
}
@@ -418,7 +427,7 @@ static int ScanFolder(const TCHAR *tszFolder, size_t cbBaseLen, int level, const
int count = 0;
// skip updater's own folder
- if ( !_tcsicmp(tszFolder, tszRoot))
+ if (!_tcsicmp(tszFolder, tszRoot))
return count;
TCHAR tszBuf[MAX_PATH];
@@ -431,7 +440,7 @@ static int ScanFolder(const TCHAR *tszFolder, size_t cbBaseLen, int level, const
do {
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
- if ( !_tcscmp(ffd.cFileName, _T(".")) || !_tcscmp(ffd.cFileName, _T("..")))
+ if (!_tcscmp(ffd.cFileName, _T(".")) || !_tcscmp(ffd.cFileName, _T("..")))
continue;
// we need to skip profile folder
@@ -444,12 +453,12 @@ static int ScanFolder(const TCHAR *tszFolder, size_t cbBaseLen, int level, const
continue;
}
- if ( !isValidExtension(ffd.cFileName))
+ if (!isValidExtension(ffd.cFileName))
continue;
// calculate the current file's relative name and store it into tszNewName
TCHAR tszNewName[MAX_PATH];
- if ( !CheckFileRename(ffd.cFileName, tszNewName)) {
+ if (!CheckFileRename(ffd.cFileName, tszNewName)) {
if (level == 0)
_tcscpy(tszNewName, ffd.cFileName);
else
@@ -555,7 +564,7 @@ static void CheckUpdates(void *)
// Show dialog
if (count == 0) {
- if ( !opts.bSilent)
+ if (!opts.bSilent)
ShowPopup(0, LPGENT("Plugin Updater"), LPGENT("No updates found."), 2, 0);
delete UpdateFiles;
}
diff --git a/plugins/PluginUpdater/src/Notifications.cpp b/plugins/PluginUpdater/src/Notifications.cpp
index 15b28ab0c6..e76ce083bb 100644
--- a/plugins/PluginUpdater/src/Notifications.cpp
+++ b/plugins/PluginUpdater/src/Notifications.cpp
@@ -115,7 +115,7 @@ static void MakePopupAction(POPUPACTION &pa, int id)
void ShowPopup(HWND hDlg, LPCTSTR ptszTitle, LPCTSTR ptszText, int Number, int ActType)
{
- if ( !ServiceExists(MS_POPUP_ADDPOPUPT) || !db_get_b(NULL, "Popup", "ModuleIsEnabled", 1) ) {
+ if (!ServiceExists(MS_POPUP_ADDPOPUPT) || !db_get_b(NULL, "Popup", "ModuleIsEnabled", 1) ) {
char setting[100];
mir_snprintf(setting, SIZEOF(setting), "Popups%dM", Number);
if (db_get_b(NULL, MODNAME, setting, DEFAULT_MESSAGE_ENABLED)) {
diff --git a/plugins/PluginUpdater/src/Options.cpp b/plugins/PluginUpdater/src/Options.cpp
index 19bfa94821..2f25bc86ed 100644
--- a/plugins/PluginUpdater/src/Options.cpp
+++ b/plugins/PluginUpdater/src/Options.cpp
@@ -64,11 +64,11 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
}
else {
SetDlgItemTextA(hwndDlg, IDC_CUSTOMURL, dbv.pszVal);
- if ( !strcmp(dbv.pszVal, DEFAULT_UPDATE_URL))
+ if (!strcmp(dbv.pszVal, DEFAULT_UPDATE_URL))
CheckDlgButton(hwndDlg, IDC_STABLE, TRUE);
- else if ( !strcmp(dbv.pszVal, DEFAULT_UPDATE_URL_TRUNK))
+ else if (!strcmp(dbv.pszVal, DEFAULT_UPDATE_URL_TRUNK))
CheckDlgButton(hwndDlg, IDC_TRUNK, TRUE);
- else if ( !strcmp(dbv.pszVal, DEFAULT_UPDATE_URL_TRUNK_SYMBOLS))
+ else if (!strcmp(dbv.pszVal, DEFAULT_UPDATE_URL_TRUNK_SYMBOLS))
CheckDlgButton(hwndDlg, IDC_TRUNK_SYMBOLS, TRUE);
else {
CheckDlgButton(hwndDlg, IDC_CUSTOM, TRUE);
diff --git a/plugins/PluginUpdater/src/checksum.cpp b/plugins/PluginUpdater/src/checksum.cpp
index cda58f10eb..7a88026b25 100644
--- a/plugins/PluginUpdater/src/checksum.cpp
+++ b/plugins/PluginUpdater/src/checksum.cpp
@@ -81,7 +81,7 @@ int CalculateModuleHash(const TCHAR *filename, char *szDest)
// check minimum and maximum size
DWORD hsize = 0, filesize = GetFileSize(map.hFile, &hsize );
- if ( !filesize || filesize == INVALID_FILE_SIZE || hsize)
+ if (!filesize || filesize == INVALID_FILE_SIZE || hsize)
return RESULT_INVALID;
if (filesize < sizeof(IMAGE_DOS_HEADER) + sizeof(IMAGE_NT_HEADERS))
diff --git a/plugins/PluginUpdater/src/unzipfile.cpp b/plugins/PluginUpdater/src/unzipfile.cpp
index 5ae9989053..b29e7e1193 100644
--- a/plugins/PluginUpdater/src/unzipfile.cpp
+++ b/plugins/PluginUpdater/src/unzipfile.cpp
@@ -65,7 +65,7 @@ bool extractCurrentFile(unzFile uf, TCHAR *ptszDestPath, TCHAR *ptszBackPath, bo
if (ptszNewName == NULL)
ptszNewName = mir_a2t(filename);
- if ( !(file_info.external_fa & FILE_ATTRIBUTE_DIRECTORY)) {
+ if (!(file_info.external_fa & FILE_ATTRIBUTE_DIRECTORY)) {
err = unzOpenCurrentFile(uf);
if (err != UNZ_OK)
return false;
@@ -131,7 +131,7 @@ bool unzip(const TCHAR *ptszZipFile, TCHAR *ptszDestPath, TCHAR *ptszBackPath,bo
unzFile uf = unzOpen2_64(ptszZipFile, &ffunc);
if (uf) {
do {
- if ( !extractCurrentFile(uf, ptszDestPath, ptszBackPath,ch))
+ if (!extractCurrentFile(uf, ptszDestPath, ptszBackPath,ch))
bResult = false;
}
while (unzGoToNextFile(uf) == UNZ_OK);