Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  5. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Updating Game While .exe Is Running

Discussion in 'Scripting' started by ShermanZero, Oct 14, 2018.

  1. ShermanZero

    ShermanZero

    Joined:
    Dec 29, 2016
    Posts:
    11
    Hey guys,

    So I have a potentially tricky question. I've been working on creating an updater for my game. It automatically pulls all the files my game uses to run from my server, and attempts to overwrite the existing ones that are on the user's local machine. The problem I'm facing is a sharing exception, which was unsurprising. Windows can't write/overwrite a file if it already exists and is currently being used. So I've brainstormed for a bit, trying to figure out a workaround for this. Before I spend too much time on it though, I wanted to ask for some advice so I don't overcomplicate everything.

    My first thought is that I don't need to download every single file, but I'm not entirely sure. If you want to check out all the files that my game downloads, you can navigate to the PHP script I have set up to list all the raw contents of the game over at:

    https://shermanzero.com/pixelate/resources/php/getRaw.php

    This is essentially what my game pulls, which is then parsed by a function into the actual directory and file locations (function parses data by: $'directory'$ 'file'# !'endOfDirectory'). After that, a coroutine is started to download each individual file. It's not complicated, and it works great... if the game isn't open. Which brings me to another thought, I could create a launcher which acts independently of the game, and then I wouldn't need to worry about files being open when written to.

    Anyway, I'm just looking for some of you guys to toss ideas around with. Let me know if you have any thoughts or advice!

    Thanks!
    Kieran
     
  2. LurkingNinjaDev

    LurkingNinjaDev

    Joined:
    Jan 20, 2015
    Posts:
    1,716
    If you really want to update during use, I would do it in this way:
    - create temp directory
    - download the update in there
    - when next time the exe starts, notices the temp directory
    - instead of normal boot, it quits and run an updater (it can be even a batch file) which applies the update
    - the updater restarts the game, which is now updated

    Why on next run? Because you cannot overwrite anything while in use.
    It's a bad idea to update when the user leaves (if you saw updating windows when you shut down, you know it). It's a risk, the player maybe shutting down the computer.

    Although there is a reason why the launchers are the industry standards. They work.
     
    ShermanZero likes this.