How should I implement an auto-updater?

后端 未结 16 1108
名媛妹妹
名媛妹妹 2020-12-04 06:11

Many programs include an auto-updater, where the program occasionally looks online for updates, and then downloads and applies any updates that are found. Program bugs are f

相关标签:
16条回答
  • 2020-12-04 06:15

    Reading Carl Seleborgs answer gave me some ideas how a generic code-repository could be useful.

    svn comes with a tool called svnsync, which sort of behaves like an svn export but keeps track of the actual revision your export is at.

    Someone could utilize this system in order to only fetch the changed files from the users actual revision.

    In actuality, you will have a repository with the binaries compiled, and running svnsync will only fetch the binaries that has been modified. It might also be able to merge local changes to text-based configuration files with new configuration-options.

    0 讨论(0)
  • 2020-12-04 06:16

    You can write an internal module of your application to do updates. You can write an external mini application to do updates.

    Also look at .NET on-the-fly compilation technology, it makes possible to create such mini application on-the-fly on demand. For example, http://fly.sf.net/

    0 讨论(0)
  • 2020-12-04 06:18

    Because auto updating is a common scenario, most languages have at least one package available to support this. (Below I list some of the available packages)

    One of the really nice idea's is the ClickOnce distribution for .NET, it's an installer which sandboxes your application and installs in the user context, so no administrator rights required. You can configure the ClickOnce in your publish to check for updates each application start.

    Java has Java Web Start which offers the same kind of functionality for java applets.

    Delphi has numerous articles about auto-updating, Torry has a list of WebUpdate components, for instance GoUpdater seems to have a very wide range of functionality.

    They all use a website/network share to check for a new version and than retrieve either a patch or a complete install file and run it. So you should try to find a nice package for your application, to save you the hassle of developing and maintaining your own solution.

    0 讨论(0)
  • 2020-12-04 06:20

    One thing that hasn't really been mentioned is that you should seriously consider that the user running your program might not actually have sufficient privileges to upgrade it. This should be pretty common at least for business users, probably less so for home users.

    I'm always working with a (self-imposed) limited account for security reasons and it always pisses me off that most auto-updaters simply assume that I'm running as admin and then after downloading just fail and offer no other way of performing the update other than actually closing the program and running it again in an administrative context. Most do not even cache the downloaded update and have to do it all over again.

    It'd be much better if the auto-updater would simply prompt for admin credentials when needed and get on with it.

    0 讨论(0)
  • 2020-12-04 06:22

    I think that "language agnostic" is going to be a limiting factor here. Applications come in so many shapes and sizes that there is no one-size-fits-all answer. I have implemented several auto-updaters in several languages, and no two were similar.

    The most general philosophy is that the application checks with some home location (web address, web query, corporate network location, etc.) to either ask if it's version is current, or ask what the most current version is. If the answer calls for an update, that process will be different for each situation.

    A popular alternative is to invite the home location to run a script when the application is initiated. The script can check the version, download updates if necessary, and ask for usage feedback, for example.

    We can probably help better if you narrow the parameters.

    UPDATE: The approach to "patching" also depends on the nature of the application, and there's a very wide diversity here. If you have a single executable file, for instance, then it's probably most practical to replace the executable. If your application has many files, you should look for ways to minimize the number of files replaced. If your application is highly customized or parameterized, you should strive to minimize the re-tailoring effort. If your application employs interpreted code (such as an Excel VBA application or MS Access MDB application), then you may be able to replace parts of the code. In a Java application you may only need to replace a JAR file, or even a subset of the JAR contents. You'll also need to have a way to recognize the current client version, and update it appropriately. I could go on and on, but I hope you see my point about diversity. This is one of those many times when the best answer usually starts with "Well, it depends ...!" That's why so many answers include "Please narrow the parameters."

    0 讨论(0)
  • 2020-12-04 06:22

    First you need a file on your application home web site with the latest version. The best way I think to have special SQL table for this task and populate it automatically after publishing new version / nightly build completion. Your application creates new thread which requests built-in http link with version and compares in with current. In .NET use can use code like this:

    Version GetLatestVersion() {
    HttpWebRequestrequest = (HttpWebRequest)WebRequest.Create(new Uri(new Uri(http://example.net), "version.txt));
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    if (request.HaveResponse)
    {
      StreamReader stream = new StreamReader(response.GetResponseStream(), Encoding.Default);
      return new Version(stream.ReadLine());
    }
    else
    {
      return null;
    }
    }
    
    Version latest = GetLatestVersion();
    Version current = new Version(Application.ProductVersion);
    if (current < latest)
    {
      // you need an update
    }
    else
    {
      // you are up-to-date
    }
    

    In this example, version.php in only one plain string like 1.0.1.0.

    Another tip I can give - how to download an update. I like very much next idea: in the resources of your application there is a string of CLR-code which you compile on-the-fly (using CodeDom) to a temporary folder, main application calls it and goes to close. Updater reads arguments, settings or registry and downloads new modules. And calls main application which deletes all temporary files. Done!

    (But everything here is about .NET)

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