Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ automatically update to new version

I've been searching for a good solution for 3 days now, but I haven't been able to find any so far. My situation is:

A client has application installed (C++, console Application). The application on start-up will check it's version number with the server and get back or it is up-to-date or that it should download a new version.

If it has to download the new version, I would like to download the new script with Curl to the name say: Application2.exe

However, I want it to replace the old Application.exe which triggered the download of the new version.

My solution was: Application.exe downloads Application2.exe. When downloaded, it should trigger Updater.exe which sleeps for let's say 5 seconds. Within these 5 seconds (or whatever timespan which suites best). Within these 5 seconds, Application.exe has time to shutdown and after 5 seconds the Updater.exe replaces Application.exe with Application2.exe.

Now the update is finished and the client has the newest version installed.

Is this solution possible regarding system locking files, etc?

like image 599
TVA van Hesteren Avatar asked Mar 24 '17 11:03

TVA van Hesteren


1 Answers

Good news, you can rename files that are open on Windows (executables and DLLs). The lock prevents you from deleting files, not renaming them.

  1. Rename the currently running program to Application_old.exe while it's running
  2. Write the downloaded program to Application.exe
  3. Run the new Application.exe
  4. Close the old one.
  5. Delete the old version using the new executed program.

This way, you'll have auto-restart after update. I do this myself all the time.

like image 158
The Quantum Physicist Avatar answered Nov 04 '22 11:11

The Quantum Physicist