File.GetCRC

number File.GetCRC ( 

string Filename )

Example 1

CRC_check = File.GetCRC(_TempFolder .. "\\setup.exe");

Gets the CRC value of the file "setup.exe" located in the user's Temp directory and stores it in the variable "CRC_check."

Note: _TempFolder is a built-in variable that contains the path to the user's system "Temp" folder.

Example 2

-- Check to see if the user is connected to the internet
connected = HTTP.TestConnection("http://www.indigorose.com", 20, 80, nil, nil);

-- If they are connected.
if connected then
    -- Download a file to their temporary directory.
    StatusDlg.Show(MB_ICONNONE, false);
    HTTP.Download("http://www.indigorose.com/setup.exe", _TempFolder.."\\setup.exe", MODE_BINARY, 20, 80, nil, nil, nil);

    -- Get any error codes that may have been returned by the download action.
    error = Application.GetLastError();
    StatusDlg.Hide();


    -- If there was an error during the download, display the error message.
    if error ~= 0 then
        result = Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);

    -- If there was no error during the download.
    else
        --Get the CRC value of the downloaded file.
        crc_value = File.GetCRC(_TempFolder.."\\setup.exe");
        -- Check to see if the CRC value matches it's expected value.
        if crc_value == 824907888 then
    
            -- Run the exectuable that was downloaded.
            File.Run(_TempFolder.."\\setup.exe", "", "", SW_SHOWNORMAL, true);


        -- The CRC value does not match. Display an error message to the user.
        else
            result = Dialog.Message("Error", "The downloaded file is incomplete. Please try downloading again.", MB_OK, MB_ICONSTOP, MB_DEFBUTTON1);
        end
    end

-- Display a notice informing them that they are not connected.
else
    Dialog.Message("Internet Error", "You are not connected to the internet. Please connect to download.");
end

This example first checks to see if the user has an internet connection. If they do, a file is downloaded to their temporary directory. That file is then checked to make sure it is complete and not corrupt before launching it. This validation on the file is accomplished using the File.GetCRC action. A series of checks are performed in this script to handle any errors that occur and displays notification messages to the user if any actions fail.

Note: _TempFolder is a built-in variable that contains the path to the user's system "Temp" folder.

See also:  Related Actions