Automatically checking for a new version of my application

前端 未结 12 1203
天命终不由人
天命终不由人 2021-01-30 18:12

Trying to honor a feature request from our customers, I\'d like that my application, when Internet is available, check on our website if a new version is available.

The

相关标签:
12条回答
  • 2021-01-30 18:28

    if you keep your files in the update directory on example.com, this PHP script should download them for you given the request previously mentioned. (your update would be yourprogram.1.2.4.exe

    $version = $_GET['version'];    
    $filename = "yourprogram" . $version . ".exe";
    $filesize = filesize($filename);
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: post-check=0, pre-check=0");
    header("Content-type: application-download");
    header('Content-Length: ' . $filesize);
    header('Content-Disposition: attachment; filename="' . basename($filename).'"');
    header("Content-Transfer-Encoding: binary");
    

    This makes your web browser think it's downloading an application.

    0 讨论(0)
  • 2021-01-30 18:29

    I would agree with @Martin and @Pilif's answer, but add;

    Consider allowing your end-users to decide if they want to actually install the update there and then, or delay the installation of the update until they've finished using the program.

    I don't know the purpose/function of your app but many applications are launched when the user needs to do something specific there and then - nothing more annoying than launching an app and then being told it's found a new version, and you having to wait for it to download, shut down the app and relaunch itself. If your program has other resources that might be updated (reference files, databases etc) the problem gets worse.

    We had an EPOS system running in about 400 shops, and initially we thought it would be great to have the program spot updates and download them (using a file containing a version number very similar to the suggestions you have above)... great idea. Until all of the shops started up their systems at around the same time (8:45-8:50am), and our server was hit serving a 20+Mb download to 400 remote servers, which would then update the local software and cause a restart. Chaos - with nobody able to trade for about 10 minutes.

    Needless to say that this caused us to subsequently turn off the 'check for updates' feature and redesign it to allow the shops to 'delay' the update until later in the day. :-)

    EDIT: And if anyone from ADOBE is reading - for god's sake why does the damn acrobat reader insist on trying to download updates and crap when I just want to fire-it-up to read a document? Isn't it slow enough at starting, and bloated enough, as it is, without wasting a further 20-30 seconds of my life looking for updates every time I want to read a PDF?
    DONT THEY USE THEIR OWN SOFTWARE??!!! :-)

    0 讨论(0)
  • 2021-01-30 18:32

    I would absolutely recommend to just do a plain HTTP request to your website. Everything else is bound to fail.

    I'd make a HTTP GET request to a certain page on your site containing the version of the local application.

    like

    http://www.example.com/update?version=1.2.4
    

    Then you can return what ever you want, probably also the download-URL of the installer of the new version.

    Why not just put a static file with the latest version to the server and let the client decide? Because you may want (or need) to have control over the process. Maybe 1.2 won't be compatible with the server in the future, so you want the server to force the update to 1.3, but the update from 1.2.4 to 1.2.6 could be uncritical, so you might want to present the client with an optional update.

    Or you want to have a breakdown over the installed base.

    Or whatever. Usually, I've learned it's best to keep as much intelligence on the server, because the server is what you have ultimate control over.

    Speaking here with a bit of experience in the field, here's a small preview of what can (and will - trust me) go wrong:

    • Your Application will be prevented from making HTTP-Requests by the various Personal Firewall applications out there.
    • A considerable percentage of users won't have the needed permissions to actually get the update process going.
    • Even if your users have allowed the old version past their personal firewall, said tool will complain because the .EXE has changed and will recommend the user not to allow the new exe to connect (users usually comply with the wishes of their security tool here).
    • In managed environments, you'll be shot and hanged (not necessarily in that order) for loading executable content from the web and then actually executing it.

    So to keep the damage as low as possible,

    • fail silently when you can't connect to the update server
    • before updating, make sure that you have write-permission to the install directory and warn the user if you do not, or just don't update at all.
    • Provide a way for administrators to turn the auto-update off.

    It's no fun to do what you are about to do - especially when you deal with non technically inclined users as I had to numerous times.

    0 讨论(0)
  • 2021-01-30 18:32

    Pilif answer was good, and I have lots of experience with this too, but I'd like to add something more:

    Remember that if you start yourapp.exe, then the "updater" will try to overwrite yourapp.exe with the newest version. Depending upon your operating system and programming environment (you've mentioned C++/QT, I have no experience with those), you will not be able to overwrite yourapp.exe because it will be in use.

    What I have done is create a launcher. I have a MyAppLauncher.exe that uses a config file (xml, very simple) to launch the "real exe". Should a new version exist, the Launcher can update the "real exe" because it's not in use, and then relaunch the new version.

    Just keep that in mind and you'll be safe.

    0 讨论(0)
  • 2021-01-30 18:40

    My Qt app just uses QHttp to read tiny XML file off my website that contains the latest version number. If this is greater than the current version number it gives the option to go to the download page. Very simple. Works fine.

    0 讨论(0)
  • 2021-01-30 18:46

    On the server you could just have a simple file "latestversion.txt" which contains the version number (and maybe download URL) of the latest version. The client then just needs to read this file using a simple HTTP request (yes, to port 80) to retrieve http://your.web.site/latestversion.txt, which you can then parse to get the version number. This way you don't need any fancy server code --- you just need to add a simple file to your existing website.

    0 讨论(0)
提交回复
热议问题