How does an application launcher update itself?

前端 未结 3 1370
情书的邮戳
情书的邮戳 2021-02-02 12:24

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 ta

3条回答
  •  旧巷少年郎
    2021-02-02 13:14

    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, dont 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.

提交回复
热议问题