I would like to make my application to automatically
check on updates from a source and if any, downloads it
and automatically updates itself with the new version.
Now because the application itself is running, I cannot
update the executable immediately, but need to request a
restart of the computer to automatically update itself.
Does anyone know how I can update the application without
having to restart the computer but is still transparent
to the user that the update is automatic?
I did this several years ago for DOS, but here is the idea:
use a small application to start the big one
Let's say we have small.exe and big.exe
small.exe (pseudocode)
do {
if( exists( big.exe.new ) ) {
rename big.exe, big.exe.bak
rename big.exe.new, big.exe
}
exit_code = start_and_wait( big.exe );
} while( exit_code == restart ) {
big.exe ( pseudocode )
main() {
if( exists codedump )
load_all_data_structures( coredump );
else
init_all_data_structures();
run_the_thing();
}
periodic_check_for_new_version() { // using a timer or what you want
if( exists new_version ) {
download( new_version );
if( check_CRC( new_version ) == OK ) {
dump_all_data_structures( coredump );
fast_exit( restart );
}
else {
delete( new_version ); // bad CRC, risky!
}
}
}
=============================
I was able do dump/load the complete data structures.
Even more, in fast_exit I was not erasing the screen, then when
the application started with coredump, I just loaded all data
and went ahead. You did not see it change. The only thing: I had
a clock showing the seconds, and sometime you can see it skeeping
a second.
Other small trick: after downloading the new application and
checking the CRC I just set a flag. Then I wait to have no input
from the user for a while before coredump & fast_exit
(assuming that if the user did not care about my app. for 5 minutes,
I will not need it in the next 2 seconds, while I coredump and coreload).
This is the main idea. Sure, if load_all_data_structures fails
you have to call init_all_data_structures, if it succeeds you delete the
coredump). With Windows you can use other systems instead of exit code
(registry keys, the fact that the coredump exists, semaphores, etc)
May not be the best way, but the application is still running
(for the last 9 years)
Mihai