Share a client program (winform) Automatic Upgrade Program, ideas + instructions + source code, winform Automatic Upgrade

Source: Internet
Author: User

Share a client program (winform) Automatic Upgrade Program, ideas + instructions + source code, winform Automatic Upgrade

No matter whether auto update is used for winform programs, at least you have thought about how auto update is implemented.

I will share a set of automatically updated versions here, which will help those who have not started writing them. I also hope that some experts will come and give some suggestions on optimization.

At the beginning, I used a socket to transmit files. Later, due to an exception in uploading large files, there was no protocol defined in the early stage. Later, I switched to webservices.

Automatic Updates are divided into three parts,Server (webservice Service, configuration and update), configuration client (or publish client), client (Main Program)

Server:

ConfigServer. asmx

Because the code is shared, the code will not be passed. Send it.

Interacts with the configuration client, releases files (uploads software), and maintains versions.

In order to consider the issue of large files, each upload is a packet transfer. UploadFileModel is the definition of a packet, which is determined by the configuration end.

Public class UploadFileModel {string _ RelativePath; // <summary> // relative path // </summary> public string RelativePath {set {_ RelativePath = value ;} get {if (_ RelativePath! = String. Empty & _ RelativePath. Substring (_ RelativePath. Length-1 )! = "\") {_ RelativePath + = "\";} return _ RelativePath ;}} /// <summary> /// file name /// </summary> public string FileName {set; get ;} /// <summary> /// file stream /// </summary> public byte [] FileStream {set; get ;} /// <summary> /// start the file location /// </summary> public int StartPosition {set; get ;} /// <summary >/// whether the file has been transferred // </summary> public bool IsFinish {set; get ;} /// <summary> /// the length of the entire file stream /// </summary> public long FileStreamLength {set; get ;} /// <summary> /// Last Update Time of the object /// </summary> public DateTime FileLastTime {set; get ;} /// <summary> /// current package number /// </summary> public int CurrentPackIndex {set; get ;} /// <summary> /// Total number of packages /// </summary> public int MaxPackIndex {set; get ;}}

The content of the uploaded file may contain subfolders. The relative path is configured here.

UpdateServer. asmx interacts with the client to download the files to be updated.

      

There are two services: GetFileList to get the file list and filter the file information to be updated using the version number of the local file.

GetFile is used to update the file. RequestFileModel defines the file stream of the specified length of the file to be requested (in fact, it can be downloaded by subcontracting. How to subcontract the file is defined by the client)

Public class RequestFileModel {// <summary> // File id /// </summary> public long FileId {set; get ;} /// <summary> /// start the file location /// </summary> public int StartPosition {set; get ;} /// <summary> /// read the length of the file stream (How many bytes are read at a time) /// </summary> public int ReadFileLength {set; get ;}}

  

Configure the client:

The operations on the main interface are relatively simple. Note that a release folder is selected during the release. The file to be released is specified by this folder because the relative path is to be obtained.

The specific process code for uploading files will not be sent. You can download the source code and check the packet sending. Instead, you can calculate the bytes sent each time and tell the server how much it has been sent.

Update the client:

The Update client I wrote here is relatively simple, but it is not automatic. You need to click it manually. You can change it as needed, or you don't need to use this interface because the upload operations are encapsulated.

The local file information is recorded through a FileInfo. data file.

There are three configuration items in app. config.

DownloadPath is the folder to which the updated file is stored.

UpdateServerUrl is the service address of webservices.

The main program to be updated after the MainApp is updated is called by the Process. Start () method.

After all files are downloaded, The FileInfo. data file is updated.

 

Finally, we will summarize the overall process of Automatic Updates:

1. Access the Update service to obtain information about all files.

2. Compare the Server File Information with the local file information to filter out the file information to be downloaded;

3. download the file to be updated and save it to the specified directory.

4. If the specified directory exists, replace the files in the specified directory with the existing program files, delete the updated folders and all files, and start the main program;

5. Start the main program and replace the update program (if an update is required, the updated program will put the alias in the same directory)

 

In the shared code, the webservices end has two class libraries. For this data operation, the configuration content is stored in the sqlite library, which can be found under the bin.

 

Source code download

 

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.