PDA

View Full Version : Download-Unzip call back functions



Josué Alba
08-27-2008, 12:31 AM
Hello, I use to have this 2 functions (don't remember the one who coded them) but they are quite slow, is there any other way to do this??

Here are the functions...

Thx


-- 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

Ulrich
08-27-2008, 04:28 PM
The only thing I can see here is that you should remove the SetText for Label LStatus_2 from both functions. It makes no sense to rewrite the labels with the same text on each iteration. Move the SetText to the main code instead, and execute it only once.

What does UpdateOverallTaskProgress do? A call to this function is present in both callbacks, and if anything is hosed there, both callbacks would degradate.

Ulrich