the problem is this consistently doesn't work for the same people, and for some people it just works
if(!isObject(SwolFileDownloaderGui))
exec("./SwolFileDownloaderGui.gui");
package swol_TCPFileDownloader
{
function Swol_FileDownloaderTCP::onConnected(%this)
{
%this.send("GET" SPC %this.dir SPC "HTTP/1.1\nHost:" SPC %this.server @ "\r\nConnection: Close\r\nAccept-Encoding: identity\r\nUser-Agent: Torque/1.0\r\n\r\n");
if(%this.showGui)
{
canvas.pushDialog(SwolFileDownloaderGui);
SwolFileDownloaderWindow.setText("Downloading " @ %this.fileName);
SwolFileDownloaderProgress.setValue(0);
SwolFileDownloaderProgressText.setText("");
SwolFileDownloaderTextTop.setText("0kb");
SwolFileDownloaderTextBottom.setText("N/A");
}
%this.timeStarted = getSimTime();
}
function Swol_FileDownloaderTCP::onLine(%this,%line)
{
if(strPos(%line,"Content-Length:") >= 0)
%this.length = getWord(%line,1);
if(%line $= "")
%this.setBinarySize(%this.length);
}
function Swol_FileDownloaderTCP::onBinChunk(%this,%chunk)
{
SwolFileDownloaderProgress.setValue(%chunk/%this.length);
SwolFileDownloaderProgressText.setText("Downloaded: " @ mFloor((%chunk/%this.length)*100) @ "%");
SwolFileDownloaderTextBottom.setText(mFloatLength(%chunk/(getSimTime()-%this.timeStarted),2) @ "kb/s");
Swol_DownloaderChunkCallBack(%chunk,%this.length,%this.timeStarted,%this.type);
if(%chunk < %this.length)
{
SwolFileDownloaderTextTop.setText(byteRoundBetter(%chunk));
return;
}
if(!isWriteableFilename(%this.saveTo))
{
messageBoxOK("Failure","Downloading the file wasn't successful.");
}
%this.saveBufferToFile(%this.saveTo);
%this.disconnect();
Swol_DownloaderCompleteCallBack(%this.type);
if(%this.showGui)
%this.closeSched = %this.schedule(5,closeGui);
}
function Swol_FileDownloaderTCP::closeGui(%this)
{
cancel(%this.closeSched);
canvas.popDialog(SwolFileDownloaderGui);
}
function Swol_FileDownloaderTCP::downloadFile(%this,%server,%dir,%port,%saveTo,%fileName,%showGUI,%type)
{
if(isFile(%saveTo))
fileDelete(%saveTo);
%this.server = %server;
%this.port = %port;
%this.dir = %dir;
%this.saveTo = %saveTo;
%this.fileName = %fileName;
%this.length = "";
%this.showGui = %showGui;
%this.type = %type;
%this.connect(%this.server @ ":" @ %this.port);
}
function Swol_DownloaderChunkCallBack(%chunk,%lenth,%timeStarted,%type)
{
}
function Swol_DownloaderCompleteCallBack(%type)
{
}
function swolDownloader_downloadFile(%server,%dir,%port,%saveTo,%fileName,%showGUI,%type)
{
new TCPObject(Swol_FileDownloaderTCP);
Swol_FileDownloaderTCP.downloadFile(%server,%dir,%port,%saveTo,%fileName,%showGUI,%type);
}
function Swol_TestDownload(%a)
{
if(%a $= "")
swolDownloader_downloadFile("dl.dropboxusercontent.com","/u/50959273/Pics/Blockland_00065.png",80,"config/test.png","test.png",1,0);
if(%a == 1)
swolDownloader_downloadFile("dl.dropboxusercontent.com","/u/50959273/Blockland%20Private/Client_BrickTextures.zip",80,"config/Client_BrickTextures.zip","Client_BrickTextures.zip",1,0);
if(%a == 2)
swolDownloader_downloadFile("dl.dropboxusercontent.com","/u/50959273/Version/version.txt",80,"config/version.txt","version.txt",1,0);
}
function byteRoundBetter(%bytes)
{
if(%bytes $= "")
return "0b";
if(%bytes > 1048576)
%result = %bytes/1048576 @ "MB";
if(%bytes > 1024)
%result = mFloatLength(%bytes/1024,2) @ "kB";
else
%result = %bytes @ "b";
return %result;
}
};
ActivatePackage(swol_TCPFileDownloader);