added: the program can check for an update at startup

git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@236 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2009-11-04 17:59:42 +00:00
parent c0a0660482
commit 58069828e5
33 changed files with 337 additions and 169 deletions

View File

@ -2,6 +2,7 @@ Version 0.9.0 prerelease (2009.11.03):
* fixed: when 'C' button was pressed, the cursor was not put in the edit window * fixed: when 'C' button was pressed, the cursor was not put in the edit window
* added: Pad window - a multiline edit window * added: Pad window - a multiline edit window
* added: Checking for update dialog box * added: Checking for update dialog box
the program can check automatically for an update at startup
* added: there are some new buttons on the standard tab * added: there are some new buttons on the standard tab
- (...) - the whole expression is surrounded by brackets (ctrl+0 short cut) - (...) - the whole expression is surrounded by brackets (ctrl+0 short cut)
- 1/(...) - 1/(...)

View File

@ -1,5 +1,5 @@
o = resource.o calculation.o convert.o download.o functions.o iniparser.o languages.o mainwindow.o pad.o parsermanager.o programresources.o tabs.o update.o variables.o winmain.o o = resource.o calculation.o convert.o download.o functions.o iniparser.o languages.o mainwindow.o pad.o parsermanager.o programresources.o tabs.o threadcontroller.o update.o variables.o winmain.o
calculation.o: calculation.cpp compileconfig.h parsermanager.h resource.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h tabs.h messages.h calculation.o: calculation.cpp compileconfig.h parsermanager.h resource.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h tabs.h messages.h
convert.o: convert.cpp convert.h compileconfig.h bigtypes.h convert.o: convert.cpp convert.h compileconfig.h bigtypes.h
download.o: download.cpp compileconfig.h download.h download.o: download.cpp compileconfig.h download.h
@ -11,9 +11,10 @@ pad.o: pad.cpp programresources.h compileconfig.h iniparser.h languages.h big
parsermanager.o: parsermanager.cpp compileconfig.h parsermanager.h resource.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h tabs.h messages.h parsermanager.o: parsermanager.cpp compileconfig.h parsermanager.h resource.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h tabs.h messages.h
programresources.o: programresources.cpp compileconfig.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h programresources.o: programresources.cpp compileconfig.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h
tabs.o: tabs.cpp compileconfig.h tabs.h resource.h messages.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h tabs.o: tabs.cpp compileconfig.h tabs.h resource.h messages.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h
threadcontroller.o: threadcontroller.cpp threadcontroller.h stopcalculating.h compileconfig.h
update.o: update.cpp compileconfig.h update.h download.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h messages.h resource.h winmain.h tabs.h pad.h update.o: update.cpp compileconfig.h update.h download.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h messages.h resource.h winmain.h tabs.h pad.h
variables.o: variables.cpp compileconfig.h tabs.h resource.h messages.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h variables.o: variables.cpp compileconfig.h tabs.h resource.h messages.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h
winmain.o: winmain.cpp compileconfig.h winmain.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h resource.h messages.h tabs.h pad.h winmain.o: winmain.cpp compileconfig.h winmain.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h resource.h messages.h tabs.h pad.h update.h download.h
.SUFFIXES: .cpp .o .SUFFIXES: .cpp .o

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>
*/ */
/* /*

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>
*/ */
/* /*

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>
*/ */
/* /*

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>
*/ */
/* /*

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>
*/ */
/* /*

View File

@ -2,7 +2,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>
*/ */
/* /*
@ -42,7 +42,7 @@
Download::Download() Download::Download()
{ {
buffer_len = 512; buffer_len = 128;
progress = 0; progress = 0;
buffer = new char[buffer_len]; buffer = new char[buffer_len];
@ -122,7 +122,7 @@ bool res = true;
down_size = 0; down_size = 0;
HINTERNET hint = InternetOpen("TTCalcDownload",INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0); HINTERNET hint = InternetOpen("TTCalcAutoUpdate",INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0);
if( !hint ) if( !hint )
return false; return false;

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>
*/ */
/* /*

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>
*/ */
/* /*

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>
*/ */
/* /*

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>
*/ */
/* /*

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>
*/ */
/* /*
@ -656,7 +656,7 @@ void Languages::InitGuiMessagesTab()
InsertGuiPair(menu_view_lang_spanish, "&Hiszpañski"); InsertGuiPair(menu_view_lang_spanish, "&Hiszpañski");
InsertGuiPair(menu_view_lang_danish, "&Duñski"); InsertGuiPair(menu_view_lang_danish, "&Duñski");
InsertGuiPair(menu_view_lang_chinese, "&Chiñski"); InsertGuiPair(menu_view_lang_chinese, "&Chiñski");
InsertGuiPair(menu_view_lang_russian, "&Russian"); InsertGuiPair(menu_view_lang_russian, "&Rosyjski");
InsertGuiPair(menu_view_lang_swedish, "&Szwedzki"); InsertGuiPair(menu_view_lang_swedish, "&Szwedzki");
InsertGuiPair(menu_view_close_program, "&Zamknij"); InsertGuiPair(menu_view_close_program, "&Zamknij");
InsertGuiPair(menu_edit_undo, "&Cofnij"); InsertGuiPair(menu_edit_undo, "&Cofnij");
@ -734,9 +734,9 @@ void Languages::InitGuiMessagesTab()
InsertGuiPair(update_downloaded_info1, "Nowa wersja programu TTCalc zosta³a œci¹gniêta"); InsertGuiPair(update_downloaded_info1, "Nowa wersja programu TTCalc zosta³a œci¹gniêta");
InsertGuiPair(update_downloaded_info2, ""); InsertGuiPair(update_downloaded_info2, "");
#endif #endif
InsertGuiPair(update_download_error, "Wystąpiły problemy ze ściąganiem, proszę spróbować ponownie później"); InsertGuiPair(update_download_error, "Wystąpiły problemy ze ściągnięciem, proszę spróbować ponownie później.");
InsertGuiPair(pad_title, "Padzzzzz"); InsertGuiPair(pad_title, "Pad");
InsertGuiPair(pad_menu_file, "&Plik"); InsertGuiPair(pad_menu_file, "&Plik");
InsertGuiPair(pad_menu_edit, "&Edycja"); InsertGuiPair(pad_menu_edit, "&Edycja");
InsertGuiPair(pad_menu_file_new, "&Nowy"); // temporarily not used InsertGuiPair(pad_menu_file_new, "&Nowy"); // temporarily not used

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>
*/ */
/* /*

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>
*/ */
/* /*
@ -385,6 +385,8 @@ HMENU menu = GetMenu(hWnd);
if( !menu ) if( !menu )
return; return;
Languages * pl = GetPrgRes()->GetLanguages();
MENUITEMINFO mi; MENUITEMINFO mi;
mi.cbSize = sizeof(mi); mi.cbSize = sizeof(mi);
mi.fMask = MIIM_TYPE; mi.fMask = MIIM_TYPE;
@ -392,18 +394,26 @@ HMENU menu = GetMenu(hWnd);
// on popup menus we're using indexes because they don't want to work correctly // on popup menus we're using indexes because they don't want to work correctly
// with the identifiers // with the identifiers
mi.dwTypeData = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::menu_view) ); mi.dwTypeData = const_cast<char*>( pl->GuiMessage(Languages::menu_view) );
SetMenuItemInfo(menu, IDM_VIEW_INDEX, true, &mi); SetMenuItemInfo(menu, IDM_VIEW_INDEX, true, &mi);
mi.dwTypeData = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::menu_edit) ); mi.dwTypeData = const_cast<char*>( pl->GuiMessage(Languages::menu_edit) );
SetMenuItemInfo(menu, IDM_EDIT_INDEX, true, &mi); SetMenuItemInfo(menu, IDM_EDIT_INDEX, true, &mi);
mi.dwTypeData = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::menu_help) ); mi.dwTypeData = const_cast<char*>( pl->GuiMessage(Languages::menu_help) );
SetMenuItemInfo(menu, IDM_HELP_INDEX, true, &mi); SetMenuItemInfo(menu, IDM_HELP_INDEX, true, &mi);
mi.dwTypeData = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::menu_language) ); if( GetPrgRes()->GetUpdateExists() )
{
mi.dwTypeData = const_cast<char*>( pl->GuiMessage(Languages::menu_update_available) );
SetMenuItemInfo(menu, IDM_UPDATE_AVAILABLE_INDEX, true, &mi);
}
mi.dwTypeData = const_cast<char*>( pl->GuiMessage(Languages::menu_language) );
SetMenuItemInfo(GetSubMenu(menu,IDM_VIEW_INDEX), IDM_LANGUAGE_INDEX, true, &mi); SetMenuItemInfo(GetSubMenu(menu,IDM_VIEW_INDEX), IDM_LANGUAGE_INDEX, true, &mi);
SetMenuLanguageItem(menu, IDM_NEW_WINDOW, Languages::menu_view_new_window); SetMenuLanguageItem(menu, IDM_NEW_WINDOW, Languages::menu_view_new_window);
SetMenuLanguageItem(menu, IDM_NORMAL_VIEW, Languages::menu_view_normal_view); SetMenuLanguageItem(menu, IDM_NORMAL_VIEW, Languages::menu_view_normal_view);
SetMenuLanguageItem(menu, IDM_COMPACT_VIEW, Languages::menu_view_compact_view); SetMenuLanguageItem(menu, IDM_COMPACT_VIEW, Languages::menu_view_compact_view);
@ -1001,6 +1011,12 @@ BOOL WmCommand_HelpCheckUpdate(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP
return true; return true;
} }
BOOL WmCommand_UpdateAvailable(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
ShowUpdateDialogAfterCheck(hWnd);
return true;
}
@ -1359,6 +1375,27 @@ return true;
} }
BOOL WmUpdateExists(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
MENUITEMINFO mi;
mi.cbSize = sizeof(mi);
mi.fMask = MIIM_TYPE | MIIM_ID;
mi.fType = MFT_STRING;
mi.dwTypeData = const_cast<char*>(GetPrgRes()->GetLanguages()->GuiMessage(Languages::menu_update_available));
mi.cch = 0;
mi.wID = IDM_UPDATE_AVAILABLE;
HMENU menu = GetMenu(hWnd);
InsertMenuItem(menu, IDM_UPDATE_AVAILABLE_INDEX, true, &mi);
GetPrgRes()->SetUpdateExists(true); // used for the dynamic menu (for changing languages)
DrawMenuBar(hWnd);
return true;
}
void CreateCommandMessagesTable(Messages<BOOL> & cmessages) void CreateCommandMessagesTable(Messages<BOOL> & cmessages)
{ {
cmessages.Associate(IDM_ALWAYS_ON_TOP, WmCommand_AlwaysOnTop); cmessages.Associate(IDM_ALWAYS_ON_TOP, WmCommand_AlwaysOnTop);
@ -1367,6 +1404,7 @@ void CreateCommandMessagesTable(Messages<BOOL> & cmessages)
cmessages.Associate(IDM_PAD, WmCommand_Pad); cmessages.Associate(IDM_PAD, WmCommand_Pad);
cmessages.Associate(IDM_HELP_ABOUT, WmCommand_HelpAbout); cmessages.Associate(IDM_HELP_ABOUT, WmCommand_HelpAbout);
cmessages.Associate(IDM_HELP_CHECK_UPDATE, WmCommand_HelpCheckUpdate); cmessages.Associate(IDM_HELP_CHECK_UPDATE, WmCommand_HelpCheckUpdate);
cmessages.Associate(IDM_UPDATE_AVAILABLE, WmCommand_UpdateAvailable);
cmessages.Associate(IDM_NEW_WINDOW, WmCommand_NewWindow); cmessages.Associate(IDM_NEW_WINDOW, WmCommand_NewWindow);
cmessages.Associate(IDM_CLOSE_PROGRAM, WmCommand_CloseProgram); cmessages.Associate(IDM_CLOSE_PROGRAM, WmCommand_CloseProgram);
cmessages.Associate(IDC_INPUT_EDIT, WmCommand_InputEditNotify); cmessages.Associate(IDC_INPUT_EDIT, WmCommand_InputEditNotify);
@ -1422,6 +1460,7 @@ void CreateMainMessagesTable(Messages<BOOL> & messages)
messages.Associate(WM_SIZING, WmSizing); messages.Associate(WM_SIZING, WmSizing);
messages.Associate(WM_SET_LAST_ERROR, WmSetLastError); messages.Associate(WM_SET_LAST_ERROR, WmSetLastError);
messages.Associate(WM_HELP, WmHelp); messages.Associate(WM_HELP, WmHelp);
messages.Associate(WM_UPDATE_EXISTS, WmUpdateExists);
} }

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>
*/ */
/* /*

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>
*/ */
/* /*

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>
*/ */
/* /*

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>
*/ */
/* /*

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>
*/ */
/* /*

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>
*/ */
/* /*
@ -574,6 +574,31 @@ int ProgramResources::GetParamSep()
} }
void ProgramResources::SetCheckUpdateStartup(bool s)
{
check_update_startup = s;
}
bool ProgramResources::GetCheckUpdateStartup()
{
return check_update_startup;
}
void ProgramResources::SetUpdateExists(bool e)
{
update_exists = e;
}
bool ProgramResources::GetUpdateExists()
{
return update_exists;
}
ProgramResources::ProgramResources() ProgramResources::ProgramResources()
{ {
// if you want to change the input buffer you have also to change // if you want to change the input buffer you have also to change
@ -641,6 +666,8 @@ ProgramResources::ProgramResources()
functions_id = 0; functions_id = 0;
show_pad = false; show_pad = false;
check_update_startup = true;
update_exists = false; // for dynamic menu
} }
@ -957,6 +984,7 @@ return err;
IniParser::Error ProgramResources::ReadFromFile() IniParser::Error ProgramResources::ReadFromFile()
{ {
IniParser iparser; IniParser iparser;
@ -996,6 +1024,7 @@ std::string ini_value[30];
iparser.Associate( "global|disp.grouping", &ini_value[23] ); iparser.Associate( "global|disp.grouping", &ini_value[23] );
iparser.Associate( "global|disp.input_comma", &ini_value[24] ); iparser.Associate( "global|disp.input_comma", &ini_value[24] );
iparser.Associate( "global|disp.param_sep", &ini_value[25] ); iparser.Associate( "global|disp.param_sep", &ini_value[25] );
iparser.Associate( "global|update_start", &ini_value[26] );
iparser.Associate( "variables", &temp_variables ); iparser.Associate( "variables", &temp_variables );
iparser.Associate( "functions", &temp_functions ); iparser.Associate( "functions", &temp_functions );
@ -1026,7 +1055,11 @@ std::string ini_value[30];
SetDisplayAlwaysScientific( bool(atoi(ini_value[9].c_str())) ); SetDisplayAlwaysScientific( bool(atoi(ini_value[9].c_str())) );
SetDisplayWhenScientific( atoi(ini_value[10].c_str()) ); SetDisplayWhenScientific( atoi(ini_value[10].c_str()) );
SetDisplayRounding( atoi(ini_value[11].c_str()) ); SetDisplayRounding( atoi(ini_value[11].c_str()) );
SetRemovingZeroes( bool(atoi(ini_value[15].c_str())) );
// remove zeroes - in there is not in the config then will be true by default
// (from the constructor)
if( !ini_value[15].empty() )
SetRemovingZeroes( bool(atoi(ini_value[15].c_str())) );
if( ini_value[13] == "6" ) if( ini_value[13] == "6" )
languages.SetCurrentLanguage(Languages::swe); languages.SetCurrentLanguage(Languages::swe);
@ -1066,6 +1099,11 @@ std::string ini_value[30];
if( err != IniParser::err_ok ) if( err != IniParser::err_ok )
bad_line = iparser.GetBadLine(); bad_line = iparser.GetBadLine();
// check update at startup - true by default (if there is not in the config)
// (default from the constructor)
if( !ini_value[26].empty() )
check_update_startup = bool( atoi(ini_value[26].c_str()) );
return err; return err;
} }
@ -1090,6 +1128,7 @@ std::ofstream file( configuration_file.c_str() );
file << "size.x = " << x_size << std::endl; file << "size.x = " << x_size << std::endl;
file << "size.y = " << y_size << std::endl; file << "size.y = " << y_size << std::endl;
file << "maximized = " << (int)maximized << std::endl; file << "maximized = " << (int)maximized << std::endl;
file << "update_start = " << (int)check_update_startup << std::endl;
file << "pad = " << (int)show_pad << std::endl; file << "pad = " << (int)show_pad << std::endl;
file << "pad.x = " << pad_x_pos << std::endl; file << "pad.x = " << pad_x_pos << std::endl;
file << "pad.y = " << pad_y_pos << std::endl; file << "pad.y = " << pad_y_pos << std::endl;

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>
*/ */
/* /*
@ -56,6 +56,18 @@
#include <windows.h> #include <windows.h>
/*!
some messages
*/
#define WM_INIT_TAB_VARIABLES WM_APP
#define WM_INIT_TAB_FUNCTIONS WM_APP+1
#define WM_INIT_TAB_PRECISION WM_APP+2
#define WM_INIT_TAB_DISPLAY WM_APP+3
#define WM_SET_LAST_ERROR WM_APP+4
#define WM_INIT_TAB_CONVERT WM_APP+5
#define WM_UPDATE_EXISTS WM_APP+6
/*! /*!
you don't have to create an object of this class but instead of it you can you don't have to create an object of this class but instead of it you can
get the pointer to the object by using 'GetPrgRes()' get the pointer to the object by using 'GetPrgRes()'
@ -421,6 +433,22 @@ public:
int GetParamSep(); int GetParamSep();
/*!
setting/getting the test which is made when the program starts
(testing for an update)
*/
void SetCheckUpdateStartup(bool s);
bool GetCheckUpdateStartup();
/*!
true if there is an update available
(used only with the dynamic menu)
*/
void SetUpdateExists(bool e);
bool GetUpdateExists();
private: private:
bool IsWhiteCharacter(int c); bool IsWhiteCharacter(int c);
@ -491,6 +519,8 @@ private:
int bad_line; int bad_line;
bool show_pad; bool show_pad;
bool check_update_startup;
bool update_exists;
}; };

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>
*/ */
/* /*
@ -206,6 +206,8 @@
#define IDM_VIEW_INDEX 0 #define IDM_VIEW_INDEX 0
#define IDM_EDIT_INDEX 1 #define IDM_EDIT_INDEX 1
#define IDM_HELP_INDEX 2 #define IDM_HELP_INDEX 2
#define IDM_UPDATE_AVAILABLE_INDEX 3
#define IDM_LANGUAGE_INDEX 8 #define IDM_LANGUAGE_INDEX 8
#define IDM_NEW_WINDOW 40001 #define IDM_NEW_WINDOW 40001
@ -238,6 +240,7 @@
#define IDM_HELP_CHECK_UPDATE 40052 #define IDM_HELP_CHECK_UPDATE 40052
#define IDM_HELP_ABOUT 40053 #define IDM_HELP_ABOUT 40053
#define IDM_UPDATE_AVAILABLE 40060
// pad menu // pad menu
#define MENUPAD_FILE_INDEX 0 #define MENUPAD_FILE_INDEX 0

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>
*/ */
/* /*

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>
*/ */
/* /*

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>
*/ */
/* /*
@ -49,12 +49,6 @@
#include "programresources.h" #include "programresources.h"
#define WM_INIT_TAB_VARIABLES WM_APP
#define WM_INIT_TAB_FUNCTIONS WM_APP+1
#define WM_INIT_TAB_PRECISION WM_APP+2
#define WM_INIT_TAB_DISPLAY WM_APP+3
#define WM_SET_LAST_ERROR WM_APP+4
#define WM_INIT_TAB_CONVERT WM_APP+5
namespace TabWindowFunctions namespace TabWindowFunctions
{ {

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>
*/ */
/* /*
@ -80,22 +80,13 @@ public:
the default constructor the default constructor
(notice that there'll be only one object of this class) (notice that there'll be only one object of this class)
*/ */
ThreadController() ThreadController();
{
calculations = 0;
ready_for_stop = 0;
exit_thread = false;
}
/*! /*!
the destructor the destructor
*/ */
~ThreadController() ~ThreadController();
{
if(calculations) CloseHandle(calculations);
if(ready_for_stop) CloseHandle(ready_for_stop);
}
/*! /*!
@ -103,38 +94,7 @@ public:
we create two system event and initialize the 'stop_calculating' object we create two system event and initialize the 'stop_calculating' object
*/ */
bool Init() volatile bool Init() volatile;
{
char * buffer = new char[300];
// with 'GetTickCount()' we're generating an unique identifier of our event
// (there can be another window of ttcalc)
sprintf((char*)buffer,"TTCalcEventForManagingThreads9928%u",
(unsigned int)GetTickCount());
// 'calculations' will be for auto-reseting and initialized as non-signaled
if( (calculations = CreateEvent(0,false,false,(char*)buffer))==NULL)
{
delete [] buffer;
return false;
}
sprintf((char*)buffer,"TTCalcEventReadyForStop5567%u",
(unsigned int)GetTickCount());
// 'ready_for_stop' will be for manual-reseting and initialized as signaled
// 'manual-reset' means that we must call ResetEvent() function (from WinAPI)
// to manually reset the state to nonsignaled
if( (ready_for_stop = CreateEvent(0,true,true,(char*)buffer))==NULL)
{
delete [] buffer;
return false;
}
delete [] buffer;
return stop_calculating.Init();
}
/*! /*!
@ -143,10 +103,7 @@ public:
string, user-defined variables, functions etc.) and when the second thread string, user-defined variables, functions etc.) and when the second thread
will have finished that then it call ReadyForStop() method will have finished that then it call ReadyForStop() method
*/ */
void ReadyForStop() volatile void ReadyForStop() volatile;
{
SetEvent( ready_for_stop );
}
/*! /*!
@ -154,14 +111,7 @@ public:
close button we call StopCalculatingAndExitThread() from the first main thread (gui), close button we call StopCalculatingAndExitThread() from the first main thread (gui),
it means that the second thread (calculations) will finish itself it means that the second thread (calculations) will finish itself
*/ */
void StopCalculatingAndExitThread() volatile void StopCalculatingAndExitThread() volatile;
{
WaitForSingleObject(ready_for_stop,INFINITE);
stop_calculating.Stop();
exit_thread = true;
SetEvent(calculations);
}
/*! /*!
@ -172,12 +122,7 @@ public:
of copying variables) then sets the 'stop object' for signaled and returns to of copying variables) then sets the 'stop object' for signaled and returns to
the caller the caller
*/ */
void StopCalculating() volatile void StopCalculating() volatile;
{
WaitForSingleObject(ready_for_stop, INFINITE);
stop_calculating.Stop();
}
/*! /*!
@ -185,67 +130,49 @@ public:
in other words it means that the calculations will start in other words it means that the calculations will start
(maybe now, maybe at once if the second thread is still working) (maybe now, maybe at once if the second thread is still working)
*/ */
void StartCalculating() volatile void StartCalculating() volatile;
{
SetEvent(calculations);
}
/*! /*!
this is the main method which is used by the second thread, this is the main method which is used by the second thread,
if there's nothing to do this method (and the second thread as well) waits if there's nothing to do this method (and the second thread as well) waits
*/ */
volatile bool WaitForCalculatingAndBlockForStop() volatile volatile bool WaitForCalculatingAndBlockForStop() volatile;
{
WaitForSingleObject(calculations,INFINITE);
ResetEvent(ready_for_stop);
stop_calculating.Start();
return !exit_thread;
}
/*! /*!
this method returns the pointer to the 'stop object' this method returns the pointer to the 'stop object'
it's used by the second thread during calculating it's used by the second thread during calculating
*/ */
const volatile ttmath::StopCalculating * GetStopObject() volatile const const volatile ttmath::StopCalculating * GetStopObject() volatile const;
{
return &stop_calculating;
}
/*! /*!
it returns 'true' if there was a stop signal during calculating it returns 'true' if there was a stop signal during calculating
the stop signal can be caused by the first thread (gui thread) the stop signal can be caused by the first thread (gui thread)
*/ */
bool WasStopSignal() volatile const bool WasStopSignal() volatile const;
{
return stop_calculating.WasStopSignal();
}
private: private:
// auto-reset, initialized as non-signaled // auto-reset, initialized as non-signaled
HANDLE calculations; HANDLE calculations;
// manual-reset, initialized as signaled // manual-reset, initialized as signaled
HANDLE ready_for_stop; HANDLE ready_for_stop;
bool exit_thread; bool exit_thread;
NewStopCalculating stop_calculating; NewStopCalculating stop_calculating;
/*! /*!
we make the copy-constructor private so that nobody will be able we make the copy-constructor private so that nobody will be able
to make a copy of the one object of this class to make a copy of the one object of this class
*/ */
ThreadController(const ThreadController &) ThreadController(const ThreadController &);
{
}
}; };

View File

@ -9,7 +9,7 @@ version.revision = 1
[portable] [portable]
url = http://downloads.sourceforge.net/project/ttcalc/ttcalc/ttcalc-0.8.7/ttcalc-portable-0.8.7-bin.tar.gz?use_mirror=dfn url = http://downloads.sourceforge.net/project/ttcalc/ttcalc/ttcalc-0.8.7/ttcalc-portable-0.8.7-bin.tar.gz?use_mirror=dfn
fillename = ttcalc-portable-0.8.7-bin.tar filename = ttcalc-portable-0.8.7-bin.tar
version.major = 0 version.major = 0
version.minor = 9 version.minor = 9
version.revision = 1 version.revision = 1

View File

@ -37,8 +37,11 @@
#include "compileconfig.h" #include "compileconfig.h"
#include <cstdlib> #include <cstdlib>
#include <shlobj.h> #include <shlobj.h>
#include <process.h>
#include "update.h" #include "update.h"
#include "programresources.h" #include "programresources.h"
#include "messages.h" #include "messages.h"
@ -49,7 +52,7 @@
namespace Update namespace Update
{ {
bool continue_download; bool continue_down;
int level; int level;
std::string url; std::string url;
std::string remote_file_name; std::string remote_file_name;
@ -57,6 +60,17 @@ namespace Update
int major; int major;
int minor; int minor;
int revision; int revision;
// this is set by another thread at the beginning
namespace Background
{
std::string url_;
std::string remote_file_name_;
int major_;
int minor_;
int revision_;
}
} }
@ -70,6 +84,7 @@ DownloadIni::DownloadIni()
file = 0; file = 0;
file_name = new char[MAX_PATH]; file_name = new char[MAX_PATH];
file_name[0] = 0; file_name[0] = 0;
continue_download = 0;
} }
@ -137,8 +152,6 @@ bool DownloadIni::Init()
if( !CreateTmpFile() ) if( !CreateTmpFile() )
return false; return false;
Update::continue_download = true;
return true; return true;
} }
@ -152,9 +165,18 @@ bool DownloadIni::Read(char * buffer, size_t size)
fwrite(buffer, size, 1, file); fwrite(buffer, size, 1, file);
CheckMessages(); CheckMessages();
return Update::continue_download; if( continue_download && !(*continue_download) )
return false;
return true;
} }
bool DownloadIni::DownloadUrl(const char * url, bool * c)
{
continue_download = c;
return Download::DownloadUrl(url);
}
void DownloadIni::Close() void DownloadIni::Close()
@ -176,6 +198,11 @@ void DownloadIni::Close()
*/ */
DownloadProgram::DownloadProgram()
{
continue_download = 0;
}
void DownloadProgram::GetLen(HINTERNET conn) void DownloadProgram::GetLen(HINTERNET conn)
{ {
@ -193,7 +220,6 @@ DWORD index = 0;
bool DownloadProgram::Init() bool DownloadProgram::Init()
{ {
file.open(Update::local_file_name.c_str(), std::ios_base::out | std::ios_base::binary); file.open(Update::local_file_name.c_str(), std::ios_base::out | std::ios_base::binary);
Update::continue_download = true;
if( !file ) if( !file )
return false; return false;
@ -208,10 +234,20 @@ bool DownloadProgram::Read(char * buffer, size_t size)
file.write(buffer, size); file.write(buffer, size);
CheckMessages(); CheckMessages();
return Update::continue_download; if( continue_download && !(*continue_download) )
return false;
return true;
} }
bool DownloadProgram::DownloadUrl(const char * url, bool * c)
{
continue_download = c;
return Download::DownloadUrl(url);
}
void DownloadProgram::Close() void DownloadProgram::Close()
{ {
@ -221,20 +257,20 @@ void DownloadProgram::Close()
namespace Update
{
/* /*
this method is called from the other thread too
make sure you don't write directly to any global variables (from Update namespace etc)
*/ */
bool CheckUpdateFromIni(HWND hwnd, std::string & url_, std::string & remote_file_name_,
bool CheckUpdateFromIni(HWND hwnd) int & major_, int & minor_, int & revision_, bool * continue_download_)
{ {
DownloadIni down_ini; DownloadIni down_ini;
down_ini.AttachProgress(GetDlgItem(hwnd, IDC_PROGRESS)); if( hwnd )
if( down_ini.DownloadUrl("http://ttcalc.sourceforge.net/ttcalc_update.ini") ) down_ini.AttachProgress(GetDlgItem(hwnd, IDC_PROGRESS));
if( down_ini.DownloadUrl("http://ttcalc.sourceforge.net/ttcalc_update.ini", continue_download_) )
{ {
IniParser iparser; IniParser iparser;
std::string ini_value[3]; std::string ini_value[3];
@ -242,14 +278,14 @@ DownloadIni down_ini;
iparser.SectionCaseSensitive(false); iparser.SectionCaseSensitive(false);
#ifndef TTCALC_PORTABLE #ifndef TTCALC_PORTABLE
iparser.Associate("normal|url", &url ); iparser.Associate("normal|url", &url_ );
iparser.Associate("normal|filename", &remote_file_name ); iparser.Associate("normal|filename", &remote_file_name_ );
iparser.Associate("normal|version.major", &ini_value[0] ); iparser.Associate("normal|version.major", &ini_value[0] );
iparser.Associate("normal|version.minor", &ini_value[1] ); iparser.Associate("normal|version.minor", &ini_value[1] );
iparser.Associate("normal|version.revision", &ini_value[2] ); iparser.Associate("normal|version.revision", &ini_value[2] );
#else #else
iparser.Associate("portable|url", &url ); iparser.Associate("portable|url", &url_ );
iparser.Associate("portable|filename", &remote_file_name ); iparser.Associate("portable|filename", &remote_file_name_ );
iparser.Associate("portable|version.major", &ini_value[0] ); iparser.Associate("portable|version.major", &ini_value[0] );
iparser.Associate("portable|version.minor", &ini_value[1] ); iparser.Associate("portable|version.minor", &ini_value[1] );
iparser.Associate("portable|version.revision", &ini_value[2] ); iparser.Associate("portable|version.revision", &ini_value[2] );
@ -259,17 +295,17 @@ DownloadIni down_ini;
if( err == IniParser::err_ok ) if( err == IniParser::err_ok )
{ {
major = atoi(ini_value[0].c_str()); major_ = atoi(ini_value[0].c_str());
minor = atoi(ini_value[1].c_str()); minor_ = atoi(ini_value[1].c_str());
revision = atoi(ini_value[2].c_str()); revision_ = atoi(ini_value[2].c_str());
if( major > TTCALC_MAJOR_VER ) if( major_ > TTCALC_MAJOR_VER )
return true; return true;
else else
if( major == TTCALC_MAJOR_VER && minor > TTCALC_MINOR_VER ) if( major_ == TTCALC_MAJOR_VER && minor_ > TTCALC_MINOR_VER )
return true; return true;
else else
if( major == TTCALC_MAJOR_VER && minor == TTCALC_MINOR_VER && revision > TTCALC_REVISION_VER ) if( major_ == TTCALC_MAJOR_VER && minor_ == TTCALC_MINOR_VER && revision_ > TTCALC_REVISION_VER )
return true; return true;
} }
} }
@ -277,18 +313,27 @@ DownloadIni down_ini;
return false; return false;
} }
namespace Update
{
void CheckUpdate(HWND hwnd) void CheckUpdate(HWND hwnd)
{ {
char buffer[200]; char buffer[200];
level = -1; // nothing to do when Next is pressed level = -1; // nothing to do when Next is pressed
continue_down = true;
Languages * pl = GetPrgRes()->GetLanguages(); Languages * pl = GetPrgRes()->GetLanguages();
EnableWindow(GetDlgItem(hwnd, IDC_BUTTON_NEXT), false); 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); ShowWindow(GetDlgItem(hwnd, IDC_PROGRESS), SW_SHOW);
CheckMessages(); CheckMessages();
if( CheckUpdateFromIni(hwnd) ) if( CheckUpdateFromIni(hwnd, url, remote_file_name, major, minor, revision, &continue_down) )
{ {
level = 1; level = 1;
sprintf(buffer, pl->GuiMessage(Languages::update_is_new_version), major, minor, revision); sprintf(buffer, pl->GuiMessage(Languages::update_is_new_version), major, minor, revision);
@ -367,6 +412,7 @@ bool DownloadUpdate(HWND hwnd)
DownloadProgram down; DownloadProgram down;
level = -1; // nothing to do when Next is pressed level = -1; // nothing to do when Next is pressed
continue_down = true;
EnableWindow(GetDlgItem(hwnd, IDC_BUTTON_NEXT), false); EnableWindow(GetDlgItem(hwnd, IDC_BUTTON_NEXT), false);
Languages * pl = GetPrgRes()->GetLanguages(); Languages * pl = GetPrgRes()->GetLanguages();
@ -379,7 +425,7 @@ DownloadProgram down;
down.AttachProgress(GetDlgItem(hwnd, IDC_PROGRESS)); down.AttachProgress(GetDlgItem(hwnd, IDC_PROGRESS));
CheckMessages(); CheckMessages();
if( down.DownloadUrl( url.c_str()) ) if( down.DownloadUrl(url.c_str(), &continue_down) )
{ {
SetDlgItemText(hwnd, IDC_UPDATE_INFO1, pl->GuiMessage(Languages::update_downloaded_info1)); SetDlgItemText(hwnd, IDC_UPDATE_INFO1, pl->GuiMessage(Languages::update_downloaded_info1));
SetDlgItemText(hwnd, IDC_UPDATE_INFO2, pl->GuiMessage(Languages::update_downloaded_info2)); SetDlgItemText(hwnd, IDC_UPDATE_INFO2, pl->GuiMessage(Languages::update_downloaded_info2));
@ -425,12 +471,28 @@ BOOL UpdateInit(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
Languages * pl = GetPrgRes()->GetLanguages(); Languages * pl = GetPrgRes()->GetLanguages();
SetDlgItemText(hwnd, IDC_UPDATE_INFO1, pl->GuiMessage(Languages::update_check_for_info)); if( level == 0 )
{
SetDlgItemText(hwnd, IDC_UPDATE_INFO1, pl->GuiMessage(Languages::update_check_for_info));
}
else
if( level == 1 )
{
char buffer[200];
sprintf(buffer, pl->GuiMessage(Languages::update_is_new_version), major, minor, revision);
SetDlgItemText(hwnd, IDC_UPDATE_INFO1, buffer);
}
SetDlgItemText(hwnd, IDC_UPDATE_INFO2, ""); SetDlgItemText(hwnd, IDC_UPDATE_INFO2, "");
SetDlgItemText(hwnd, IDC_BUTTON_NEXT, pl->GuiMessage(Languages::update_button_next)); SetDlgItemText(hwnd, IDC_BUTTON_NEXT, pl->GuiMessage(Languages::update_button_next));
SetDlgItemText(hwnd, IDC_BUTTON_CANCEL, pl->GuiMessage(Languages::update_button_cancel)); SetDlgItemText(hwnd, IDC_BUTTON_CANCEL, pl->GuiMessage(Languages::update_button_cancel));
SetWindowText(hwnd, pl->GuiMessage(Languages::update_title)); SetWindowText(hwnd, pl->GuiMessage(Languages::update_title));
SetDlgItemText(hwnd, IDC_CHECK_UPDATE_STURTUP, pl->GuiMessage(Languages::update_check_at_startup)); SetDlgItemText(hwnd, IDC_CHECK_UPDATE_STURTUP, pl->GuiMessage(Languages::update_check_at_startup));
if( GetPrgRes()->GetCheckUpdateStartup() )
CheckDlgButton(hwnd, IDC_CHECK_UPDATE_STURTUP, BST_CHECKED);
ShowWindow(GetDlgItem(hwnd, IDC_PROGRESS), SW_HIDE); ShowWindow(GetDlgItem(hwnd, IDC_PROGRESS), SW_HIDE);
return true; return true;
@ -441,11 +503,16 @@ BOOL UpdateCommand(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
if( LOWORD(wParam)==IDCANCEL || LOWORD(wParam)==IDC_BUTTON_CANCEL ) if( LOWORD(wParam)==IDCANCEL || LOWORD(wParam)==IDC_BUTTON_CANCEL )
{ {
continue_download = false; continue_down = false;
EndDialog(hwnd, 0); EndDialog(hwnd, 0);
return 0; return 0;
} }
if( LOWORD(wParam) == IDC_CHECK_UPDATE_STURTUP )
{
GetPrgRes()->SetCheckUpdateStartup( IsDlgButtonChecked(hwnd, IDC_CHECK_UPDATE_STURTUP)==BST_CHECKED );
}
else
if( LOWORD(wParam) == IDC_BUTTON_NEXT ) if( LOWORD(wParam) == IDC_BUTTON_NEXT )
{ {
switch(level) switch(level)
@ -494,10 +561,32 @@ return messages.Call(msg, hwnd, msg, wParam, lParam);
} }
unsigned __stdcall UpdateBackgroundProc(void *)
{
using namespace Background;
if( CheckUpdateFromIni(0, url_, remote_file_name_, major_, minor_, revision_, 0) )
{
HWND main = GetPrgRes()->GetMainWindow();
SendMessage(main, WM_UPDATE_EXISTS, 0, 0);
}
_endthreadex(0);
return 0;
}
} // namespace } // namespace
void ShowUpdateDialog(HWND hwnd) void ShowUpdateDialog(HWND hwnd)
{ {
using namespace Update; using namespace Update;
@ -511,5 +600,33 @@ using namespace Update;
} }
void ShowUpdateDialogAfterCheck(HWND hwnd)
{
using namespace Update;
level = 1;
local_file_name.clear();
// make sure that there is a memory barrier before reading next objects (those from Background::)
// objects from Background:: are set by an another thread at the beginning
// when we are here then the thread is not writing (it exited)
remote_file_name = Background::remote_file_name_;
url = Background::url_;
major = Background::major_;
minor = Background::minor_;
revision = Background::revision_;
DialogBox(GetPrgRes()->GetInstance(), MAKEINTRESOURCE(IDD_UPDATE_DIALOG), hwnd, UpdateProc);
}
void CheckUpdateInBackground()
{
if( GetPrgRes()->GetCheckUpdateStartup() )
{
unsigned int thread_id;
_beginthreadex(0, 0, Update::UpdateBackgroundProc, 0, 0, &thread_id);
}
}

View File

@ -45,6 +45,8 @@
void ShowUpdateDialog(HWND hwnd); void ShowUpdateDialog(HWND hwnd);
void ShowUpdateDialogAfterCheck(HWND hwnd);
void CheckUpdateInBackground();
@ -55,6 +57,7 @@ public:
~DownloadIni(); ~DownloadIni();
void DeleteTmpFile(); void DeleteTmpFile();
const char * GetFileName(); const char * GetFileName();
bool DownloadUrl(const char * url, bool * continue_download = 0);
private: private:
@ -66,16 +69,27 @@ private:
char * file_name; char * file_name;
FILE * file; FILE * file;
bool * continue_download;
}; };
class DownloadProgram : public Download class DownloadProgram : public Download
{ {
public:
DownloadProgram();
bool DownloadUrl(const char * url, bool * continue_download = 0);
private:
virtual void GetLen(HINTERNET conn); virtual void GetLen(HINTERNET conn);
virtual bool Init(); virtual bool Init();
virtual bool Read(char * buffer, size_t size); virtual bool Read(char * buffer, size_t size);
virtual void Close(); virtual void Close();
std::ofstream file; std::ofstream file;
bool * continue_download;
}; };

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>
*/ */
/* /*

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>
*/ */
/* /*
@ -37,6 +37,7 @@
#include "compileconfig.h" #include "compileconfig.h"
#include "winmain.h" #include "winmain.h"
#include "update.h"
/*! /*!
\file mainwin.cpp \file mainwin.cpp
@ -97,6 +98,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
if( !CreatePadWindow() ) if( !CreatePadWindow() )
return ShowError( Languages::cant_create_pad ); return ShowError( Languages::cant_create_pad );
// checking for an update (in an another thread)
CheckUpdateInBackground();
// the main loop of messages // the main loop of messages
MainMessagesLoop(); MainMessagesLoop();

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>
*/ */
/* /*
@ -52,7 +52,6 @@
#include <windows.h> #include <windows.h>
#include <commctrl.h> #include <commctrl.h>
#include <process.h> #include <process.h>
#include <map> #include <map>