Browse Source

fixed: the algorithm for downloading didn't check whether a file

was correctly received
added: ttcalc_update.ini
       this file is downloaded from a webserver
       it contains information about updating (version, file name, url)


git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@220 e52654a7-88a9-db11-a3e9-0013d4bc506e
master
Tomasz Sowa 13 years ago
parent
commit
19abe8ff12
  1. 48
      src/download.cpp
  2. 2
      src/download.h
  3. 16
      src/ttcalc_update.ini
  4. 12
      src/update.cpp

48
src/download.cpp

@ -36,6 +36,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "compileconfig.h"
#include "download.h"
@ -84,12 +85,42 @@ void Download::ClearProgress()
}
bool Download::DownloadLoop(HINTERNET conn)
{
DWORD read;
while( true )
{
bool res = InternetReadFile(conn, buffer, buffer_len, &read);
if( !res )
// some problems with downloading
return false;
if( read > 0 )
{
down_size += read;
ChangeProgress(down_size);
if( !Read(buffer, read) )
return false;
}
else
{
// end
return true;
}
}
}
bool Download::DownloadUrl(const char * url)
{
DWORD read;
bool res = true;
size_t down_size = 0;
down_size = 0;
HINTERNET hint = InternetOpen("TTCalcDownload",INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0);
if( !hint )
@ -105,18 +136,7 @@ size_t down_size = 0;
if( Init() )
{
while( InternetReadFile(conn, buffer, buffer_len, &read) && read > 0 )
{
down_size += read;
ChangeProgress(down_size);
if( !Read(buffer, read) )
{
res = false;
break;
}
}
res = DownloadLoop(conn);
Close();
ClearProgress();
}

2
src/download.h

@ -53,6 +53,7 @@ public:
void AttachProgress(HWND p) { progress = p; }
protected:
virtual bool DownloadLoop(HINTERNET conn);
virtual void GetLen(HINTERNET conn) { all_len = 0; }
virtual bool Init() { return false; }
virtual bool Read(char * buffer, size_t size) { return false; }
@ -65,6 +66,7 @@ protected:
size_t buffer_len;
size_t all_len;
HWND progress;
size_t down_size;
};

16
src/ttcalc_update.ini

@ -0,0 +1,16 @@
# this file is downloaded from a webserver during checking for an update
[normal]
url = http://downloads.sourceforge.net/project/ttcalc/ttcalc/ttcalc-0.8.7/ttcalc-0.8.7-setup.exe?use_mirror=dfn
filename = ttcalc-0.8.7-setup.exe
version.major = 0
version.minor = 9
version.revision = 1
[portable]
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
version.major = 0
version.minor = 9
version.revision = 1

12
src/update.cpp

@ -52,7 +52,7 @@ namespace Update
int level;
std::string url;
std::string remote_file_name;
std::string download_file_name;
std::string local_file_name;
int major;
int minor;
int revision;
@ -191,7 +191,7 @@ DWORD index = 0;
bool DownloadProgram::Init()
{
file.open(Update::download_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 )
@ -351,7 +351,7 @@ char buf[MAX_PATH], desktop[MAX_PATH];
if( GetSaveFileName(&o) )
{
download_file_name = buf;
local_file_name = buf;
return true;
}
@ -392,7 +392,7 @@ DownloadProgram down;
else
{
level = 100;
DeleteFile(download_file_name.c_str());
DeleteFile(local_file_name.c_str());
SetDlgItemText(hwnd, IDC_UPDATE_INFO1, "There was a problem with downloading, please try again later");
SetDlgItemText(hwnd, IDC_UPDATE_INFO2, "");
}
@ -453,7 +453,7 @@ BOOL UpdateCommand(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
break;
case 2:
ShellExecute(0, "open", download_file_name.c_str(), "", "", SW_SHOWNORMAL);
ShellExecute(0, "open", local_file_name.c_str(), "", "", SW_SHOWNORMAL);
EndDialog(hwnd, 0);
PostQuitMessage(0);
break;
@ -497,7 +497,7 @@ void ShowUpdateDialog(HWND hwnd)
using namespace Update;
level = 0;
download_file_name.clear();
local_file_name.clear();
remote_file_name.clear();
url.clear();

Loading…
Cancel
Save