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
This commit is contained in:
Tomasz Sowa 2009-10-18 18:59:21 +00:00
parent 787557590a
commit 2fd7432920
6 changed files with 102 additions and 39 deletions

View File

@ -19,7 +19,8 @@ OutputBaseFilename=ttcalc-setup
Compression=lzma Compression=lzma
SolidCompression=yes SolidCompression=yes
ShowUndisplayableLanguages=yes ShowUndisplayableLanguages=yes
PrivilegesRequired=none PrivilegesRequired=admin
UsePreviousAppDir=yes
[Languages] [Languages]
Name: "english"; MessagesFile: "compiler:Default.isl" Name: "english"; MessagesFile: "compiler:Default.isl"

View File

@ -1,5 +1,5 @@
CC = g++ 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 name = ttcalcp.exe
compressor = upx compressor = upx

View File

@ -216,7 +216,10 @@
// update dialog // update dialog
#define IDC_UPDATE_INFO1 1300 #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 #endif

View File

@ -283,21 +283,23 @@ BEGIN
END END
#endif #endif
IDD_UPDATE_DIALOG DIALOG DISCARDABLE 0, 0, 256, 86 IDD_UPDATE_DIALOG DIALOG DISCARDABLE 0, 0, 357, 86
STYLE DS_MODALFRAME | WS_POPUP STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Check for update"
FONT 8, "MS Sans Serif" FONT 8, "MS Sans Serif"
BEGIN BEGIN
CONTROL "Checking for update",IDC_UPDATE_INFO1,"Static",SS_LEFTNOWORDWRAP | CTEXT "Checking for update",IDC_UPDATE_INFO1,7,15,343,10
WS_GROUP,7,14,242,8 CONTROL "Progress1",IDC_PROGRESS,"msctls_progress32",WS_BORDER,7,
38,343,14
CONTROL "Progress1",IDC_PROGRESS,"msctls_progress32",WS_BORDER, DEFPUSHBUTTON "Next",IDC_BUTTON_NEXT,226,65,60,14
7,33,242,14 PUSHBUTTON "Cancel",IDC_BUTTON_CANCEL,290,65,60,14
DEFPUSHBUTTON "Next",IDOK,146,65,50,14 CTEXT "url",IDC_UPDATE_INFO2,7,26,343,8
PUSHBUTTON "Cancel",IDCANCEL,199,65,50,14
END END
#ifndef TTCALC_PORTABLE #ifndef TTCALC_PORTABLE
1201 BITMAP "..\\res\\abacus_01.bmp" 1201 BITMAP "..\\res\\abacus_01.bmp"
#endif #endif

View File

@ -1,7 +1,7 @@
/* /*
* This file is a part of TTCalc - a mathematical calculator * This file is a part of TTCalc - a mathematical calculator
* and is distributed under the (new) BSD licence. * and is distributed under the (new) BSD licence.
* Author: Tomasz Sowa <t.sowa@slimaczek.pl> * Author: Tomasz Sowa <t.sowa@ttmath.org>
*/ */
/* /*
@ -36,7 +36,9 @@
*/ */
#include "compileconfig.h"
#include <cstdlib> #include <cstdlib>
#include <shlobj.h>
#include "update.h" #include "update.h"
#include "programresources.h" #include "programresources.h"
#include "messages.h" #include "messages.h"
@ -49,6 +51,7 @@ namespace Update
bool continue_download; bool continue_download;
int level; int level;
std::string url; std::string url;
std::string remote_file_name;
std::string download_file_name; std::string download_file_name;
int major; int major;
int minor; int minor;
@ -230,16 +233,26 @@ bool CheckUpdateFromIni(HWND hwnd)
DownloadIni down_ini; DownloadIni down_ini;
down_ini.AttachProgress(GetDlgItem(hwnd, IDC_PROGRESS)); 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; IniParser iparser;
std::string ini_value[3]; std::string ini_value[3];
iparser.SectionCaseSensitive(false); iparser.SectionCaseSensitive(false);
iparser.Associate( "normal|url", &url );
iparser.Associate( "normal|version.major", &ini_value[0] ); #ifndef TTCALC_PORTABLE
iparser.Associate( "normal|version.minor", &ini_value[1] ); iparser.Associate("normal|url", &url );
iparser.Associate( "normal|version.revision", &ini_value[2] ); 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() ); IniParser::Error err = iparser.ReadFromFile( down_ini.GetFileName() );
@ -267,8 +280,11 @@ void CheckUpdate(HWND hwnd)
{ {
char buffer[200]; 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); EnableWindow(GetDlgItem(hwnd, IDC_UPDATE_INFO1), false);
ShowWindow(GetDlgItem(hwnd, IDC_PROGRESS), SW_SHOW);
CheckMessages();
if( CheckUpdateFromIni(hwnd) ) if( CheckUpdateFromIni(hwnd) )
{ {
@ -280,22 +296,36 @@ char buffer[200];
{ {
level = 100; level = 100;
SetDlgItemText(hwnd, IDC_UPDATE_INFO1, "There is not a new version available."); 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); 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); EnableWindow(GetDlgItem(hwnd, IDC_UPDATE_INFO1), true);
ShowWindow(GetDlgItem(hwnd, IDC_PROGRESS), SW_HIDE);
SetFocus(GetDlgItem(hwnd, IDC_BUTTON_NEXT));
} }
bool SaveDialog(HWND hwnd) bool SaveDialog(HWND hwnd)
{ {
OPENFILENAME o; 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.lStructSize = sizeof(o);
o.hwndOwner = hwnd; o.hwndOwner = hwnd;
@ -308,7 +338,7 @@ char buf[MAX_PATH];
o.nMaxFile = MAX_PATH; o.nMaxFile = MAX_PATH;
o.lpstrFileTitle = 0; o.lpstrFileTitle = 0;
o.nMaxFileTitle = 0; o.nMaxFileTitle = 0;
o.lpstrInitialDir = 0; // dac pulpit o.lpstrInitialDir = (desktop[0]) ? desktop : 0;
o.lpstrTitle = 0; o.lpstrTitle = 0;
o.Flags = OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST; o.Flags = OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
o.nFileOffset = 0; o.nFileOffset = 0;
@ -333,34 +363,51 @@ return false;
bool DownloadUpdate(HWND hwnd) bool DownloadUpdate(HWND hwnd)
{ {
DownloadProgram down; 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) ) if( SaveDialog(hwnd) )
{ {
_snprintf(buf, 100, "Downloading: %s", url.c_str()); SetDlgItemText(hwnd, IDC_UPDATE_INFO1, "Downloading from:");
SetDlgItemText(hwnd, IDC_UPDATE_INFO1, buf); SetDlgItemText(hwnd, IDC_UPDATE_INFO2, url.c_str());
ShowWindow(GetDlgItem(hwnd, IDC_PROGRESS), SW_SHOW);
down.AttachProgress(GetDlgItem(hwnd, IDC_PROGRESS)); down.AttachProgress(GetDlgItem(hwnd, IDC_PROGRESS));
CheckMessages();
if( down.DownloadUrl( url.c_str()) ) 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 else
{ {
level = 100;
DeleteFile(download_file_name.c_str()); 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_INFO1, "There was a problem with downloading, please try again later");
SetDlgItemText(hwnd, IDC_UPDATE_INFO2, "");
} }
ShowWindow(GetDlgItem(hwnd, IDC_PROGRESS), SW_HIDE); ShowWindow(GetDlgItem(hwnd, IDC_PROGRESS), SW_HIDE);
SetDlgItemText(hwnd, IDOK, "Finish"); SetDlgItemText(hwnd, IDC_BUTTON_NEXT, "Finish");
}
else
{
level = 100; level = 100;
EndDialog(hwnd, 0);
} }
EnableWindow(GetDlgItem(hwnd, IDOK), true); EnableWindow(GetDlgItem(hwnd, IDC_BUTTON_NEXT), true);
EnableWindow(GetDlgItem(hwnd, IDCANCEL), false); SetFocus(GetDlgItem(hwnd, IDC_BUTTON_NEXT));
return false; return false;
} }
@ -375,8 +422,10 @@ return false;
BOOL UpdateInit(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) BOOL UpdateInit(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
SetDlgItemText(hwnd, IDC_UPDATE_INFO1, "Press Next to check for the update..."); SetDlgItemText(hwnd, IDC_UPDATE_INFO1, "Press Next to check for the update...");
SetDlgItemText(hwnd, IDOK, "Next"); SetDlgItemText(hwnd, IDC_UPDATE_INFO2, "");
SetDlgItemText(hwnd, IDCANCEL, "Cancel"); SetDlgItemText(hwnd, IDC_BUTTON_NEXT, "Next");
SetDlgItemText(hwnd, IDC_BUTTON_CANCEL, "Cancel");
ShowWindow(GetDlgItem(hwnd, IDC_PROGRESS), SW_HIDE);
return true; return true;
} }
@ -384,14 +433,14 @@ return true;
BOOL UpdateCommand(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 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; continue_download = false;
EndDialog(hwnd, 0); EndDialog(hwnd, 0);
return 0; return 0;
} }
if( LOWORD(wParam) == IDOK ) if( LOWORD(wParam) == IDC_BUTTON_NEXT )
{ {
switch(level) switch(level)
{ {
@ -403,6 +452,12 @@ BOOL UpdateCommand(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
DownloadUpdate(hwnd); DownloadUpdate(hwnd);
break; break;
case 2:
ShellExecute(0, "open", download_file_name.c_str(), "", "", SW_SHOWNORMAL);
EndDialog(hwnd, 0);
PostQuitMessage(0);
break;
case 100: case 100:
EndDialog(hwnd, 0); EndDialog(hwnd, 0);
break; break;
@ -443,8 +498,10 @@ using namespace Update;
level = 0; level = 0;
download_file_name.clear(); 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);
} }

View File

@ -1,7 +1,7 @@
/* /*
* This file is a part of TTCalc - a mathematical calculator * This file is a part of TTCalc - a mathematical calculator
* and is distributed under the (new) BSD licence. * and is distributed under the (new) BSD licence.
* Author: Tomasz Sowa <t.sowa@slimaczek.pl> * Author: Tomasz Sowa <t.sowa@ttmath.org>
*/ */
/* /*