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?
Because I'm lazy I'd just tell the user to run updater.exe manually 
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.
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.
What about if front.exe is to be updated?
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)
The theory would be that front is simple enough that you won't need to update it.
Otherwise, shellexecute should do what you want.
I see no problem erasing the .exe while it's still running. It wont actually be erased until the program ends.
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
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")
I can't find any documentation on an exec command for windows.
exec is POSIX.
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.
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.