Design and Implementation of Automatic System Upgrade (source code)

Source: Internet
Author: User

For PC desktop applications, automatic upgrade is often essential. The automatic upgrade can be developed as an independent C/S system, so that it can be reused in different desktop applications. Based on the file transfer function of esframework, I implemented a reusable automatic upgrade system, oaus, and now I will share it with you. This article focuses on the background and usage of us. For detailed implementation details, you can directly download the source code. If you understand the use of oaus, it is very easy to understand the source code. If you need to directly deploy and use the automatic upgrade system, you can download the executable program compressed package at the end of this article.

I. Main Functions of oaus

Currently, the mainstream automatic program upgrade policy is to re-download the latest installation package and then reinstall the entire client. This method is simple and intuitive, but its defects are also obvious. For example, even if the entire client has 100 MB, and this update only modifies a 1 k dll, it also means to download all the content of MB. This is a great waste of bandwidth, and it has extended the upgrade time, and correspondingly increased the waiting time of the customer.

In the above scenario, can we update only the modified 1 k dll during automatic upgrade? Of course, it is easy to use the automatic upgrade System of us. The automatic upgrade System of us can manage versions of each file in the distributed client program. The basic unit for each upgrade is not the entire client program, but a single file. Update a single file in three forms:

(1) The file is modified.

(2) The file is deleted.

(3) Add a new file.

Oaus supports these three forms of file updates. Each automatic upgrade can change n files, delete M files, and add new L files.

Ii. Use of oaus 1. Structure of oaus

Oaus provides directly executable server programs and client programs: autoupdatersystem.server.exe and autoupdater.exe. The directory structure of the oaus server is as follows:

Through tcpcommunication between the client and the server, you can configure the TCP port through which the server provides the automatic upgrade service in the autoupdatersystem.server.exe. config configuration file.

The filefolder folder is initially empty and is used to deploy the latest versions of each file of the program to be distributed. Note that the file structure under it must be exactly the same as that of the program to be distributed after normal deployment-that is, it is equivalent to deploying a program to be distributed under the filefolder folder.

The directory structure of the oaus client is as follows:

You can configure the IP address and port of the US us server in the autoupdater.exe. config configuration file, as shown in the following figure:

<Configuration> <etettings> <! -- Server IP --> <add key = "serverip" value = "127.0.0.1"/> <! -- Server port --> <add key = "SERVERPORT" value = "4530"/> <! -- After the upgrade, the name of the executable program to be called back --> <add key = "callbackexename" value = "demo.exe"/> <! -- Title of the main form --> <add key = "title" value = "file update"/> </appsettings> </configuration>

Pay attention to the configured callbackexename, which indicates the name of the EXE of the dispatching program to be started after the upgrade is complete. Why is the callbackexename configured by name instead of path? This is because there are requirements for using and deploying the oaus client:

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

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

In this way, autoupdater knows the relative path of the distribution program's exe, so that it can determine the absolute path of the distribution program's exe, so you can start the target EXE after the upgrade is complete. In addition, according to the above two conventions, combined with the structure conventions of the filefolder folder of the server mentioned above, when the server updates a file, autoupdater can determine the absolute path of the file on the client machine.

2. Automatic Upgrade process for us

The following describes how to use oaus to build an automatic upgrade system. The steps are as follows.

(1) run the oaus server.

The main interface of the server displays information about all the OA clients that are being automatically upgraded.

(2) Place all the content of the client program to the filefolder folder of the oaus server. The structure of the client program should be exactly the same as that of the client program after normal deployment. We deploy videochatsystem as an example.

(3) use the oaus server to generate a default version number for each file of the distributed client program, and create the updateconfiguration. XML version configuration file. This configuration file will also be used by the client.

Click the version management sub-menu under tools on the server. The file version information form for managing each file version is displayed.

Double-click any row in the list to modify the version value of the corresponding file (float type value ). Note: The version information in this list and the actual version attributes of the file (for example, the dll version attribute X. x. x. x) It can be unrelated. The version value in the list is only used to mark whether the file is modified. Therefore, each time the file is modified, the value of the corresponding version in the list should be increased.

When the [file version information] form is closed, the value (INT type) of the "Last integrated version" increases by 1 as long as a file version changes. Compare the value of the "final integrated version" Saved by the client of oaus with the value of the latest "final integrated version" of the oaus server, you can quickly identify whether the client is the latest version.

In addition, when this window is opened for the first time, a version configuration file updateconfiguration. XML is automatically generated under the directory of the oaus server. In addition, every time you use this form to set a new version of a file, updateconfiguration. XML is automatically updated at the same time.

(4) add updateconfiguration. XML to the client program (the folder of the autoupdater mentioned above) of oaus.

(5) When creating the installation program of the client to be distributed, package the client of oaus (that is, the folder of autoupdater) and, as mentioned earlier, you need to deploy it directly under the running directory (basedirectory) (the same directory as the distribution exe ).

In this way, the preparation is complete. After the client installs videochatsystem through the installation package, its directory structure is as follows:

(6) When we have a new version to be released, such as updating a file (because the file is modified), we can do this:

A. Copy the modified file to the correct location (or overwrite the old file) in the filefolder folder of the oaus server ).

B. Open the file version information form on the oaus server, double-click the row corresponding to the modified file, modify the version number of the corresponding file on the pop-up form, and increase the value of the version number. (If you want to delete an old file or add a new file, you can also perform operations here)

(7)if this is the case, when the client starts autoupdater.exe again, it will automatically upgrade and update those files that have changed. In the following example, autoupdater.exe is run.

(8) after the upgrade is complete, the callback EXE configured in the preceding oaus client configuration file will be started. (Videochatsystem.exe in this example)

(9)usus the client will log on to the log file updatelog.txt (located in the autoupdater folder and automatically generate the file when the oaus client is running for the first time) and record the status of each automatic upgrade.

3. When will automatic client upgrade be started?

If a system downloads a client, how does the client know whether a new version is available? Then why should I start autoupdater.exe?

Our experience is as follows: after successfully logging on to the client, obtain the value of "final comprehensive version" from the server and compare it with the value of the local "final comprehensive version, if the local value is small, the client needs to be updated. This process can be achieved as follows:

(1) When a new file is placed in the filefolder folder of the oaus server, and the version number is correctly updated through the [file version information] form, when you close the [file version information] form, the value of "last integrated version" is automatically added with 1.

(2) The System Client can call the static hasnewversion () method of the autoupdater. versionhelper class to determine whether a new version exists.

(3) If the hasnewversion method returns true, there are two modes: whether to upgrade or force upgrade.

Generally, if the latest client program is compatible with the old version and does not affect the upgrade, you can decide whether to upgrade it. If the latest client program is not compatible with the old version or has a major update, the Force upgrade will be started. If the process is to be imported into the startup upgrade, you only need to start autoupdater.exe in the file folder of autoupdater. To disable the current client process, after the autoupdater.exe process is started, some files may fail to be overwritten. The code is roughly as follows:

If (versionhelper. hasnewversion (oausserverip, oausserverport) {string updateexepath = appdomain. currentdomain. basedirectory + "autoupdater \ autoupdater.exe"; system. diagnostics. process myprocess = system. diagnostics. process. start (updateexepath );...... // exit the current process}
Iii. Related downloads

1. automatically upgrade the system to us US-source code

2. automatically upgrade the system OA us (which can be directly deployed)

If you have any suggestions or questions, please leave a message to me.

 

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.