ScriptFunc_C.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. unit ScriptFunc_C;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2020 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. Script support functions (compile time)
  8. }
  9. interface
  10. uses
  11. Generics.Collections, uPSCompiler, uPSUtils;
  12. procedure ScriptFuncLibraryRegister_C(ScriptCompiler: TPSPascalCompiler;
  13. ObsoleteFunctionWarnings: TDictionary<String, String>);
  14. implementation
  15. uses
  16. Windows, SysUtils, TypInfo,
  17. CmnFunc2, MsgIDs, Struct,
  18. SetupTypes, ScriptFunc, CompMsgs, DotNet;
  19. { This type copied from CmnFunc.pas. We don't actually 'use' CmnFunc since
  20. it would cause VCL units to be linked in. }
  21. type
  22. TMsgBoxType = (mbInformation, mbConfirmation, mbError, mbCriticalError);
  23. procedure ScriptFuncLibraryRegister_C(ScriptCompiler: TPSPascalCompiler;
  24. ObsoleteFunctionWarnings: TDictionary<String, String>);
  25. procedure RegisterType(const Name, Value: tbtstring);
  26. begin
  27. ScriptCompiler.AddTypeS(Name, Value);
  28. end;
  29. procedure RegisterFunctionTable(const FunctionTable: array of tbtstring);
  30. var
  31. I: Integer;
  32. begin
  33. for I := Low(FunctionTable) to High(FunctionTable) do
  34. ScriptCompiler.AddFunction(FunctionTable[I]);
  35. end;
  36. procedure RegisterDelphiFunctionTable(const FunctionTable: array of tbtstring);
  37. var
  38. I: Integer;
  39. begin
  40. for I := Low(FunctionTable) to High(FunctionTable) do
  41. ScriptCompiler.AddDelphiFunction(FunctionTable[I]);
  42. end;
  43. procedure RegisterConst(const Name: tbtstring; const Value: LongInt);
  44. var
  45. C: TPSConstant;
  46. begin
  47. C := ScriptCompiler.AddConstant(Name, ScriptCompiler.FindType('Longint'));
  48. C.Value.tU32 := Value;
  49. end;
  50. procedure RegisterEnum(const TypeInfo: PTypeInfo; const MinValue, MaxValue: Integer);
  51. var
  52. Value: Integer;
  53. begin
  54. for Value := MinValue to MaxValue do
  55. RegisterConst(tbtstring(GetEnumName(TypeInfo, Value)), Value);
  56. end;
  57. procedure RegisterRealEnum(const Name: tbtstring; const TypeInfo: PTypeInfo);
  58. var
  59. TypeData: PTypeData;
  60. S: tbtstring;
  61. I: Integer;
  62. begin
  63. TypeData := GetTypeData(TypeInfo);
  64. if (TypeInfo.Kind <> tkEnumeration) or (TypeData.MinValue <> 0) then
  65. raise Exception.Create('Internal error: RegisterRealEnum not passed a valid enum type');
  66. S := '(';
  67. for I := 0 to TypeData.MaxValue do begin
  68. if I > 0 then
  69. S := S + ',';
  70. S := S + tbtstring(GetEnumName(TypeInfo, I));
  71. end;
  72. S := S + ')';
  73. ScriptCompiler.AddTypeS(Name, S);
  74. end;
  75. begin
  76. RegisterType('TArrayOfString', 'array of String');
  77. RegisterType('TArrayOfChar', 'array of Char');
  78. RegisterType('TArrayOfBoolean', 'array of Boolean');
  79. RegisterType('TArrayOfInteger', 'array of Integer');
  80. RegisterType('DWORD', 'LongWord');
  81. RegisterType('UINT', 'LongWord');
  82. RegisterType('BOOL', 'LongBool');
  83. { Note: In a native 64-bit build, these must be expanded to 64 bits }
  84. RegisterType('DWORD_PTR', 'LongWord');
  85. RegisterType('UINT_PTR', 'LongWord');
  86. RegisterType('INT_PTR', 'Longint');
  87. RegisterType('TFileTime',
  88. 'record' +
  89. ' dwLowDateTime: DWORD;' +
  90. ' dwHighDateTime: DWORD;' +
  91. 'end');
  92. RegisterRealEnum('TMsgBoxType', TypeInfo(TMsgBoxType));
  93. RegisterRealEnum('TSetupMessageID', TypeInfo(TSetupMessageID));
  94. RegisterRealEnum('TSetupStep', TypeInfo(TSetupStep));
  95. RegisterRealEnum('TUninstallStep', TypeInfo(TUninstallStep));
  96. RegisterRealEnum('TSetupProcessorArchitecture', TypeInfo(TSetupProcessorArchitecture));
  97. RegisterRealEnum('TDotNetVersion', TypeInfo(TDotNetVersion));
  98. RegisterType('TExecWait', '(ewNoWait, ewWaitUntilTerminated, ewWaitUntilIdle)');
  99. RegisterType('TFindRec',
  100. 'record' +
  101. ' Name: String;' +
  102. ' Attributes: LongWord;' +
  103. ' SizeHigh: LongWord;' +
  104. ' SizeLow: LongWord;' +
  105. ' CreationTime: TFileTime;' +
  106. ' LastAccessTime: TFileTime;' +
  107. ' LastWriteTime: TFileTime;' +
  108. ' AlternateName: String;' +
  109. ' FindHandle: THandle;' +
  110. 'end');
  111. RegisterType('TWindowsVersion',
  112. 'record' +
  113. ' Major: Cardinal;' +
  114. ' Minor: Cardinal;' +
  115. ' Build: Cardinal;' +
  116. ' ServicePackMajor: Cardinal;' +
  117. ' ServicePackMinor: Cardinal;' +
  118. ' NTPlatform: Boolean;' +
  119. ' ProductType: Byte;' +
  120. ' SuiteMask: Word;' +
  121. 'end');
  122. {$IFNDEF PS_NOINT64}
  123. RegisterType('TOnDownloadProgress', 'function(const Url, FileName: string; const Progress, ProgressMax: Int64): Boolean;');
  124. {$ENDIF}
  125. RegisterFunctionTable(ScriptDlgTable);
  126. RegisterFunctionTable(NewDiskTable);
  127. RegisterFunctionTable(BrowseFuncTable);
  128. RegisterFunctionTable(CmnFuncTable);
  129. RegisterFunctionTable(CmnFunc2Table);
  130. ObsoleteFunctionWarnings.Add('IsAdminLoggedOn', Format(SCompilerCodeFunctionRenamedWithAlternative, ['IsAdminLoggedOn', 'IsAdmin', 'IsAdminInstallMode']));
  131. RegisterFunctionTable(InstallTable);
  132. RegisterFunctionTable(InstFuncTable);
  133. RegisterFunctionTable(InstFnc2Table);
  134. RegisterFunctionTable(MainTable);
  135. ObsoleteFunctionWarnings.Add('IsComponentSelected', Format(SCompilerCodeFunctionRenamed, ['IsComponentSelected', 'WizardIsComponentSelected']));
  136. ObsoleteFunctionWarnings.Add('IsTaskSelected', Format(SCompilerCodeFunctionRenamed, ['IsTaskSelected', 'WizardIsTaskSelected']));
  137. RegisterFunctionTable(MsgsTable);
  138. RegisterDelphiFunctionTable(MsgsDelphiTable);
  139. RegisterFunctionTable(SystemTable);
  140. RegisterFunctionTable(SysUtilsTable);
  141. RegisterDelphiFunctionTable(SysUtilsDelphiTable);
  142. RegisterFunctionTable(VerInfoTable);
  143. RegisterFunctionTable(WindowsTable);
  144. RegisterFunctionTable(Ole2Table);
  145. RegisterFunctionTable(LoggingTable);
  146. RegisterFunctionTable(OtherTable);
  147. RegisterConst('MaxInt', MaxInt);
  148. ScriptCompiler.AddConstantN('irInstall', 'Boolean').SetUInt(1);
  149. RegisterConst('wpWelcome', wpWelcome);
  150. RegisterConst('wpLicense', wpLicense);
  151. RegisterConst('wpPassword', wpPassword);
  152. RegisterConst('wpInfoBefore', wpInfoBefore);
  153. RegisterConst('wpUserInfo', wpUserInfo);
  154. RegisterConst('wpSelectDir', wpSelectDir);
  155. RegisterConst('wpSelectComponents', wpSelectComponents);
  156. RegisterConst('wpSelectProgramGroup', wpSelectProgramGroup);
  157. RegisterConst('wpSelectTasks', wpSelectTasks);
  158. RegisterConst('wpReady', wpReady);
  159. RegisterConst('wpPreparing', wpPreparing);
  160. RegisterConst('wpInstalling', wpInstalling);
  161. RegisterConst('wpInfoAfter', wpInfoAfter);
  162. RegisterConst('wpFinished', wpFinished);
  163. RegisterConst('MB_OK', MB_OK);
  164. RegisterConst('MB_OKCANCEL', MB_OKCANCEL);
  165. RegisterConst('MB_ABORTRETRYIGNORE', MB_ABORTRETRYIGNORE);
  166. RegisterConst('MB_YESNOCANCEL', MB_YESNOCANCEL);
  167. RegisterConst('MB_YESNO', MB_YESNO);
  168. RegisterConst('MB_RETRYCANCEL', MB_RETRYCANCEL);
  169. RegisterConst('MB_DEFBUTTON1', MB_DEFBUTTON1);
  170. RegisterConst('MB_DEFBUTTON2', MB_DEFBUTTON2);
  171. RegisterConst('MB_DEFBUTTON3', MB_DEFBUTTON3);
  172. RegisterConst('MB_SETFOREGROUND', MB_SETFOREGROUND);
  173. RegisterConst('IDOK', IDOK);
  174. RegisterConst('IDCANCEL', IDCANCEL);
  175. RegisterConst('IDABORT', IDABORT);
  176. RegisterConst('IDRETRY', IDRETRY);
  177. RegisterConst('IDIGNORE', IDIGNORE);
  178. RegisterConst('IDYES', IDYES);
  179. RegisterConst('IDNO', IDNO);
  180. RegisterConst('HWND_BROADCAST', HWND_BROADCAST);
  181. RegisterConst('HKEY_AUTO', LongInt(HKEY_AUTO));
  182. RegisterConst('HKEY_AUTO_32', LongInt(HKEY_AUTO or CodeRootKeyFlag32Bit));
  183. RegisterConst('HKEY_AUTO_64', LongInt(HKEY_AUTO or CodeRootKeyFlag64Bit));
  184. RegisterConst('HKEY_CLASSES_ROOT', LongInt(HKEY_CLASSES_ROOT));
  185. RegisterConst('HKEY_CLASSES_ROOT_32', LongInt(HKEY_CLASSES_ROOT or CodeRootKeyFlag32Bit));
  186. RegisterConst('HKEY_CLASSES_ROOT_64', LongInt(HKEY_CLASSES_ROOT or CodeRootKeyFlag64Bit));
  187. RegisterConst('HKEY_CURRENT_USER', LongInt(HKEY_CURRENT_USER));
  188. RegisterConst('HKEY_CURRENT_USER_32', LongInt(HKEY_CURRENT_USER or CodeRootKeyFlag32Bit));
  189. RegisterConst('HKEY_CURRENT_USER_64', LongInt(HKEY_CURRENT_USER or CodeRootKeyFlag64Bit));
  190. RegisterConst('HKEY_LOCAL_MACHINE', LongInt(HKEY_LOCAL_MACHINE));
  191. RegisterConst('HKEY_LOCAL_MACHINE_32', LongInt(HKEY_LOCAL_MACHINE or CodeRootKeyFlag32Bit));
  192. RegisterConst('HKEY_LOCAL_MACHINE_64', LongInt(HKEY_LOCAL_MACHINE or CodeRootKeyFlag64Bit));
  193. RegisterConst('HKEY_USERS', LongInt(HKEY_USERS));
  194. RegisterConst('HKEY_USERS_32', LongInt(HKEY_USERS or CodeRootKeyFlag32Bit));
  195. RegisterConst('HKEY_USERS_64', LongInt(HKEY_USERS or CodeRootKeyFlag64Bit));
  196. RegisterConst('HKEY_PERFORMANCE_DATA', LongInt(HKEY_PERFORMANCE_DATA));
  197. RegisterConst('HKEY_CURRENT_CONFIG', LongInt(HKEY_CURRENT_CONFIG));
  198. RegisterConst('HKEY_CURRENT_CONFIG_32', LongInt(HKEY_CURRENT_CONFIG or CodeRootKeyFlag32Bit));
  199. RegisterConst('HKEY_CURRENT_CONFIG_64', LongInt(HKEY_CURRENT_CONFIG or CodeRootKeyFlag64Bit));
  200. RegisterConst('HKEY_DYN_DATA', LongInt(HKEY_DYN_DATA));
  201. RegisterConst('HKA', LongInt(HKEY_AUTO));
  202. RegisterConst('HKA32', LongInt(HKEY_AUTO or CodeRootKeyFlag32Bit));
  203. RegisterConst('HKA64', LongInt(HKEY_AUTO or CodeRootKeyFlag64Bit));
  204. RegisterConst('HKCR', LongInt(HKEY_CLASSES_ROOT));
  205. RegisterConst('HKCR32', LongInt(HKEY_CLASSES_ROOT or CodeRootKeyFlag32Bit));
  206. RegisterConst('HKCR64', LongInt(HKEY_CLASSES_ROOT or CodeRootKeyFlag64Bit));
  207. RegisterConst('HKCU', LongInt(HKEY_CURRENT_USER));
  208. RegisterConst('HKCU32', LongInt(HKEY_CURRENT_USER or CodeRootKeyFlag32Bit));
  209. RegisterConst('HKCU64', LongInt(HKEY_CURRENT_USER or CodeRootKeyFlag64Bit));
  210. RegisterConst('HKLM', LongInt(HKEY_LOCAL_MACHINE));
  211. RegisterConst('HKLM32', LongInt(HKEY_LOCAL_MACHINE or CodeRootKeyFlag32Bit));
  212. RegisterConst('HKLM64', LongInt(HKEY_LOCAL_MACHINE or CodeRootKeyFlag64Bit));
  213. RegisterConst('HKU', LongInt(HKEY_USERS));
  214. RegisterConst('HKU32', LongInt(HKEY_USERS or CodeRootKeyFlag32Bit));
  215. RegisterConst('HKU64', LongInt(HKEY_USERS or CodeRootKeyFlag64Bit));
  216. RegisterConst('HKCC', LongInt(HKEY_CURRENT_CONFIG));
  217. RegisterConst('HKCC32', LongInt(HKEY_CURRENT_CONFIG or CodeRootKeyFlag32Bit));
  218. RegisterConst('HKCC64', LongInt(HKEY_CURRENT_CONFIG or CodeRootKeyFlag64Bit));
  219. RegisterConst('SW_HIDE', SW_HIDE);
  220. RegisterConst('SW_SHOWNORMAL', SW_SHOWNORMAL);
  221. RegisterConst('SW_SHOWMINIMIZED', SW_SHOWMINIMIZED);
  222. RegisterConst('SW_SHOWMAXIMIZED', SW_SHOWMAXIMIZED);
  223. RegisterConst('SW_SHOWMINNOACTIVE', SW_SHOWMINNOACTIVE);
  224. RegisterConst('SW_SHOW', SW_SHOW);
  225. RegisterConst('FILE_ATTRIBUTE_READONLY', FILE_ATTRIBUTE_READONLY);
  226. RegisterConst('FILE_ATTRIBUTE_HIDDEN', FILE_ATTRIBUTE_HIDDEN);
  227. RegisterConst('FILE_ATTRIBUTE_SYSTEM', FILE_ATTRIBUTE_SYSTEM);
  228. RegisterConst('FILE_ATTRIBUTE_DIRECTORY', FILE_ATTRIBUTE_DIRECTORY);
  229. RegisterConst('FILE_ATTRIBUTE_ARCHIVE', FILE_ATTRIBUTE_ARCHIVE);
  230. RegisterConst('FILE_ATTRIBUTE_DEVICE', $00000040);
  231. RegisterConst('FILE_ATTRIBUTE_NORMAL', FILE_ATTRIBUTE_NORMAL);
  232. RegisterConst('FILE_ATTRIBUTE_TEMPORARY', FILE_ATTRIBUTE_TEMPORARY);
  233. RegisterConst('FILE_ATTRIBUTE_SPARSE_FILE', $00000200);
  234. RegisterConst('FILE_ATTRIBUTE_REPARSE_POINT', $00000400);
  235. RegisterConst('FILE_ATTRIBUTE_COMPRESSED', $00000800);
  236. RegisterConst('FILE_ATTRIBUTE_OFFLINE', $00001000);
  237. RegisterConst('FILE_ATTRIBUTE_NOT_CONTENT_INDEXED', $00002000);
  238. RegisterConst('FILE_ATTRIBUTE_ENCRYPTED', $00004000);
  239. RegisterConst('VER_NT_WORKSTATION', $0000001);
  240. RegisterConst('VER_NT_DOMAIN_CONTROLLER', $0000002);
  241. RegisterConst('VER_NT_SERVER', $0000003);
  242. RegisterConst('VER_SUITE_SMALLBUSINESS', $00000001);
  243. RegisterConst('VER_SUITE_ENTERPRISE', $00000002);
  244. RegisterConst('VER_SUITE_BACKOFFICE', $00000004);
  245. RegisterConst('VER_SUITE_COMMUNICATIONS', $00000008);
  246. RegisterConst('VER_SUITE_TERMINAL', $00000010);
  247. RegisterConst('VER_SUITE_SMALLBUSINESS_RESTRICTED', $00000020);
  248. RegisterConst('VER_SUITE_EMBEDDEDNT', $00000040);
  249. RegisterConst('VER_SUITE_DATACENTER', $00000080);
  250. RegisterConst('VER_SUITE_SINGLEUSERTS', $00000100);
  251. RegisterConst('VER_SUITE_PERSONAL', $00000200);
  252. RegisterConst('VER_SUITE_BLADE', $00000400);
  253. RegisterConst('VER_SUITE_EMBEDDED_RESTRICTED', $00000800);
  254. RegisterConst('VER_SUITE_SECURITY_APPLIANCE', $00001000);
  255. end;
  256. end.