4. Cleaning Up
We are not done yet. We still have to delete the *.old files. There is really no easy way other than having the user to restart the program. I’m being lazy again here by using “del *.old /Q“. The proper way is to check for .old extension and delete them one by one using QT’s built in function.
int main(int argc, char **argv) { // Delete all the old files system("del *.old /Q"); QApplication app(argc, argv); app.setStyle("Plastique"); GUI gui; gui.show(); return app.exec(); }
I hope this is helpful to you. Please leave a comment or shoot me an email if this code is helpful to you. Standard Licensing apply to all content of this post.
2 Responses to “Implement an auto update system”
April 29th, 2009 at 3:15 AM
Hi Roland, I like the article, I have a small concern i am a C # developer, so i was looking at the code not very througly, I could not understand a part ,
I understood that we created a temp folder and downloaded latest files in them, we also copied all current files to a new folder for backup how can i rename the current files to .old extension these files are already in use and also how i am going to tell my icon for instance to load from temp folder where new files are present.
thanks
April 29th, 2009 at 10:01 AM
Hi Kaleem,
I’m not too familiar with C#, but I will try my best to answer your question.
Files which are in use cannot be deleted, but they can be renamed. In the example above, there is a vector filelist that stores a list of files to be updated. So just loop through it to and rename all the existing files in it.
As far as I know, there is a function in C# is good for this purpose: System.IO.File.Move(@”C:\From.txt”, @”C:\TO.txt”);. Use it to add “.old” to all the existing files.
After that, you can copy the newly downloaded files into the working folder since there is no file overwriting issue.
In order for the new files to take effect, the program MUST be restarted. And in your main loop, before anything else take place, check if the working folder has any “.old” file, if so, delete them all.
I hope that answers your question.