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
This commit is contained in:
parent
2fd7432920
commit
19abe8ff12
|
@ -36,6 +36,7 @@
|
||||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "compileconfig.h"
|
||||||
#include "download.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)
|
bool Download::DownloadUrl(const char * url)
|
||||||
{
|
{
|
||||||
DWORD read;
|
|
||||||
bool res = true;
|
bool res = true;
|
||||||
size_t down_size = 0;
|
|
||||||
|
down_size = 0;
|
||||||
|
|
||||||
HINTERNET hint = InternetOpen("TTCalcDownload",INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0);
|
HINTERNET hint = InternetOpen("TTCalcDownload",INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0);
|
||||||
if( !hint )
|
if( !hint )
|
||||||
|
@ -105,18 +136,7 @@ size_t down_size = 0;
|
||||||
|
|
||||||
if( Init() )
|
if( Init() )
|
||||||
{
|
{
|
||||||
while( InternetReadFile(conn, buffer, buffer_len, &read) && read > 0 )
|
res = DownloadLoop(conn);
|
||||||
{
|
|
||||||
down_size += read;
|
|
||||||
ChangeProgress(down_size);
|
|
||||||
|
|
||||||
if( !Read(buffer, read) )
|
|
||||||
{
|
|
||||||
res = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
ClearProgress();
|
ClearProgress();
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ public:
|
||||||
void AttachProgress(HWND p) { progress = p; }
|
void AttachProgress(HWND p) { progress = p; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual bool DownloadLoop(HINTERNET conn);
|
||||||
virtual void GetLen(HINTERNET conn) { all_len = 0; }
|
virtual void GetLen(HINTERNET conn) { all_len = 0; }
|
||||||
virtual bool Init() { return false; }
|
virtual bool Init() { return false; }
|
||||||
virtual bool Read(char * buffer, size_t size) { return false; }
|
virtual bool Read(char * buffer, size_t size) { return false; }
|
||||||
|
@ -65,6 +66,7 @@ protected:
|
||||||
size_t buffer_len;
|
size_t buffer_len;
|
||||||
size_t all_len;
|
size_t all_len;
|
||||||
HWND progress;
|
HWND progress;
|
||||||
|
size_t down_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace Update
|
||||||
int level;
|
int level;
|
||||||
std::string url;
|
std::string url;
|
||||||
std::string remote_file_name;
|
std::string remote_file_name;
|
||||||
std::string download_file_name;
|
std::string local_file_name;
|
||||||
int major;
|
int major;
|
||||||
int minor;
|
int minor;
|
||||||
int revision;
|
int revision;
|
||||||
|
@ -191,7 +191,7 @@ DWORD index = 0;
|
||||||
|
|
||||||
bool DownloadProgram::Init()
|
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;
|
Update::continue_download = true;
|
||||||
|
|
||||||
if( !file )
|
if( !file )
|
||||||
|
@ -351,7 +351,7 @@ char buf[MAX_PATH], desktop[MAX_PATH];
|
||||||
|
|
||||||
if( GetSaveFileName(&o) )
|
if( GetSaveFileName(&o) )
|
||||||
{
|
{
|
||||||
download_file_name = buf;
|
local_file_name = buf;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,7 +392,7 @@ DownloadProgram down;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
level = 100;
|
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_INFO1, "There was a problem with downloading, please try again later");
|
||||||
SetDlgItemText(hwnd, IDC_UPDATE_INFO2, "");
|
SetDlgItemText(hwnd, IDC_UPDATE_INFO2, "");
|
||||||
}
|
}
|
||||||
|
@ -453,7 +453,7 @@ BOOL UpdateCommand(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
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);
|
EndDialog(hwnd, 0);
|
||||||
PostQuitMessage(0);
|
PostQuitMessage(0);
|
||||||
break;
|
break;
|
||||||
|
@ -497,7 +497,7 @@ void ShowUpdateDialog(HWND hwnd)
|
||||||
using namespace Update;
|
using namespace Update;
|
||||||
|
|
||||||
level = 0;
|
level = 0;
|
||||||
download_file_name.clear();
|
local_file_name.clear();
|
||||||
remote_file_name.clear();
|
remote_file_name.clear();
|
||||||
url.clear();
|
url.clear();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue