How should I implement an auto-updater?

后端 未结 16 1114
名媛妹妹
名媛妹妹 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:37

    This is not so much a complete answer, but rather one example of auto-updating mechanism I implemented recently. The situation is a little different from the tradition Firefox-type of user application, since it was an internal tool used at work.

    Basically, it's a little script that manages a queue of Subversion branches to be built and packaged in an installer. It reads a little file, where the names of the branches are written, takes the first one, re-writes it at the end of the file, and launches the build process, which involves calling a bunch of scripts. The configuration for each branch to build is written in a .INI file, stored in a Subversion repository along with the tool itself.

    Because this tool runs on several computers, I wanted a way to update it automatically on all machines as soon as I made a change either to the tool itself, or to the configuration scripts.

    The way I implemented it was simple: when I launch the tool, it becomes an "outer shell". This outer shell does 2 very simple things:

    • svn update on itself and on the configuration files
    • launch itself again, this time as the "inner shell", the one that actually handles one configuration (and then exits again).

    This very simple update-myself-in-a-loop system has served us very well for a few months now. It's very elegant, because it is self-contained: the auto-updater is the program itself. Because "outer shell" (the auto-updater part) is so simple, it doesn't matter that it does not benefit from the updates as the "inner shell" (which gets executed from the updated source file every time).

提交回复
热议问题