We have an windows application (let's say MyApp) installed by an *.msi
file and we need to update it whenever a newer version is released. What we would like to do that:
1) We install the new version of the program by using the setup file to a Server location.
2) We copy the installed files from C:\\Program Files (x86)\\MyApp to a shared folder on a server (let's say MyServer\\C:\\MyApp).
3) We create a click once
application and want to let our users to give a link so that they can install and update their program (MyApp) using click once from the published location (MyServer\\C:\\MyApp).
So, in that case how can we do that? I think we create a Windows Form
project in Visual Studio 2015, but not any idea about the next steps. Any hepl would be appreciated.
So you have your files on your server. When there will be an actual update happening you will need to download all the files to the install directory on a users computer. To make this easier, create an archive (.zip) from those file. We will also need a file containing the version number of the application that is archived. So create a simple text file (.txt) . The content of the file should be the version number only (example: 1000). The version number in this file can't be negative or 0. When you would like to update , create a new archive (.zip) file and increase the version number in the text file.
Now the magic starts. Create a Visual Studio Windows Forms application . This application when executed, will check for updates, download them if needed and then run the application (that is on the server). To do this we will need a kind of way of telling which version is installed. For that we will use Application Settings . Create a setting called "version", that is an integer . The value must be 0 , meaning that the application (the server one) was never installed before.
When the application starts, we will download the string inside the "version.txt", that is on the server using (C# example):
WebClient client = new WebClient ();
string latest_string = client.DownloadString ("MyServer.net/version.txt");
Then convert the string into an integer so we can compare it to the version stored in the application settings (C# example):
int latest = Int32.Parse(latest_string);
Then we use a simple if statement (C# example):
if(Properties.Settings.Default.version < latest){
//Update available
}else {
//Lunch the program and skip the update
}
If the update is available we want to download the archive , extract it to the lunch location and execute the program .
Downloading (C# exapmle):
using (var client = new WebClient(){
client.DownloadFile("MyServer.net/Update.zip", "Update.zip");
}
For extracting we use the ZipFile class ( help link ) (C# example):
string dir = Environment.CurrentDirectory + "MyApp";
if(Directory.Exists(path)){
Directory.Delete(dir, true);
}
ZipFile.ExtractToDirectory("Update.zip", dir);
We need to update the version setting, because the application was updated and we don't want to continuously download (C# example):
Properties.Settings.Default.version = "latest";
Properties.Settings.Default.Save();
Start the process (C# example):
Process myProcess = new Process();
myProcess.StartInfo.FileName = "dir + "run.exe";
myProcess.Start();
And finally we close the application and let the app run (C# example):
Environment.Exit(0);
I did my best explaining this and I hope, that I helped you. I am 15 yrs old and English is not my first language, so sorry for the mistakes in the anwser.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.