I am writing a c++ program which sooner or later will need to be updated. I want this to require as little interaction with the user as possible since the program runs constantly in the background and never terminates. I know that under normal circumstances, you can't write to a file that's being executed, so this is my question: is it possible for an application to modify itself without just running another executable and letting that one take over? I can't have more than one file.
Most programs using auto-update features use another executable to take over execution in order to avoid that problem.
However I see a somewhat simple solution:
new programinto a temporary location
new program(possibly with a special parameter) and terminates itself
new programcopies itself over
old program(it should be ok for a running program to read itself, as long as it doesn't open itself for writing)
new program (copy)with a special argument, and then terminates itself
new program (copy)deletes
new programand resumes normal operations
Is it clear enough ? :)