How does an application launcher update itself?

会有一股神秘感。 提交于 2019-12-03 05:49:30

问题


Launchers are most common in games. Think of League of Legends, Starcraft II, or almost any MMO out there. Before starting the actual game, you have a small launcher app that takes care of updates and patching.

I want to move this direction with a particular non-game application I am developing. The concept of the launcher makes perfect sense: it checks for updates, replaces the appropriate binaries/libraries, maybe runs an integrity check, and launches the application. However, how do launchers update themselves? This tends to be a rare event, but how is it done? Does the launcher literally just write over the very binary it is currently running from? Or is there some kind of swap step after the download? I need to be able to push out (rare) updates to the launcher (especially if I discover some bug in my launcher).

My particular project will be in C#, but I am interested in conceptually similar C++ and/or Java solutions as well for future reference.


回答1:


I've never tried, but this is what I would guess (assuming you can't overwrite a file being executed. If you can, this is all simpler)

Updater A checks if its the newest version
If launcher isnt the newest version
    Download the differences (to save bandwidth) to file B
    Apply the delta to own code into file C
    Launch file C.
    Close
If file C exists (update happened recently)
    Try to delete C  (update was previous launch, delete temporary file)
    If delete fails  (We are C, means A is out of date)
        Copy C over A  (update launcher)
        Note that you can keep going, don't have to restart even though we are C.
If game isnt newest version
    Download the differences (to save bandwidth) to file B
    Apply the delta to game into file D
    delete game
    Rename D -> game
Run game

André Caron has shown me that the swap trick is done better with transactional file IO.




回答2:


If you are in the .NET world, there is a deployment strategy called 'Click Once'. This was created to solve the problem you have described...

ClickOnce is a deployment technology that allows you to create self-updating Windows-based applications that can be installed and run with minimal user interaction. ClickOnce deployment overcomes three major issues inherent in deployment:

Source: Click Once

Before embarking on this strategy, I suggest researching its pros and cons because there are avid fans and detractors.

Briefly, you upload new versions to a web site (which the application is configured to know about). At start up time, the application checks the site and if there's an update offers the user a dialog. When the user elects to apply the update, the application is stopped and simultaneously a 'click once' component is activated to apply the changes. The component then restarts the executable and this all appears as a seamless operation to the end user...




回答3:


Basically the launcher checks to see if there is a newer version of it self, and if so kicks off a task to get the new version and then executes it and then closes.

Given the updater app is small and loads up quick, you can have it detect, download, stick up a dialog to say there's a new version, and barely flicker as the old version closes and the new one runs up.



来源:https://stackoverflow.com/questions/8944681/how-does-an-application-launcher-update-itself

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!