Skip to content

Commit

Permalink
Downloader::setOptions method.
Browse files Browse the repository at this point in the history
ReadBufferSize option.
Version updated to 1.5.1
  • Loading branch information
mitrich-k committed Apr 14, 2016
1 parent 1a9c114 commit 793b3e3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
18 changes: 16 additions & 2 deletions idp/downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Downloader::Downloader()
stopOnError = true;
ownMsgLoop = false;
preserveFtpDirs = true;
readBufferSize = DEFAULT_READ_BUFSIZE;
filesSize = 0;
downloadedFilesSize = 0;
ui = NULL;
Expand Down Expand Up @@ -43,6 +44,13 @@ void Downloader::setInternetOptions(InternetOptions opt)
}
}

void Downloader::setOptions(Downloader *d)
{
stopOnError = d->stopOnError;
preserveFtpDirs = d->preserveFtpDirs;
readBufferSize = d->readBufferSize;
}

void Downloader::setComponents(tstring comp)
{
tstringtoset(components, comp, _T(','));
Expand Down Expand Up @@ -489,7 +497,7 @@ bool Downloader::checkMirrors(tstring url, bool download/* or get size */)

bool Downloader::downloadFile(NetFile *netFile)
{
BYTE buffer[READ_BUFFER_SIZE];
BYTE *buffer = new BYTE[readBufferSize];
DWORD bytesRead;
File file;

Expand All @@ -506,6 +514,7 @@ bool Downloader::downloadFile(NetFile *netFile)
setMarquee(false, stopOnError ? (netFile->size == FILE_SIZE_UNKNOWN) : false);
updateStatus(msg(e.what()));
storeError(msg(e.what()));
delete[] buffer;
return false;
}

Expand All @@ -514,6 +523,7 @@ bool Downloader::downloadFile(NetFile *netFile)
setMarquee(false, stopOnError ? (netFile->size == FILE_SIZE_UNKNOWN) : false);
updateStatus(msg("Cannot connect"));
storeError();
delete[] buffer;
return false;
}

Expand All @@ -523,6 +533,7 @@ bool Downloader::downloadFile(NetFile *netFile)
tstring errstr = msg("Cannot create file") + _T(" ") + netFile->name;
updateStatus(errstr);
storeError(errstr);
delete[] buffer;
return false;
}

Expand All @@ -542,16 +553,18 @@ bool Downloader::downloadFile(NetFile *netFile)
{
file.close();
netFile->close();
delete[] buffer;
return true;
}

if(!netFile->read(buffer, READ_BUFFER_SIZE, &bytesRead))
if(!netFile->read(buffer, readBufferSize, &bytesRead))
{
setMarquee(false, netFile->size == FILE_SIZE_UNKNOWN);
updateStatus(msg("Download failed"));
storeError();
file.close();
netFile->close();
delete[] buffer;
return false;
}

Expand Down Expand Up @@ -582,6 +595,7 @@ bool Downloader::downloadFile(NetFile *netFile)
netFile->close();
netFile->downloaded = true;

delete[] buffer;
return true;
}

Expand Down
4 changes: 3 additions & 1 deletion idp/downloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "ftpdir.h"

#define DOWNLOAD_CANCEL_TIMEOUT 30000
#define READ_BUFFER_SIZE 1024
#define DEFAULT_READ_BUFSIZE 1024

using namespace std;

Expand Down Expand Up @@ -50,6 +50,7 @@ class Downloader
void setComponents(tstring comp);
void setUi(Ui *newUi);
void setInternetOptions(InternetOptions opt);
void setOptions(Downloader *d);
void setFinishedCallback(FinishedCallback callback);
void processMessages();

Expand All @@ -58,6 +59,7 @@ class Downloader
bool preserveFtpDirs;
bool downloadCancelled;
bool downloadPaused;
int readBufferSize;

protected:
bool openInternet();
Expand Down
14 changes: 14 additions & 0 deletions idp/idp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ bool idpGetFileSize(_TCHAR *url, DWORDLONG *size)
{
Downloader d;
d.setInternetOptions(internetOptions);
d.setOptions(&downloader);
d.setMirrorList(&downloader);
d.addFile(STR(url), _T(""));
*size = d.getFileSizes();
Expand All @@ -90,6 +91,7 @@ bool idpDownloadFile(_TCHAR *url, _TCHAR *filename)
{
Downloader d;
d.setInternetOptions(internetOptions);
d.setOptions(&downloader);
d.setMirrorList(&downloader);
d.addFile(STR(url), STR(filename));
return d.downloadFiles();
Expand Down Expand Up @@ -313,6 +315,17 @@ DWORD proxyVal(_TCHAR *value)
return INTERNET_OPEN_TYPE_PRECONFIG;
}

int bufSizeVal(_TCHAR *value)
{
string val = toansi(tstrlower(STR(value)));

if(val.compare("default") == 0) return DEFAULT_READ_BUFSIZE;
if(val.compare("auto") == 0) return DEFAULT_READ_BUFSIZE;

int bufSize = _ttoi(value);
return bufSize ? bufSize : DEFAULT_READ_BUFSIZE;
}

void idpSetInternalOption(_TCHAR *name, _TCHAR *value)
{
if(!name)
Expand All @@ -329,6 +342,7 @@ void idpSetInternalOption(_TCHAR *name, _TCHAR *value)
}
else if(key.compare("stoponerror") == 0) downloader.stopOnError = boolVal(value);
else if(key.compare("preserveftpdirs") == 0) downloader.preserveFtpDirs = boolVal(value);
else if(key.compare("readbuffersize") == 0) downloader.readBufferSize = bufSizeVal(value);
else if(key.compare("retrybutton") == 0) ui.hasRetryButton = boolVal(value);
else if(key.compare("redrawbackground") == 0) ui.redrawBackground = boolVal(value);
else if(key.compare("errordialog") == 0) ui.errorDlgMode = dlgVal(value);
Expand Down
8 changes: 4 additions & 4 deletions idp/idp.rc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,5,0,0
PRODUCTVERSION 1,5,0,0
FILEVERSION 1,5,1,0
PRODUCTVERSION 1,5,1,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -46,12 +46,12 @@ BEGIN
VALUE "Comments", "https://code.google.com/p/inno-download-plugin, http://mitrichsoftware.wordpress.com"
VALUE "CompanyName", "Mitrich Software"
VALUE "FileDescription", "Inno Download Plugin"
VALUE "FileVersion", "1, 5, 0, 0"
VALUE "FileVersion", "1, 5, 1, 0"
VALUE "InternalName", "idp"
VALUE "LegalCopyright", "Copyright (C) 2013-2015 Mitrich Software"
VALUE "OriginalFilename", "idp.dll"
VALUE "ProductName", "Inno Download Plugin"
VALUE "ProductVersion", "1, 5, 0, 0"
VALUE "ProductVersion", "1, 5, 1, 0"
END
END
BLOCK "VarFileInfo"
Expand Down

0 comments on commit 793b3e3

Please sign in to comment.