diff --git a/Support Files/nsProcess/COPYING b/Support Files/nsProcess/COPYING new file mode 100644 index 0000000..bb6b304 --- /dev/null +++ b/Support Files/nsProcess/COPYING @@ -0,0 +1,144 @@ +COPYRIGHT +--------- + +Copyright (C) 1999-2021 Contributors + +More detailed copyright information can be found in the individual source code files. + +APPLICABLE LICENSES +------------------- + +* All NSIS source code, plug-ins, documentation, examples, header files and graphics, with the exception of the compression modules and where otherwise noted, are licensed under the zlib/libpng license. + +* The zlib compression module for NSIS is licensed under the zlib/libpng license. + +* The bzip2 compression module for NSIS is licensed under the bzip2 license. + +* The LZMA compression module for NSIS is licensed under the Common Public License version 1.0. + +ZLIB/LIBPNG LICENSE +------------------- + +This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. + +BZIP2 LICENSE +------------- + +This program, "bzip2" and associated library "libbzip2", are copyright (C) 1996-2000 Julian R Seward. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. + + 3. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. + + 4. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Julian Seward, Cambridge, UK. + +jseward@acm.org + +COMMON PUBLIC LICENSE VERSION 1.0 +--------------------------------- + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + + a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and + b) in the case of each subsequent Contributor: + + i) changes to the Program, and + + ii) additions to the Program; + + where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. + +"Contributor" means any person or entity that distributes the Program. + +"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. + +"Program" means the Contributions distributed in accordance with this Agreement. + +"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. + +2. GRANT OF RIGHTS + + a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. + + b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. + + c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. + + d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. + +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: + + a) it complies with the terms and conditions of this Agreement; and + + b) its license agreement: + + i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; + + ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; + + iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and + + iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. + +When the Program is made available in source code form: + + a) it must be made available under this Agreement; and + + b) a copy of this Agreement must be included with each copy of the Program. + +Contributors may not remove or alter any copyright notices contained within the Program. + +Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. + +For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against a Contributor with respect to a patent applicable to software (including a cross-claim or counterclaim in a lawsuit), then any patent licenses granted by that Contributor to such Recipient under this Agreement shall terminate as of the date such litigation is filed. In addition, if Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. + +Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. IBM is the initial Agreement Steward. IBM may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. + +This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. + +SPECIAL EXCEPTION FOR LZMA COMPRESSION MODULE +--------------------------------------------- + +Igor Pavlov and Amir Szekely, the authors of the LZMA compression module for NSIS, expressly permit you to statically or dynamically link your code (or bind by name) to the files from the LZMA compression module for NSIS without subjecting your linked code to the terms of the Common Public license version 1.0. Any modifications or additions to files from the LZMA compression module for NSIS, however, are subject to the terms of the Common Public License version 1.0. diff --git a/Support Files/nsProcess/ConvFunc.h b/Support Files/nsProcess/ConvFunc.h new file mode 100644 index 0000000..739737b --- /dev/null +++ b/Support Files/nsProcess/ConvFunc.h @@ -0,0 +1,825 @@ +/***************************************************************** + * Conversion functions header v1.9 * + * * + * 2006 Shengalts Aleksander aka Instructor (Shengalts@mail.ru) * + * * + * * + *Functions (ALLCONVFUNC): * + * xatoi, xatoiW, xitoa, xitoaW, xatoui, xatouiW, * + * xuitoa, xuitoaW, xatoi64, xatoi64W, xi64toa, xi64toaW, * + * hex2dec, hex2decW, dec2hex, dec2hexW * + * * + *Special functions (ALLCONVFUNCS): * + * str2hex, hex2str * + * * + *****************************************************************/ + +#ifndef _CONVFUNC_ +#define _CONVFUNC_ + +int xatoi(char *str); +int xatoiW(wchar_t *wstr); +char* xitoa(int number, char *str, int width); +wchar_t* xitoaW(int number, wchar_t *wstr, int width); +unsigned int xatoui(char *str); +unsigned int xatouiW(wchar_t *wstr); +char* xuitoa(unsigned int number, char *str, int width); +wchar_t* xuitoaW(unsigned int number, wchar_t *wstr, int width); +__int64 xatoi64(char *str); +__int64 xatoi64W(wchar_t *wstr); +char* xi64toa(__int64 number, char *str, int width); +wchar_t* xi64toaW(__int64 number, wchar_t *wstr, int width); +int hex2dec(char *hex); +int hex2decW(wchar_t *whex); +void dec2hex(unsigned int dec, char *hex, BOOL lowercase, unsigned int width); +void dec2hexW(unsigned int dec, wchar_t *whex, BOOL lowercase, unsigned int width); + +void str2hex(unsigned char *str, char *hex, BOOL lowercase, unsigned int bytes); +void hex2str(char *hex, char *str); + +#endif + +/******************************************************************** + * + * xatoi + * + *Converts string to int. + * + *[in] char *str -string number + * + *Returns: integer + * + *Examples: + * xatoi("45") == 45; + * xatoi(" -0045:value") == -45; + ********************************************************************/ +#if defined xatoi || defined ALLCONVFUNC +#define xatoi_INCLUDED +#undef xatoi +int xatoi(char *str) +{ + int nNumber=0; + BOOL bMinus=FALSE; + + while (*str == ' ') + ++str; + if (*str == '+') + ++str; + else if (*str == '-') + { + bMinus=TRUE; + ++str; + } + for (; *str != '\0' && *str >= '0' && *str <= '9'; ++str) + nNumber=(nNumber * 10) + (*str - '0'); + if (bMinus == TRUE) + nNumber=0 - nNumber; + return nNumber; +} +#endif + +/******************************************************************** + * + * xatoiW + * + *Converts unicode string to int. + * + *[in] wchar_t *wstr -string number + * + *Returns: integer + * + *Examples: + * xatoiW(L"45") == 45; + * xatoiW(L" -0045:value") == -45; + ********************************************************************/ +#if defined xatoiW || defined ALLCONVFUNC +#define xatoiW_INCLUDED +#undef xatoiW +int xatoiW(wchar_t *wstr) +{ + int nNumber=0; + BOOL bMinus=FALSE; + + while (*wstr == ' ') + ++wstr; + if (*wstr == '+') + ++wstr; + else if (*wstr == '-') + { + bMinus=TRUE; + ++wstr; + } + for (; *wstr != '\0' && *wstr >= '0' && *wstr <= '9'; ++wstr) + nNumber=(nNumber * 10) + (*wstr - '0'); + if (bMinus == TRUE) + nNumber=0 - nNumber; + return nNumber; +} +#endif + +/******************************************************************** + * + * xitoa [API: wsprintf(szResult, "%d", 45)] + * + *Converts int to string. + * + *[in] int number -integer + *[out] char *str -string number + *[in] int width -minimum number of characters to the output + * + *Returns: a pointer to string + * + *Examples: + * xitoa(45, szResult, 0); //szResult == "45" + * xitoa(-45, szResult, 0); //szResult == "-45" + * xitoa(45, szResult, 4); //szResult == "0045" + ********************************************************************/ +#if defined xitoa || defined ALLCONVFUNC +#define xitoa_INCLUDED +#undef xitoa +char* xitoa(int number, char *str, int width) +{ + char tmp[128]; + int a=0; + int b=0; + *tmp = 0; + + if (number == 0) + { + str[0]='0'; + --width; + b=1; + } + else if (number < 0) + { + str[0]='-'; + number=0 - number; + --width; + b=1; + } + for (tmp[a]='\0'; number != 0; ++a) + { + tmp[a]=(number % 10) + '0'; + number=number / 10; + } + if (a < width) + do + { + tmp[a]='0'; + } while (++a= 0; --a, ++b) str[b]=tmp[a]; + + str[b]='\0'; + return str; +} +#endif + +/******************************************************************** + * + * xitoaW [API: wsprintfW(wszResult, L"%d", 45)] + * + *Converts int to unicode string. + * + *[in] int number -integer + *[out] wchar_t *wstr -unicode string number + *[in] int width -minimum number of characters to the output + * + *Returns: a pointer to unicode string + * + *Examples: + * xitoaW(45, wszResult, 0); //wszResult == L"45" + * xitoaW(-45, wszResult, 0); //wszResult == L"-45" + * xitoaW(45, wszResult, 4); //wszResult == L"0045" + ********************************************************************/ +#if defined xitoaW || defined ALLCONVFUNC +#define xitoaW_INCLUDED +#undef xitoaW +wchar_t* xitoaW(int number, wchar_t *wstr, int width) +{ + wchar_t wtmp[128]=L""; + int a=0; + int b=0; + + if (number == 0) + { + wstr[0]='0'; + --width; + b=1; + } + else if (number < 0) + { + wstr[0]='-'; + number=0 - number; + --width; + b=1; + } + for (wtmp[a]='\0'; number != 0; ++a) + { + wtmp[a]=(number % 10) + '0'; + number=number / 10; + } + for (; width > a; ++a) wtmp[a]='0'; + for (--a; a >= 0; --a, ++b) wstr[b]=wtmp[a]; + + wstr[b]='\0'; + return wstr; +} +#endif + +/******************************************************************** + * + * xatoui + * + *Converts string to unsigned int. + * + *[in] char *str -string number + * + *Returns: unsigned integer + * + *Examples: + * xatoui("45") == 45; + * xatoui(" -0045:value") == 0; + ********************************************************************/ +#if defined xatoui || defined ALLCONVFUNC +#define xatoui_INCLUDED +#undef xatoui +unsigned int xatoui(char *str) +{ + unsigned int nNumber=0; + + while (*str == ' ') + ++str; + if (*str == '+') + ++str; + else if (*str == '-') + return 0; + for (; *str != '\0' && *str >= '0' && *str <= '9'; ++str) + nNumber=(nNumber * 10) + (*str - '0'); + return nNumber; +} +#endif + +/******************************************************************** + * + * xatouiW + * + *Converts unicode string to unsigned int. + * + *[in] wchar_t *wstr -unicode string number + * + *Returns: unsigned integer + * + *Examples: + * xatouiW(L"45") == 45; + * xatouiW(L" -0045:value") == 0; + ********************************************************************/ +#if defined xatouiW || defined ALLCONVFUNC +#define xatouiW_INCLUDED +#undef xatouiW +unsigned int xatouiW(wchar_t *wstr) +{ + unsigned int nNumber=0; + + while (*wstr == ' ') + ++wstr; + if (*wstr == '+') + ++wstr; + else if (*wstr == '-') + return 0; + for (; *wstr != '\0' && *wstr >= '0' && *wstr <= '9'; ++wstr) + nNumber=(nNumber * 10) + (*wstr - '0'); + return nNumber; +} +#endif + +/******************************************************************** + * + * xuitoa + * + *Converts unsigned int to string. + * + *[in] unsigned int number -unsigned integer + *[out] char *str -string number + *[in] int width -minimum number of characters to the output + * + *Returns: a pointer to string + * + *Examples: + * xuitoa(45, szResult, 0); //szResult == "45" + * xuitoa(45, szResult, 4); //szResult == "0045" + ********************************************************************/ +#if defined xuitoa || defined ALLCONVFUNC +#define xuitoa_INCLUDED +#undef xuitoa +char* xuitoa(unsigned int number, char *str, int width) +{ + char tmp[128]=""; + int a=0; + int b=0; + + if (number == 0) + { + str[0]='0'; + --width; + b=1; + } + for (tmp[a]='\0'; number != 0; ++a) + { + tmp[a]=(number % 10) + '0'; + number=number / 10; + } + for (; width > a; ++a) tmp[a]='0'; + for (--a; a >= 0; --a, ++b) str[b]=tmp[a]; + + str[b]='\0'; + return str; +} +#endif + +/******************************************************************** + * + * xuitoaW + * + *Converts unsigned int to unicode string. + * + *[in] unsigned int number -unsigned integer + *[out] wchar_t *wstr -unicode string number + *[in] int width -minimum number of characters to the output + * + *Returns: a pointer to unicode string + * + *Examples: + * xuitoaW(45, wszResult, 0); //wszResult == L"45" + * xuitoaW(45, wszResult, 4); //wszResult == L"0045" + ********************************************************************/ +#if defined xuitoaW || defined ALLCONVFUNC +#define xuitoaW_INCLUDED +#undef xuitoaW +wchar_t* xuitoaW(unsigned int number, wchar_t *wstr, int width) +{ + wchar_t wtmp[128]=L""; + int a=0; + int b=0; + + if (number == 0) + { + wstr[0]='0'; + --width; + b=1; + } + for (wtmp[a]='\0'; number != 0; ++a) + { + wtmp[a]=(number % 10) + '0'; + number=number / 10; + } + for (; width > a; ++a) wtmp[a]='0'; + for (--a; a >= 0; --a, ++b) wstr[b]=wtmp[a]; + + wstr[b]='\0'; + return wstr; +} +#endif + +/******************************************************************** + * + * xatoi64 + * + *Converts string to int64. + * + *[in] char *str -string number + * + *Returns: 64-bit integer + * + *Examples: + * xatoi64("45") == 45; + * xatoi64(" -0045:value") == -45; + ********************************************************************/ +#if defined xatoi64 || defined ALLCONVFUNC +#define xatoi64_INCLUDED +#undef xatoi64 +__int64 xatoi64(char *str) +{ + __int64 nNumber=0; + BOOL bMinus=FALSE; + + while (*str == ' ') + ++str; + if (*str == '+') + ++str; + else if (*str == '-') + { + bMinus=TRUE; + ++str; + } + for (; *str != '\0' && *str >= '0' && *str <= '9'; ++str) + nNumber=(nNumber * 10) + (*str - '0'); + if (bMinus == TRUE) + nNumber=0 - nNumber; + return nNumber; +} +#endif + +/******************************************************************** + * + * xatoi64W + * + *Converts unicode string to int64. + * + *[in] wchar_t *wstr -unicode string number + * + *Returns: 64-bit integer + * + *Examples: + * xatoi64W(L"45") == 45; + * xatoi64W(L" -0045:value") == -45; + ********************************************************************/ +#if defined xatoi64W || defined ALLCONVFUNC +#define xatoi64W_INCLUDED +#undef xatoi64W +__int64 xatoi64W(wchar_t *wstr) +{ + __int64 nNumber=0; + BOOL bMinus=FALSE; + + while (*wstr == ' ') + ++wstr; + if (*wstr == '+') + ++wstr; + else if (*wstr == '-') + { + bMinus=TRUE; + ++wstr; + } + for (; *wstr != '\0' && *wstr >= '0' && *wstr <= '9'; ++wstr) + nNumber=(nNumber * 10) + (*wstr - '0'); + if (bMinus == TRUE) + nNumber=0 - nNumber; + return nNumber; +} +#endif + +/******************************************************************** + * + * xitoa64 + * + *Converts int64 to string. + * + *[in] __int64 number -64-bit integer + *[out] char *str -string number + *[in] int width -minimum number of characters to the output + * + *Returns: a pointer to string + * + *Examples: + * xi64toa(45, szResult, 0); //szResult == "45" + * xi64toa(-45, szResult, 0); //szResult == "-45" + * xi64toa(45, szResult, 4); //szResult == "0045" + ********************************************************************/ +#if defined xi64toa || defined ALLCONVFUNC +#define xi64toa_INCLUDED +#undef xi64toa +char* xi64toa(__int64 number, char *str, int width) +{ + char tmp[128]=""; + int a=0; + int b=0; + + if (number == 0) + { + str[0]='0'; + --width; + b=1; + } + else if (number < 0) + { + str[0]='-'; + number=0 - number; + --width; + b=1; + } + for (tmp[a]='\0'; number != 0; ++a) + { + tmp[a]=(char)((number % 10) + '0'); + number=number / 10; + } + for (; width > a; ++a) tmp[a]='0'; + for (--a; a >= 0; --a, ++b) str[b]=tmp[a]; + + str[b]='\0'; + return str; +} +#endif + +/******************************************************************** + * + * xitoa64W + * + *Converts int64 to unicode string. + * + *[in] __int64 number -64-bit integer + *[out] wchar_t *wstr -unicode string number + *[in] int width -minimum number of characters to the output + * + *Returns: a pointer to unicode string + * + *Examples: + * xi64toaW(45, wszResult, 0); //wszResult == L"45" + * xi64toaW(-45, wszResult, 0); //wszResult == L"-45" + * xi64toaW(45, wszResult, 4); //wszResult == L"0045" + ********************************************************************/ +#if defined xi64toaW || defined ALLCONVFUNC +#define xi64toaW_INCLUDED +#undef xi64toaW +wchar_t* xi64toaW(__int64 number, wchar_t *wstr, int width) +{ + wchar_t wtmp[128]=L""; + int a=0; + int b=0; + + if (number == 0) + { + wstr[0]='0'; + --width; + b=1; + } + else if (number < 0) + { + wstr[0]='-'; + number=0 - number; + --width; + b=1; + } + for (wtmp[a]='\0'; number != 0; ++a) + { + wtmp[a]=(char)((number % 10) + '0'); + number=number / 10; + } + for (; width > a; ++a) wtmp[a]='0'; + for (--a; a >= 0; --a, ++b) wstr[b]=wtmp[a]; + + wstr[b]='\0'; + return wstr; +} +#endif + +/******************************************************************** + * + * hex2dec + * + *Converts hex value to decimal. + * + *[in] char *hex -hex value + * + *Returns: integer + * -1 wrong hex value + * + *Examples: + * hex2dec("A1F") == 2591; + ********************************************************************/ +#if defined hex2dec || defined ALLCONVFUNC +#define hex2dec_INCLUDED +#undef hex2dec +int hex2dec(char *hex) +{ + int a; + int b=0; + + while (1) + { + a=*hex++; + if (a >= '0' && a <= '9') a-='0'; + else if (a >= 'a' && a <= 'f') a-='a'-10; + else if (a >= 'A' && a <= 'F') a-='A'-10; + else return -1; + + if (*hex) b=(b + a) * 16; + else return (b + a); + } +} +#endif + +/******************************************************************** + * + * hex2decW + * + *Converts unicode hex value to decimal. + * + *[in] wchar_t *whex -unicode hex value + * + *Returns: integer + * -1 wrong hex value + * + *Examples: + * hex2decW(L"A1F") == 2591; + ********************************************************************/ +#if defined hex2decW || defined ALLCONVFUNC +#define hex2decW_INCLUDED +#undef hex2decW +int hex2decW(wchar_t *whex) +{ + int a; + int b=0; + + while (1) + { + a=*whex++; + if (a >= '0' && a <= '9') a-='0'; + else if (a >= 'a' && a <= 'f') a-='a'-10; + else if (a >= 'A' && a <= 'F') a-='A'-10; + else return -1; + + if (*whex) b=(b + a) * 16; + else return (b + a); + } +} +#endif + +/******************************************************************** + * + * dec2hex [API: wsprintf(szResult, "%02x", 2591)] + * + *Converts decimal to hex value. + * + *[in] unsigned int dec -positive integer + *[out] char *hex -hex value (output) + *[in] BOOL lowercase -if TRUE hexadecimal value in lowercase + * if FALSE in uppercase. + *[in] unsigned int width -minimum number of characters to the output + * + *Examples: + * dec2hex(2591, szResult, FALSE, 2); //szResult == "A1F" + * dec2hex(10, szResult, TRUE, 2); //szResult == "0a" + ********************************************************************/ +#if defined dec2hex || defined ALLCONVFUNC +#define dec2hex_INCLUDED +#undef dec2hex +void dec2hex(unsigned int dec, char *hex, BOOL lowercase, unsigned int width) +{ + unsigned int a=dec; + unsigned int b=0; + unsigned int c=0; + char d='1'; + if (a == 0) d='0'; + + while (a) + { + b=a % 16; + a=a / 16; + if (b < 10) hex[c++]=b + '0'; + else if (lowercase == TRUE) hex[c++]=b + 'a' - 10; + else hex[c++]=b + 'A' - 10; + } + while (width > c) hex[c++]='0'; + hex[c]='\0'; + + if (d == '1') + for (b=0, --c; b < c; d=hex[b], hex[b++]=hex[c], hex[c--]=d); +} +#endif + +/******************************************************************** + * + * dec2hexW [API: wsprintfW(wszResult, L"%02x", 2591)] + * + *Converts decimal to unicode hex value. + * + *[in] unsigned int dec -positive integer + *[out] wchar_t *whex -unicode hex value (output) + *[in] BOOL lowercase -if TRUE hexadecimal value in lowercase + * if FALSE in uppercase. + *[in] unsigned int width -minimum number of characters to the output + * + *Examples: + * dec2hexW(2591, wszResult, FALSE, 2); //wszResult == L"A1F" + * dec2hexW(10, wszResult, TRUE, 2); //wszResult == L"0a" + ********************************************************************/ +#if defined dec2hexW || defined ALLCONVFUNC +#define dec2hexW_INCLUDED +#undef dec2hexW +void dec2hexW(unsigned int dec, wchar_t *whex, BOOL lowercase, unsigned int width) +{ + unsigned int a=dec; + unsigned int b=0; + unsigned int c=0; + wchar_t d='1'; + if (a == 0) d='0'; + + while (a) + { + b=a % 16; + a=a / 16; + if (b < 10) whex[c++]=b + '0'; + else if (lowercase == TRUE) whex[c++]=b + 'a' - 10; + else whex[c++]=b + 'A' - 10; + } + while (width > c) whex[c++]='0'; + whex[c]='\0'; + + if (d == '1') + for (b=0, --c; b < c; d=whex[b], whex[b++]=whex[c], whex[c--]=d); +} +#endif + +/******************************************************************** + * + * str2hex + * + *Converts string to hex values. + * + *[in] unsigned char *str -string + *[out] char *hex -hex string + *[in] BOOL lowercase -if TRUE hexadecimal value in lowercase + * if FALSE in uppercase. + *[in] unsigned int bytes -number of bytes in string + * + *Note: + * str2hex uses dec2hex + * + *Examples: + * str2hex((unsigned char *)"Some Text", szResult, TRUE, lstrlen("Some Text")); //szResult == "536f6d652054657874" + ********************************************************************/ +#if defined str2hex || defined ALLCONVFUNCS +#define str2hex_INCLUDED +#undef str2hex +void str2hex(unsigned char *str, char *hex, BOOL lowercase, unsigned int bytes) +{ + char a[16]; + unsigned int b=0; + + for (hex[0]='\0'; b < bytes; ++b) + { + //wsprintf(a, "%02x", (unsigned int)str[b]); + dec2hex((unsigned int)str[b], a, lowercase, 2); + lstrcat(hex, a); + } +} +#endif + +/******************************************************************** + * + * hex2str + * + *Converts hex values to string. + * + *[in] char *hex -hex string + *[out] char *str -string + * + *Examples: + * hex2str("536f6d652054657874", szResult); //szResult == "Some Text" + ********************************************************************/ +#if defined hex2str || defined ALLCONVFUNCS +#define hex2str_INCLUDED +#undef hex2str +void hex2str(char *hex, char *str) +{ + char a[4]; + int b; + + while (*hex) + { + a[0]=*hex; + a[1]=*++hex; + a[2]='\0'; + + if (*hex++) + { + if ((b=hex2dec(a)) > 0) *str++=b; + else break; + } + else break; + } + *str='\0'; +} +#endif + + +/******************************************************************** + * * + * Example * + * * + ******************************************************************** + +#define WIN32_LEAN_AND_MEAN +#include +#include +#include "ConvFunc.h" + +//insert functions +#define xatoi +#define xitoa +#include "ConvFunc.h" + +void main() +{ + char szResult[MAX_PATH]="43"; + char *pResult; + int nError; + + nError=xatoi(szResult); + printf("nError={%d}\n", nError); + + pResult=xitoa(45, szResult, 0); + printf("szResult={%s}, pResult={%s}\n", szResult, pResult); +} + +*/ \ No newline at end of file diff --git a/Support Files/nsProcess/README_JamulusChanges.txt b/Support Files/nsProcess/README_JamulusChanges.txt new file mode 100644 index 0000000..7f37b65 --- /dev/null +++ b/Support Files/nsProcess/README_JamulusChanges.txt @@ -0,0 +1,12 @@ +Since we do not want to use the binary of nsProcess (https://nsis.sourceforge.io/NsProcess_plugin), +we compile the source code of the NSIS Plugin. Unfortunately it seems to be quite old. That's +why I (@ann0see) updated it on 2020-02-06 to support compilation +with Visual Studio 2019. Probably a lot more could be done to this. + +According to Anders from the NSIS forum: + +> The nsProcess plug-in also exists on the NSIS wiki and all files on this wiki are ZLib licensed unless otherwise noted. + +See: http://forums.winamp.com/showthread.php?t=230998&page=2 + +And: http://forums.winamp.com/showpost.php?p=3200634&postcount=68 diff --git a/Support Files/nsProcess/Readme.txt b/Support Files/nsProcess/Readme.txt new file mode 100644 index 0000000..099e645 --- /dev/null +++ b/Support Files/nsProcess/Readme.txt @@ -0,0 +1,68 @@ +***************************************************************** +*** nsProcess NSIS plugin v1.6 *** +***************************************************************** + +2006 Shengalts Aleksander aka Instructor (Shengalts@mail.ru) + +Source function FIND_PROC_BY_NAME based + upon the Ravi Kochhar (kochhar@physiology.wisc.edu) code +Thanks iceman_k (FindProcDLL plugin) and + DITMan (KillProcDLL plugin) for direct me +NSIS UNICODE compatible version (1.6) by brainsucker + (sorry, installer missing, i'm too lazy :) +Move project files to vcxproj for Jamulus by ann0see + +Features: +- Find a process by name +- Kill all processes with specified name (not only one) +- Close all processes with specified name (first tries to close all process windows, +waits for 3 seconds for process to exit, terminates if still alive) +- The process name is case-insensitive +- Win95/98/ME/NT/2000/XP/Win7 support +- Small plugin size (4 Kb) +- NSIS UNICODE support (just rename nsProcessW.dll into nsProcess.dll) + +**** Find process **** +${nsProcess::FindProcess} "[file.exe]" $var + +"[file.exe]" - Process name (e.g. "notepad.exe") + +$var 0 Success + 603 Process was not currently running + 604 Unable to identify system type + 605 Unsupported OS + 606 Unable to load NTDLL.DLL + 607 Unable to get procedure address from NTDLL.DLL + 608 NtQuerySystemInformation failed + 609 Unable to load KERNEL32.DLL + 610 Unable to get procedure address from KERNEL32.DLL + 611 CreateToolhelp32Snapshot failed + + +**** Kill/Close process **** +${nsProcess::KillProcess} "[file.exe]" $var +${nsProcess::CloseProcess} "[file.exe]" $var + +"[file.exe]" - Process name (e.g. "notepad.exe") + +$var 0 Success + 601 No permission to terminate process + 602 Not all processes terminated successfully + 603 Process was not currently running + 604 Unable to identify system type + 605 Unsupported OS + 606 Unable to load NTDLL.DLL + 607 Unable to get procedure address from NTDLL.DLL + 608 NtQuerySystemInformation failed + 609 Unable to load KERNEL32.DLL + 610 Unable to get procedure address from KERNEL32.DLL + 611 CreateToolhelp32Snapshot failed + +**** Comment from brainsucker **** +I'm actually not using macros in my code, plugin calls are easy: + +nsProcess:_CloseProcess "notepad.exe" +Pop $R0 + +**** Unload plugin **** +${nsProcess::Unload} diff --git a/Support Files/nsProcess/api.h b/Support Files/nsProcess/api.h new file mode 100644 index 0000000..ed014b2 --- /dev/null +++ b/Support Files/nsProcess/api.h @@ -0,0 +1,83 @@ +/* + * apih + * + * This file is a part of NSIS. + * + * Copyright (C) 1999-2008 Nullsoft and Contributors + * + * Licensed under the zlib/libpng license (the "License"); + * you may not use this file except in compliance with the License. + * + * Licence details can be found in the file COPYING. + * + * This software is provided 'as-is', without any express or implied + * warranty. + */ + +#ifndef _NSIS_EXEHEAD_API_H_ +#define _NSIS_EXEHEAD_API_H_ + +// Starting with NSIS 2.42, you can check the version of the plugin API in exec_flags->plugin_api_version +// The format is 0xXXXXYYYY where X is the major version and Y is the minor version (MAKELONG(y,x)) +// When doing version checks, always remember to use >=, ex: if (pX->exec_flags->plugin_api_version >= NSISPIAPIVER_1_0) {} + +#define NSISPIAPIVER_1_0 0x00010000 +#define NSISPIAPIVER_CURR NSISPIAPIVER_1_0 + +// NSIS Plug-In Callback Messages +enum NSPIM +{ + NSPIM_UNLOAD, // This is the last message a plugin gets, do final cleanup + NSPIM_GUIUNLOAD, // Called after .onGUIEnd +}; + +// Prototype for callbacks registered with extra_parameters->RegisterPluginCallback() +// Return NULL for unknown messages +// Should always be __cdecl for future expansion possibilities +typedef UINT_PTR (*NSISPLUGINCALLBACK)(enum NSPIM); + +// extra_parameters data structures containing other interesting stuff +// but the stack, variables and HWND passed on to plug-ins. +typedef struct +{ + int autoclose; + int all_user_var; + int exec_error; + int abort; + int exec_reboot; // NSIS_SUPPORT_REBOOT + int reboot_called; // NSIS_SUPPORT_REBOOT + int XXX_cur_insttype; // depreacted + int plugin_api_version; // see NSISPIAPIVER_CURR + // used to be XXX_insttype_changed + int silent; // NSIS_CONFIG_SILENT_SUPPORT + int instdir_error; + int rtl; + int errlvl; + int alter_reg_view; + int status_update; +} exec_flags_t; + +#ifndef NSISCALL +# define NSISCALL __stdcall +#endif + +typedef struct { + exec_flags_t *exec_flags; + int (NSISCALL *ExecuteCodeSegment)(int, HWND); + void (NSISCALL *validate_filename)(TCHAR *); + BOOL (NSISCALL *RegisterPluginCallback)(HMODULE, NSISPLUGINCALLBACK); +} extra_parameters; + +// Definitions for page showing plug-ins +// See Ui.c to understand better how they're used + +// sent to the outer window to tell it to go to the next inner window +#define WM_NOTIFY_OUTER_NEXT (WM_USER+0x8) + +// custom pages should send this message to let NSIS know they're ready +#define WM_NOTIFY_CUSTOM_READY (WM_USER+0xd) + +// sent as wParam with WM_NOTIFY_OUTER_NEXT when user cancels - heed its warning +#define NOTIFY_BYE_BYE 'x' + +#endif /* _PLUGIN_H_ */ diff --git a/Support Files/nsProcess/build_nsprocess.ps1 b/Support Files/nsProcess/build_nsprocess.ps1 new file mode 100644 index 0000000..8e4a280 --- /dev/null +++ b/Support Files/nsProcess/build_nsprocess.ps1 @@ -0,0 +1,146 @@ +param ( + [string] $BuildOption = "" +) + +# Fail early on all errors +$ErrorActionPreference = "Stop" + +# Invoke-WebRequest is really slow by default because it renders a progress bar. +# Disabling this, improves vastly performance: +$ProgressPreference = 'SilentlyContinue' + +# Global constants +$RootPath = "$PWD" + + +# Execute native command with errorlevel handling +Function Invoke-Native-Command { + param( + [string] $Command, + [string[]] $Arguments + ) + + & "$Command" @Arguments + + if ($LastExitCode -Ne 0) + { + Throw "Native command $Command returned with exit code $LastExitCode" + } +} + +function Initialize-Module-Here ($m) { # see https://stackoverflow.com/a/51692402 + + # If module is imported say that and do nothing + if (Get-Module | Where-Object {$_.Name -eq $m}) { + Write-Output "Module $m is already imported." + } + else { + + # If module is not imported, but available on disk then import + if (Get-Module -ListAvailable | Where-Object {$_.Name -eq $m}) { + Import-Module $m + } + else { + + # If module is not imported, not available on disk, but is in online gallery then install and import + if (Find-Module -Name $m | Where-Object {$_.Name -eq $m}) { + Install-Module -Name $m -Force -Verbose -Scope CurrentUser + Import-Module $m + } + else { + + # If module is not imported, not available and not in online gallery then abort + Write-Output "Module $m not imported, not available and not in online gallery, exiting." + EXIT 1 + } + } + } +} + + +# Install VSSetup (Visual Studio detection) +Function Install-Dependencies +{ + if (-not (Get-PackageProvider -Name nuget).Name -eq "nuget") { + Install-PackageProvider -Name "Nuget" -Scope CurrentUser -Force + } + Initialize-Module-Here -m "VSSetup" +} + +# Setup environment variables and build tool paths +Function Initialize-Build-Environment +{ + param( + [Parameter(Mandatory=$true)] + [string] $BuildArch + ) + + # Look for Visual Studio/Build Tools 2017 or later (version 15.0 or above) + $VsInstallPath = Get-VSSetupInstance | ` + Select-VSSetupInstance -Product "*" -Version "15.0" -Latest | ` + Select-Object -ExpandProperty "InstallationPath" + + if ($VsInstallPath -Eq "") { $VsInstallPath = "" } + + if ($BuildArch -Eq "x86_64") + { + $VcVarsBin = "$VsInstallPath\VC\Auxiliary\build\vcvars64.bat" + } + else + { + $VcVarsBin = "$VsInstallPath\VC\Auxiliary\build\vcvars32.bat" + } + + "" + "**********************************************************************" + "Using Visual Studio/Build Tools environment settings located at" + $VcVarsBin + "**********************************************************************" + "" + + if (-Not (Test-Path -Path $VcVarsBin)) + { + Throw "Microsoft Visual Studio ($BuildArch variant) is not installed. " + ` + "Please install Visual Studio 2017 or above it before running this script." + } + + # Import environment variables set by vcvarsXX.bat into current scope + $EnvDump = [System.IO.Path]::GetTempFileName() + Invoke-Native-Command -Command "cmd" ` + -Arguments ("/c", "`"$VcVarsBin`" && set > `"$EnvDump`"") + + foreach ($_ in Get-Content -Path $EnvDump) + { + if ($_ -Match "^([^=]+)=(.*)$") + { + Set-Item "Env:$($Matches[1])" $Matches[2] + } + } + + Remove-Item -Path $EnvDump -Force +} + + +# Build and copy NS-Process dll +Function Build-NSProcess +{ + if (!(Test-Path -path "$RootPath\..\..\nsis\plugins\nsProcess.dll")) { + + echo "Building nsProcess..." + + $OriginalEnv = Get-ChildItem Env: + Initialize-Build-Environment -BuildArch "x86" + + Invoke-Native-Command -Command "msbuild" ` + -Arguments ("$RootPath\nsProcess.sln", '/p:Configuration="Release UNICODE"', ` + "/p:Platform=Win32") + + Move-Item -Path "$RootPath\Release\nsProcess.dll" -Destination "$RootPath\..\..\nsis\plugins\nsProcess.dll" -Force + Remove-Item -Path "$RootPath\Release\" -Force -Recurse + $OriginalEnv | % { Set-Item "Env:$($_.Name)" $_.Value } + } +} + +Install-Dependencies +Build-NSProcess + diff --git a/Support Files/nsProcess/nsProcess.c b/Support Files/nsProcess/nsProcess.c new file mode 100644 index 0000000..b792db4 --- /dev/null +++ b/Support Files/nsProcess/nsProcess.c @@ -0,0 +1,416 @@ +/***************************************************************** + * nsProcess NSIS plugin v1.5 * + * * + * 2006 Shengalts Aleksander aka Instructor (Shengalts@mail.ru) * + * * + * Source function FIND_PROC_BY_NAME based * + * upon the Ravi Kochhar (kochhar@physiology.wisc.edu) code * + * Thanks iceman_k (FindProcDLL plugin) and * + * DITMan (KillProcDLL plugin) for point me up * + *****************************************************************/ + + +#define WIN32_LEAN_AND_MEAN +#include +#include +//#include "ConvFunc.h" +#include "pluginapi.h" + +/* Defines */ +#define NSIS_MAX_STRLEN 1024 + +#define SystemProcessInformation 5 +#define STATUS_SUCCESS 0x00000000L +#define STATUS_INFO_LENGTH_MISMATCH 0xC0000004L + +typedef struct _SYSTEM_THREAD_INFO { + FILETIME ftCreationTime; + DWORD dwUnknown1; + DWORD dwStartAddress; + DWORD dwOwningPID; + DWORD dwThreadID; + DWORD dwCurrentPriority; + DWORD dwBasePriority; + DWORD dwContextSwitches; + DWORD dwThreadState; + DWORD dwUnknown2; + DWORD dwUnknown3; + DWORD dwUnknown4; + DWORD dwUnknown5; + DWORD dwUnknown6; + DWORD dwUnknown7; +} SYSTEM_THREAD_INFO; + +typedef struct _SYSTEM_PROCESS_INFO { + DWORD dwOffset; + DWORD dwThreadCount; + DWORD dwUnkown1[6]; + FILETIME ftCreationTime; + DWORD dwUnkown2; + DWORD dwUnkown3; + DWORD dwUnkown4; + DWORD dwUnkown5; + DWORD dwUnkown6; + WCHAR *pszProcessName; + DWORD dwBasePriority; + DWORD dwProcessID; + DWORD dwParentProcessID; + DWORD dwHandleCount; + DWORD dwUnkown7; + DWORD dwUnkown8; + DWORD dwVirtualBytesPeak; + DWORD dwVirtualBytes; + DWORD dwPageFaults; + DWORD dwWorkingSetPeak; + DWORD dwWorkingSet; + DWORD dwUnkown9; + DWORD dwPagedPool; + DWORD dwUnkown10; + DWORD dwNonPagedPool; + DWORD dwPageFileBytesPeak; + DWORD dwPageFileBytes; + DWORD dwPrivateBytes; + DWORD dwUnkown11; + DWORD dwUnkown12; + DWORD dwUnkown13; + DWORD dwUnkown14; + SYSTEM_THREAD_INFO ati[ANYSIZE_ARRAY]; +} SYSTEM_PROCESS_INFO; + + +/* Include conversion functions */ +//#define xatoi +//#define xitoa +//#include "ConvFunc.h" + +/* Global variables */ +TCHAR szBuf[NSIS_MAX_STRLEN]; + +/* Funtions prototypes and macros */ +int FIND_PROC_BY_NAME(TCHAR *szProcessName, BOOL bTerminate, BOOL bClose); + +/* NSIS functions code */ +void __declspec(dllexport) _FindProcess(HWND hwndParent, int string_size, + TCHAR *variables, stack_t **stacktop, extra_parameters *extra) +{ + EXDLL_INIT(); + { + int nError; + + popstringn(szBuf, NSIS_MAX_STRLEN); + nError=FIND_PROC_BY_NAME(szBuf, FALSE, FALSE); + pushint(nError); + } +} + +void __declspec(dllexport) _KillProcess(HWND hwndParent, int string_size, + TCHAR *variables, stack_t **stacktop, extra_parameters *extra) +{ + EXDLL_INIT(); + { + int nError=0; + + popstringn(szBuf, NSIS_MAX_STRLEN); + nError=FIND_PROC_BY_NAME(szBuf, TRUE, FALSE); + pushint(nError); + } +} + +void __declspec(dllexport) _CloseProcess(HWND hwndParent, int string_size, + TCHAR *variables, stack_t **stacktop, extra_parameters *extra) +{ + EXDLL_INIT(); + { + int nError=0; + + popstringn(szBuf, NSIS_MAX_STRLEN); + nError=FIND_PROC_BY_NAME(szBuf, TRUE, TRUE); + pushint(nError); + } +} + +void __declspec(dllexport) _Unload(HWND hwndParent, int string_size, + TCHAR *variables, stack_t **stacktop, extra_parameters *extra) +{ +} + +BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) +{ + return TRUE; +} + +BOOL CALLBACK EnumWindowsProc( HWND hwnd, + LPARAM lParam +) +{ + HANDLE *data = lParam; + DWORD pid; + GetWindowThreadProcessId(hwnd, &pid); + if (pid == data[0]) + { + PostMessage(data[1], WM_CLOSE, 0, 0); + data[1] = hwnd; + } + return TRUE; +} + +void NiceTerminate(DWORD id, BOOL bClose, BOOL *bSuccess, BOOL *bFailed) +{ + HANDLE hProc; + HANDLE data[2]; + DWORD ec; + BOOL bDone = FALSE; + if (hProc=OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, id)) + { + data[0] = id; + data[1] = NULL; + + if (bClose) + EnumWindows(EnumWindowsProc, data); + if (data[1] != NULL) + { + if (GetExitCodeProcess(hProc,&ec) && ec == STILL_ACTIVE) + if (WaitForSingleObject(hProc, 3000) == WAIT_OBJECT_0) + { + *bSuccess = bDone = TRUE; + } + else; + else + { + *bSuccess = bDone = TRUE; + } + } + if (!bDone) + { + // Open for termination + if (TerminateProcess(hProc, 0)) + *bSuccess=TRUE; + else + *bFailed=TRUE; + } + CloseHandle(hProc); + } +} + +int FIND_PROC_BY_NAME(TCHAR *szProcessName, BOOL bTerminate, BOOL bClose) +// Find the process "szProcessName" if it is currently running. +// This works for Win95/98/ME and also WinNT/2000/XP. +// The process name is case-insensitive, i.e. "notepad.exe" and "NOTEPAD.EXE" +// will both work. If bTerminate is TRUE, then process will be terminated. +// +// Return codes are as follows: +// 0 = Success +// 601 = No permission to terminate process +// 602 = Not all processes terminated successfully +// 603 = Process was not currently running +// 604 = Unable to identify system type +// 605 = Unsupported OS +// 606 = Unable to load NTDLL.DLL +// 607 = Unable to get procedure address from NTDLL.DLL +// 608 = NtQuerySystemInformation failed +// 609 = Unable to load KERNEL32.DLL +// 610 = Unable to get procedure address from KERNEL32.DLL +// 611 = CreateToolhelp32Snapshot failed +// +// Change history: +// created 06/23/2000 - Ravi Kochhar (kochhar@physiology.wisc.edu) +// http://www.neurophys.wisc.edu/ravi/software/ +// modified 03/08/2002 - Ravi Kochhar (kochhar@physiology.wisc.edu) +// - Borland-C compatible if BORLANDC is defined as +// suggested by Bob Christensen +// modified 03/10/2002 - Ravi Kochhar (kochhar@physiology.wisc.edu) +// - Removed memory leaks as suggested by +// Jonathan Richard-Brochu (handles to Proc and Snapshot +// were not getting closed properly in some cases) +// modified 14/11/2005 - Shengalts Aleksander aka Instructor (Shengalts@mail.ru): +// - Combine functions FIND_PROC_BY_NAME and KILL_PROC_BY_NAME +// - Code has been optimized +// - Now kill all processes with specified name (not only one) +// - Cosmetic improvements +// - Removed error 632 (Invalid process name) +// - Changed error 602 (Unable to terminate process for some other reason) +// - BORLANDC define not needed +// modified 04/01/2006 - Shengalts Aleksander aka Instructor (Shengalts@mail.ru): +// - Removed CRT dependency +// modified 21/04/2006 - Shengalts Aleksander aka Instructor (Shengalts@mail.ru): +// - Removed memory leak as suggested by {_trueparuex^} +// (handle to hSnapShot was not getting closed properly in some cases) +// modified 21/04/2006 - Shengalts Aleksander aka Instructor (Shengalts@mail.ru): +// - Removed memory leak as suggested by {_trueparuex^} +// (handle to hSnapShot was not getting closed properly in some cases) +// modified 19/07/2006 - Shengalts Aleksander aka Instructor (Shengalts@mail.ru): +// - Code for WinNT/2000/XP has been rewritten +// - Changed error codes +// modified 31/08/2006 - Shengalts Aleksander aka Instructor (Shengalts@mail.ru): +// - Removed memory leak as suggested by Daniel Vanesse +{ + TCHAR szName[MAX_PATH]; + OSVERSIONINFO osvi; + HMODULE hLib; + HANDLE hProc; + ULONG uError; + BOOL bFound=FALSE; + BOOL bSuccess=FALSE; + BOOL bFailed=FALSE; + + // First check what version of Windows we're in + osvi.dwOSVersionInfoSize=sizeof(OSVERSIONINFO); + if (!GetVersionEx(&osvi)) return 604; + + if (osvi.dwPlatformId != VER_PLATFORM_WIN32_NT && + osvi.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) + return 605; + + if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) + { + // WinNT/2000/XP + + SYSTEM_PROCESS_INFO *spi; + SYSTEM_PROCESS_INFO *spiCount; + DWORD dwSize=0x4000; + DWORD dwData; + ULONG (WINAPI *NtQuerySystemInformationPtr)(ULONG, PVOID, LONG, PULONG); + + if (hLib=LoadLibraryW(L"NTDLL.DLL")) + { + NtQuerySystemInformationPtr=(ULONG(WINAPI *)(ULONG, PVOID, LONG, PULONG))GetProcAddress(hLib, "NtQuerySystemInformation"); + + if (NtQuerySystemInformationPtr) + { + while (1) + { + if (spi=LocalAlloc(LMEM_FIXED, dwSize)) + { + uError=(*NtQuerySystemInformationPtr)(SystemProcessInformation, spi, dwSize, &dwData); + + if (uError == STATUS_SUCCESS) break; + + LocalFree(spi); + + if (uError != STATUS_INFO_LENGTH_MISMATCH) + { + uError=608; + break; + } + } + else + { + uError=608; + break; + } + dwSize*=2; + } + } + else uError=607; + + FreeLibrary(hLib); + } + else uError=606; + + if (uError != STATUS_SUCCESS) return uError; + + spiCount=spi; + + while (1) + { + if (spiCount->pszProcessName) + { + +#ifdef UNICODE + lstrcpyn(szName, spiCount->pszProcessName, MAX_PATH); +#else + WideCharToMultiByte(CP_ACP, 0, spiCount->pszProcessName, -1, szName, MAX_PATH, NULL, NULL); +#endif + + if (!lstrcmpi(szName, szProcessName)) + { + // Process found + bFound=TRUE; + + if (bTerminate == TRUE) + { + NiceTerminate(spiCount->dwProcessID, bClose, &bSuccess, &bFailed); + } + else break; + } + } + if (spiCount->dwOffset == 0) break; + spiCount=(SYSTEM_PROCESS_INFO *)((char *)spiCount + spiCount->dwOffset); + } + LocalFree(spi); + } + else + { + // Win95/98/ME + + PROCESSENTRY32 pe; + char *pName; + HANDLE hSnapShot; + BOOL bResult; + HANDLE (WINAPI *CreateToolhelp32SnapshotPtr)(DWORD, DWORD); + BOOL (WINAPI *Process32FirstPtr)(HANDLE, LPPROCESSENTRY32); + BOOL (WINAPI *Process32NextPtr)(HANDLE, LPPROCESSENTRY32); + + if (hLib=LoadLibraryA("KERNEL32.DLL")) + { + CreateToolhelp32SnapshotPtr=(HANDLE(WINAPI *)(DWORD, DWORD)) GetProcAddress(hLib, "CreateToolhelp32Snapshot"); + Process32FirstPtr=(BOOL(WINAPI *)(HANDLE, LPPROCESSENTRY32)) GetProcAddress(hLib, "Process32First"); + Process32NextPtr=(BOOL(WINAPI *)(HANDLE, LPPROCESSENTRY32)) GetProcAddress(hLib, "Process32Next"); + + if (CreateToolhelp32SnapshotPtr && Process32NextPtr && Process32FirstPtr) + { + // Get a handle to a Toolhelp snapshot of all the systems processes. + if ((hSnapShot=(*CreateToolhelp32SnapshotPtr)(TH32CS_SNAPPROCESS, 0)) != INVALID_HANDLE_VALUE) + { + // Get the first process' information. + pe.dwSize=sizeof(PROCESSENTRY32); + bResult=(*Process32FirstPtr)(hSnapShot, &pe); + + // While there are processes, keep looping and checking. + while (bResult) + { + //Get file name + for (pName=pe.szExeFile + lstrlen(pe.szExeFile) - 1; *pName != '\\' && *pName != '\0'; --pName); + + ++pName; + +#ifdef UNICODE + MultiByteToWideChar(CP_ACP, 0, pName, lstrlenA(pName)+1, szName, MAX_PATH); +#else + lstrcpyn(szName, pName, MAX_PATH); +#endif + + if (!lstrcmpi(szName, szProcessName)) + { + // Process found + bFound=TRUE; + + if (bTerminate == TRUE) + { + // Open for termination + NiceTerminate(pe.th32ProcessID, bClose, &bSuccess, &bFailed); + } + else break; + } + //Keep looking + bResult=(*Process32NextPtr)(hSnapShot, &pe); + } + CloseHandle(hSnapShot); + } + else uError=611; + } + else uError=610; + + FreeLibrary(hLib); + } + else uError=609; + } + + if (bFound == FALSE) return 603; + if (bTerminate == TRUE) + { + if (bSuccess == FALSE) return 601; + if (bFailed == TRUE) return 602; + } + return 0; +} diff --git a/Support Files/nsProcess/nsProcess.sln b/Support Files/nsProcess/nsProcess.sln new file mode 100644 index 0000000..3e1f748 --- /dev/null +++ b/Support Files/nsProcess/nsProcess.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30907.101 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nsProcess", "nsProcess.vcxproj", "{BD73F235-28DE-40F5-B047-14222BC77FDC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release ANSI|Win32 = Release ANSI|Win32 + Release UNICODE|Win32 = Release UNICODE|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BD73F235-28DE-40F5-B047-14222BC77FDC}.Debug|Win32.ActiveCfg = Debug|Win32 + {BD73F235-28DE-40F5-B047-14222BC77FDC}.Debug|Win32.Build.0 = Debug|Win32 + {BD73F235-28DE-40F5-B047-14222BC77FDC}.Release ANSI|Win32.ActiveCfg = Release ANSI|Win32 + {BD73F235-28DE-40F5-B047-14222BC77FDC}.Release ANSI|Win32.Build.0 = Release ANSI|Win32 + {BD73F235-28DE-40F5-B047-14222BC77FDC}.Release UNICODE|Win32.ActiveCfg = Release UNICODE|Win32 + {BD73F235-28DE-40F5-B047-14222BC77FDC}.Release UNICODE|Win32.Build.0 = Release UNICODE|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9188A750-3130-4D95-BFC9-C8FA7601EBAA} + EndGlobalSection +EndGlobal diff --git a/Support Files/nsProcess/nsProcess.vcxproj b/Support Files/nsProcess/nsProcess.vcxproj new file mode 100644 index 0000000..e33f84b --- /dev/null +++ b/Support Files/nsProcess/nsProcess.vcxproj @@ -0,0 +1,219 @@ + + + + + Debug + Win32 + + + Release ANSI + Win32 + + + Release UNICODE + Win32 + + + + {BD73F235-28DE-40F5-B047-14222BC77FDC} + nsProcess + + + + DynamicLibrary + v143 + false + MultiByte + + + DynamicLibrary + v143 + false + Unicode + + + DynamicLibrary + v143 + false + MultiByte + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>16.0.30804.86 + + + .\Debug\ + .\Debug\ + true + + + .\Release\ + .\Release\ + false + + + $(Configuration)\ + $(Configuration)\ + false + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + Win32 + .\Debug/nsProcess.tlb + + + + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;nsProcess_EXPORTS;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebug + .\Debug/nsProcess.pch + .\Debug/ + .\Debug/ + .\Debug/ + Level3 + true + EditAndContinue + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + .\Debug/nsProcess.dll + true + false + true + .\Debug/nsProcess.pdb + false + + .\Debug/nsProcess.lib + MachineX86 + + + true + .\Debug/nsProcess.bsc + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + Win32 + .\Release/nsProcess.tlb + + + + MinSpace + OnlyExplicitInline + WIN32;NDEBUG;_WINDOWS;_USRDLL;nsProcess_EXPORTS;%(PreprocessorDefinitions) + true + + MultiThreaded + false + true + .\Release/nsProcess.pch + .\Release/ + .\Release/ + .\Release/ + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + Release\nsProcess.dll + true + true + .\Release/nsProcess.pdb + DllMain + false + + .\Release/nsProcess.lib + MachineX86 + + + true + .\Release/nsProcess.bsc + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + Win32 + .\Release/nsProcess.tlb + + + + MinSpace + OnlyExplicitInline + WIN32;NDEBUG;_WINDOWS;_USRDLL;nsProcess_EXPORTS;%(PreprocessorDefinitions) + true + + MultiThreaded + false + true + .\Release/nsProcess.pch + .\Release/ + .\Release/ + .\Release/ + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + nsProcess.dll + true + true + .\Release/nsProcess.pdb + DllMain + false + + .\Release/nsProcess.lib + MachineX86 + + + true + .\Release/nsProcess.bsc + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Support Files/nsProcess/nsProcess.vcxproj.filters b/Support Files/nsProcess/nsProcess.vcxproj.filters new file mode 100644 index 0000000..4ece389 --- /dev/null +++ b/Support Files/nsProcess/nsProcess.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {d172976c-738c-43be-8ef9-85cf7b612e55} + cpp;c;cxx;rc;def;r;odl;idl;hpj;bat + + + {a180c8d9-d81d-4f9e-9a43-1062a49fc171} + h;hpp;hxx;hm;inl + + + {1c8718c3-49cd-4da0-a847-7c19d0891023} + ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe + + + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/Support Files/nsProcess/nsis_tchar.h b/Support Files/nsProcess/nsis_tchar.h new file mode 100644 index 0000000..92025cc --- /dev/null +++ b/Support Files/nsProcess/nsis_tchar.h @@ -0,0 +1,214 @@ +/* + * nsis_tchar.h + * + * This file is a part of NSIS. + * + * Copyright (C) 1999-2007 Nullsoft and Contributors + * + * This software is provided 'as-is', without any express or implied + * warranty. + * + * For Unicode support by Jim Park -- 08/30/2007 + */ + +// Jim Park: Only those we use are listed here. + +#pragma once + +#ifdef _UNICODE + +#ifndef _T +#define __T(x) L ## x +#define _T(x) __T(x) +#define _TEXT(x) __T(x) +#endif +typedef wchar_t TCHAR; +typedef wchar_t _TUCHAR; + +// program +#define _tmain wmain +#define _tWinMain wWinMain +#define _tenviron _wenviron +#define __targv __wargv + +// printfs +#define _ftprintf fwprintf +#define _sntprintf _snwprintf +#define _stprintf _swprintf +#define _tprintf wprintf +#define _vftprintf vfwprintf +#define _vsntprintf _vsnwprintf +#define _vstprintf _vswprintf + +// scanfs +#define _tscanf wscanf +#define _stscanf swscanf + +// string manipulations +#define _tcscat wcscat +#define _tcschr wcschr +#define _tcsclen wcslen +#define _tcscpy wcscpy +#define _tcsdup _wcsdup +#define _tcslen wcslen +#define _tcsnccpy wcsncpy +#define _tcsncpy wcsncpy +#define _tcsrchr wcsrchr +#define _tcsstr wcsstr +#define _tcstok wcstok + +// string comparisons +#define _tcscmp wcscmp +#define _tcsicmp _wcsicmp +#define _tcsncicmp _wcsnicmp +#define _tcsncmp wcsncmp +#define _tcsnicmp _wcsnicmp + +// upper / lower +#define _tcslwr _wcslwr +#define _tcsupr _wcsupr +#define _totlower towlower +#define _totupper towupper + +// conversions to numbers +#define _tcstoi64 _wcstoi64 +#define _tcstol wcstol +#define _tcstoul wcstoul +#define _tstof _wtof +#define _tstoi _wtoi +#define _tstoi64 _wtoi64 +#define _ttoi _wtoi +#define _ttoi64 _wtoi64 +#define _ttol _wtol + +// conversion from numbers to strings +#define _itot _itow +#define _ltot _ltow +#define _i64tot _i64tow +#define _ui64tot _ui64tow + +// file manipulations +#define _tfopen _wfopen +#define _topen _wopen +#define _tremove _wremove +#define _tunlink _wunlink + +// reading and writing to i/o +#define _fgettc fgetwc +#define _fgetts fgetws +#define _fputts fputws +#define _gettchar getwchar + +// directory +#define _tchdir _wchdir + +// environment +#define _tgetenv _wgetenv +#define _tsystem _wsystem + +// time +#define _tcsftime wcsftime + +#else // ANSI + +#ifndef _T +#define _T(x) x +#define _TEXT(x) x +#endif +typedef char TCHAR; +typedef unsigned char _TUCHAR; + +// program +#define _tmain main +#define _tWinMain WinMain +#define _tenviron environ +#define __targv __argv + +// printfs +#define _ftprintf fprintf +#define _sntprintf _snprintf +#define _stprintf sprintf +#define _tprintf printf +#define _vftprintf vfprintf +#define _vsntprintf _vsnprintf +#define _vstprintf vsprintf + +// scanfs +#define _tscanf scanf +#define _stscanf sscanf + +// string manipulations +#define _tcscat strcat +#define _tcschr strchr +#define _tcsclen strlen +#define _tcscnlen strnlen +#define _tcscpy strcpy +#define _tcsdup _strdup +#define _tcslen strlen +#define _tcsnccpy strncpy +#define _tcsrchr strrchr +#define _tcsstr strstr +#define _tcstok strtok + +// string comparisons +#define _tcscmp strcmp +#define _tcsicmp _stricmp +#define _tcsncmp strncmp +#define _tcsncicmp _strnicmp +#define _tcsnicmp _strnicmp + +// upper / lower +#define _tcslwr _strlwr +#define _tcsupr _strupr + +#define _totupper toupper +#define _totlower tolower + +// conversions to numbers +#define _tcstol strtol +#define _tcstoul strtoul +#define _tstof atof +#define _tstoi atoi +#define _tstoi64 _atoi64 +#define _tstoi64 _atoi64 +#define _ttoi atoi +#define _ttoi64 _atoi64 +#define _ttol atol + +// conversion from numbers to strings +#define _i64tot _i64toa +#define _itot _itoa +#define _ltot _ltoa +#define _ui64tot _ui64toa + +// file manipulations +#define _tfopen fopen +#define _topen _open +#define _tremove remove +#define _tunlink _unlink + +// reading and writing to i/o +#define _fgettc fgetc +#define _fgetts fgets +#define _fputts fputs +#define _gettchar getchar + +// directory +#define _tchdir _chdir + +// environment +#define _tgetenv getenv +#define _tsystem system + +// time +#define _tcsftime strftime + +#endif + +// is functions (the same in Unicode / ANSI) +#define _istgraph isgraph +#define _istascii __isascii + +#define __TFILE__ _T(__FILE__) +#define __TDATE__ _T(__DATE__) +#define __TTIME__ _T(__TIME__) diff --git a/Support Files/nsProcess/pluginapi.c b/Support Files/nsProcess/pluginapi.c new file mode 100644 index 0000000..a6562fa --- /dev/null +++ b/Support Files/nsProcess/pluginapi.c @@ -0,0 +1,290 @@ +#include + +#include "pluginapi.h" + +unsigned int g_stringsize; +stack_t **g_stacktop; +TCHAR *g_variables; + +// utility functions (not required but often useful) + +int NSISCALL popstring(TCHAR *str) +{ + stack_t *th; + if (!g_stacktop || !*g_stacktop) return 1; + th=(*g_stacktop); + lstrcpy(str,th->text); + *g_stacktop = th->next; + GlobalFree((HGLOBAL)th); + return 0; +} + +int NSISCALL popstringn(TCHAR *str, int maxlen) +{ + stack_t *th; + if (!g_stacktop || !*g_stacktop) return 1; + th=(*g_stacktop); + if (str) lstrcpyn(str,th->text,maxlen?maxlen:g_stringsize); + *g_stacktop = th->next; + GlobalFree((HGLOBAL)th); + return 0; +} + +void NSISCALL pushstring(const TCHAR *str) +{ + stack_t *th; + if (!g_stacktop) return; + th=(stack_t*)GlobalAlloc(GPTR,(sizeof(stack_t)+(g_stringsize)*sizeof(TCHAR))); + lstrcpyn(th->text,str,g_stringsize); + th->next=*g_stacktop; + *g_stacktop=th; +} + +TCHAR * NSISCALL getuservariable(const int varnum) +{ + if (varnum < 0 || varnum >= __INST_LAST) return NULL; + return g_variables+varnum*g_stringsize; +} + +void NSISCALL setuservariable(const int varnum, const TCHAR *var) +{ + if (var != NULL && varnum >= 0 && varnum < __INST_LAST) + lstrcpy(g_variables + varnum*g_stringsize, var); +} + +#ifdef _UNICODE +int NSISCALL PopStringA(char* ansiStr) +{ + wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, g_stringsize*sizeof(wchar_t)); + int rval = popstring(wideStr); + WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); + GlobalFree((HGLOBAL)wideStr); + return rval; +} + +int NSISCALL PopStringNA(char* ansiStr, int maxlen) +{ + int realLen = maxlen ? maxlen : g_stringsize; + wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, realLen*sizeof(wchar_t)); + int rval = popstringn(wideStr, realLen); + WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, realLen, NULL, NULL); + GlobalFree((HGLOBAL)wideStr); + return rval; +} + +void NSISCALL PushStringA(const char* ansiStr) +{ + wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, g_stringsize*sizeof(wchar_t)); + MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); + pushstring(wideStr); + GlobalFree((HGLOBAL)wideStr); + return; +} + +void NSISCALL GetUserVariableW(const int varnum, wchar_t* wideStr) +{ + lstrcpyW(wideStr, getuservariable(varnum)); +} + +void NSISCALL GetUserVariableA(const int varnum, char* ansiStr) +{ + wchar_t* wideStr = getuservariable(varnum); + WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); +} + +void NSISCALL SetUserVariableA(const int varnum, const char* ansiStr) +{ + if (ansiStr != NULL && varnum >= 0 && varnum < __INST_LAST) + { + wchar_t* wideStr = g_variables + varnum * g_stringsize; + MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); + } +} + +#else +// ANSI defs +int NSISCALL PopStringW(wchar_t* wideStr) +{ + char* ansiStr = (char*) GlobalAlloc(GPTR, g_stringsize); + int rval = popstring(ansiStr); + MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); + GlobalFree((HGLOBAL)ansiStr); + return rval; +} + +int NSISCALL PopStringNW(wchar_t* wideStr, int maxlen) +{ + int realLen = maxlen ? maxlen : g_stringsize; + char* ansiStr = (char*) GlobalAlloc(GPTR, realLen); + int rval = popstringn(ansiStr, realLen); + MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, realLen); + GlobalFree((HGLOBAL)ansiStr); + return rval; +} + +void NSISCALL PushStringW(wchar_t* wideStr) +{ + char* ansiStr = (char*) GlobalAlloc(GPTR, g_stringsize); + WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); + pushstring(ansiStr); + GlobalFree((HGLOBAL)ansiStr); +} + +void NSISCALL GetUserVariableW(const int varnum, wchar_t* wideStr) +{ + char* ansiStr = getuservariable(varnum); + MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); +} + +void NSISCALL GetUserVariableA(const int varnum, char* ansiStr) +{ + lstrcpyA(ansiStr, getuservariable(varnum)); +} + +void NSISCALL SetUserVariableW(const int varnum, const wchar_t* wideStr) +{ + if (wideStr != NULL && varnum >= 0 && varnum < __INST_LAST) + { + char* ansiStr = g_variables + varnum * g_stringsize; + WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); + } +} +#endif + +// playing with integers + +int NSISCALL myatoi(const TCHAR *s) +{ + int v=0; + if (*s == _T('0') && (s[1] == _T('x') || s[1] == _T('X'))) + { + s++; + for (;;) + { + int c=*(++s); + if (c >= _T('0') && c <= _T('9')) c-=_T('0'); + else if (c >= _T('a') && c <= _T('f')) c-=_T('a')-10; + else if (c >= _T('A') && c <= _T('F')) c-=_T('A')-10; + else break; + v<<=4; + v+=c; + } + } + else if (*s == _T('0') && s[1] <= _T('7') && s[1] >= _T('0')) + { + for (;;) + { + int c=*(++s); + if (c >= _T('0') && c <= _T('7')) c-=_T('0'); + else break; + v<<=3; + v+=c; + } + } + else + { + int sign=0; + if (*s == _T('-')) sign++; else s--; + for (;;) + { + int c=*(++s) - _T('0'); + if (c < 0 || c > 9) break; + v*=10; + v+=c; + } + if (sign) v = -v; + } + + return v; +} + +unsigned NSISCALL myatou(const TCHAR *s) +{ + unsigned int v=0; + + for (;;) + { + unsigned int c=*s++; + if (c >= _T('0') && c <= _T('9')) c-=_T('0'); + else break; + v*=10; + v+=c; + } + return v; +} + +int NSISCALL myatoi_or(const TCHAR *s) +{ + int v=0; + if (*s == _T('0') && (s[1] == _T('x') || s[1] == _T('X'))) + { + s++; + for (;;) + { + int c=*(++s); + if (c >= _T('0') && c <= _T('9')) c-=_T('0'); + else if (c >= _T('a') && c <= _T('f')) c-=_T('a')-10; + else if (c >= _T('A') && c <= _T('F')) c-=_T('A')-10; + else break; + v<<=4; + v+=c; + } + } + else if (*s == _T('0') && s[1] <= _T('7') && s[1] >= _T('0')) + { + for (;;) + { + int c=*(++s); + if (c >= _T('0') && c <= _T('7')) c-=_T('0'); + else break; + v<<=3; + v+=c; + } + } + else + { + int sign=0; + if (*s == _T('-')) sign++; else s--; + for (;;) + { + int c=*(++s) - _T('0'); + if (c < 0 || c > 9) break; + v*=10; + v+=c; + } + if (sign) v = -v; + } + + // Support for simple ORed expressions + if (*s == _T('|')) + { + v |= myatoi_or(s+1); + } + + return v; +} + +int NSISCALL popint() +{ + TCHAR buf[128]; + if (popstringn(buf,sizeof(buf)/sizeof(TCHAR))) + return 0; + + return myatoi(buf); +} + +int NSISCALL popint_or() +{ + TCHAR buf[128]; + if (popstringn(buf,sizeof(buf)/sizeof(TCHAR))) + return 0; + + return myatoi_or(buf); +} + +void NSISCALL pushint(int value) +{ + TCHAR buffer[1024]; + wsprintf(buffer, _T("%d"), value); + pushstring(buffer); +} diff --git a/Support Files/nsProcess/pluginapi.h b/Support Files/nsProcess/pluginapi.h new file mode 100644 index 0000000..b9bfee9 --- /dev/null +++ b/Support Files/nsProcess/pluginapi.h @@ -0,0 +1,101 @@ +#ifndef ___NSIS_PLUGIN__H___ +#define ___NSIS_PLUGIN__H___ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "api.h" +#include "nsis_tchar.h" + +#ifndef NSISCALL +# define NSISCALL __stdcall +#endif + +#define EXDLL_INIT() { \ + g_stringsize=string_size; \ + g_stacktop=stacktop; \ + g_variables=variables; } + +typedef struct _stack_t { + struct _stack_t *next; + TCHAR text[1]; // this should be the length of string_size +} stack_t; + +enum +{ +INST_0, // $0 +INST_1, // $1 +INST_2, // $2 +INST_3, // $3 +INST_4, // $4 +INST_5, // $5 +INST_6, // $6 +INST_7, // $7 +INST_8, // $8 +INST_9, // $9 +INST_R0, // $R0 +INST_R1, // $R1 +INST_R2, // $R2 +INST_R3, // $R3 +INST_R4, // $R4 +INST_R5, // $R5 +INST_R6, // $R6 +INST_R7, // $R7 +INST_R8, // $R8 +INST_R9, // $R9 +INST_CMDLINE, // $CMDLINE +INST_INSTDIR, // $INSTDIR +INST_OUTDIR, // $OUTDIR +INST_EXEDIR, // $EXEDIR +INST_LANG, // $LANGUAGE +__INST_LAST +}; + +extern unsigned int g_stringsize; +extern stack_t **g_stacktop; +extern TCHAR *g_variables; + +int NSISCALL popstring(TCHAR *str); // 0 on success, 1 on empty stack +int NSISCALL popstringn(TCHAR *str, int maxlen); // with length limit, pass 0 for g_stringsize +int NSISCALL popint(); // pops an integer +int NSISCALL popint_or(); // with support for or'ing (2|4|8) +int NSISCALL myatoi(const TCHAR *s); // converts a string to an integer +unsigned NSISCALL myatou(const TCHAR *s); // converts a string to an unsigned integer, decimal only +int NSISCALL myatoi_or(const TCHAR *s); // with support for or'ing (2|4|8) +void NSISCALL pushstring(const TCHAR *str); +void NSISCALL pushint(int value); +TCHAR * NSISCALL getuservariable(const int varnum); +void NSISCALL setuservariable(const int varnum, const TCHAR *var); + +#ifdef _UNICODE +#define PopStringW(x) popstring(x) +#define PushStringW(x) pushstring(x) +#define SetUserVariableW(x,y) setuservariable(x,y) + +int NSISCALL PopStringA(char* ansiStr); +void NSISCALL PushStringA(const char* ansiStr); +void NSISCALL GetUserVariableW(const int varnum, wchar_t* wideStr); +void NSISCALL GetUserVariableA(const int varnum, char* ansiStr); +void NSISCALL SetUserVariableA(const int varnum, const char* ansiStr); + +#else +// ANSI defs + +#define PopStringA(x) popstring(x) +#define PushStringA(x) pushstring(x) +#define SetUserVariableA(x,y) setuservariable(x,y) + +int NSISCALL PopStringW(wchar_t* wideStr); +void NSISCALL PushStringW(wchar_t* wideStr); +void NSISCALL GetUserVariableW(const int varnum, wchar_t* wideStr); +void NSISCALL GetUserVariableA(const int varnum, char* ansiStr); +void NSISCALL SetUserVariableW(const int varnum, const wchar_t* wideStr); + +#endif + +#ifdef __cplusplus +} +#endif + +#endif//!___NSIS_PLUGIN__H___ diff --git a/nsis/dialogs/service-config.nsddef b/nsis/dialogs/service-config.nsddef index 05ed8ad..a09b8a1 100644 --- a/nsis/dialogs/service-config.nsddef +++ b/nsis/dialogs/service-config.nsddef @@ -1,10 +1,10 @@  - +