ISPPBuiltins.iss 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. // Inno Setup Preprocessor
  2. //
  3. // Inno Setup (C) 1997-2026 Jordan Russell. All Rights Reserved.
  4. // Portions Copyright (C) 2000-2026 Martijn Laan. All Rights Reserved.
  5. // Portions Copyright (C) 2001-2004 Alex Yackimoff. All Rights Reserved.
  6. //
  7. // See the ISPP help file for more documentation of the functions defined by this file
  8. //
  9. #if defined(ISPP_INVOKED) && !defined(_BUILTINS_ISS_)
  10. //
  11. #if PREPROCVER < 0x01000000
  12. # error Inno Setup Preprocessor version is outdated
  13. #endif
  14. //
  15. #define _BUILTINS_ISS_
  16. //
  17. #ifdef __OPT_E__
  18. # define private EnableOptE
  19. # pragma option -e-
  20. #endif
  21. #ifndef __POPT_P__
  22. # define private DisablePOptP
  23. #else
  24. # pragma parseroption -p-
  25. #endif
  26. #define NewLine "\n"
  27. #define Tab "\t"
  28. #pragma parseroption -p+
  29. #pragma spansymbol "\"
  30. #define True 1
  31. #define False 0
  32. #define Yes True
  33. #define No False
  34. #define MaxInt 0x7FFFFFFFFFFFFFFFL
  35. #define MinInt 0x8000000000000000L
  36. #define NULL
  37. #define void
  38. // TypeOf constants
  39. #define TYPE_ERROR 0
  40. #define TYPE_NULL 1
  41. #define TYPE_INTEGER 2
  42. #define TYPE_STRING 3
  43. #define TYPE_MACRO 4
  44. #define TYPE_FUNC 5
  45. #define TYPE_ARRAY 6
  46. // Helper macro to find out the type of an array element or expression. TypeOf
  47. // standard function only allows identifier as its parameter. Use this macro
  48. // to convert an expression to identifier.
  49. #define TypeOf2(any Expr) TypeOf(Expr)
  50. // ReadReg constants
  51. #define HKEY_CLASSES_ROOT 0x80000000UL
  52. #define HKEY_CURRENT_USER 0x80000001UL
  53. #define HKEY_LOCAL_MACHINE 0x80000002UL
  54. #define HKEY_USERS 0x80000003UL
  55. #define HKEY_CURRENT_CONFIG 0x80000005UL
  56. #define HKEY_CLASSES_ROOT_64 0x82000000UL
  57. #define HKEY_CURRENT_USER_64 0x82000001UL
  58. #define HKEY_LOCAL_MACHINE_64 0x82000002UL
  59. #define HKEY_USERS_64 0x82000003UL
  60. #define HKEY_CURRENT_CONFIG_64 0x82000005UL
  61. #define HKEY_CLASSES_ROOT_32 0x81000000UL
  62. #define HKEY_CURRENT_USER_32 0x81000001UL
  63. #define HKEY_LOCAL_MACHINE_32 0x81000002UL
  64. #define HKEY_USERS_32 0x81000003UL
  65. #define HKEY_CURRENT_CONFIG_32 0x81000005UL
  66. #define HKCR HKEY_CLASSES_ROOT
  67. #define HKCU HKEY_CURRENT_USER
  68. #define HKLM HKEY_LOCAL_MACHINE
  69. #define HKU HKEY_USERS
  70. #define HKCC HKEY_CURRENT_CONFIG
  71. #define HKCR64 HKEY_CLASSES_ROOT_64
  72. #define HKCU64 HKEY_CURRENT_USER_64
  73. #define HKLM64 HKEY_LOCAL_MACHINE_64
  74. #define HKU64 HKEY_USERS_64
  75. #define HKCC64 HKEY_CURRENT_CONFIG_64
  76. #define HKCR32 HKEY_CLASSES_ROOT_32
  77. #define HKCU32 HKEY_CURRENT_USER_32
  78. #define HKLM32 HKEY_LOCAL_MACHINE_32
  79. #define HKU32 HKEY_USERS_32
  80. #define HKCC32 HKEY_CURRENT_CONFIG_32
  81. // Exec constants
  82. #define SW_HIDE 0
  83. #define SW_SHOWNORMAL 1
  84. #define SW_NORMAL 1
  85. #define SW_SHOWMINIMIZED 2
  86. #define SW_SHOWMAXIMIZED 3
  87. #define SW_MAXIMIZE 3
  88. #define SW_SHOWNOACTIVATE 4
  89. #define SW_SHOW 5
  90. #define SW_MINIMIZE 6
  91. #define SW_SHOWMINNOACTIVE 7
  92. #define SW_SHOWNA 8
  93. #define SW_RESTORE 9
  94. #define SW_SHOWDEFAULT 10
  95. #define SW_MAX 10
  96. // Find constants
  97. #define FIND_MATCH 0x00
  98. #define FIND_BEGINS 0x01
  99. #define FIND_ENDS 0x02
  100. #define FIND_CONTAINS 0x03
  101. #define FIND_CASESENSITIVE 0x04
  102. #define FIND_SENSITIVE FIND_CASESENSITIVE
  103. #define FIND_AND 0x00
  104. #define FIND_OR 0x08
  105. #define FIND_NOT 0x10
  106. #define FIND_TRIM 0x20
  107. // FindFirst constants
  108. #define faReadOnly 0x00000001
  109. #define faHidden 0x00000002
  110. #define faSysFile 0x00000004
  111. #define faVolumeID 0x00000008
  112. #define faDirectory 0x00000010
  113. #define faArchive 0x00000020
  114. #define faSymLink 0x00000040
  115. #define faAnyFile 0x0000003F
  116. // GetStringFileInfo standard names
  117. #define COMPANY_NAME "CompanyName"
  118. #define FILE_DESCRIPTION "FileDescription"
  119. #define FILE_VERSION "FileVersion"
  120. #define INTERNAL_NAME "InternalName"
  121. #define LEGAL_COPYRIGHT "LegalCopyright"
  122. #define ORIGINAL_FILENAME "OriginalFilename"
  123. #define PRODUCT_NAME "ProductName"
  124. #define PRODUCT_VERSION "ProductVersion"
  125. // GetStringFileInfo helpers
  126. #define GetFileCompany(str FileName) GetStringFileInfo(FileName, COMPANY_NAME)
  127. #define GetFileDescription(str FileName) GetStringFileInfo(FileName, FILE_DESCRIPTION)
  128. #define GetFileVersionString(str FileName) GetStringFileInfo(FileName, FILE_VERSION)
  129. #define GetFileCopyright(str FileName) GetStringFileInfo(FileName, LEGAL_COPYRIGHT)
  130. #define GetFileOriginalFilename(str FileName) GetStringFileInfo(FileName, ORIGINAL_FILENAME)
  131. #define GetFileProductVersion(str FileName) GetStringFileInfo(FileName, PRODUCT_VERSION)
  132. #define DeleteToFirstPeriod(str *S) \
  133. Local[1] = Copy(S, 1, (Local[0] = Pos(".", S)) - 1), \
  134. S = Copy(S, Local[0] + 1), \
  135. Local[1]
  136. #define GetVersionComponents(str FileName, *Major, *Minor, *Rev, *Build) \
  137. Local[1] = Local[0] = GetVersionNumbersString(FileName), \
  138. Local[1] == "" ? "" : ( \
  139. Major = Int(DeleteToFirstPeriod(Local[1])), \
  140. Minor = Int(DeleteToFirstPeriod(Local[1])), \
  141. Rev = Int(DeleteToFirstPeriod(Local[1])), \
  142. Build = Int(Local[1]), \
  143. Local[0])
  144. #define GetPackedVersion(str FileName, *Version) \
  145. Local[0] = GetVersionComponents(FileName, Local[1], Local[2], Local[3], Local[4]), \
  146. Version = PackVersionComponents(Local[1], Local[2], Local[3], Local[4]), \
  147. Local[0]
  148. #define GetVersionNumbers(str FileName, *MS, *LS) \
  149. Local[0] = GetPackedVersion(FileName, Local[1]), \
  150. UnpackVersionNumbers(Local[1], MS, LS), \
  151. Local[0]
  152. #define PackVersionNumbers(int VersionMS, int VersionLS) \
  153. VersionMS << 32 | (VersionLS & 0xFFFFFFFF)
  154. #define PackVersionComponents(int Major, int Minor, int Rev, int Build) \
  155. Major << 48 | (Minor & 0xFFFF) << 32 | (Rev & 0xFFFF) << 16 | (Build & 0xFFFF)
  156. #define UnpackVersionNumbers(int Version, *VersionMS, *VersionLS) \
  157. VersionMS = Version >> 32, \
  158. VersionLS = Version & 0xFFFFFFFF, \
  159. void
  160. #define UnpackVersionComponents(int Version, *Major, *Minor, *Rev, *Build) \
  161. Major = Version >> 48, \
  162. Minor = (Version >> 32) & 0xFFFF, \
  163. Rev = (Version >> 16) & 0xFFFF, \
  164. Build = Version & 0xFFFF, \
  165. void
  166. #define VersionToStr(int Version) \
  167. Str(Version >> 48 & 0xFFFF) + "." + Str(Version >> 32 & 0xFFFF) + "." + \
  168. Str(Version >> 16 & 0xFFFF) + "." + Str(Version & 0xFFFF)
  169. #define StrToVersion(str Version) \
  170. Local[0] = Version, \
  171. Local[1] = Int(DeleteToFirstPeriod(Local[0])), \
  172. Local[2] = Int(DeleteToFirstPeriod(Local[0])), \
  173. Local[3] = Int(DeleteToFirstPeriod(Local[0])), \
  174. Local[4] = Int(Local[0]), \
  175. PackVersionComponents(Local[1], Local[2], Local[3], Local[4])
  176. #define EncodeVer(int Major, int Minor, int Revision = 0, int Build = -1) \
  177. (Major & 0xFF) << 24 | (Minor & 0xFF) << 16 | (Revision & 0xFF) << 8 | (Build >= 0 ? Build & 0xFF : 0)
  178. #define DecodeVer(int Version, int Digits = 3) \
  179. Str(Version >> 24 & 0xFF) + (Digits > 1 ? "." : "") + \
  180. (Digits > 1 ? \
  181. Str(Version >> 16 & 0xFF) + (Digits > 2 ? "." : "") : "") + \
  182. (Digits > 2 ? \
  183. Str(Version >> 8 & 0xFF) + (Digits > 3 && (Local = Version & 0xFF) ? "." : "") : "") + \
  184. (Digits > 3 && Local ? \
  185. Str(Version & 0xFF) : "")
  186. #define FindSection(str Section = "Files") \
  187. Find(0, "[" + Section + "]", FIND_MATCH | FIND_TRIM) + 1
  188. #if VER >= 0x03000000
  189. # define FindNextSection(int Line) \
  190. Find(Line, "[", FIND_BEGINS | FIND_TRIM, "]", FIND_ENDS | FIND_AND)
  191. # define FindSectionEnd(str Section = "Files") \
  192. FindNextSection(FindSection(Section))
  193. #else
  194. # define FindSectionEnd(str Section = "Files") \
  195. FindSection(Section) + EntryCount(Section)
  196. #endif
  197. #define FindCode() \
  198. Local[1] = FindSection("Code"), \
  199. Local[0] = Find(Local[1] - 1, "program", FIND_BEGINS, ";", FIND_ENDS | FIND_AND), \
  200. (Local[0] < 0 ? Local[1] : Local[0] + 1)
  201. #define ExtractFilePath(str PathName) \
  202. Local[0] = \
  203. !(Local[1] = RPos("\", PathName)) ? \
  204. "" : \
  205. Copy(PathName, 1, Local[1])
  206. #define ExtractFileDir(str PathName) \
  207. RemoveBackslashUnlessRoot(ExtractFilePath(PathName))
  208. #define ExtractFileExt(str PathName) \
  209. Local[0] = RPos(".", PathName), \
  210. Copy(PathName, Local[0] + 1)
  211. #define ExtractFileName(str PathName) \
  212. !(Local[0] = RPos("\", PathName)) ? \
  213. PathName : \
  214. Copy(PathName, Local[0] + 1)
  215. #define ChangeFileExt(str FileName, str NewExt) \
  216. !(Local[0] = RPos(".", FileName)) ? \
  217. FileName + "." + NewExt : \
  218. Copy(FileName, 1, Local[0]) + NewExt
  219. #define RemoveFileExt(str FileName) \
  220. !(Local[0] = RPos(".", FileName)) ? \
  221. FileName : \
  222. Copy(FileName, 1, Local[0] - 1)
  223. #define AddBackslash(str S) \
  224. Copy(S, Len(S)) == "\" ? S : S + "\"
  225. #define RemoveBackslashUnlessRoot(str S) \
  226. Local[0] = Len(S), \
  227. Local[0] > 0 ? \
  228. Copy(S, Local[0]) == "\" ? \
  229. (Local[0] == 3 && Copy(S, 2, 1) == ":" ? \
  230. S : \
  231. Copy(S, 1, Local[0] - 1)) : \
  232. S : \
  233. ""
  234. #define RemoveBackslash(str S) \
  235. WarnRenamedVersion("RemoveBackslash", "RemoveBackslashUnlessRoot"), \
  236. RemoveBackslashUnlessRoot(S)
  237. #define Delete(str *S, int Index, int Count = MaxInt) \
  238. S = Copy(S, 1, Index - 1) + Copy(S, Index + Count)
  239. #define Insert(str *S, int Index, str Substr) \
  240. Index > Len(S) + 1 ? \
  241. S : \
  242. S = Copy(S, 1, Index - 1) + SubStr + Copy(S, Index)
  243. #define YesNo(str S) \
  244. S == "yes" || S == "true" || S == "1"
  245. #define IsDirSet(str SetupDirective) \
  246. YesNo(SetupSetting(SetupDirective))
  247. #define Power(int X, int P = 2) \
  248. !P ? 1 : X * Power(X, P - 1)
  249. #define Min(int A, int B, int C = MaxInt) \
  250. A < B ? A < C ? Int(A) : Int(C) : Int(B)
  251. #define Max(int A, int B, int C = MinInt) \
  252. A > B ? A > C ? Int(A) : Int(C) : Int(B)
  253. #define SameText(str S1, str S2) \
  254. S1 == S2
  255. #define WarnRenamedVersion(str OldName, str NewName) \
  256. Warning("Function """ + OldName + """ has been renamed. Use """ + NewName + """ instead.")
  257. #define ParseVersion(str FileName, *Major, *Minor, *Rev, *Build) \
  258. WarnRenamedVersion("ParseVersion", "GetVersionComponents"), \
  259. GetVersionComponents(FileName, Major, Minor, Rev, Build)
  260. #define GetFileVersion(str FileName) \
  261. WarnRenamedVersion("GetFileVersion", "GetVersionNumbersString"), \
  262. GetVersionNumbersString(FileName)
  263. #sub GLS_ProcessFoundLanguagesFile
  264. #define Filename FindGetFileName(GLS_FindHandle)
  265. #define Name LowerCase(RemoveFileExt(Filename))
  266. #define MessagesFile "compiler:Languages\" + Filename
  267. #emit "Name: " + Name + "; MessagesFile: " + MessagesFile
  268. #endsub
  269. #define GLS_FindPathName
  270. #define GLS_FindHandle
  271. #define GLS_FindResult
  272. #sub GLS_DoFindFiles
  273. #for {GLS_FindHandle = GLS_FindResult = FindFirst(GLS_FindPathName + "*.isl", 0); GLS_FindResult; GLS_FindResult = FindNext(GLS_FindHandle)} GLS_ProcessFoundLanguagesFile
  274. #if GLS_FindHandle
  275. #expr FindClose(GLS_FindHandle)
  276. #endif
  277. #endsub
  278. #define GLS_FindFiles(str PathName) \
  279. GLS_FindPathName = PathName, \
  280. GLS_DoFindFiles
  281. #sub EmitLanguagesSection
  282. #emit "[Languages]"
  283. #emit "Name: english; MessagesFile: compiler:Default.isl"
  284. #expr GLS_FindFiles(CompilerPath + "Languages\")
  285. #endsub
  286. #ifdef DisablePOptP
  287. # pragma parseroption -p-
  288. #endif
  289. #ifdef EnableOptE
  290. # pragma option -e+
  291. #endif
  292. #endif