Share a client program (WinForm) automatic upgrade program, ideas + instructions + source code

Source: Internet
Author: User

Do WinForm program, no matter with no use of automatic updates, at least think of how Automatic updates are implemented.

I am here to share a set of automatic Updates, to the people who have not yet started to write some help, but also hope that the great God came to give guidance to optimize the opinion.

At the beginning, I was through the socket to transfer files, and later because of the large file to appear abnormal, the previous period did not define a better protocol, and then switched to WebServices.

Automatic Update in three parts, server (WebService service, configuration and update), configure client (or call publishing client), client (main program)

service side:

Configserver.asmx

Because the code is shared, do not pass the code, send a bar.

      Responsible for interacting with the configuration client, the release of the file (software upload), and version maintenance.

Here in order to consider the problem of large files, each upload is a sub-packet transmission. Uploadfilemodel is the definition of subcontracting, which is determined by the configuration side to determine the sub-package value.

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)! = "\") {_RELATIVEP                Ath + = "\";            } return _relativepath;  }}///<summary>/////</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 to complete the transfer of the file///</summary> public bool Isfinish {set; Get }///<summary>///The length of the entire file stream///</summary> public long filestreamlength {set; GE T }///<summary>//The last updated time for the file///</summary> public DateTime filelasttime {set; g Et }///<summary>///is currently the first package///</summary> public int Currentpackindex {set; get;    }//<summary>///Total packages///</summary> public int Maxpackindex {set; get;} }

Consider uploading the contents of the file may contain subfolders, where there is a relative path configuration.

Updateserver.asmx is responsible for interacting with the client to download files that need to be updated.

      

There are two services, Getfilelist gets the file list, and the local file filters out the file information to be updated with the version number.

GetFile is used to update the file, Requestfilemodel defines the file stream for the specified length of the file to be requested (in fact, it can be downloaded by sub-package, specifically, how the sub-package is client-defined)

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;}    }

  

To Configure the client:

The main interface operation is relatively simple, it is important to note that when publishing is to select a publishing folder, the file to be published by the folder specified, because to get the relative path.

upload the file's specific process code will not be sent, download the source to see for themselves, sub-package sent, but to calculate the bytes sent each time, tell the server how much, is not finished.

Update client:

I write the update client is relatively simple is not automatic, need to manually click, this can be changed slightly depending on the needs, or simply do not use this interface, because the upload of related operations have been encapsulated.

Local file information I recorded it through a fileinfo.data file.

There are three configuration items in the App. Config.

Downloadpath is the folder under which the updated files are placed.

Updateserverurl is the service address of WebServices.

The main program that needs to be updated after the Mainapp update is completed is called by the Process.Start () method.

When all files are downloaded, the Fileinfo.data file information is updated.

Finally, summarize the overall flow of Automatic Updates:

1. Access the update service to get all the file information.

2. Compare server file information, compare with local file information, filter out the file information that need to be downloaded;

3. Download the files that need to be updated and save them 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 the files, and then start the main program;

5. Start the main program and replace the update (if necessary, the update will be placed in the same directory as the alias)

The webservices side of the shared code has two class libraries, this data operation, the configuration content is placed in the SQLite library, the two class libraries can be found under the bin.

SOURCE download

Share a client program (WinForm) automatic upgrade program, ideas + instructions + source code

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.