Announcement

Collapse
No announcement yet.

How to build a simple "CHECK FOR UPDATE"?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • jassing
    replied
    My spidey sense was tingling that you'd ask for code...

    There are two methods that work -- one is the Globalpaths plugin -- however, I had some errors with it -- and why include another file in your project, when a few lines of code will do it -- drop this into your "Global functions"

    Code:
    function System.LaunchFolder()
      local cProgramFolder = _SourceFolder;
      if Table.Count(_CommandLineArgs) > 0 then
        local x;
        for x=Table.Count(_CommandLineArgs),1,-1 do
          -- The SFXSource is always at the end/last -so we look there 1st -- however, it's not specified in the docs
          -- so we scan the whole thing 'just in case' -- and if this changes in future versions of AMS....
    		  if String.Left(_CommandLineArgs[x], 10) == "SFXSOURCE:" then
    		    local tPath = String.Replace(_CommandLineArgs[x], "SFXSOURCE:", "", true)
    		    tPath = String.SplitPath(tPath)
    		    cProgramFolder = tPath.Drive..tPath.Folder
    		    break; -- we have the real start path, so leave the loop!
    		  end -- if
    	  end -- for loop
      end
      return cProgramFolder;
    end
    And then when looking for "Version1.0.exe" use: System.LaunchFolder().."Version1.0.exe" instead.

    I cannot take credit for the code, but mine is somewhat modified from the original.

    Leave a comment:


  • jassing
    replied
    Originally posted by jpdragon View Post
    The code you give me below does not work.
    Code:
    version = File.GetVersionInfo(<my exe>).FileVersion;
    I didn't know I had to be that specific, sorry -- you need to replace the <my exe> with the full or relative path to your exe.

    Originally posted by jpdragon View Post
    but if I put this code below
    Code:
    version = File.GetVersionInfo("Version1.0.exe").FileVersion;
    I got this error said "On Click, Line 1: attempt to index a nil value."
    that's because it didn't find "Version1.0.exe" -- you need to give some path info to find it.

    HINT: if you're building your AMS to an EXE (web/email) _SourceFolder is not what you want...

    Leave a comment:


  • jpdragon
    replied
    I just update the code and it's work like a charm.

    If I change the version="1.0.0.0" the program will download new Update.exe. If I change it to 2.0.0.0 the program will not download since the version.txt is also 2.0.0.0.


    Code:
    version="2.0.0.0"
    HTTP.Download("http://10.186.157.8/E911PCTool/update/version.txt", _TempFolder.."\\version.txt", MODE_BINARY, 20, 80, nil, nil, nil);
    local cMyVer = "1.0.0.0" -- would be better to read from file version itself, no?
    local tTargetVer = TextFile.ReadToTable(_TempFolder.."\\version.txt");
    
    if String.CompareFileVersions(tTargetVer[1],cMyVer)>0 then
      -- perform update
    -- //if (TextFile.ReadToString(_TempFolder.."\\version.txt")>version) then
    -- Download a file to their temporary directory.
        StatusDlg.Show(MB_ICONNONE, false);
        HTTP.Download("http://10.186.157.8/E911PCTool/update/Update.exe", _TempFolder.."\\Update.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
            File.Open(_TempFolder.."\\Update.exe", "", SW_SHOWNORMAL, true);
            Application.Exit(0);
    
    
        end
    
    end
    The code you give me below does not work.
    Code:
    version = File.GetVersionInfo(<my exe>).FileVersion;
    but if I put this code below
    Code:
    version = File.GetVersionInfo("Version1.0.exe").FileVersion;
    I got this error said "On Click, Line 1: attempt to index a nil value."

    Leave a comment:


  • jassing
    replied
    Hard to control a bit of sarcasm...

    If you didn't modify your code, you have this:

    Code:
    version="1.0.0.0"
    Which means you're comparing 1.0.0.0 to 2.0.0.0 and thus, an update is needed.

    You need to change your code in version 2 so it is version 2 in code.
    If you're using file resources in your project, consider using:
    Code:
    version = File.GetVersionInfo(<my exe>).FileVersion;

    Leave a comment:


  • jpdragon
    replied
    Jassing,

    I got most of it working now.

    One more thing that I can't figure out yet.

    on the content of file version.txt has 2.0.0.0
    and my current file version is 2.0.0.0. When I launch Current_****_v2.0.0.0.exe. The script still download the new Update.exe

    Well it's mean the code is still not working.

    Leave a comment:


  • jassing
    replied
    select your code, cut it fro preload,
    create a button, add it to the "onclick" event.

    --

    it's "always updating" becuase you need to add code to test for if the file was actually downloaded
    http://10.186.157.8/E911PCTool/update/version.txt does not return a file...

    Leave a comment:


  • jpdragon
    replied
    Hi Jassing.

    It's work but no matter what I put on the version.txt it's still download the new Update.exe and run it. How can I make these script below to a button that allow user to click on the button to check for update instead run on preload?


    Code:
    version="1.0.0.0"
    HTTP.Download("http://10.186.157.8/E911PCTool/update/version.txt", _TempFolder.."\\version.txt", MODE_BINARY, 20, 80, nil, nil, nil);
    local cMyVer = "1.0.0.0" -- would be better to read from file version itself, no?
    local tTargetVer = TextFile.ReadToTable(_TempFolder.."\\version.txt");
    
    if String.CompareFileVersions(tTargetVer[1],cMyVer)>0 then
      -- perform update
    -- //if (TextFile.ReadToString(_TempFolder.."\\version.txt")>version) then
    -- Download a file to their temporary directory.
        StatusDlg.Show(MB_ICONNONE, false);
        HTTP.Download("http://10.186.157.8/E911PCTool/update/Update.exe", _TempFolder.."\\Update.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
            File.Open(_TempFolder.."\\Update.exe", "", SW_SHOWNORMAL, true);
            Application.Exit(0);
    
    
        end
    
    end

    Leave a comment:


  • jassing
    replied
    instead of using
    Code:
    if (TextFile.ReadToString(_TempFolder.."\\version.txt")>version) then
    You'll want to read in the text file into a table, then use String.CompareFileVersion()

    Something like this:
    Code:
    local cMyVer = "1.0.0.0" -- would be better to read from file version itself, no?
    local tTargetVer = TextFile.ReadToTable(_TempFolder.."\\version.txt");
    
    if String.CompareFileVersions(tTargetVer[1],cMyVer)>0 then
      -- perform update

    Leave a comment:


  • jpdragon
    replied
    Hi,

    I had try your new script and it's still didn't work.

    I just want a simple script to do the following:

    1. create a button "Check for update"
    2. When you click on a button "check for update". It will check the file verson.txt on http://1.1.1.1/update/version.txt
    3. If it's compare and has different version like 2.0.0.0. A popup said new version is available. Do you want to download now?
    4. Start download http://1.1.1.1/update/newversion.exe and replace the existing version 1.0.0.0

    Leave a comment:


  • pabloko
    replied
    Try this

    PHP Code:
    version="1.0.0.0"
    HTTP.Download("http://www.ethansalterations.com/systemver.txt"_TempFolder.."\\version.txt"MODE_BINARY2080nilnilnil);
    if (
    TextFile.ReadToString(_TempFolder.."\\version.txt")>versionthen
    -- Download a file to their temporary directory.
        
    StatusDlg.Show(MB_ICONNONEfalse);
        
    HTTP.Download("http://www.ethansalterations.com/version2.0.exe"_TempFolder.."\\setup.exe"MODE_BINARY2080nilnilnil);

        -- 
    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 downloaddisplay the error message.
        if 
    error ~= 0 then
            result 
    Dialog.Message("Error"_tblErrorMessages[error], MB_OKMB_ICONEXCLAMATIONMB_DEFBUTTON1);

        -- If 
    there was no error during the download.
        else
            
    File.Open(_TempFolder.."\\setup.exe"""SW_SHOWNORMALtrue);
            
    Application.Exit(0);


        
    end

    end 
    Last edited by pabloko; 09-19-2009, 08:13 AM.

    Leave a comment:


  • jassing
    replied
    I think you are a bit confused in your code.

    In your "check for update" you "run"
    File.Run("http://www.ethansalterations.com/systemver.txt", tgMyIpTable[1]);
    how would that do anything useful?

    Your pre-load code is also confused.
    2.0 is not greater than 1000

    Leave a comment:


  • jpdragon
    replied
    Hi Pabloko,

    I had insert these code above into the "On Preload" section and it's still didn't run.

    I upload the systemver.txt file onto http://www.ethansalterations.com/systemver.txt. This file contain one line said "2.0"

    My goal is to launch this **** and click on the button "check for updates." The respond would said new version 2.0 is available. Would you like to upgrade now? If yes, then go to http://www.ethansalterations.com/version2.0.exe download and override version 1.0.
    Attached Files

    Leave a comment:


  • jassing
    replied
    Sure it's an OPTION, perhaps not a viable one.

    Just downloading/ running an update is always an option.

    If you can use FTP, you can use "FTP.ListFiles ();" to examine the date/time of the installer/setup to see if it's newer than what you have now....

    Leave a comment:


  • ShadowUK
    replied
    Originally posted by OP
    I am looking for a painless way to do it instead of using trueupdate. I have try trueupdate and does not want to bundle additional .exe file.
    Originally posted by jassing View Post
    no one is thinking TrueUpdate???
    It's not an option.

    Leave a comment:


  • rexzooly
    replied
    Originally posted by jassing View Post
    no one is thinking TrueUpdate???
    don't you have to pay more for that tho lol.

    thanks pabloko for the demo :yes i didn't have time to do one

    Leave a comment:

Working...
X