应用程序启动器如何更新自身?

The*_*Saw 19 c# c++ java launcher

发射器在游戏中最常见.想想英雄联盟,星际争霸II,或几乎所有的MMO.在开始实际游戏之前,您有一个小型启动器应用程序,负责更新和修补.

我想用我正在开发的特定非游戏应用程序来移动这个方向.启动器的概念非常有意义:它检查更新,替换相应的二进制文件/库,可能运行完整性检查,并启动应用程序.但是,发射器如何更新自己?这往往是一个罕见的事件,但它是如何完成的?启动程序是否真的只是写了它当前正在运行的二进制文件?或者下载后是否有某种交换步骤?我需要能够将(罕见的)更新推送到启动器(特别是如果我在发射器中发现了一些错误).

我的特定项目将在C#中,但我对概念上类似的C++和/或Java解决方案感兴趣以供将来参考.

Moo*_*uck 5

我从来没有尝试过,但这是我猜的(假设你不能覆盖正在执行的文件.如果可以的话,这就更简单了)

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
Run Code Online (Sandbox Code Playgroud)

AndréCaron向我展示了使用事务文件IO可以更好地完成交换技巧.