Game Updater
ImLeftFooted

Whats the best way to do this on windows? Do I have to use CreateProcess and then quit the game? How do i detect when the game has actually shut down so i can delete / modify the executable?

Could I just download an updater executable, do a system("updater.exe"); and then quit? How do I get the system call to not block?

Anybody done this sort of thing before?

ixilom

Because I'm lazy I'd just tell the user to run updater.exe manually :P
You could still check for new versions within the game, but just bluntly tell them to quit the game and run updater.exe when new version is available.

Wetimer

My suggestion:

Have two exes.
front.exe - what the user loads.
game.exe - the actual game.

If you download an update, the game.exe stores the update in the current directory and then exits. My suggestion would be that the update is a zip file.

Front does something like this:

while(1)
{
    RunGame();
    if(UpdateIsWaiting())
         InstallUpdate())
    else
         break;
}

Also, you probably want shellexecute over system. System may produce a "dos" box with bad side effects.

miran

What about if front.exe is to be updated? :-X

wiseguy

You need to spawn the updater as an atexit, setting your program to not wait for a return...I knew how to do this back in DOS but haven't used spawn for a long time (not sure how the allegro one is set up)

Wetimer

The theory would be that front is simple enough that you won't need to update it.

Otherwise, shellexecute should do what you want.

clovekx

I see no problem erasing the .exe while it's still running. It wont actually be erased until the program ends.

ImLeftFooted
Quote:

I see no problem erasing the .exe while it's still running. It wont actually be erased until the program ends.

My understanding is that Windows puts a 'lock' on the file and the operation just fails.

[edit]
My plan so far is to use CreateProcess to start the update.exe program and then quit the game. I just need some way for the update.exe program to detect when the game has finally closed. It could just wait for a given period of time but that is unclean...

My ideas so far are:

  • Watch the PID and use windows API to detect if its still running

  • named mutex

clovekx

and what about using exec? That will replace the process with another so you can download updater and then use something like exec("updater.exe")

ImLeftFooted

I can't find any documentation on an exec command for windows.

X-G

exec is POSIX.

Billybob
FILE *fp = NULL;
while((fp = fopen("game.exe", "wb")) == NULL)
{
     // TODO: Check if it has been too long, and if so then throw a critical error
     Sleep(1);
}
fclose(fp);
// TODO: Now you can update

Loops until the file is available for writing (and hence the program has closed). Windows only.

kentl

I haven't been following the discussion, so this might have been suggested already. But what about having a small file gamename.exe which only executes (when the user starts the game) gamename<versionnr>.exe and exists immediately without waiting for a return value. Then that file could be overwritten by the updater telling it to run the new version next time. And the next time the game is executed the new version does some cleaning.

ImLeftFooted

Thanks for all the help. Gonna re-open this thread when it comes closer to time for me to actually make the updater, but now I got most of my theories down :)

P.S.
exec sounds interesting, I wonder about its support on windows.

Thread #588652. Printed from Allegro.cc