Automatically checking for a new version of my application

前端 未结 12 1213
天命终不由人
天命终不由人 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: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.

提交回复
热议问题