Debian Codegraph @

Docs/src/generalpurpose.but

raw
1 \S1{generalpurpose} General Purpose Instructions
2
3 \S2{callinstdll} CallInstDLL
4
5 \c dllfile function_name
6
7 Calls a function named \e{function_name} inside a NSIS extension DLL, a plug-in. See the \L{../Examples/Plugin/}{example plugin} for how to make one. Extension DLLs can access the stack and variables. Note: To automatically extract and call plug-in DLLs, use a plug-in command instead of \R{callinstdll}{CallInstDLL}.
8
9 \c Push "a parameter"
10 \c Push "another parameter"
11 \c CallInstDLL $INSTDIR\somedll.dll somefunction
12
13 For easier plug-in handling, use the new \R{plugindlls}{plug-in call syntax}.
14
15 \S2{copyfiles} CopyFiles
16
17 \c [/SILENT] [/FILESONLY] filespec_on_destsys destination_path [size_of_files_in_kb]
18
19 Copies files from the source to the destination on the installing system. Useful with $EXEDIR if you want to copy from installation media, or to copy from one place to another on the system. You might see a Windows status window of the copy operation if the operation takes a lot of time (to disable this, use /SILENT). The last parameter can be used to specify the size of the files that will be copied (in kilobytes), so that the installer can approximate the disk space requirements. On error, or if the user cancels the copy (only possible when /SILENT was omitted), the error flag is set. If /FILESONLY is specified, only files are copied.
20
21 Fully-qualified path names should always be used with this instruction. Using relative paths will have unpredictable results.
22
23 \c CreateDirectory $INSTDIR\backup
24 \c CopyFiles $INSTDIR\*.dat $INSTDIR\backup
25
26 \S2{createdirectory} CreateDirectory
27
28 \c path_to_create
29
30 Creates (recursively if necessary) the specified directory. The error flag is set if the directory couldn't be created.
31
32 You should always specify an absolute path.
33
34 \c CreateDirectory $INSTDIR\some\directory
35
36 \S2{createshortcut} CreateShortcut
37
38 \c [/NoWorkingDir] link.lnk target.file [parameters [icon.file [icon_index_number [start_options [keyboard_shortcut [description]]]]]]
39
40 Creates a shortcut 'link.lnk' that links to 'target.file', with optional parameters 'parameters'.
41 You must specify an absolute path to the .lnk file.
42 The icon used for the shortcut is 'icon.file,icon_index_number'; for default icon settings use empty strings for both icon.file and icon_index_number.
43 start_options should be one of: \e{SW_SHOWNORMAL}, \e{SW_SHOWMAXIMIZED}, \e{SW_SHOWMINIMIZED}, or an empty string.
44 keyboard_shortcut should be in the form of 'flag|c' where flag can be a combination (using |) of: \e{ALT}, \e{CONTROL}, \e{EXT}, or \e{SHIFT}. c is the character to use (a-z, A-Z, 0-9, F1-F24, etc). Note that no spaces are allowed in this string. A good example is "ALT|CONTROL|F8". $OUTDIR is stored as the shortcut's working directory property. You can change it by using \R{setoutpath}{SetOutPath} before creating the shortcut or use /NoWorkingDir if you don't need to set the working directory property.
45 description should be the description of the shortcut, or comment as it is called under XP.
46 The error flag is set if the shortcut cannot be created (i.e. either of the paths (link or target) does not exist, or some other error).
47
48 \c CreateShortcut "$DESKTOP\My Program.lnk" "$INSTDIR\My Program.exe"
49 \c CreateDirectory "$SMPROGRAMS\My Company"
50 \c CreateShortcut "$SMPROGRAMS\My Company\My Program.lnk" "$INSTDIR\My Program.exe" \
51 \c "some command line parameters" "$INSTDIR\My Program.exe" 2 SW_SHOWNORMAL \
52 \c ALT|CONTROL|SHIFT|F5 "a description"
53
54 \S2{getwinver} GetWinVer
55
56 \c user_var(output) Major|Minor|Build|ServicePack
57
58 Gets the Windows version as reported by GetVersionEx. WinVer.nsh is the preferred method for performing Windows version checks.
59
60 \c GetWinVer $1 Build
61
62 \S2{getdllversion} GetDLLVersion
63
64 \c [/ProductVersion] filename user_var(high dword output) user_var(low dword output)
65
66 Gets the version information from the DLL (or any other executable containing version information) in "filename". Sets the user output variables with the high and low dwords of version information on success; on failure the outputs are empty and the error flag is set. The following example reads the DLL version and copies a human readable version of it into $0:
67
68 \c GetDllVersion "$INSTDIR\MyDLL.dll" $R0 $R1
69 \c IntOp $R2 $R0 / 0x00010000
70 \c IntOp $R3 $R0 & 0x0000FFFF
71 \c IntOp $R4 $R1 / 0x00010000
72 \c IntOp $R5 $R1 & 0x0000FFFF
73 \c StrCpy $0 "$R2.$R3.$R4.$R5"
74
75 \S2{getdllversionlocal} GetDLLVersionLocal
76
77 \c [/ProductVersion] localfilename user_var(high dword output) user_var(low dword output)
78
79 This is similar to \R{getdllversion}{GetDLLVersion}, only it acts on the system building the installer (it actually compiles into two \R{StrCpy}{StrCpy} commands). Sets the two output variables with the DLL version information of the DLL on the build system. Use \R{ppgetdllversion}{!getdllversion} if you need to use the values with \R{viproductversion}{VIProductVersion}.
80
81 \S2{getfiletime} GetFileTime
82
83 \c filename user_var(high dword output) user_var(low dword output)
84
85 Gets the last write time of "filename". Sets the user output variables with the high and low dwords of the FILETIME timestamp on success; on failure the outputs are empty and the error flag is set.
86
87 \S2{getfiletimelocal} GetFileTimeLocal
88
89 \c localfilename user_var(high dword output) user_var(low dword output)
90
91 This is similar to \R{getfiletime}{GetFileTime}, only it acts on the system building the installer (it actually compiles into two \R{StrCpy}{StrCpy} commands). Sets the two output variables with the file timestamp of the file on the build system.
92
93 \S2{getknownfolderpath} GetKnownFolderPath
94
95 \c user_var(output) knownfolderid
96
97 Get the path of a \W{https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid}{known folder}. The error flag is set and the output variable is empty if the call fails or the knownfolderid guid is not available. This function is only able to resolve known folders on Windows Vista or higher.
98
99 \c !include WinCore.nsh
100 \c !include LogicLib.nsh
101 \c
102 \c Function .onInit
103 \c ${If} $InstDir == ""
104 \c GetKnownFolderPath $InstDir ${FOLDERID_UserProgramFiles} ; This exists on Win7+
105 \c StrCmp $InstDir "" 0 +2
106 \c StrCpy $InstDir "$LocalAppData\Programs" ; Fallback directory
107 \c StrCpy $InstDir "$InstDir\$(^Name)"
108 \c ${EndIf}
109 \c FunctionEnd
110
111 \S2{getfullpathname} GetFullPathName
112
113 \c [/SHORT] user_var(output) path_or_file
114
115 Assign the full path of the file specified to user variable $x. If the path portion of the parameter is not found, the error flag will be set and $x will be empty. If /SHORT is specified, the path is converted to the short filename form. However, if /SHORT is not specified, the path isn't converted to its long filename form. To get the long filename, call GetLongPathName using the System plug-in. Note that GetLongPathName is only available on Windows 98, Windows 2000 and above.
116
117 \c StrCpy $INSTDIR $PROGRAMFILES\NSIS
118 \c SetOutPath $INSTDIR
119 \c GetFullPathName $0 ..
120 \c DetailPrint $0 # will print C:\Program Files
121 \c GetFullPathName /SHORT $0 $INSTDIR
122 \c DetailPrint $0 # will print C:\Progra~1\NSIS
123
124 \c StrCpy $0 C:\Progra~1\NSIS
125 \c System::Call 'kernel32::GetLongPathName(t r0, t .r1, i ${NSIS_MAX_STRLEN}) i .r2'
126 \c StrCmp $2 error +2
127 \c StrCpy $0 $1
128 \c DetailPrint $0 # will print C:\Program Files\NSIS, where supported
129
130 \S2{gettempfilename} GetTempFileName
131
132 \c user_var(output) [base_dir]
133
134 Assign to the user variable $x, the name of a temporary file. The file will be created for you and it will be empty. The name of the temporary file is guaranteed to be unique. If to want the temporary file to be created in another directory other than the Windows temp directory, specify a base_dir. You should \R{delete}{Delete} the file when you are done with it.
135
136 \c GetTempFileName $0
137 \c File /oname=$0 something.dat
138 \c # do something with something.dat
139 \c Delete $0
140
141 \S2{searchpath} SearchPath
142
143 \c user_var(output) filename
144
145 Assign to the user variable $x, the full path of the file named by the second parameter. The error flag will be set and $x will be empty if the file cannot be found. Uses \W{http://msdn.microsoft.com/en-us/library/aa365527}{SearchPath()} to search the system paths for the file.
146
147 \S2{setfileattributes} SetFileAttributes
148
149 \c filename attribute1|attribute2|...
150
151 Sets the file attributes of 'filename'. Valid attributes can be combined with | and are:
152
153 \b \e{NORMAL} or \e{FILE_ATTRIBUTE_NORMAL} (you can use 0 to abbreviate this)
154
155 \b \e{ARCHIVE} or \e{FILE_ATTRIBUTE_ARCHIVE}
156
157 \b \e{HIDDEN} or \e{FILE_ATTRIBUTE_HIDDEN}
158
159 \b \e{OFFLINE} or \e{FILE_ATTRIBUTE_OFFLINE}
160
161 \b \e{READONLY} or \e{FILE_ATTRIBUTE_READONLY}
162
163 \b \e{SYSTEM} or \e{FILE_ATTRIBUTE_SYSTEM}
164
165 \b \e{TEMPORARY} or \e{FILE_ATTRIBUTE_TEMPORARY}
166
167 \b \e{NOTINDEXED} or \e{FILE_ATTRIBUTE_NOT_CONTENT_INDEXED}
168
169 The error flag will be set if the file's attributes cannot be set (i.e. the file doesn't exist, or you don't have the right permissions). You can only set attributes. It's not possible to unset them. If you want to remove an attribute use NORMAL. This way all attributes are erased. This command doesn't support wildcards.
170
171 \S2{regdll} RegDLL
172
173 \c dllfile [entrypoint_name]
174
175 Loads the specified DLL and calls DllRegisterServer (or entrypoint_name if specified). The error flag is set if an error occurs (i.e. it can't load the DLL, initialize OLE, find the entry point, or the function returned anything other than ERROR_SUCCESS (=0)).
176
177 Use \R{setoutpath}{SetOutPath} to set the current directory for DLLs that depend on other DLLs that are now in the path or in the Windows directory. For example, if foo.dll depends on bar.dll which is located in $INSTDIR use:
178
179 \c SetOutPath $INSTDIR
180 \c RegDLL $INSTDIR\foo.dll
181
182 \S2{unregdll} UnRegDLL
183
184 \c dllfile
185
186 Loads the specified DLL and calls DllUnregisterServer. The error flag is set if an error occurs (i.e. it can't load the DLL, initialize OLE, find the entry point, or the function returned anything other than ERROR_SUCCESS (=0)).