StdUtils plug-in: Difference between revisions
LoRd MuldeR (talk | contribs) |
LoRd MuldeR (talk | contribs) |
||
Line 11: | Line 11: | ||
StdUtils makes the following functions available in NSIS: | StdUtils makes the following functions available in NSIS: | ||
<highlight-nsis>!define StdUtils.Time | <highlight-nsis>!define StdUtils.Time [...] #time() | ||
!define StdUtils.Rand | !define StdUtils.GetMinutes [...] #GetSystemTimeAsFileTime() as number of minutes | ||
!define StdUtils.RandMax | !define StdUtils.GetHours [...] #GetSystemTimeAsFileTime() as number of hours | ||
!define StdUtils.RandMinMax | !define StdUtils.GetDays [...] #GetSystemTimeAsFileTime() as number of days | ||
!define StdUtils.RandList | !define StdUtils.Rand [...] #rand() | ||
!define StdUtils.FormatStr | !define StdUtils.RandMax [...] #rand() with maximum | ||
!define StdUtils.FormatStr2 | !define StdUtils.RandMinMax [...] #rand() with minimum/maximum | ||
!define StdUtils.FormatStr3 | !define StdUtils.RandList [...] #rand() with list support | ||
!define StdUtils.ScanStr | !define StdUtils.FormatStr [...] #sprintf() with one format tag (only %d supported!) | ||
!define StdUtils.ScanStr2 | !define StdUtils.FormatStr2 [...] #sprintf() with two format tags (only %d supported!) | ||
!define StdUtils.ScanStr3 | !define StdUtils.FormatStr3 [...] #sprintf() with three format tags (only %d supported!) | ||
!define StdUtils.TrimStr | !define StdUtils.ScanStr [...] #sscanf() with one format tag (only %d supported!) | ||
!define StdUtils.TrimStrLeft | !define StdUtils.ScanStr2 [...] #sscanf() with two format tags (only %d supported!) | ||
!define StdUtils.TrimStrRight | !define StdUtils.ScanStr3 [...] #sscanf() with three format tags (only %d supported!) | ||
!define StdUtils.RevStr | !define StdUtils.TrimStr [...] #Remove whitspaces from string (left and right) | ||
!define StdUtils.SHFileMove | !define StdUtils.TrimStrLeft [...] #Remove whitspaces from string (left side only) | ||
!define StdUtils.SHFileCopy | !define StdUtils.TrimStrRight [...] #Remove whitspaces from string (right side only) | ||
!define StdUtils.ExecShellAsUser | !define StdUtils.RevStr [...] #Reverse a string | ||
!define StdUtils.InvokeShellVerb | !define StdUtils.SHFileMove [...] #SHFileOperation with FO_MOVE | ||
!define StdUtils. | !define StdUtils.SHFileCopy [...] #SHFileOperation with FO_COPY | ||
!define StdUtils. | !define StdUtils.ExecShellAsUser [...] #ShellExecute() with user context (for elevated installers) | ||
!define StdUtils.GetParameter | !define StdUtils.InvokeShellVerb [...] #Invokes a Shell Verb on the specified item | ||
!define StdUtils.GetAllParameters | !define StdUtils.ExecShellWaitEx [...] #ShellExecuteEx() with process handle to wait for | ||
!define StdUtils.SetVerbose | !define StdUtils.WaitForProcEx [...] #WaitForSingleObject() to wait for process termination | ||
!define StdUtils.GetParameter [...] #Get the value of a specific commandline paramater | |||
!define StdUtils.GetAllParameters [...] #Get complete command-line, but without executable name | |||
!define StdUtils.GetRealOSVersion [...] #Get the *real* operating system version, on Windows 8.1+ | |||
!define StdUtils.VerifyOSVersion [...] #Compare *real* operating system to the expected version | |||
!define StdUtils.GetLibVersion [...] #Get the StdUtils library version | |||
!define StdUtils.SetVerbose [...] #Verbose mode (for debugging)</highlight-nsis> | |||
<b style="color:red">For details please see the manual <tt>Docs\StdUtils\StdUtils.html</tt> included in the download!</b> | <b style="color:red">For details please see the manual <tt>"Docs\StdUtils\StdUtils.html"</tt> included in the download!</b> | ||
== General Usage == | == General Usage == |
Revision as of 13:17, 16 February 2014
Author: LoRd MuldeR (talk, contrib) |
This plug-in provides access to a number of "standard" functions from the C Standard Library, which programmers are used to from their C/C++ compilers (and other languages), but which are not available in NSIS by default. In order to keep the plug-in size as small as possible (~15 KB) and for maximum compatibility, the Visual C++ Run-Time v6.0 (MSVCRT.DLL), which is included with all versions of Windows (since Windows 2000), is used - instead of linking the Visual C++ Run-Time library into the plug-in DLL.
Many additional functions, not directly related to the C Standard Library, have sneaked in over the years. For example, this plug-in provides a wrapper for the SHFileOperation function. Moreover it provides a method for launching programs in a non-elevated way (user context) from an elevated installer (admin mode) on UAC-enabled systems (Vista and later) - see below for details! Last but not least, a version of ExecShell with "wait for process termination" feature (based on ShellExecuteEx) as well as a function to invoke "shell verbs" (e.g. for pinning items to the Taskbar in Windows 7) are provided. Overall I use this plug-in as my "Swiss army Army knife" for all the small things I needed in my NSIS-based installers but NSIS didn't provide out-of-the-box.
ANSI and Unicode builds available. Support operating systems: Windows 2000 and later.
Available Functions
StdUtils makes the following functions available in NSIS:
!define StdUtils.Time [...] #time() !define StdUtils.GetMinutes [...] #GetSystemTimeAsFileTime() as number of minutes !define StdUtils.GetHours [...] #GetSystemTimeAsFileTime() as number of hours !define StdUtils.GetDays [...] #GetSystemTimeAsFileTime() as number of days !define StdUtils.Rand [...] #rand() !define StdUtils.RandMax [...] #rand() with maximum !define StdUtils.RandMinMax [...] #rand() with minimum/maximum !define StdUtils.RandList [...] #rand() with list support !define StdUtils.FormatStr [...] #sprintf() with one format tag (only %d supported!) !define StdUtils.FormatStr2 [...] #sprintf() with two format tags (only %d supported!) !define StdUtils.FormatStr3 [...] #sprintf() with three format tags (only %d supported!) !define StdUtils.ScanStr [...] #sscanf() with one format tag (only %d supported!) !define StdUtils.ScanStr2 [...] #sscanf() with two format tags (only %d supported!) !define StdUtils.ScanStr3 [...] #sscanf() with three format tags (only %d supported!) !define StdUtils.TrimStr [...] #Remove whitspaces from string (left and right) !define StdUtils.TrimStrLeft [...] #Remove whitspaces from string (left side only) !define StdUtils.TrimStrRight [...] #Remove whitspaces from string (right side only) !define StdUtils.RevStr [...] #Reverse a string !define StdUtils.SHFileMove [...] #SHFileOperation with FO_MOVE !define StdUtils.SHFileCopy [...] #SHFileOperation with FO_COPY !define StdUtils.ExecShellAsUser [...] #ShellExecute() with user context (for elevated installers) !define StdUtils.InvokeShellVerb [...] #Invokes a Shell Verb on the specified item !define StdUtils.ExecShellWaitEx [...] #ShellExecuteEx() with process handle to wait for !define StdUtils.WaitForProcEx [...] #WaitForSingleObject() to wait for process termination !define StdUtils.GetParameter [...] #Get the value of a specific commandline paramater !define StdUtils.GetAllParameters [...] #Get complete command-line, but without executable name !define StdUtils.GetRealOSVersion [...] #Get the *real* operating system version, on Windows 8.1+ !define StdUtils.VerifyOSVersion [...] #Compare *real* operating system to the expected version !define StdUtils.GetLibVersion [...] #Get the StdUtils library version !define StdUtils.SetVerbose [...] #Verbose mode (for debugging)
For details please see the manual "Docs\StdUtils\StdUtils.html" included in the download!
General Usage
In order to use the StdUtils plug-in in your script, simply include "StdUtils.nsh" and then use the pre-defined ${StdUtils.FunctionName} macros like this:
!include 'StdUtils.nsh' Section ${StdUtils.Rand} $1 DetailPrint "Random number obtained via StdUtils::Rand is: $1" SectionEnd
Note: We highly recommend to not call the plug-in functions directly. Instead, use the pre-defind macros from StdUtils.nsh, which will ensure that the plug-in functions are used in the "proper" way.
For more details, please have a look at the example scripts located in the Examples\StdUtils directory of the download!
Acknowledgment
- The StdUtils plug-in for NSIS was created by LoRd_MuldeR.
- This plug-in has partly been inspired by the ShellExecAsUser plug-in, created by installer32.
- This plug-in has partly been inspired by the InvokeShellVerb plug-in, created by Robert Strong.
License
StdUtils plug-in for NSIS Copyright (C) 2004-2013 LoRd_MuldeR <mulder2@gmx.de> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
The author of the StdUtils plug-in Library for NSIS adds the following clarification to the GNU Lesser General Public License version 2.1: Installer programs (executables) created with NSIS (Nullsoft Scriptable Install System) that make use of the StdUtils plug-in Library (strictly through the NSIS plug-in interface) and that contain/distribute verbatim copies of the StdUtils plug-in Library are considered a "work that uses the Library"; they do not represent a derivative of the Library.
Please see the GNU Lesser General Public License (version 2.1) for details!
Download
Download latest version from GitHub:
https://github.com/lordmulder/stdutils/releases/latest
Download previous version:
StdUtils.2013-02-21.zip (128 KB)
Download previous version:
StdUtils.2012-10-28.zip (121 KB)
Download historic version:
StdUtils.2011-10-18.zip (105 KB)
Source Code
Public Git Repository:
git://github.com/lordmulder/stdutils.git (Browse)
Public SVN Repository:
http://code.google.com/p/mulder/source/browse/trunk/Utils/nsis_stdutils/
Support
Discussion thread at NSIS Forums:
http://forums.winamp.com/showthread.php?t=335435
E-Mail:
MuldeR2 (at) gmx (dot) de