Location:Index > News >

Create online install package using nsNiuniuSkin

Browsing History: 170Date: 2023-12-04

In certain installation scenarios, the complete installation package can be large, leading to long download times and requiring manual intervention for installation. This can significantly reduce the user experience. The nsNiuniuSkin installation package solution offers an online version of the installation package, allowing the actual installation content to be hosted on a server. The installation package program then downloads and installs it automatically. The online installation package created can be kept under 1MB, making it convenient for distribution and promotion.

Implementation Principle

In the nsNiuniuSkin installation package solution, the scripts for online installation and complete installation are the same, except that during compilation, a macro is defined: INSTALL_DOWNLOAD_7Z (dynamically passed through a batch script without modifying the script). When this macro is defined, the installation process will include a download step. During the download, information such as the total size of the installation files, download speed, and download completion percentage is displayed, indicating the download progress. After the download, the files are unpacked, and the installation progress is seamlessly integrated with the download process.

It's worth mentioning that the program downloaded is a 7z file (compressed from a list of all files under the FilesToInstall directory). After the installation program is downloaded, the nsis7zU plugin is used to extract and install it.

!ifdef INSTALL_DOWNLOAD_7Z
   # Online installation package
   nsNiuniuSkin::SetControlAttribute $hInstallDlg "slrProgress" "value" "0"
   nsNiuniuSkin::SetControlAttribute $hInstallDlg "progress_pos" "text" ""   
   nsNiuniuSkin::SetControlAttribute $hInstallDlg "progress_tip" "text" "[msg.downloading]"
   # Start downloading the online data package
   GetFunctionAddress $0 DownloadFile
   BgWorker::CallAndWait
   Pop $R4   
   # Retrieve the download result and check if it was successful and verified  
   ${If} "$R4" != "0"       
        Pop $R5
        StrCpy $R5 "[msg.downloadfailed]: $R5"
        nsNiuniuSkin::SetControlAttribute $hInstallDlg "progress_tip" "text" "$R5"
        nsNiuniuSkin::SetControlAttribute $hInstallDlg "progress_tip" "textcolor" "#fff43a3a"
        nsNiuniuSkin::SetControlAttribute $hInstallDlg "btnClose" "enabled" "true"
        StrCpy $InstallState "2"
        goto InstallAbort
   ${EndIf}
!endif
   # Reset the progress bar and start the installation
   nsNiuniuSkin::SetControlAttribute $hInstallDlg "slrProgress" "value" "0"
   nsNiuniuSkin::SetControlAttribute $hInstallDlg "progress_pos" "text" ""   
   nsNiuniuSkin::SetControlAttribute $hInstallDlg "progress_tip" "text" "[msg.installing]"

   # Start a low-priority background thread
   GetFunctionAddress $0 ExtractFunc
   BgWorker::CallAndWait

Prerequisites

For online installation, the actual data package needs to be downloaded from a server. Therefore, a server supporting HTTP or HTTPS download is required.

Because errors may occur during the download of online installation files, the downloaded files are checked for MD5 and size after downloading. This is to prevent missing or corrupted files. Therefore, before downloading the 7z file, a configuration file is downloaded first. This file identifies the software package's name, size, and MD5 values (later configurations can specify to skip this check). The server URL for config.ini and app.7z is assumed to be http://www.ggniu.cn/test_online_install/. Next, the generated files need to be uploaded to the corresponding server directory under http://www.ggniu.cn/test_online_install/.

Actual Application

To keep the online installation package as small as possible, the uninstallation program is not directly packaged into the installation package. Instead, it is packaged into the data file app.7z. With the server environment set up, we can proceed with the actual packaging. During the packaging of the online installation package, the following steps are taken:

Pre-packaging Configuration

Before actual packaging, the server URL paths mentioned earlier need to be configured. In the NSI file, macros control the download path of the online installation package data file:

# ====================== Custom Macros for Online Installation Control ========================
!define INSTALL_DOWNLOAD_BASEURL    "http://www.ggniu.cn/test_online_install/"
!define INSTALL_DOWNLOAD_CONFIG        "config.ini"

Skip Verification Configuration If verification of the installation package size and MD5 value is not required during download, the configuration is as follows:

# ====================== Custom Macros for Online Installation Control ========================
!define INSTALL_DOWNLOAD_BASEURL    "http://www.ggniu.cn/test_online_install/"
!define INSTALL_DOWNLOAD_CONFIG        "config.ini"
!define INSTALL_DOWNLOAD_IGNOREMD5    0                     # If enabled, do not read the configuration, skip MD5 check, and download directly
!define INSTALL_DOWNLOAD_SERVERFILENAME    "app1.7z"    # This is the file name on the server, will be appended to BASEURL for download
!define INSTALL_DOWNLOAD_INITSIZE    80102400               # Approximate size of the server file when not checking, used for displaying progress

Once configured, you can compile the corresponding batch script (the one with "online" in its filename) to generate the online installation package and the data file package for online installation. Upload the data file package and configuration file (app.7z and config.ini) to the specified server directory, and the entire process is complete. Now you can use the online installation package for installation.

Note: The online installation package and data package do not require a one-to-one match, meaning online installation packages and data packages created in different runs can be applied interchangeably. When upgrading the online installation package later, if the interface and download logic remain unchanged, only the data package needs to be updated!

Installation Effect

As you can see, the size of the compiled online installation package is approximately 860KB:

The following shows the complete effect of online installation:

More Flexible Extensions

Currently, the download and installation share the same progress bar, meaning the download progress goes from 1 to 100%. After the download is complete, the progress bar resets to zero, and then the installation progress goes from 1 to 100%. If you want the download to occupy only the first 50% and the installation to occupy the next 50%, you can make a few modifications to the progress callback display.

Conclusion

During the installation process, an exquisite UI can leave a lasting impression on customers about the installed product, showcasing the software provider's dedication and attention to user experience. We hope our efforts make the installation package creation a bit easier and more enjoyable.

May there be no difficult installation packages in the world!

Copyright © 2015 - 2023 SHENZHEN LEEQIA TECHNOLOGY CO., LTD All Rights Reserved