Obtain the Winamp NSIs tutorial

Source: Internet
Author: User

Habit of creating NSIs scripts: Create an include directory to save the files used for installation ,. the NSI file is placed in the parent directory of include, and a resource is created in the include directory to save some resource file comparison labels, interface bitmaps, and self-modified UIS.

Then analyze the official installation program. Well, first clear the Temporary Folder to find something convenient, then start the installation program, and then find an nxxx in the temporary directory. in a directory such as TMP, there are some released resources, such as gaydata.ini?modern-header.bmp, classic256.bmp, modern256.bmp, and opt2page. INI, opt3page. ini. Those figures can be understood at a glance, without explanation, gaydata. INI, there are definitions from sec0 to sec47, so we can determine that there are a total of 47 segments, and the segment name is based on gaydata. INI to determine, how to know is based on gaydata. INI to confirm, you find the temporary directory (that is, the $ pluginsdir directory in NSIs) When the installation program is started (when the license page is displayed ), change the name of a partition, for example, change "Winamp (required)" to AAA. When you enter the component selection page, the first one is AAA. If you change "Winamp (required) "If it is cleared, the first section will disappear. Opt2page. ini and opt3page. ini are the last two pages used to select the connection method and appearance. After analysis, you can start ......

1. Create a basic structure

First, define the version number equivalent in the script header, such

! Deprecision version "5.05"
! Define version_num" 505"

In this way, you can change the version number in the script header.
Define the output file name to facilitate switching between the full, pro, and lite versions.

! Define file_name "Winamp $ {version_num} _ full"

For more information about the definition, see here.

Next, it is the setup of the installer attributes. The required settings include:
Name "Winamp"
OUTFILE "too many file_namecmd.exe"

Of course

Setcompressor lzma

It should also be necessary. lzma not only has a much larger compression ratio, but also an inaccurate attribute is that it is much faster to start, and then another section constitutes the main part and can be compiled.

Section "main program"
Sectionend

2. insert page

First

! Include "Mui. nsh"

In this way, some NSIs macros can be used to insert pages. The page to be inserted is

! Insertmacro mui_page_license "./resource/license.txt"
! Insertmacro mui_page_components
! Insertmacro mui_page_directory
! Insertmacro mui_page_components
! Insertmacro mui_page_instfiles
! Insertmacro mui_unpage_confirm
! Insertmacro mui_unpage_instfiles

Insert language

! Insertmacro mui_language English

3. Complete setup property settings
Of course, some settings need to be added to the attributes of the installer.

Brandingtext "Nullsoft install System -- built on $ {__ date __} at $ {__ time __}"

This is the personal identifier of setup.

Installdir "$ ProgramFiles/Winamp"

Set a default installation path

Installdirregkey hkcu "software/Winamp """

The path saved in the registry is read first. If the path exists, it is saved in the registry.

4. Settings page
Icon Definition

! Define mui_icon "./resource/Inst. ICO"
! Define mui_unicon "./resource/uninst. ICO"

The installer and uninstall icons are defined.

! Define mui_headerimage

Displays a bitmap at the top of the installer.

! Define mui_headerimage_bitmap "./resource/modern-header.bmp"

Define the bitmap to be displayed, which must be on the local machine

! Define mui_componentspage_nodesc

The specified component selection page does not use the description area.

5. Set page text

! Define mui_licensepage_text_top "please read and agree to the license terms below before installing ."

Specify the text displayed at the top of the license page

! Define mui_componentspage_text_top "This will install Winamp $ {version}. This installer contains the full install ."

Specify the component to select the text at the top of the page

! Define mui_directorypage_text_top "setup has determined the optimal location to install. If you wowould like to change the folder, do so now ."

Specify the text of the Directory selection page

! Define mui_abortwarning

When you press the cancel button, the system prompts whether to exit.

6. Set the installation type and complete all the sections.

Insttype "full"
Insttype "standard"
Insttype "Lite"
Insttype "minimal"

There are four installation types in total, and a custom type system will be automatically added without intervention

Then, you can create 46 CIDR blocks with a total of 47, which can be named at will, because the CIDR Block name will be named by gaydata. ini later, for example

Section ""
Sectionend

7. oninit Function

This function starts to execute the code when the installation program GUI is started. The resource files should be released to the user's computer for use at this stage.

Initpluginsdir

Initialize $ pluginsdir, that is, the plug-in directory.

File "/oname = $ pluginsdir/gaydata. ini" "./resource/gaydata. ini"
File "/oname = $ pluginsdir/opt2page. ini" "./resource/opt2page. ini"
File "/oname = $ pluginsdir/opt3page. ini" "./resource/opt3page. ini"
File "/oname = $ pluginsdir/classic256.bmp" "./resource/classic256.bmp"
File "/oname = $ pluginsdir/modern256.bmp" "./resource/modern256.bmp"

Because using file in. oninit will take a long time to search for the program during startup, you should also use reservefile. For details about reservefile, see here.
In! Include "Mui. nsh" added above

Reservefile "./resource/gaydata. ini"
Reservefile "./resource/opt2page. ini"
Reservefile "./resource/opt3page. ini"
Reservefile "./resource/classic256.bmp"
Reservefile "./resource/modern256.bmp"
Reservefile "$ {nsisdir}/plugins/installoptions. dll"

Because installoptions. dll must be used on the custom interface

8. Hide and display components
Careful friends have seen two scripts! Insertmacro mui_page_components, the component selection page appears twice. Check gaydata. ini and you will know that sec0 to sec36 is displayed for the first time, and sec37 to SEC 47 is displayed for the second time.
For more information about the page, see here.
Each page has three functions: PRE, show, and leave. They are pre-loaded, displayed, and left. On the Mui interface, you can use the defined method to insert functions. For example, in! Before insertmacro mui_page_components (after the previous page is inserted), define a mui_page_customfunction_pre function to insert a pre-load function. In this script, the following definitions are made on the first component selection page:

! Define mui_page_customfunction_pre componentpre
! Define mui_page_customfunction_show componentshow

The componentpre and componentshow functions are defined above. Of course, the function names can be defined at will, but generally the names must express their meanings for ease of reading.

You need to define some content before creating these two functions.

! Define section_component_end 36
! Define section_asscoiation_start 37
! Define section_total 47

As defined above, 36 is the index of the last segment of the component to be installed, 37 is the index number of the Start segment of the file association, and 47 is the total number of segments. The contents of the componentpre function are as follows:

Function componentpre
Push $0
Push $1

Call sectiontextreset

Strcpy $1 0
Loop:
Readinistr $0 "$ pluginsdir/gaydata. ini" "secnames" Sec $1"
Strcmp $0 "" 0 + 2
Sectionsettext $1 ""
Strcmp $1 $ {section_component_end} loop_quit
Intop $1 $1 + 1
Goto Loop
Loop_quit:

Strcpy $1 $ {section_asscoiation_start}
Sectionsettext $1 ""
Strcmp $1 $ {section_total} + 3
Intop $1 $1 + 1
Goto-3

Pop $1
Pop $0
Functionend

This function calls the sectiontextreset function. The sectiontextreset function is as follows:

Function sectiontextreset
Push $ R0

Strcpy $ R0 0
Sectionsettext $ R0 ""
Strcmp $ R0 $ {section_total} + 3
Intop $ R0 $ R0 + 1
Goto-3

Pop $ R0
Functionend

The sectiontextreset function forms a loop. $ R0 increments from 0 until it is equal to $ {section_total} And then jumps out of the loop. This loop resets the names of all segments to spaces, the pre-loaded functions on both mui_page_components pages are called once. This is because the show function hides some segments, that is, it sets the segment name to a null value. It must be given a name in the PRE stage of the next mui_page_components page, otherwise it will remain hidden.

After the sectiontextreset function is called, a loop reads "$ pluginsdir/gaydata. from sec0 to $ {section_component_end} of ini ", if the value read by an SEC is null, the segment is hidden, that is, the segment name is set to null. You can try the original English version. Set sec0 of "$ pluginsdir/gaydata. ini" to null at startup, and the Winamp (required) Section on the component selection page will be hidden.

It is also a loop that hides the CIDR blocks from $ {section_asscoiation_start} to $ {section_total}, because the first mui_page_components only needs to display the CIDR blocks from 0 to $ {section_component_end. The componentshow function is as follows:

Function componentshow
Push $0
Push $1

Strcpy $1 0
Loop:
Readinistr $0 "$ pluginsdir/gaydata. ini" "secnames" Sec $1"
Sectionsettext $1 $0
Strcmp $1 $ {section_component_end} loop_quit
Intop $1 $1 + 1
Goto Loop
Loop_quit:

Pop $1
Pop $0
Functionend

It is also a loop. The value of $1 increases progressively from 0 to $ {section_component_end}, and then reads gaydata from sec0 to sec36 in sequence. the corresponding value of INI, and the name of the namespace segment according to the value of the read path.

The asscoiationpre and asscoiationshow corresponding to the second component page are basically the same as the above, except that the partition indexes to be hidden are different.

9. Hide controls
When the component page is displayed for the second time, several controls are hidden. Use resource hacker to open the 104 dialog box in $ {nsisdir}/contrib/UIS/modern.exe, which is the component display page, the ID of the space to be hidden is 1017 (the installation type is displayed) and 1021 (the text displayed on the left), and 1023 (the control of the disk space display ). The command for displaying and hiding controls is showwindow. For more information, see here.
The code for hiding the control must be added to the asscoiationshow function.

Findwindow $0 "#32770" "$ hwndparent

Get a window handle and save it in $0

Getdlgitem $1 $0 1017

Get the handle of the 1017 Control

Showwindow $1 $ {sw_hide}

Hide the 1017 control. The hidden commands of the other controls are as follows:

Getdlgitem $1 $0 1021
Showwindow $1 $ {sw_hide}
Getdlgitem $1 $0 1023
Showwindow $1 $ {sw_hide}

In addition to the control hiding, there are also two texts to be changed, because of the use! Define can only be changed for the component page displayed for the first time, so the text displayed for the second time can only be changed by sendmessage.

Getdlgitem $1 $0 1006
Sendmessage $1 $ {wm_settext} 0 "str: select which icons you want installed, and whether you want files and CDs associated"
Getdlgitem $1 $0 1022
Sendmessage $1 $ {wm_settext} 0 "str: Select icons to install and media associations :"

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.