Nowadays, more and more software has the automatic upgrade function. When users use the software, the software automatically obtains the latest software version information from the specified server through the network, and automatically download the corresponding upgrade files to update the software version, eliminating the trouble of checking the Internet and downloading the latest software version. This is a very considerate function, to some extent, it increases the ease of use and friendliness of the software.
The automatic upgrade function of the software can be independent of the main program and has a certain degree of universality. It can be used as a separate executable program to be scheduled and run by the main program. The following are some of my experiences in designing an automatic update software on Windows.
The automatic upgrade software is an Independent Application Program (an exclusive Executable File autoupdate.exe) that allows software developers to write code and run other programs, such as calling the ShellExecute API function or using different methods in various programming languages, C language can use system functions, Visual Basic language can use shell functions, and other languages have similar methods.
The basic function of automatic software upgrade is to upgrade the software. First, you must be able to detect the latest version of the software. The software Developer Saves the latest software version information as a file in a certain format and places it to a fixed address on the network. The software is automatically upgraded to access this address to download the file to the local device, parse the file content for upgrade. The file format can be arbitrary, but considering the versatility, it is recommended to use a file format that is easy to read and easy to parse. I use the ini initialization file format (the file content in this format is saved in plain text, and the content is divided into one or more sections. The key and value pairs are stored under the section, you can obtain the corresponding value through the partition name and key name. In Windows, you can read the value through the getprivateprofile series API functions ). The communication protocol used for file download can also be arbitrary, but it is best to use common mature protocols, such as HTTP and FTP, to make full use of existing technologies, reduce the workload of developing new protocols. I use HTTP and use wininet APIs to download files. Each time the software is automatically upgraded, the information file of the latest software version is downloaded at the specified URL. The URL is passed in as a command line parameter, for example, autoupdate.exe
/Checkurl = http://www.mysite.org/updatecofig.ini. If the local configuration file already exists, you can omit this parameter. In this case, the software will read the updatecofig. ini file in the same directory to obtain the latest version of the software.
After downloading the information file of the latest software version (hereinafter referred to as the configuration file), the software will be parsed to complete the software upgrade based on the file content. The configuration file must meet certain formats. I read the appname value of the [update] section to determine whether the file format is correct, if empty content is read, the file format is incorrect and the upgrade is stopped. The configuration file contains the latest version of the software, which is used to compare with the local software version. The local software version is passed in as a command line parameter, for example, autoupdate.exe/CurrentVersion = 1.1. In the configuration file, you can define a series of operation commands, including downloading, copying, moving, deleting files, and running external programs (it is best to add functions such as creating shortcuts, modifying the registry, and registering dynamic link library files, because the time relationship has not been implemented, you can run an external program to achieve the same effect), and finally complete the software upgrade. There are usually more than one file to be updated during an upgrade. The configuration file specifies the total number of files to be downloaded (filecount), the file name (name), and the (URL) of each file) file size and the path to be updated (destpath). To ensure the correctness of the downloaded file content, the file Verification Code (hash) is also provided ), when the file is downloaded, verify the file and re-download the file that failed the verification. Some downloaded files must be updated to special directories (such as Windows Directories). When specifying destpath, you must specify replacement strings for some special directories (see Appendix 3 ), replace the copied, moved, or deleted file with the actual path.
During file replacement upgrade, if the executable file or dynamic link library already reside in the memory, the file replacement cannot be successful due to operating system protection, at this point, you need to end the program running and then replace the file, that is, the automatic upgrade program should notify the running main program that the upgrade is ready, and you need to temporarily end the program to complete the upgrade. You can send messages between application processes to transfer the upgraded messages. The target window handle, window title, and message content of the received messages are passed in with command line parameters. For example: autoupdate.exe/yywindow = 12345/notifywindowtitle = myprogram/notifyfinish = 65535,/notifywindow and/notifywindowtitle only need one of them, after the upgrade, a message of the wm_user type will be sent to the target window. The value of wparam is the value of the/policyfinish parameter.
Another feature of automatic software upgrade is that the upgrade is automated and requires few or no manual operations. The upgrade can be performed silently in the background. After the upgrade is completed, the system prompts that the software has been upgraded. Add/silence to the command line parameters to run the Automatic Upgrade Program silently. The automatic update software can also run in a window with a progress display to display the current downloaded file, download speed, completion ratio, and overall upgrade progress, this gives you a clear understanding of the upgrade process. To maintain the friendliness of software, software developers should allow users to control the Software Update behavior when scheduling automatic upgrade programs, that is, designing the main program, you can set whether to detect updates and the time period for detecting updates. Unless necessary, you should retain the option not to upgrade the software. The upgrade is only a kind of suggestion. It is best to prompt that the new version of the software is better than the features of the previous version, so that you can decide whether to upgrade the software.
To meet the needs of multi-language software, I have designed a multi-language feature in the auto upgrade software, in addition to automatically displaying different languages and prompts on the interface based on the language of the user's operating system (currently, automatic switching can be performed between Simplified Chinese, traditional Chinese, and English versions, files to be updated during software upgrade may also vary depending on the operating system language. The language code of the operating system can be obtained by calling the getsystemdefaultlangid API function. Public files are not differentiated from operating system languages, while help documents and other files often need to be differentiated from languages. Help documents in simplified Chinese are not applicable to traditional operating systems, in turn, the help documentation for traditional Chinese is not applicable to the simplified operating system. In the upgrade configuration file, you can specify the prompt information and files to be downloaded in the [language] section under the operating system of various languages.
The Automatic Upgrade Program of different software should be able to run independently without interfering with each other. However, the Automatic Upgrade Program of the same software must run only one instance, otherwise, file read/write conflicts may occur. When the automatic upgrade software is started, the name of the software to be upgraded is transmitted as an imperative, for example, autoupdate.exe/appname = myprogram/CurrentVersion = 1.1. The automatic upgrade software creates mutex Based on the software name to avoid running multiple Automatic Upgrade Program instances of the same software simultaneously.
Appendix 1: Definition of command line parameters for automatic software upgrade
Autoupdate.exe [/debug] </appname =...> </CurrentVersion =...> [/checkurl =...] [/notifywindow =...] [/notifywindowtitle =...] [/policyfinish =...] [/silence]
/Debug # enable log. Information During the upgrade will be written to the debug. log file in the same directory.
/Appname = # Name of the software to be upgraded. The auto-update software creates mutex based on this name.
/CurrentVersion = # current version of the software to be upgraded
/Checkurl = # download the URL of the upgrade configuration file (required to be HTTP)
/Yywindow = # handle for receiving notification messages after upgrade
/Notifywindowtitle = # title of the window for receiving notification messages after upgrade
/Yyfinish = # Notification Message Type sent after upgrade
/Silence # Run the automatic upgrade software in silent mode without displaying the interface or any prompts
Note: parameters enclosed by Angle brackets <> are required parameters, and parameters enclosed by square brackets [] are optional parameters. If the file path contains spaces, the full path should also be enclosed in quotation marks.
Appendix 2: update the content format of the configuration file updatecofig. ini
[Update] # basic software upgrade information
Appname = myprogram # software name, used to verify the validity of the updated configuration file
Version = 1.2.3 # Software Version
Runafterdownload=update.exe # Name of the program file to be executed after the update is complete
[Common] # public files of different language versions
Filecount = 2 # number of files to be downloaded
File1folder myprogram.exe # first file name
File21_update.exe # Second file name
File3 = # Third file name
[Language] # section name corresponding to the supported language code page
Default = ENG # default language-English
0x0404 = CHT # traditional Chinese
0x0c04 = CHT
1028 = CHT
3076 = CHT
0x0804 = CHS # Simplified Chinese
0x1004 = CHS
2052 = CHS
4100 = CHS
[ENG]
Information = new version description... # feature description of the new version is better than that of the previous version)
Filecount = 1 # number of dedicated files in English
File1 = help. chm # first file name
File2 = # Second file name
[CHT]
Information = Traditional Chinese (Traditional Chinese)
Filecount = 1 # number of dedicated files in the Traditional Chinese version
File1 = help. chm # first file name
File2 = # Second file name
[Chs]
Information = Software Update description ...... # Features of the new software version that are better than previous versions (Simplified Chinese)
Filecount = 1 # number of dedicated files in simplified Chinese
File1 = help. chm # first file name
File2 = # Second file name
[Commonfile1] # The first public file
Name1_myprogram.exe # file name
Size = 3567811 # File Size
URLs = http://www.mysite.org/download/1.2.3/MyProgram.exe # files
Compressmethod = none # File compression method
Hash = 3177d58949143219e06e5c316674ae02 # file digest code, which is obtained using the standard MD5 Algorithm
Destpath = <instdir> # File Installation path, which can contain PATH variables. See Appendix 3.
[Commonfile2] # Second Public File
Name1_update.exe # file name
Size = 172864 # File Size
URLs = http://www.mysite.org/download/1.2.3/Update.exe # files
Compressmethod = none # File compression method
Hash = 4914324ae021c3319e06e577d5894667 # file digest code, which is obtained using the standard MD5 Algorithm
Destpath = <instdir> # File Installation path, which can contain PATH variables. See Appendix 3.
[Engfile1] # The first file in English
Name = help. chm # file name
Size = 1581671 # File Size
URLs = http://www.mysite.org/download/1.2.3/Help.ENG.chm # files
Compressmethod = none # File compression method
Hash = 7d586493193219e0714e0274e5c3466a # file digest code, which is obtained using the standard MD5 Algorithm
Destpath = <instdir> # File Installation path, which can contain PATH variables. See Appendix 3.
[Chtfile1] # The first file in the Traditional Chinese version
Name = help. chm # file name
Size = 1581369 # File Size
URLs = http://www.mysite.org/download/1.2.3/Help.CHT.chm # files
Compressmethod = none # File compression method
Hash = 66a3197d58649274e5c343219e0714e0 # file digest code, obtained using the standard MD5 Algorithm
Destpath = <instdir> # File Installation path, which can contain PATH variables. See Appendix 3.
[Chsfile1] # The first file in simplified Chinese
Name = help. chm # file name
Size = 1581888 # File Size
URLs = http://www.mysite.org/download/1.2.3/Help.CHS.chm # files
Compressmethod = none # File compression method
Hash = 931932197d5864e0714e0c3466a274e5 # file digest code, which is obtained using the standard MD5 Algorithm
Destpath = <instdir> # File Installation path, which can contain PATH variables. See Appendix 3.
Appendix 3: Replacement of fixed variables in path string variables
<Instdir> # automatically update the software running directory, that is, the software installation directory.
<ProgramFiles> # windows program file directory, such as C:/Program Files
<Commonfiles> # windows public program file directory, such as C:/program files/common files
<Desktop> # user desktop directory
<WINDIR> # Windows Directory, such as C:/Windows
<Sysdir> # Windows System File directory, such as C:/Windows/system32
<Temp> # temporary file directory, such as C:/Windows/temp
<Startmenu> # Start Menu directory
<Smprograms> # program directory under the Start Menu
<Smstartup> # Start directory under the Start Menu
<Quicklaunch> # Windows Task Bar Quick Start directory
<Documents> # My document directory
<Appdata> # Application Data Directory
<Profile> # user directory, such as C:/Documents ents and settings/Administrator