SetupLdr.dpr 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. program SetupLdr;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2024 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. Setup Loader
  8. }
  9. uses
  10. SafeDLLPath in '..\Components\SafeDLLPath.pas',
  11. SetupLdrAndSetup.XPTheme in 'Src\SetupLdrAndSetup.XPTheme.pas',
  12. Windows,
  13. Messages,
  14. SysUtils,
  15. Compression.Base in 'Src\Compression.Base.pas',
  16. Compression.LZMA1SmallDecompressor in 'Src\Compression.LZMA1SmallDecompressor.pas',
  17. Shared.SetupEntFunc in 'Src\Shared.SetupEntFunc.pas',
  18. PathFunc in '..\Components\PathFunc.pas',
  19. Shared.CommonFunc in 'Src\Shared.CommonFunc.pas',
  20. SetupLdrAndSetup.Messages in 'Src\SetupLdrAndSetup.Messages.pas',
  21. Shared.SetupMessageIDs in 'Src\Shared.SetupMessageIDs.pas',
  22. Shared.Struct in 'Src\Shared.Struct.pas',
  23. SetupLdrAndSetup.InstFunc in 'Src\SetupLdrAndSetup.InstFunc.pas',
  24. Shared.FileClass in 'Src\Shared.FileClass.pas',
  25. Shared.Int64Em in 'Src\Shared.Int64Em.pas',
  26. SHA256 in '..\Components\SHA256.pas',
  27. SetupLdrAndSetup.RedirFunc in 'Src\SetupLdrAndSetup.RedirFunc.pas',
  28. Shared.VerInfoFunc in 'Src\Shared.VerInfoFunc.pas';
  29. {$SETPEOSVERSION 6.1}
  30. {$SETPESUBSYSVERSION 6.1}
  31. {$WEAKLINKRTTI ON}
  32. {$R Res\Setup.icon.res}
  33. {$R Res\SetupLdr.version.res}
  34. {$R Res\SetupLdr.offsettable.res}
  35. procedure RaiseLastError(const Msg: TSetupMessageID);
  36. var
  37. ErrorCode: DWORD;
  38. begin
  39. ErrorCode := GetLastError;
  40. raise Exception.Create(FmtSetupMessage(msgLastErrorMessage,
  41. [SetupMessages[Msg], IntToStr(ErrorCode), Win32ErrorString(ErrorCode)]));
  42. end;
  43. procedure ShowExceptionMsg;
  44. begin
  45. if ExceptObject is EAbort then
  46. Exit;
  47. MessageBox(0, PChar(GetExceptMessage), Pointer(SetupMessages[msgErrorTitle]),
  48. MB_OK or MB_ICONSTOP);
  49. { ^ use a Pointer cast instead of a PChar cast so that it will use "nil"
  50. if SetupMessages[msgErrorTitle] is empty due to the messages not being
  51. loaded yet. MessageBox displays 'Error' as the caption if the lpCaption
  52. parameter is nil. }
  53. end;
  54. const
  55. { Exit codes that are returned by SetupLdr.
  56. Note: Setup also returns exit codes with the same numbers. }
  57. ecInitializationError = 1; { Setup failed to initialize. }
  58. ecCancelledBeforeInstall = 2; { User clicked Cancel before the actual
  59. installation started. }
  60. type
  61. PLanguageEntryArray = ^TLanguageEntryArray;
  62. TLanguageEntryArray = array[0..999999] of TSetupLanguageEntry;
  63. var
  64. InitShowHelp: Boolean = False;
  65. InitDisableStartupPrompt: Boolean = False;
  66. InitLang: String;
  67. ActiveLanguage: Integer = -1;
  68. PendingNewLanguage: Integer = -1;
  69. SetupHeader: TSetupHeader;
  70. LanguageEntries: PLanguageEntryArray;
  71. LanguageEntryCount: Integer;
  72. SetupLdrExitCode: Integer = ecInitializationError;
  73. SetupLdrWnd: HWND = 0;
  74. OrigWndProc: Pointer;
  75. RestartSystem: Boolean = False;
  76. procedure ProcessCommandLine;
  77. var
  78. I: Integer;
  79. Name: String;
  80. begin
  81. for I := 1 to NewParamCount do begin
  82. Name := NewParamStr(I);
  83. if (CompareText(Name, '/SP-') = 0) or
  84. (CompareText(Copy(Name, 1, 10), '/SPAWNWND=') = 0) then
  85. InitDisableStartupPrompt := True
  86. else if CompareText(Copy(Name, 1, 6), '/Lang=') = 0 then
  87. InitLang := Copy(Name, 7, Maxint)
  88. else if (CompareText(Name, '/HELP') = 0) or
  89. (CompareText(Name, '/?') = 0) then
  90. InitShowHelp := True;
  91. end;
  92. end;
  93. procedure SetActiveLanguage(const I: Integer);
  94. { Activates the specified language }
  95. begin
  96. if (I >= 0) and (I < LanguageEntryCount) and (I <> ActiveLanguage) then begin
  97. AssignSetupMessages(LanguageEntries[I].Data[1], Length(LanguageEntries[I].Data));
  98. ActiveLanguage := I;
  99. end;
  100. end;
  101. function GetLanguageEntryProc(Index: Integer; var Entry: PSetupLanguageEntry): Boolean;
  102. begin
  103. Result := False;
  104. if Index < LanguageEntryCount then begin
  105. Entry := @LanguageEntries[Index];
  106. Result := True;
  107. end;
  108. end;
  109. procedure ActivateDefaultLanguage;
  110. { Auto-detects the most appropriate language and activates it.
  111. Note: A like-named version of this function is also present in Main.pas. }
  112. var
  113. I: Integer;
  114. begin
  115. DetermineDefaultLanguage(GetLanguageEntryProc, SetupHeader.LanguageDetectionMethod,
  116. InitLang, I);
  117. SetActiveLanguage(I);
  118. end;
  119. function SetupLdrWndProc(Wnd: HWND; Msg: UINT; WParam: WPARAM; LParam: LPARAM): LRESULT;
  120. stdcall;
  121. begin
  122. Result := 0;
  123. case Msg of
  124. WM_QUERYENDSESSION: begin
  125. { Return zero so that a shutdown attempt can't kill SetupLdr }
  126. end;
  127. WM_USER + 150: begin
  128. if WParam = 10000 then begin
  129. { Setup wants SetupLdr to restart the computer before it exits }
  130. RestartSystem := True;
  131. end
  132. else if WParam = 10001 then begin
  133. { Setup wants SetupLdr to change its active language }
  134. PendingNewLanguage := LParam;
  135. end;
  136. end;
  137. else
  138. Result := CallWindowProc(OrigWndProc, Wnd, Msg, WParam, LParam);
  139. end;
  140. end;
  141. procedure ProcessMessages;
  142. var
  143. Msg: TMsg;
  144. begin
  145. while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do begin
  146. TranslateMessage(Msg);
  147. DispatchMessage(Msg);
  148. end;
  149. end;
  150. procedure ExecAndWait(const Filename, Parms: String; var ExitCode: Integer);
  151. var
  152. CmdLine: String;
  153. StartupInfo: TStartupInfo;
  154. ProcessInfo: TProcessInformation;
  155. begin
  156. CmdLine := '"' + Filename + '" ' + Parms;
  157. FillChar(StartupInfo, SizeOf(StartupInfo), 0);
  158. StartupInfo.cb := SizeOf(StartupInfo);
  159. if not CreateProcess(nil, PChar(CmdLine), nil, nil, False, 0, nil, nil,
  160. StartupInfo, ProcessInfo) then
  161. RaiseLastError(msgLdrCannotExecTemp);
  162. CloseHandle(ProcessInfo.hThread);
  163. { Wait for the process to terminate, processing messages in the meantime }
  164. repeat
  165. ProcessMessages;
  166. until MsgWaitForMultipleObjects(1, ProcessInfo.hProcess, False, INFINITE,
  167. QS_ALLINPUT) <> WAIT_OBJECT_0+1;
  168. { Now that the process has exited, process any remaining messages.
  169. (There may be an asynchronously-sent "restart request" message still
  170. queued if MWFMO saw the process terminate before checking for new
  171. messages.) }
  172. ProcessMessages;
  173. GetExitCodeProcess(ProcessInfo.hProcess, DWORD(ExitCode));
  174. CloseHandle(ProcessInfo.hProcess);
  175. end;
  176. procedure SetupCorruptError;
  177. begin
  178. if SetupMessages[msgSetupFileCorrupt] <> '' then
  179. raise Exception.Create(SetupMessages[msgSetupFileCorrupt])
  180. else
  181. { In case the messages haven't been loaded yet, use the constant }
  182. raise Exception.Create(SSetupFileCorrupt);
  183. end;
  184. procedure RunImageLocally(const Module: HMODULE);
  185. { Force all of the specified module to be paged in to ensure subsequent
  186. accesses don't cause the disk image to be read.
  187. Based on code from http://www.microsoft.com/msj/0398/win320398.htm, with
  188. some fixes incorporated. }
  189. procedure Touch(var X: DWORD);
  190. { Note: Uses asm to ensure it isn't optimized away }
  191. asm
  192. xor edx, edx
  193. lock or [eax], edx
  194. end;
  195. var
  196. SysInfo: TSystemInfo;
  197. CurAddr: Pointer;
  198. MemInfo: TMemoryBasicInformation;
  199. ChangedProtection: Boolean;
  200. OrigProtect: DWORD;
  201. Offset: Cardinal;
  202. begin
  203. { Get system's page size }
  204. GetSystemInfo(SysInfo);
  205. CurAddr := Pointer(Module);
  206. if VirtualQuery(CurAddr, MemInfo, SizeOf(MemInfo)) = 0 then
  207. Exit;
  208. { Perform this loop until we find a region beyond the end of the file }
  209. while MemInfo.AllocationBase = Pointer(Module) do begin
  210. { We can only force committed pages into RAM.
  211. We do not want to trigger guard pages and confuse the application. }
  212. if (MemInfo.State = MEM_COMMIT) and (MemInfo.Protect and PAGE_GUARD = 0) then begin
  213. ChangedProtection := False;
  214. { Determine if the pages in this region are nonwriteable }
  215. if (MemInfo.Protect = PAGE_NOACCESS) or
  216. (MemInfo.Protect = PAGE_READONLY) or
  217. (MemInfo.Protect = PAGE_EXECUTE) or
  218. (MemInfo.Protect = PAGE_EXECUTE_READ) then begin
  219. { Nonwriteable region, make it writeable (with the least protection) }
  220. if VirtualProtect(MemInfo.BaseAddress, MemInfo.RegionSize,
  221. PAGE_EXECUTE_READWRITE, @OrigProtect) then
  222. ChangedProtection := True;
  223. end;
  224. { Write to every page in the region.
  225. This forces the page to be in RAM and swapped to the paging file. }
  226. Offset := 0;
  227. while Offset < Cardinal(MemInfo.RegionSize) do begin
  228. Touch(PDWORD(Cardinal(MemInfo.BaseAddress) + Offset)^);
  229. Inc(Offset, SysInfo.dwPageSize);
  230. end;
  231. { If we changed the protection, change it back }
  232. if ChangedProtection then
  233. VirtualProtect(MemInfo.BaseAddress, MemInfo.RegionSize, OrigProtect,
  234. @OrigProtect);
  235. end;
  236. { Get next region }
  237. Cardinal(CurAddr) := Cardinal(MemInfo.BaseAddress) + MemInfo.RegionSize;
  238. if VirtualQuery(CurAddr, MemInfo, SizeOf(MemInfo)) = 0 then
  239. Break;
  240. end;
  241. end;
  242. function GetSetupLdrOffsetTable: PSetupLdrOffsetTable;
  243. { Locates the offset table resource, and returns a pointer to it }
  244. var
  245. Rsrc: HRSRC;
  246. ResData: HGLOBAL;
  247. begin
  248. Rsrc := FindResource(0, MAKEINTRESOURCE(SetupLdrOffsetTableResID), RT_RCDATA);
  249. if Rsrc = 0 then
  250. SetupCorruptError;
  251. if SizeofResource(0, Rsrc) <> SizeOf(Result^) then
  252. SetupCorruptError;
  253. ResData := LoadResource(0, Rsrc);
  254. if ResData = 0 then
  255. SetupCorruptError;
  256. Result := LockResource(ResData);
  257. if Result = nil then
  258. SetupCorruptError;
  259. end;
  260. procedure ShowHelp(const CustomNote: String);
  261. const
  262. SNewLine = #13#10;
  263. var
  264. PrNote, Help: String;
  265. begin
  266. { do not localize }
  267. if proCommandLine in SetupHeader.PrivilegesRequiredOverridesAllowed then begin
  268. PrNote := '/ALLUSERS' + SNewLine +
  269. 'Instructs Setup to install in administrative install mode.' + SNewLine +
  270. '/CURRENTUSER' + SNewLine +
  271. 'Instructs Setup to install in non administrative install mode.' + SNewLine;
  272. end else
  273. PrNote := '';
  274. Help := 'The Setup program accepts optional command line parameters.' + SNewLine +
  275. SNewLine +
  276. '/HELP, /?' + SNewLine +
  277. 'Shows this information.' + SNewLine +
  278. '/SP-' + SNewLine +
  279. 'Disables the "This will install... Do you wish to continue?" message box at the beginning of Setup.' + SNewLine +
  280. '/SILENT, /VERYSILENT' + SNewLine +
  281. 'Instructs Setup to be silent or very silent.' + SNewLine +
  282. '/SUPPRESSMSGBOXES' + SNewLine +
  283. 'Instructs Setup to suppress message boxes.' + SNewLine +
  284. '/LOG' + SNewLine +
  285. 'Causes Setup to create a log file in the user''s TEMP directory.' + SNewLine +
  286. '/LOG="filename"' + SNewLine +
  287. 'Same as /LOG, except it allows you to specify a fixed path/filename to use for the log file.' + SNewLine +
  288. '/NOCANCEL' + SNewLine +
  289. 'Prevents the user from cancelling during the installation process.' + SNewLine +
  290. '/NORESTART' + SNewLine +
  291. 'Prevents Setup from restarting the system following a successful installation, or after a Preparing to Install failure that requests a restart.' + SNewLine +
  292. '/RESTARTEXITCODE=exit code' + SNewLine +
  293. 'Specifies a custom exit code that Setup is to return when the system needs to be restarted.' + SNewLine +
  294. '/CLOSEAPPLICATIONS' + SNewLine +
  295. 'Instructs Setup to close applications using files that need to be updated.' + SNewLine +
  296. '/NOCLOSEAPPLICATIONS' + SNewLine +
  297. 'Prevents Setup from closing applications using files that need to be updated.' + SNewLine +
  298. '/FORCECLOSEAPPLICATIONS' + SNewLine +
  299. 'Instructs Setup to force close when closing applications.' + SNewLine +
  300. '/FORCENOCLOSEAPPLICATIONS' + SNewLine +
  301. 'Prevents Setup from force closing when closing applications.' + SNewLine +
  302. '/LOGCLOSEAPPLICATIONS' + SNewLine +
  303. 'Instructs Setup to create extra logging when closing applications for debugging purposes.' + SNewLine +
  304. '/RESTARTAPPLICATIONS' + SNewLine +
  305. 'Instructs Setup to restart applications.' + SNewLine +
  306. '/NORESTARTAPPLICATIONS' + SNewLine +
  307. 'Prevents Setup from restarting applications.' + SNewLine +
  308. '/LOADINF="filename"' + SNewLine +
  309. 'Instructs Setup to load the settings from the specified file after having checked the command line.' + SNewLine +
  310. '/SAVEINF="filename"' + SNewLine +
  311. 'Instructs Setup to save installation settings to the specified file.' + SNewLine +
  312. '/LANG=language' + SNewLine +
  313. 'Specifies the internal name of the language to use.' + SNewLine +
  314. '/DIR="x:\dirname"' + SNewLine +
  315. 'Overrides the default directory name.' + SNewLine +
  316. '/GROUP="folder name"' + SNewLine +
  317. 'Overrides the default folder name.' + SNewLine +
  318. '/NOICONS' + SNewLine +
  319. 'Instructs Setup to initially check the Don''t create a Start Menu folder check box.' + SNewLine +
  320. '/TYPE=type name' + SNewLine +
  321. 'Overrides the default setup type.' + SNewLine +
  322. '/COMPONENTS="comma separated list of component names"' + SNewLine +
  323. 'Overrides the default component settings.' + SNewLine +
  324. '/TASKS="comma separated list of task names"' + SNewLine +
  325. 'Specifies a list of tasks that should be initially selected.' + SNewLine +
  326. '/MERGETASKS="comma separated list of task names"' + SNewLine +
  327. 'Like the /TASKS parameter, except the specified tasks will be merged with the set of tasks that would have otherwise been selected by default.' + SNewLine +
  328. '/PASSWORD=password' + SNewLine +
  329. 'Specifies the password to use.' + SNewLine +
  330. PrNote +
  331. CustomNote +
  332. SNewLine +
  333. 'For more detailed information, please visit https://jrsoftware.org/ishelp/index.php?topic=setupcmdline';
  334. MessageBox(0, PChar(Help), 'Setup', MB_OK or MB_ICONSTOP);
  335. end;
  336. var
  337. SelfFilename: String;
  338. SourceF, DestF: TFile;
  339. OffsetTable: PSetupLdrOffsetTable;
  340. TempDir: String;
  341. S: String;
  342. TempFile: String;
  343. TestID: TSetupID;
  344. P: Pointer;
  345. Reader: TCompressedBlockReader;
  346. I: Integer;
  347. begin
  348. try
  349. { Ensure all of SetupLdr is paged in so that in the case of a disk spanning
  350. install Windows will never complain when the disk/CD containing SetupLdr
  351. is ejected. }
  352. RunImageLocally(HInstance);
  353. ProcessCommandLine;
  354. SelfFilename := NewParamStr(0);
  355. SourceF := TFile.Create(SelfFilename, fdOpenExisting, faRead, fsRead);
  356. try
  357. OffsetTable := GetSetupLdrOffsetTable;
  358. { Note: We don't check the OffsetTable.ID here because it would put a
  359. copy of the ID in the data section, and that would confuse external
  360. programs that search for the offset table by ID. }
  361. if (OffsetTable.Version <> SetupLdrOffsetTableVersion) or
  362. (GetCRC32(OffsetTable^, SizeOf(OffsetTable^) - SizeOf(OffsetTable.TableCRC)) <> OffsetTable.TableCRC) or
  363. ((SourceF.Size.Hi = 0) and (SourceF.Size.Lo < OffsetTable.TotalSize)) then
  364. SetupCorruptError;
  365. SourceF.Seek(OffsetTable.Offset0);
  366. SourceF.ReadBuffer(TestID, SizeOf(TestID));
  367. if TestID <> SetupID then
  368. SetupCorruptError;
  369. try
  370. Reader := TCompressedBlockReader.Create(SourceF, TLZMA1SmallDecompressor);
  371. try
  372. SECompressedBlockRead(Reader, SetupHeader, SizeOf(SetupHeader),
  373. SetupHeaderStrings, SetupHeaderAnsiStrings);
  374. LanguageEntryCount := SetupHeader.NumLanguageEntries;
  375. LanguageEntries := AllocMem(LanguageEntryCount * SizeOf(TSetupLanguageEntry));
  376. for I := 0 to LanguageEntryCount-1 do
  377. SECompressedBlockRead(Reader, LanguageEntries[I], SizeOf(LanguageEntries[I]),
  378. SetupLanguageEntryStrings, SetupLanguageEntryAnsiStrings);
  379. finally
  380. Reader.Free;
  381. end;
  382. except
  383. on ECompressDataError do
  384. SetupCorruptError;
  385. end;
  386. ActivateDefaultLanguage;
  387. if InitShowHelp then begin
  388. { Show the command line help. }
  389. ShowHelp(SetupMessages[msgHelpTextNote]);
  390. SetupLdrExitCode := 0;
  391. end else begin
  392. { Show the startup prompt. If this is enabled, SetupHeader.AppName won't
  393. have constants. }
  394. if not(shDisableStartupPrompt in SetupHeader.Options) and
  395. not InitDisableStartupPrompt and
  396. (MessageBox(0, PChar(FmtSetupMessage1(msgSetupLdrStartupMessage, SetupHeader.AppName)),
  397. PChar(SetupMessages[msgSetupAppTitle]), MB_YESNO or MB_ICONQUESTION) <> IDYES) then begin
  398. SetupLdrExitCode := ecCancelledBeforeInstall;
  399. Abort;
  400. end;
  401. { Create a temporary directory, and extract the embedded setup program
  402. there }
  403. Randomize;
  404. TempDir := CreateTempDir(IsAdminLoggedOn);
  405. S := AddBackslash(TempDir) + PathChangeExt(PathExtractName(SelfFilename), '.tmp');
  406. TempFile := S; { assign only if string was successfully constructed }
  407. SourceF.Seek(OffsetTable.OffsetEXE);
  408. try
  409. P := nil;
  410. DestF := TFile.Create(TempFile, fdCreateAlways, faWrite, fsNone);
  411. try
  412. GetMem(P, OffsetTable.UncompressedSizeEXE);
  413. FillChar(P^, OffsetTable.UncompressedSizeEXE, 0);
  414. try
  415. Reader := TCompressedBlockReader.Create(SourceF, TLZMA1SmallDecompressor);
  416. try
  417. Reader.Read(P^, OffsetTable.UncompressedSizeEXE);
  418. finally
  419. Reader.Free;
  420. end;
  421. except
  422. on ECompressDataError do
  423. SetupCorruptError;
  424. end;
  425. TransformCallInstructions(P^, OffsetTable.UncompressedSizeEXE, False, 0);
  426. if GetCRC32(P^, OffsetTable.UncompressedSizeEXE) <> OffsetTable.CRCEXE then
  427. SetupCorruptError;
  428. { Preallocate the bytes to avoid file system fragmentation }
  429. DestF.Seek(OffsetTable.UncompressedSizeEXE);
  430. DestF.Truncate;
  431. DestF.Seek(0);
  432. DestF.WriteBuffer(P^, OffsetTable.UncompressedSizeEXE);
  433. finally
  434. FreeMem(P);
  435. DestF.Free;
  436. end;
  437. except
  438. on E: EFileError do begin
  439. SetLastError(E.ErrorCode);
  440. RaiseLastError(msgLdrCannotCreateTemp);
  441. end;
  442. end;
  443. FreeAndNil(SourceF);
  444. { Create SetupLdrWnd, which is used by Setup to communicate with
  445. SetupLdr }
  446. SetupLdrWnd := CreateWindowEx(0, 'STATIC', 'InnoSetupLdrWindow', 0,
  447. 0, 0, 0, 0, HWND_DESKTOP, 0, HInstance, nil);
  448. Longint(OrigWndProc) := SetWindowLong(SetupLdrWnd, GWL_WNDPROC,
  449. Longint(@SetupLdrWndProc));
  450. { Now execute Setup. Use the exit code it returns as our exit code. }
  451. ExecAndWait(TempFile, Format('/SL5="$%x,%d,%d,',
  452. [SetupLdrWnd, OffsetTable.Offset0, OffsetTable.Offset1]) +
  453. SelfFilename + '" ' + GetCmdTail, SetupLdrExitCode);
  454. { Synchronize our active language with Setup's, in case we need to
  455. display any messages below }
  456. if PendingNewLanguage <> -1 then
  457. SetActiveLanguage(PendingNewLanguage);
  458. end;
  459. finally
  460. SourceF.Free;
  461. if TempFile <> '' then
  462. { Even though Setup has terminated by now, the system may still have
  463. the file locked for a short period of time (esp. on multiprocessor
  464. systems), so use DelayDeleteFile to delete it. }
  465. DelayDeleteFile(False, TempFile, 13, 50, 250);
  466. if TempDir <> '' then
  467. RemoveDirectory(PChar(TempDir));
  468. if SetupLdrWnd <> 0 then
  469. { SetupLdrWnd must be destroyed before RestartComputer is called,
  470. otherwise SetupLdrWndProc would deny the shutdown request }
  471. DestroyWindow(SetupLdrWnd);
  472. if Assigned(LanguageEntries) then begin
  473. Finalize(LanguageEntries[0], LanguageEntryCount);
  474. FreeMem(LanguageEntries);
  475. LanguageEntries := nil;
  476. end;
  477. end;
  478. if RestartSystem then begin
  479. if not RestartComputer then
  480. MessageBox(0, PChar(SetupMessages[msgErrorRestartingComputer]),
  481. PChar(SetupMessages[msgErrorTitle]), MB_OK or MB_ICONEXCLAMATION or
  482. MB_SETFOREGROUND);
  483. end;
  484. except
  485. ShowExceptionMsg;
  486. end;
  487. Halt(SetupLdrExitCode);
  488. end.