From 2fd7432920909b6ec0a140f4250bf44120960883 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sun, 18 Oct 2009 18:59:21 +0000 Subject: [PATCH] changed: some improvements in Update Dialog changed: in setup config: PrivilegesRequired=admin it is better to use administrative privileges when doing an update (if an unprivileged user has installed TTCalc in a special folder before then he would not be able to install it now - and the default directory in the setup would be other than previous one - this would be very misleading) git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@219 e52654a7-88a9-db11-a3e9-0013d4bc506e --- setup/innosetup.iss | 3 +- src/Makefileportable | 2 +- src/resource.h | 5 +- src/resource.rc | 20 ++++---- src/update.cpp | 109 ++++++++++++++++++++++++++++++++----------- src/update.h | 2 +- 6 files changed, 102 insertions(+), 39 deletions(-) diff --git a/setup/innosetup.iss b/setup/innosetup.iss index ba6ab23..4ba65bc 100644 --- a/setup/innosetup.iss +++ b/setup/innosetup.iss @@ -19,7 +19,8 @@ OutputBaseFilename=ttcalc-setup Compression=lzma SolidCompression=yes ShowUndisplayableLanguages=yes -PrivilegesRequired=none +PrivilegesRequired=admin +UsePreviousAppDir=yes [Languages] Name: "english"; MessagesFile: "compiler:Default.isl" diff --git a/src/Makefileportable b/src/Makefileportable index 8d03f7b..2b50045 100644 --- a/src/Makefileportable +++ b/src/Makefileportable @@ -1,5 +1,5 @@ CC = g++ -CFLAGS = -Wall -pedantic -s -Os -fno-default-inline -mwindows -I../../ttmath -DTTCALC_PORTABLE +CFLAGS = -Wall -pedantic -s -Os -fno-default-inline -mwindows -I../../ttmath -DTTMATH_RELEASE -DTTCALC_PORTABLE name = ttcalcp.exe compressor = upx diff --git a/src/resource.h b/src/resource.h index 13fe85e..a63ce6e 100644 --- a/src/resource.h +++ b/src/resource.h @@ -216,7 +216,10 @@ // update dialog #define IDC_UPDATE_INFO1 1300 -#define IDC_PROGRESS 1301 +#define IDC_UPDATE_INFO2 1301 +#define IDC_PROGRESS 1302 +#define IDC_BUTTON_NEXT 1303 +#define IDC_BUTTON_CANCEL 1304 #endif diff --git a/src/resource.rc b/src/resource.rc index 12c70d8..a7a5c85 100644 --- a/src/resource.rc +++ b/src/resource.rc @@ -283,21 +283,23 @@ BEGIN END #endif -IDD_UPDATE_DIALOG DIALOG DISCARDABLE 0, 0, 256, 86 -STYLE DS_MODALFRAME | WS_POPUP +IDD_UPDATE_DIALOG DIALOG DISCARDABLE 0, 0, 357, 86 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Check for update" FONT 8, "MS Sans Serif" BEGIN - CONTROL "Checking for update",IDC_UPDATE_INFO1,"Static",SS_LEFTNOWORDWRAP | - WS_GROUP,7,14,242,8 - - CONTROL "Progress1",IDC_PROGRESS,"msctls_progress32",WS_BORDER, - 7,33,242,14 - DEFPUSHBUTTON "Next",IDOK,146,65,50,14 - PUSHBUTTON "Cancel",IDCANCEL,199,65,50,14 + CTEXT "Checking for update",IDC_UPDATE_INFO1,7,15,343,10 + CONTROL "Progress1",IDC_PROGRESS,"msctls_progress32",WS_BORDER,7, + 38,343,14 + DEFPUSHBUTTON "Next",IDC_BUTTON_NEXT,226,65,60,14 + PUSHBUTTON "Cancel",IDC_BUTTON_CANCEL,290,65,60,14 + CTEXT "url",IDC_UPDATE_INFO2,7,26,343,8 END + + #ifndef TTCALC_PORTABLE 1201 BITMAP "..\\res\\abacus_01.bmp" #endif diff --git a/src/update.cpp b/src/update.cpp index 55e5b9a..e6682d7 100644 --- a/src/update.cpp +++ b/src/update.cpp @@ -1,7 +1,7 @@ /* * This file is a part of TTCalc - a mathematical calculator * and is distributed under the (new) BSD licence. - * Author: Tomasz Sowa + * Author: Tomasz Sowa */ /* @@ -36,7 +36,9 @@ */ +#include "compileconfig.h" #include +#include #include "update.h" #include "programresources.h" #include "messages.h" @@ -49,6 +51,7 @@ namespace Update bool continue_download; int level; std::string url; + std::string remote_file_name; std::string download_file_name; int major; int minor; @@ -230,16 +233,26 @@ bool CheckUpdateFromIni(HWND hwnd) DownloadIni down_ini; down_ini.AttachProgress(GetDlgItem(hwnd, IDC_PROGRESS)); - if( down_ini.DownloadUrl("http://ttcalc.sourceforge.net/ttcalc.ini") ) + if( down_ini.DownloadUrl("http://ttcalc.sourceforge.net/ttcalc_update.ini") ) { IniParser iparser; std::string ini_value[3]; iparser.SectionCaseSensitive(false); - iparser.Associate( "normal|url", &url ); - iparser.Associate( "normal|version.major", &ini_value[0] ); - iparser.Associate( "normal|version.minor", &ini_value[1] ); - iparser.Associate( "normal|version.revision", &ini_value[2] ); + + #ifndef TTCALC_PORTABLE + iparser.Associate("normal|url", &url ); + iparser.Associate("normal|filename", &remote_file_name ); + iparser.Associate("normal|version.major", &ini_value[0] ); + iparser.Associate("normal|version.minor", &ini_value[1] ); + iparser.Associate("normal|version.revision", &ini_value[2] ); + #else + iparser.Associate("portable|url", &url ); + iparser.Associate("portable|filename", &remote_file_name ); + iparser.Associate("portable|version.major", &ini_value[0] ); + iparser.Associate("portable|version.minor", &ini_value[1] ); + iparser.Associate("portable|version.revision", &ini_value[2] ); + #endif IniParser::Error err = iparser.ReadFromFile( down_ini.GetFileName() ); @@ -267,8 +280,11 @@ void CheckUpdate(HWND hwnd) { char buffer[200]; - EnableWindow(GetDlgItem(hwnd, IDOK), false); + level = -1; // nothing to do when Next is pressed + EnableWindow(GetDlgItem(hwnd, IDC_BUTTON_NEXT), false); EnableWindow(GetDlgItem(hwnd, IDC_UPDATE_INFO1), false); + ShowWindow(GetDlgItem(hwnd, IDC_PROGRESS), SW_SHOW); + CheckMessages(); if( CheckUpdateFromIni(hwnd) ) { @@ -280,22 +296,36 @@ char buffer[200]; { level = 100; SetDlgItemText(hwnd, IDC_UPDATE_INFO1, "There is not a new version available."); - SetDlgItemText(hwnd, IDOK, "Finish"); + SetDlgItemText(hwnd, IDC_BUTTON_NEXT, "Finish"); ShowWindow(GetDlgItem(hwnd, IDC_PROGRESS), SW_HIDE); - EnableWindow(GetDlgItem(hwnd, IDCANCEL), false); + EnableWindow(GetDlgItem(hwnd, IDC_BUTTON_CANCEL), false); } - EnableWindow(GetDlgItem(hwnd, IDOK), true); + EnableWindow(GetDlgItem(hwnd, IDC_BUTTON_NEXT), true); EnableWindow(GetDlgItem(hwnd, IDC_UPDATE_INFO1), true); + ShowWindow(GetDlgItem(hwnd, IDC_PROGRESS), SW_HIDE); + SetFocus(GetDlgItem(hwnd, IDC_BUTTON_NEXT)); } bool SaveDialog(HWND hwnd) { OPENFILENAME o; -char buf[MAX_PATH]; +char buf[MAX_PATH], desktop[MAX_PATH]; - strcpy(buf, "TTCalc_setup.exe"); + if( !remote_file_name.empty() ) + sprintf(buf, remote_file_name.c_str()); + else + { + #ifndef TTCALC_PORTABLE + sprintf(buf, "ttcalc-%d.%d.%d-setup.exe", major, minor, revision); + #else + sprintf(buf, "ttcalc-portable-%d.%d.%d-bin.tar.gz", major, minor, revision); + #endif + } + + if( !SHGetSpecialFolderPath(hwnd, desktop, CSIDL_DESKTOPDIRECTORY, 0) ) + desktop[0] = 0; o.lStructSize = sizeof(o); o.hwndOwner = hwnd; @@ -308,7 +338,7 @@ char buf[MAX_PATH]; o.nMaxFile = MAX_PATH; o.lpstrFileTitle = 0; o.nMaxFileTitle = 0; - o.lpstrInitialDir = 0; // dac pulpit + o.lpstrInitialDir = (desktop[0]) ? desktop : 0; o.lpstrTitle = 0; o.Flags = OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST; o.nFileOffset = 0; @@ -333,34 +363,51 @@ return false; bool DownloadUpdate(HWND hwnd) { DownloadProgram down; -char buf[300]; - EnableWindow(GetDlgItem(hwnd, IDOK), false); + level = -1; // nothing to do when Next is pressed + EnableWindow(GetDlgItem(hwnd, IDC_BUTTON_NEXT), false); if( SaveDialog(hwnd) ) { - _snprintf(buf, 100, "Downloading: %s", url.c_str()); - SetDlgItemText(hwnd, IDC_UPDATE_INFO1, buf); + SetDlgItemText(hwnd, IDC_UPDATE_INFO1, "Downloading from:"); + SetDlgItemText(hwnd, IDC_UPDATE_INFO2, url.c_str()); + ShowWindow(GetDlgItem(hwnd, IDC_PROGRESS), SW_SHOW); down.AttachProgress(GetDlgItem(hwnd, IDC_PROGRESS)); + CheckMessages(); if( down.DownloadUrl( url.c_str()) ) { - SetDlgItemText(hwnd, IDC_UPDATE_INFO1, "File has been correctly saved."); + #ifndef TTCALC_PORTABLE + level = 2; + SetDlgItemText(hwnd, IDC_UPDATE_INFO1, "A new setup program has been downloaded."); + SetDlgItemText(hwnd, IDC_UPDATE_INFO2, "Press Finish to close TTCalc and run the installer."); + #else + level = 100; + SetDlgItemText(hwnd, IDC_UPDATE_INFO1, "A new version of TTCalc has been downloaded"); + SetDlgItemText(hwnd, IDC_UPDATE_INFO2, ""); + EnableWindow(GetDlgItem(hwnd, IDC_BUTTON_CANCEL), false); + #endif } else { + level = 100; DeleteFile(download_file_name.c_str()); SetDlgItemText(hwnd, IDC_UPDATE_INFO1, "There was a problem with downloading, please try again later"); + SetDlgItemText(hwnd, IDC_UPDATE_INFO2, ""); } ShowWindow(GetDlgItem(hwnd, IDC_PROGRESS), SW_HIDE); - SetDlgItemText(hwnd, IDOK, "Finish"); + SetDlgItemText(hwnd, IDC_BUTTON_NEXT, "Finish"); + } + else + { level = 100; + EndDialog(hwnd, 0); } - EnableWindow(GetDlgItem(hwnd, IDOK), true); - EnableWindow(GetDlgItem(hwnd, IDCANCEL), false); + EnableWindow(GetDlgItem(hwnd, IDC_BUTTON_NEXT), true); + SetFocus(GetDlgItem(hwnd, IDC_BUTTON_NEXT)); return false; } @@ -375,8 +422,10 @@ return false; BOOL UpdateInit(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { SetDlgItemText(hwnd, IDC_UPDATE_INFO1, "Press Next to check for the update..."); - SetDlgItemText(hwnd, IDOK, "Next"); - SetDlgItemText(hwnd, IDCANCEL, "Cancel"); + SetDlgItemText(hwnd, IDC_UPDATE_INFO2, ""); + SetDlgItemText(hwnd, IDC_BUTTON_NEXT, "Next"); + SetDlgItemText(hwnd, IDC_BUTTON_CANCEL, "Cancel"); + ShowWindow(GetDlgItem(hwnd, IDC_PROGRESS), SW_HIDE); return true; } @@ -384,14 +433,14 @@ return true; BOOL UpdateCommand(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - if( LOWORD(wParam) == IDCANCEL ) + if( LOWORD(wParam)==IDCANCEL || LOWORD(wParam)==IDC_BUTTON_CANCEL ) { continue_download = false; EndDialog(hwnd, 0); return 0; } - if( LOWORD(wParam) == IDOK ) + if( LOWORD(wParam) == IDC_BUTTON_NEXT ) { switch(level) { @@ -403,6 +452,12 @@ BOOL UpdateCommand(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) DownloadUpdate(hwnd); break; + case 2: + ShellExecute(0, "open", download_file_name.c_str(), "", "", SW_SHOWNORMAL); + EndDialog(hwnd, 0); + PostQuitMessage(0); + break; + case 100: EndDialog(hwnd, 0); break; @@ -443,8 +498,10 @@ using namespace Update; level = 0; download_file_name.clear(); - DialogBox(GetPrgRes()->GetInstance(), MAKEINTRESOURCE(IDD_UPDATE_DIALOG), hwnd, UpdateProc); + remote_file_name.clear(); + url.clear(); + DialogBox(GetPrgRes()->GetInstance(), MAKEINTRESOURCE(IDD_UPDATE_DIALOG), hwnd, UpdateProc); } diff --git a/src/update.h b/src/update.h index b51766a..0f3f718 100644 --- a/src/update.h +++ b/src/update.h @@ -1,7 +1,7 @@ /* * This file is a part of TTCalc - a mathematical calculator * and is distributed under the (new) BSD licence. - * Author: Tomasz Sowa + * Author: Tomasz Sowa */ /*