Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 7 of 7

Thread: Cancel button

  1. #1
    Join Date
    Apr 2005
    Posts
    172

    Cancel button

    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 CHANGEDTHESE 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(sDestinationPathnPercentagenStatus)
        
    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 wholeupdate progress
            Progress
    .SetCurrentPos("Progress2"nPercentage);
            
    UpdateOverallTaskProgress(2nPercentage);
            
    Progress.SetText("Progress2""Installing (" .. nPercentage .. "%)");
        
    end
        
    -- No matter whatwe want to continue extracting!
        return 
    true;
    end


    -- callback function for http.download action
    function HTTPCallback (nBytesReadnFileSizenTransferRatenSecondsLeftsSecondsLeftFormatsMessage)
        -- 
    check if current message is a server status message
        
    if sMessage == "" then
            
    -- no server message is presentupdate status
            Label
    .SetText("L_Status2""Downloading:");
            
    nPercent Math.Round((nBytesRead/nFileSize)*100,0);
            
    Progress.SetCurrentPos("Progress2"nPercent);
            
    Progress.SetText("Progress2"nPercent .. "%");
            
    UpdateOverallTaskProgress(1nPercent);
        
    end
        
    -- keep the download running!
        return 
    true;
    end


    -- Update the overall task progress called from both above callback functions
    function UpdateOverallTaskProgress (nTaskNumbernTaskPercentComplete)
        
    nTotalTasks 2;
        
    Progress.SetRange("Progress1"1100*nTotalTasks);
        
    Progress.SetCurrentPos("Progress1", (nTaskNumber-1)*100 nTaskPercentComplete);
    end

    -- Error checking function (not neededbut it makes error checking easier)
    function 
    CheckError(sOptionalMessage)
        -- 
    get the last error
        err 
    Application.GetLastError();
        if 
    err ~= 0 then
        
    -- last error wasn't 'successcheck it out!
            if 
    sOptionalMessage then
                
    -- An optional message was providedtack it on to the output
                sTitle 
    "ERROR (" .. sOptionalMessage .. ")";
                
    sMessage err .. ": " .. _tblErrorMessages[err];
            else
                -- 
    No optional messagejust output the error
                sTitle 
    "ERROR";
                
    sMessage err .. ": " .. _tblErrorMessages[err];
            
    end
        
    -- output to the user!
        
    Dialog.Message(sTitlesMessage);
        
    end
    end





    StatusDlg
    .ShowCancelButton(true"Cancel");


    -- 
    Ensure temp destination folder exists
    Folder
    .Create(sDownloadFolder);
    CheckError("Folder.Create");
        
    -- 
    Download the zip file
    HTTP
    .Download(sURLsDownloadFolder .. "\\" .. sDownloadFileNamenDownloadModenTimeoutnPorttHTTPAuthtProxyDataHTTPCallback);
    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 .. "\\" .. sDownloadFileNametFilesToExtractsDestinationbRecursebUseInternalFolderStructuresZipPasswordnZipOverwriteZipCallback);
    CheckError("Zip.Extract");

    -- 
    Delete the temporarily downloaded file
    File
    .Delete(sDownloadFolder .. "\\" .. sDownloadFileNamefalsefalsefalsenil);
    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

  2. #2
    Join Date
    Apr 2005
    Posts
    172
    Anyone a idea?

    Many thanks

  3. #3
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    I think what you need to do is integrate a check into your HTTPCallBack function that checks to see if the statusdlg was cancelled. If someone presses the Cancel button set a global variable to something specific like g_SDlgCancel = true and then in your call back add this as one of your checks.

    Code:
    -- 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 
        
        if g_SDlgCancel then
            --Stop the download if the status dialog button was pressed
            return false;
        else
            -- keep the download running! 
            return true; 
        end
    end
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  4. #4
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    And If I thought about it a little more you can use the StatusDlg.IsCancelled instead of using a global variable. Practically the same thing. I guess the question I have is are you using the status dlg or the progress bar. I see that you reference both?

    Code:
    -- 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 
        
        if StatusDlg.IsCancelled() then
            --Stop the download if the status dialog button was pressed
            return false;
        else
            -- keep the download running! 
            return true; 
        end
    end
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  5. #5
    Join Date
    Apr 2005
    Posts
    172
    Many Thanks for your replay TJ_Tigger

    Not anymore am using only the progress bar function. So the status dlg function dont apply anymore.

    Am thinking of a cancel button in the project so if the user click, automaticly cancel the download. But am recking my brain on that one. Its a lot easyer to use a status dlg, but it isnt fancy .

    Many thanks for your time

  6. #6
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    In that way I would set a variable on the press of a button so when the http callback fires it will cancel the download.

    Define the variable when the page is defined

    g_ContinueDownload = true;

    Then you define the call back like this

    Code:
    -- 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 
        
            return g_ContinueDownload; 
    end
    Then when the button is pressed to cancel the download change the variable to false

    g_ContinueDownload = false;

    And your download will stop.

    Just make sure the change it back to true when you want to start the download again.

    Tigg
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  7. #7
    Join Date
    Apr 2005
    Posts
    172
    Many thanks it works

Similar Threads

  1. Cancel button does not work on Dialog.PasswordInput
    By mierlp in forum AutoPlay Media Studio 5.0
    Replies: 0
    Last Post: 09-12-2004, 03:54 AM
  2. Update Available Screen - Cancel Button doesn't work
    By bnasmmbaker in forum TrueUpdate 1.0
    Replies: 6
    Last Post: 08-05-2004, 03:29 PM
  3. Example: Creating an on/off button to toggle background audio
    By Jonas DK in forum AutoPlay Media Studio 5.0 Examples
    Replies: 0
    Last Post: 07-10-2004, 02:54 PM
  4. Dialog.GetInformation box, concerning CANCEL button
    By SilverFalcon in forum AutoPlay Media Studio 4.0
    Replies: 5
    Last Post: 01-30-2003, 01:10 PM
  5. Can I catch Cancel button ??
    By mtway in forum Setup Factory 5.0
    Replies: 3
    Last Post: 11-30-2001, 09:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts