Ideas:
① Check if an update is required (get the latest version number and local version number from the database (the local version number can exist in the TXT file, and some encryption and decryption operations are required))
② Download the latest version of the program from the specified directory to overwrite local files (compressed files when downloading files)
③ compressed files in-program decompression (it is possible that the client computer is not installed compression software, so only through the program itself to extract)
④ Call the main program after decompression is complete
Realize:
Download: WebClient
1 if(webclient.isbusy)//whether there is a Web request in progress2 {3 Webclient.cancelasync ();4 }5 //add an event for WebClient6Webclient.downloadprogresschanged + =NewDownloadprogresschangedeventhandler (webclient_downloadprogresschanged);7webclient.downloadfilecompleted + =NewAsynccompletedeventhandler (webclient_downloadfilecompleted);8 //Start Download9 stringPath = ExePath +@"\update.rar";TenWebclient.downloadfileasync (NewUri ( This. Txtfilepath.text), path);
1 Private voidWebclient_downloadprogresschanged (Objectsender, DownloadProgressChangedEventArgs e)2 {3 4 This. progressBar1.Value =E.progresspercentage;5 This. Lbl_pro. Text = e.progresspercentage.tostring () +"%";6 This. Lbl_detail. Text =string. Format ("downloading....,{0}/{1} (Byte)"7 , e.bytesreceived8 , e.totalbytestoreceive);9 if(E.totalbytestoreceive = =e.bytesreceived)Ten { One This. Lbl_detail. Text = ("DownLoad success. Update now, wait a second! "); A } -}
1 Private voidWebclient_downloadfilecompleted (Objectsender, AsyncCompletedEventArgs e)2 {3 if(e.cancelled)4 {5DevExpress.XtraEditors.XtraMessageBox.Show ("Download is canceled!","Error", MessageBoxButtons.OK, Messageboxicon.error, messageboxdefaultbutton.button1);6 return;7 }8 Else9 {Ten One if( This. Lbl_detail. Text = = ("DownLoad success. Update now, wait a second! ")) A { -Thread T =NewThread (//the method of actually updating); -Checkforillegalcrossthreadcalls =false; the T.start (); - } - - } +}
Program update based on C/s mode-download