Hello all
I want to have a cancel button to abort a download, the StatusDlg.SetCancelled(true); doesnt work.
Anyone a idea?
PHP Code:-- VARIABLES THAT SHOULD BE CHANGED: THESE ARE THE THINGS YOU SHOULD CHANGE TO MAKE THIS WORK AS YOU WANT IT TO
sURL = "yourserver/loper.zip"; -- where you'll download from
sDestination = _SourceFolder .. "\\Data\\Downloads"; -- Where the files should be 'installed' to
sZipPassword = ""; -- the password to your zip file (or "" for no password)
-- VARIABLES THAT PROBABLY SHOULDN'T BE CHANGED
-- HTTP Action Variables
sDownloadFolder = _TempFolder .. "\\TempZipInstall"; -- temp location to download to
sDownloadFileName = "TempZip.zip"; -- Temp filename to use
nDownloadMode = MODE_BINARY; -- The download mode to use
nTimeout = 20; -- The timeout in seconds for your http server
nPort = 80; -- The port your http server uses
tProxyData = nil; -- a table of proxy data (nil for none)
tAuthData = nil; -- A table of http auth data (nil for none)
-- Zip Action Variables
nZipOverwrite = ZIP_OVERWRITE_ALWAYS; -- How existing files should be handled
bRecurse = true; -- How zip file recursion should be handled
bUseInternalFolderStructure = true; -- Whether the folder structure in the zip file should be used when extracting
tFilesToExtract = {"*.*"} -- A table of files to extract ({"*.*"} to extract everything
-- Callback function for zip action
function ZipCallback(sDestinationPath, nPercentage, nStatus)
Label.SetText("L_Status2", "Installing:");
-- Update progress bar if percentage is for entire zip file
if nStatus == ZIP_STATUS_MAJOR then
-- Info is for zip file as a whole, update progress
Progress.SetCurrentPos("Progress2", nPercentage);
UpdateOverallTaskProgress(2, nPercentage);
Progress.SetText("Progress2", "Installing (" .. nPercentage .. "%)");
end
-- No matter what, we want to continue extracting!
return true;
end
-- callback function for http.download action
function HTTPCallback (nBytesRead, nFileSize, nTransferRate, nSecondsLeft, sSecondsLeftFormat, sMessage)
-- check if current message is a server status message
if sMessage == "" then
-- no server message is present, update status
Label.SetText("L_Status2", "Downloading:");
nPercent = Math.Round((nBytesRead/nFileSize)*100,0);
Progress.SetCurrentPos("Progress2", nPercent);
Progress.SetText("Progress2", nPercent .. "%");
UpdateOverallTaskProgress(1, nPercent);
end
-- keep the download running!
return true;
end
-- Update the overall task progress - called from both above callback functions
function UpdateOverallTaskProgress (nTaskNumber, nTaskPercentComplete)
nTotalTasks = 2;
Progress.SetRange("Progress1", 1, 100*nTotalTasks);
Progress.SetCurrentPos("Progress1", (nTaskNumber-1)*100 + nTaskPercentComplete);
end
-- Error checking function (not needed, but it makes error checking easier)
function CheckError(sOptionalMessage)
-- get the last error
err = Application.GetLastError();
if err ~= 0 then
-- last error wasn't 'success, check it out!
if sOptionalMessage then
-- An optional message was provided, tack it on to the output
sTitle = "ERROR (" .. sOptionalMessage .. ")";
sMessage = err .. ": " .. _tblErrorMessages[err];
else
-- No optional message, just output the error
sTitle = "ERROR";
sMessage = err .. ": " .. _tblErrorMessages[err];
end
-- output to the user!
Dialog.Message(sTitle, sMessage);
end
end
StatusDlg.ShowCancelButton(true, "Cancel");
-- Ensure temp destination folder exists
Folder.Create(sDownloadFolder);
CheckError("Folder.Create");
-- Download the zip file
HTTP.Download(sURL, sDownloadFolder .. "\\" .. sDownloadFileName, nDownloadMode, nTimeout, nPort, tHTTPAuth, tProxyData, HTTPCallback);
CheckError("HTTP.Download");
-- Ensure install to directory exists
Folder.Create(sDestination);
CheckError("Folder.Create");
-- Extract the contents of the zip file to the specified folder
Zip.Extract(sDownloadFolder .. "\\" .. sDownloadFileName, tFilesToExtract, sDestination, bRecurse, bUseInternalFolderStructure, sZipPassword, nZipOverwrite, ZipCallback);
CheckError("Zip.Extract");
-- Delete the temporarily downloaded file
File.Delete(sDownloadFolder .. "\\" .. sDownloadFileName, false, false, false, nil);
CheckError("File.Delete");
-- Delete the temp download folder
Folder.Delete(sDownloadFolder);
CheckError("Folder.Delete");
-- Clean up output
Progress.SetText("Progress1", "");
Progress.SetText("Progress2", "");
Progress.SetCurrentPos("Progress1", 0);
Progress.SetCurrentPos("Progress2", 0);
Label.SetText("L_Status2", "");
Many thanks![]()

.