Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » Game Updater

Credits go to Billybob, clovekx, ixilom, kentl, miran, Wetimer, wiseguy, and X-G for helping out!
This thread is locked; no one can reply to it. rss feed Print
Game Updater
ImLeftFooted
Member #3,935
October 2003
avatar

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
Member #7,167
April 2006
avatar

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.

___________________________________________
Democracy in Sweden? Not since 2008-Jun-18.
<someone> The lesbians next door bought me a rolex for my birthday.
<someone> I think they misunderstood when I said I wanna watch...

Wetimer
Member #1,622
November 2001

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.

<code>if(Windows.State = Crash) Computer.halt();</code>

miran
Member #2,407
June 2002

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

--
sig used to be here

wiseguy
Member #44
April 2000
avatar

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
Member #1,622
November 2001

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

Otherwise, shellexecute should do what you want.

<code>if(Windows.State = Crash) Computer.halt();</code>

clovekx
Member #3,479
April 2003
avatar

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

ImLeftFooted
Member #3,935
October 2003
avatar

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
Member #3,479
April 2003
avatar

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
Member #3,935
October 2003
avatar

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

X-G
Member #856
December 2000
avatar

exec is POSIX.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Billybob
Member #3,136
January 2003

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
Member #2,905
November 2002

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
Member #3,935
October 2003
avatar

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.

Go to: