ISPPBuiltins.iss 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. ; BEGIN ISPPBUILTINS.ISS
  2. //
  3. // Inno Setup Preprocessor
  4. //
  5. // Copyright (C) 2001-2004 Alex Yackimoff. All Rights Reserved.
  6. // Portions by Martijn Laan.
  7. //
  8. // Inno Setup (C) 1997-2019 Jordan Russell. All Rights Reserved.
  9. // Portions by Martijn Laan.
  10. //
  11. #if defined(ISPP_INVOKED) && !defined(_BUILTINS_ISS_)
  12. //
  13. #if PREPROCVER < 0x01000000
  14. # error Inno Setup Preprocessor version is outdated
  15. #endif
  16. //
  17. #define _BUILTINS_ISS_
  18. //
  19. // ===========================================================================
  20. //
  21. // Default states for options.
  22. //
  23. //#pragma parseroption -b+ ; short circuit boolean evaluation: on
  24. //#pragma parseroption -m- ; short circuit multiplication evaluation (0 * A will not eval A): off
  25. //#pragma parseroption -p+ ; string literals without escape sequences: on
  26. //#pragma parseroption -u- ; allow undeclared identifiers: off
  27. //#pragma option -c+ ; pass script to the compiler: on
  28. //#pragma option -e- ; emit empty lines to translation: off
  29. //#pragma option -v- ; verbose mode: off
  30. //
  31. // ---------------------------------------------------------------------------
  32. //
  33. // Verbose levels:
  34. // 0 - #include and #file acknowledgements
  35. // 1 - information about any temp files created by #file
  36. // 2 - #insert and #append acknowledgements
  37. // 3 - reserved
  38. // 4 - #dim, #define and #undef acknowledgements
  39. // 5 - reserved
  40. // 6 - conditional inclusion acknowledgements
  41. // 7 - reserved
  42. // 8 - show strings emitted with #emit directive
  43. // 9 - macro and functions successful call acknowledgements
  44. //10 - Local macro array allocation acknowledgements
  45. //
  46. //#pragma verboselevel 0
  47. //
  48. #ifndef __POPT_P__
  49. # define private CStrings
  50. #else
  51. # pragma parseroption -p-
  52. #endif
  53. //
  54. #define NewLine "\n"
  55. #define Tab "\t"
  56. //
  57. #pragma parseroption -p+
  58. //
  59. #pragma spansymbol "\"
  60. //
  61. #define True 1
  62. #define False 0
  63. #define Yes True
  64. #define No False
  65. //
  66. #define MaxInt 0x7FFFFFFFL
  67. #define MinInt 0x80000000L
  68. //
  69. #define NULL
  70. #define void
  71. //
  72. // TypeOf constants
  73. //
  74. #define TYPE_ERROR 0
  75. #define TYPE_NULL 1
  76. #define TYPE_INTEGER 2
  77. #define TYPE_STRING 3
  78. #define TYPE_MACRO 4
  79. #define TYPE_FUNC 5
  80. #define TYPE_ARRAY 6
  81. //
  82. // Helper macro to find out the type of an array element or expression. TypeOf
  83. // standard function only allows identifier as its parameter. Use this macro
  84. // to convert an expression to identifier.
  85. //
  86. #define TypeOf2(any Expr) TypeOf(Expr)
  87. //
  88. // ReadReg constants
  89. //
  90. #define HKEY_CLASSES_ROOT 0x80000000UL
  91. #define HKEY_CURRENT_USER 0x80000001UL
  92. #define HKEY_LOCAL_MACHINE 0x80000002UL
  93. #define HKEY_USERS 0x80000003UL
  94. #define HKEY_CURRENT_CONFIG 0x80000005UL
  95. #define HKEY_CLASSES_ROOT_64 0x82000000UL
  96. #define HKEY_CURRENT_USER_64 0x82000001UL
  97. #define HKEY_LOCAL_MACHINE_64 0x82000002UL
  98. #define HKEY_USERS_64 0x82000003UL
  99. #define HKEY_CURRENT_CONFIG_64 0x82000005UL
  100. //
  101. #define HKCR HKEY_CLASSES_ROOT
  102. #define HKCU HKEY_CURRENT_USER
  103. #define HKLM HKEY_LOCAL_MACHINE
  104. #define HKU HKEY_USERS
  105. #define HKCC HKEY_CURRENT_CONFIG
  106. #define HKCR64 HKEY_CLASSES_ROOT_64
  107. #define HKCU64 HKEY_CURRENT_USER_64
  108. #define HKLM64 HKEY_LOCAL_MACHINE_64
  109. #define HKU64 HKEY_USERS_64
  110. #define HKCC64 HKEY_CURRENT_CONFIG_64
  111. //
  112. // Exec constants
  113. //
  114. #define SW_HIDE 0
  115. #define SW_SHOWNORMAL 1
  116. #define SW_NORMAL 1
  117. #define SW_SHOWMINIMIZED 2
  118. #define SW_SHOWMAXIMIZED 3
  119. #define SW_MAXIMIZE 3
  120. #define SW_SHOWNOACTIVATE 4
  121. #define SW_SHOW 5
  122. #define SW_MINIMIZE 6
  123. #define SW_SHOWMINNOACTIVE 7
  124. #define SW_SHOWNA 8
  125. #define SW_RESTORE 9
  126. #define SW_SHOWDEFAULT 10
  127. #define SW_MAX 10
  128. //
  129. // Find constants
  130. //
  131. #define FIND_MATCH 0x00
  132. #define FIND_BEGINS 0x01
  133. #define FIND_ENDS 0x02
  134. #define FIND_CONTAINS 0x03
  135. #define FIND_CASESENSITIVE 0x04
  136. #define FIND_SENSITIVE FIND_CASESENSITIVE
  137. #define FIND_AND 0x00
  138. #define FIND_OR 0x08
  139. #define FIND_NOT 0x10
  140. #define FIND_TRIM 0x20
  141. //
  142. // FindFirst constants
  143. //
  144. #define faReadOnly 0x00000001
  145. #define faHidden 0x00000002
  146. #define faSysFile 0x00000004
  147. #define faVolumeID 0x00000008
  148. #define faDirectory 0x00000010
  149. #define faArchive 0x00000020
  150. #define faSymLink 0x00000040
  151. #define faAnyFile 0x0000003F
  152. //
  153. // GetStringFileInfo standard names
  154. //
  155. #define COMPANY_NAME "CompanyName"
  156. #define FILE_DESCRIPTION "FileDescription"
  157. #define FILE_VERSION "FileVersion"
  158. #define INTERNAL_NAME "InternalName"
  159. #define LEGAL_COPYRIGHT "LegalCopyright"
  160. #define ORIGINAL_FILENAME "OriginalFilename"
  161. #define PRODUCT_NAME "ProductName"
  162. #define PRODUCT_VERSION "ProductVersion"
  163. //
  164. // GetStringFileInfo helpers
  165. //
  166. #define GetFileCompany(str FileName) GetStringFileInfo(FileName, COMPANY_NAME)
  167. #define GetFileDescription(str FileName) GetStringFileInfo(FileName, FILE_DESCRIPTION)
  168. #define GetFileVersionString(str FileName) GetStringFileInfo(FileName, FILE_VERSION)
  169. #define GetFileCopyright(str FileName) GetStringFileInfo(FileName, LEGAL_COPYRIGHT)
  170. #define GetFileOriginalFilename(str FileName) GetStringFileInfo(FileName, ORIGINAL_FILENAME)
  171. #define GetFileProductVersion(str FileName) GetStringFileInfo(FileName, PRODUCT_VERSION)
  172. //
  173. // ParseVersion
  174. //
  175. // Macro internally calls GetFileVersion function and parses string returned
  176. // by that function (in form "0.0.0.0"). All four version elements are stored
  177. // in by-reference parameters Major, Minor, Rev, and Build. Macro returns
  178. // string returned by GetFileVersion.
  179. //
  180. #define DeleteToFirstPeriod(str *S) \
  181. Local[1] = Copy(S, 1, (Local[0] = Pos(".", S)) - 1), \
  182. S = Copy(S, Local[0] + 1), \
  183. Local[1]
  184. //
  185. #define ParseVersion(str FileName, *Major, *Minor, *Rev, *Build) \
  186. Local[1] = Local[0] = GetFileVersion(FileName), \
  187. Local[1] == "" ? "" : ( \
  188. Major = Int(DeleteToFirstPeriod(Local[1])), \
  189. Minor = Int(DeleteToFirstPeriod(Local[1])), \
  190. Rev = Int(DeleteToFirstPeriod(Local[1])), \
  191. Build = Int(Local[1]), \
  192. Local[0])
  193. //
  194. // EncodeVer
  195. //
  196. // Encodes given four version elements to a 32 bit integer number (8 bits for
  197. // each element, i.e. elements must be within 0...255 range).
  198. //
  199. #define EncodeVer(int Major, int Minor, int Revision = 0, int Build = -1) \
  200. Major << 24 | (Minor & 0xFF) << 16 | (Revision & 0xFF) << 8 | (Build >= 0 ? Build & 0xFF : 0)
  201. //
  202. // DecodeVer
  203. //
  204. // Decodes given 32 bit integer encoded version to its string representation,
  205. // Digits parameter indicates how many elements to show (if the fourth element
  206. // is 0, it won't be shown anyway).
  207. //
  208. #define DecodeVer(int Ver, int Digits = 3) \
  209. Str(Ver >> 0x18 & 0xFF) + (Digits > 1 ? "." : "") + \
  210. (Digits > 1 ? \
  211. Str(Ver >> 0x10 & 0xFF) + (Digits > 2 ? "." : "") : "") + \
  212. (Digits > 2 ? \
  213. Str(Ver >> 0x08 & 0xFF) + (Digits > 3 && (Local = Ver & 0xFF) ? "." : "") : "") + \
  214. (Digits > 3 && Local ? \
  215. Str(Ver & 0xFF) : "")
  216. //
  217. // FindSection
  218. //
  219. // Returns index of the line following the header of the section. This macro
  220. // is intended to be used with #insert directive.
  221. //
  222. #define FindSection(str Section = "Files") \
  223. Find(0, "[" + Section + "]", FIND_MATCH | FIND_TRIM) + 1
  224. //
  225. // FindSectionEnd
  226. //
  227. // Returns index of the line following last entry of the section. This macro
  228. // is intended to be used with #insert directive.
  229. //
  230. #if VER >= 0x03000000
  231. # define FindNextSection(int Line) \
  232. Find(Line, "[", FIND_BEGINS | FIND_TRIM, "]", FIND_ENDS | FIND_AND)
  233. # define FindSectionEnd(str Section = "Files") \
  234. FindNextSection(FindSection(Section))
  235. #else
  236. # define FindSectionEnd(str Section = "Files") \
  237. FindSection(Section) + EntryCount(Section)
  238. #endif
  239. //
  240. // FindCode
  241. //
  242. // Returns index of the line (of translation) following either [Code] section
  243. // header, or "program" keyword, if any.
  244. //
  245. #define FindCode() \
  246. Local[1] = FindSection("Code"), \
  247. Local[0] = Find(Local[1] - 1, "program", FIND_BEGINS, ";", FIND_ENDS | FIND_AND), \
  248. (Local[0] < 0 ? Local[1] : Local[0] + 1)
  249. //
  250. // ExtractFilePath
  251. //
  252. // Returns directory portion of the given filename without backslash (unless
  253. // it is a root directory). If PathName doesn't contain directory portion,
  254. // the result is an empty string.
  255. //
  256. #define ExtractFilePath(str PathName) \
  257. (Local[0] = \
  258. !(Local[1] = RPos("\", PathName)) ? \
  259. "" : \
  260. Copy(PathName, 1, Local[1] - 1)), \
  261. Local[0] + \
  262. ((Local[2] = Len(Local[0])) == 2 && Copy(Local[0], Local[2]) == ":" ? \
  263. "\" : \
  264. "")
  265. #define ExtractFileDir(str PathName) \
  266. RemoveBackslash(ExtractFilePath(PathName))
  267. #define ExtractFileExt(str PathName) \
  268. Local[0] = RPos(".", PathName), \
  269. Copy(PathName, Local[0] + 1)
  270. //
  271. // ExtractFileName
  272. //
  273. // Returns name portion of the given filename. If PathName ends with
  274. // a backslash, the result is an empty string.
  275. //
  276. #define ExtractFileName(str PathName) \
  277. !(Local[0] = RPos("\", PathName)) ? \
  278. PathName : \
  279. Copy(PathName, Local[0] + 1)
  280. //
  281. // ChangeFileExt
  282. //
  283. // Changes extension in FileName with NewExt. NewExt must not contain
  284. // period.
  285. //
  286. #define ChangeFileExt(str FileName, str NewExt) \
  287. !(Local[0] = RPos(".", FileName)) ? \
  288. FileName + "." + NewExt : \
  289. Copy(FileName, 1, Local[0]) + NewExt
  290. //
  291. // RemoveFileExt
  292. //
  293. // Removes extension in FileName.
  294. //
  295. #define RemoveFileExt(str FileName) \
  296. !(Local[0] = RPos(".", FileName)) ? \
  297. FileName : \
  298. Copy(FileName, 1, Local[0] - 1)
  299. //
  300. // AddBackslash
  301. //
  302. // Adds a backslash to the string, if it's not already there.
  303. //
  304. #define AddBackslash(str S) \
  305. Copy(S, Len(S)) == "\" ? S : S + "\"
  306. //
  307. // RemoveBackslash
  308. //
  309. // Removes trailing backslash from the string unless the string points to
  310. // a root directory.
  311. //
  312. #define RemoveBackslash(str S) \
  313. Local[0] = Len(S), \
  314. Local[0] > 0 ? \
  315. Copy(S, Local[0]) == "\" ? \
  316. (Local[0] == 3 && Copy(S, 2, 1) == ":" ? \
  317. S : \
  318. Copy(S, 1, Local[0] - 1)) : \
  319. S : \
  320. ""
  321. //
  322. // Delete
  323. //
  324. // Deletes specified number of characters beginning with Index from S. S is
  325. // passed by reference (therefore is modified). Acts like Delete function in
  326. // Delphi (from System unit).
  327. //
  328. #define Delete(str *S, int Index, int Count = MaxInt) \
  329. S = Copy(S, 1, Index - 1) + Copy(S, Index + Count)
  330. //
  331. // Insert
  332. //
  333. // Inserts specified Substr at Index'th character into S. S is passed by
  334. // reference (therefore is modified).
  335. //
  336. #define Insert(str *S, int Index, str Substr) \
  337. Index > Len(S) + 1 ? \
  338. S : \
  339. S = Copy(S, 1, Index - 1) + SubStr + Copy(S, Index)
  340. //
  341. // YesNo, IsDirSet
  342. //
  343. // Returns nonzero value if given string is "yes", "true" or "1". Intended to
  344. // be used with SetupSetting function. This macro replaces YesNo function
  345. // available in previous releases.
  346. //
  347. #define YesNo(str S) \
  348. (S = LowerCase(S)) == "yes" || S == "true" || S == "1"
  349. //
  350. #define IsDirSet(str SetupDirective) \
  351. YesNo(SetupSetting(SetupDirective))
  352. //
  353. //
  354. #define Power(int X, int P = 2) \
  355. !P ? 1 : X * Power(X, P - 1)
  356. //
  357. #define Min(int A, int B, int C = MaxInt) \
  358. A < B ? A < C ? Int(A) : Int(C) : Int(B)
  359. //
  360. #define Max(int A, int B, int C = MinInt) \
  361. A > B ? A > C ? Int(A) : Int(C) : Int(B)
  362. //
  363. // SameText
  364. //
  365. // Returns True if the given strings are identical, ignoring case.
  366. //
  367. #define SameText(str S1, str S2) \
  368. LowerCase(S1) == LowerCase(S2)
  369. //
  370. // SameStr
  371. //
  372. // Returns True if the given strings are identical, with case-sensitivity.
  373. //
  374. #define SameStr(str S1, str S2) \
  375. S1 == S2
  376. //
  377. #ifdef CStrings
  378. # pragma parseroption -p-
  379. #endif
  380. #endif
  381. ; END ISPPBUILTINS.ISS