|
|
|
@@ -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 <t.sowa@slimaczek.pl>
|
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@@ -36,7 +36,9 @@
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "compileconfig.h"
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <shlobj.h>
|
|
|
|
|
#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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|