C # Implementation of automatic upgrade (with source)

Source: Internet
Author: User

For PC desktop applications, the automatic upgrade feature is often necessary. The automatic upgrade can be developed as a standalone C/s system, so that it can be reused in different desktop applications. This article will focus on the relevant background, the use of Oaus, as for detailed implementation details, we can directly download the source code research. If you understand the use of Oaus, the source of understanding is very easy. If you need to use the automatic upgrade system for direct deployment, you can download the executable program compression package at the end of the article.

I. Main functions of Oaus

The current mainstream program automatic upgrade strategy is to re-download the latest installation package, and then reinstall the entire client. This approach is simple and intuitive, but the flaw is obvious. For example, even if the entire client has 100M, and this update just modifies a 1k-sized DLL, it also means that you want to download all of the 100M content again. This is a huge waste of bandwidth, and it extends the time to upgrade, which in turn increases the customer's vacant waiting time.

In the above scenario, can we only update the modified 1k DLL when we upgrade automatically? Of course, this can be done easily by using the Oaus automatic upgrade system. The Oaus automatic upgrade system can be versioned for each file in the client program being distributed, and each upgrade of the base unit is no longer the entire client program, but a single file within it. Updates for individual files, including three types:

(1) The file has been modified.

(2) The file is deleted.

(3) Add a new file.

Oaus supports these three types of file updates. Each automatic upgrade, you can change n files, delete m files, new add l files.

Two. The structure of the Oaus using 1.OAUS

Oaus provides server-side programs and client programs that can be executed directly: AutoUpdaterSystem.Server.exe and AutoUpdater.exe. The directory structure of the Oaus server is as follows:

Oaus between the client and server through TCP communication, you can configure which TCP port the server provides for automatic upgrade services in the AutoUpdaterSystem.Server.exe.config configuration file.

The Filefolder folder is initially empty and is used to deploy the latest version of each file of the program being distributed. Note that the file structure under it must be fully consistent with the structure of the program being distributed properly-that is, the equivalent of deploying a distributed program under the Filefolder folder.

The directory structure of the Oaus client is as follows:

You can configure the IP, port, and other information for the Oaus server in the AutoUpdater.exe.config configuration file, as follows:

<Configuration>  <appSettings>    <!--Server IP -    <AddKey= "ServerIP"value= "127.0.0.1"/>    <!--Server Port -    <AddKey= "ServerPort"value= "4530"/>    <!--The name of the executable program that will be recalled after the upgrade is completed -    <AddKey= "Callbackexename"value= "Demo.exe"/>    <!--title of the main form -    <AddKey= "Title"value= "File Update"/>  </appSettings></Configuration>

Note The callbackexename of the configuration, which represents the name of the EXE that will be launched after the upgrade is complete. Why is this callbackexename configuration a name instead of a path? This is because there are requirements when using and deploying Oaus clients:

(1) The executable EXE of the program being distributed must be located in the root directory of the deployment directory.

(2) The Oaus client (that is, the entire Autoupdater folder) must also be located in this root directory.

So, autoupdater know the EXE of the distribution program relative to their own path, so you can determine the distribution program EXE's absolute path, so you can start the target EXE after the upgrade is complete. In addition, according to the above two conventions, combined with the previous service side of the Filefolder folder structure convention, when the server update a file, Autoupdater can determine the file on the client machine absolute path.

2. Oaus Automatic upgrade process

Below we will explain in detail how to use Oaus to build the automatic upgrade system, the approximate steps are as follows.

(1) Run the Oaus service side.

(2) Put all the contents of the client program being distributed to the Filefolder folder on the Oaus server, and its structure is exactly the same as the structure of the client program after normal deployment. Let's take the example of deploying Videochatsystem.

(3) Use the Oaus server to generate a default version number for each file of the client program being distributed and create a version information profile Updateconfiguration.xml. This configuration file will also be used by the client.

Clicking on the "File Versioning" button on the server interface will bring up the "File version information" form for managing individual file versions.

   

When the new version of the file overwrite the old file, click on the " Auto scan " button, the server will retrieve the Filefolder folder file name, size, last update time, and then the results of this update: changed several files, several new files, deleted several files. The automatic scanning function simplifies all previous manual operations.

If manual action is required, you can do this:

Double-click any row in the list to modify the value of the version of its corresponding file (numeric value of type int). Note that the version information in this list can have no connection with the real version of the file property (such as the DLL's version attribute x.x.x.x), and the value of the version in the list is only used to mark whether the file has been modified, so the value of the corresponding version in the list should be increased each time the file is modified.

When you close the file version information form, the value of the last composite version (int type) increments by 1 as long as there is a file version change. By comparing the value of the "last consolidated version" Saved by the Oaus client with the latest "final comprehensive version" of Oaus's server, it is possible to quickly identify whether the client is already the latest version.

In addition, the first time you open this window, you will automatically generate a version information profile updateconfiguration.xml in the directory on the Oaus server. Also, Updateconfiguration.xml automatically synchronizes updates whenever a new version of a file is set up through the form.

(4) Add Updateconfiguration.xml to the Oaus client program (that is, the Autoupdater folder above).

(5) When creating the Setup program for the distributed client, the Oaus client (that is, the Autoupdater folder) is also packaged and, as previously stated, deployed directly under the running Directory (basedirectory) (the same directory as the distributed EXE).

So, the preparation is done, and when the client installs the Videochatsystem through the installation package, its directory structure looks like this:

(6) When we have a new version to publish, such as to update a file (because the file is modified), then you can do this:

A. Copy the modified file to the correct location (or overwrite the old file) under the Filefolder folder on the Oaus server.

B. On the Oaus server, open the file version information form, double-click the row for the modified file, modify the version number of the corresponding file on the popup form, and increase the number of the version. (You can also do this if you delete old files or add new files)

(7) This way, when the client restarts AutoUpdater.exe, it will automatically upgrade and update the files that have changed. The following is the AutoUpdater.exe after the run-up.

(8) When the upgrade is complete, the callback exe configured in the Oaus client configuration file described above will be started. (In this case, VideoChatSystem.exe)

(9) The Oaus client records each automatic upgrade in the log file UpdateLog.txt (under Autoupdater's folder, which is automatically generated when the Oaus client first runs).

(10) If the upgrade process, the connection with the server is interrupted, it will automatically reconnect, after the reconnection succeeds, will start the breakpoint to resume.

3. When do I start the auto-upgrade client?

If a system is a download client, how does the client know if a new version is available? And then when is it time to start AutoUpdater.exe?

Our experience is this: after the client login succeeds, the value of the "last consolidated version" is obtained from the server, and then compared to the local "last synthetic version" value, if the local value is small, the client needs to be updated. This process can do this:

(1) When a new file is placed under the Filefolder folder on the Oaus server and the version number is updated correctly through the file version information form, the value of the final composite version is automatically added 1 when the file version information form is closed.

(2) The system client can call Oaus.core. The static method of the Versionhelper class hasnewversion () to determine if there is a new version.

(3) If the Hasnewversion method returns True, there are usually two modes: the user chooses whether to upgrade, or to force the upgrade.

In general, if the latest client program is compatible with older versions and does not have a significant impact, it can be left to the user to decide whether to upgrade, or if the latest client program is incompatible with the old version, or if there is a major update, a forced upgrade will be initiated. If the process is going to start the upgrade, just start the Autoupdater folder under AutoUpdater.exe. Note that after starting the AutoUpdater.exe process, to exit the current client process, some files may fail because they cannot be overwritten. The code is roughly as follows:

if(Versionhelper. Hasnewversion (Oausserverip,oausserverport))   {             stringUpdateexepath = AppDomain.CurrentDomain. BaseDirectory +"Autoupdater\\autoupdater.exe"; System.Diagnostics. Process myprocess=System.Diagnostics. Process.            Start (Updateexepath); ......//exiting the current process}
Three. Related Downloads

1. Automatic upgrade system Oaus-source code

2. Automatic Upgrade system Oaus (can be deployed directly)



C # Implementation of automatic upgrade (with source)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.