IDE.MainForm.ToolsHelper.pas 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. unit IDE.MainForm.ToolsHelper;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2025 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. Compiler form - Tools helper which has the menu update helper as ancestor
  8. Not used by MainForm: it uses IDE.MainForm.FinalHelper instead
  9. }
  10. interface
  11. uses
  12. Menus,
  13. ScintEdit,
  14. IDE.MainForm, IDE.MainForm.UpdateMenuHelper;
  15. type
  16. TMainFormToolsHelper = class helper(TMainFormUpdateMenuHelper) for TMainForm
  17. procedure StartAddRemovePrograms;
  18. procedure InsertGeneratedGuid(const AMemo: TScintEdit);
  19. procedure ShowMsgBoxDesignerForm(const AMemo: TScintEdit);
  20. procedure ShowRegistryDesignerForm(const AMemo: TScintEdit);
  21. procedure ShowFilesDesignerForm(const AMemo: TScintEdit);
  22. procedure ShowSignToolsForm;
  23. end;
  24. implementation
  25. uses
  26. Windows,
  27. SysUtils, Forms, UITypes,
  28. PathFunc,
  29. Shared.CommonFunc, Shared.CommonFunc.Vcl, Shared.ConfigIniFile,
  30. IDE.Messages, IDE.HelperFunc, IDE.ScintStylerInnoSetup, IDE.SignToolsForm, IDE.MsgBoxDesignerForm,
  31. IDE.FilesDesignerForm, IDE.RegistryDesignerForm, IDE.Wizard.WizardFormRegistryHelper;
  32. procedure TMainFormToolsHelper.StartAddRemovePrograms;
  33. var
  34. Dir: String;
  35. Wow64DisableWow64FsRedirectionFunc: function(var OldValue: Pointer): BOOL; stdcall;
  36. Wow64RevertWow64FsRedirectionFunc: function(OldValue: Pointer): BOOL; stdcall;
  37. RedirDisabled: Boolean;
  38. RedirOldValue: Pointer;
  39. StartupInfo: TStartupInfo;
  40. ProcessInfo: TProcessInformation;
  41. begin
  42. Dir := GetSystemDir;
  43. FillChar(StartupInfo, SizeOf(StartupInfo), 0);
  44. StartupInfo.cb := SizeOf(StartupInfo);
  45. { Have to disable file system redirection because the 32-bit version of
  46. appwiz.cpl is buggy on XP x64 RC2 -- it doesn't show any Change/Remove
  47. buttons on 64-bit MSI entries, and it doesn't list non-MSI 64-bit apps
  48. at all. }
  49. Wow64DisableWow64FsRedirectionFunc := GetProcAddress(GetModuleHandle(kernel32),
  50. 'Wow64DisableWow64FsRedirection');
  51. Wow64RevertWow64FsRedirectionFunc := GetProcAddress(GetModuleHandle(kernel32),
  52. 'Wow64RevertWow64FsRedirection');
  53. RedirDisabled := Assigned(Wow64DisableWow64FsRedirectionFunc) and
  54. Assigned(Wow64RevertWow64FsRedirectionFunc) and
  55. Wow64DisableWow64FsRedirectionFunc(RedirOldValue);
  56. try
  57. Win32Check(CreateProcess(nil, PChar('"' + AddBackslash(Dir) + 'control.exe" appwiz.cpl'),
  58. nil, nil, False, 0, nil, PChar(Dir), StartupInfo, ProcessInfo));
  59. finally
  60. if RedirDisabled then
  61. Wow64RevertWow64FsRedirectionFunc(RedirOldValue);
  62. end;
  63. CloseHandle(ProcessInfo.hProcess);
  64. CloseHandle(ProcessInfo.hThread);
  65. end;
  66. procedure TMainFormToolsHelper.InsertGeneratedGuid(const AMemo: TScintEdit);
  67. begin
  68. if MsgBox('The generated GUID will be inserted into the editor at the cursor position. Continue?',
  69. SCompilerFormCaption, mbConfirmation, MB_YESNO) = IDYES then
  70. AMemo.MainSelText := GenerateGuid;
  71. end;
  72. procedure TMainFormToolsHelper.ShowMsgBoxDesignerForm(const AMemo: TScintEdit);
  73. begin
  74. if (FMemosStyler.GetSectionFromLineState(AMemo.Lines.State[AMemo.CaretLine]) <> scCode) and
  75. (MsgBox('The generated Pascal script will be inserted into the editor at the cursor position, but the cursor is not in the [Code] section. Continue anyway?',
  76. SCompilerFormCaption, mbConfirmation, MB_YESNO) = IDNO) then
  77. Exit;
  78. var MsgBoxForm := TMsgBoxDesignerForm.Create(Application);
  79. try
  80. if MsgBoxForm.ShowModal = mrOk then
  81. AMemo.MainSelText := MsgBoxForm.GetText(FOptions.TabWidth, FOptions.UseTabCharacter);
  82. finally
  83. MsgBoxForm.Free;
  84. end;
  85. end;
  86. procedure TMainFormToolsHelper.ShowRegistryDesignerForm(const AMemo: TScintEdit);
  87. begin
  88. var RegistryDesignerForm := TRegistryDesignerForm.Create(Application);
  89. try
  90. var PrivilegesRequired := FindSetupDirectiveValue('PrivilegesRequired', 'admin');
  91. var PrivilegesRequiredOverridesAllowed := FindSetupDirectiveValue('PrivilegesRequiredOverridesAllowed', '');
  92. if PrivilegesRequiredOverridesAllowed = '' then begin
  93. if SameText(PrivilegesRequired, 'admin') then
  94. RegistryDesignerForm.PrivilegesRequired := prAdmin
  95. else
  96. RegistryDesignerForm.PrivilegesRequired := prLowest
  97. end else
  98. RegistryDesignerForm.PrivilegesRequired := prDynamic;
  99. if RegistryDesignerForm.ShowModal = mrOk then
  100. begin
  101. AMemo.CaretColumn := 0;
  102. var Text := RegistryDesignerForm.Text;
  103. if FMemosStyler.GetSectionFromLineState(AMemo.Lines.State[AMemo.CaretLine]) <> scRegistry then
  104. Text := '[Registry]' + SNewLine + Text;
  105. AMemo.MainSelText := Text;
  106. end;
  107. finally
  108. RegistryDesignerForm.Free;
  109. end;
  110. end;
  111. procedure TMainFormToolsHelper.ShowFilesDesignerForm(const AMemo: TScintEdit);
  112. begin
  113. var FilesDesignerForm := TFilesDesignerForm.Create(Application);
  114. try
  115. FilesDesignerForm.CreateAppDir := FindSetupDirectiveValue('CreateAppDir', True);
  116. if FilesDesignerForm.ShowModal = mrOk then begin
  117. AMemo.CaretColumn := 0;
  118. var Text := FilesDesignerForm.Text;
  119. if FMemosStyler.GetSectionFromLineState(AMemo.Lines.State[AMemo.CaretLine]) <> scFiles then
  120. Text := '[Files]' + SNewLine + Text;
  121. AMemo.MainSelText := Text;
  122. end;
  123. finally
  124. FilesDesignerForm.Free;
  125. end;
  126. end;
  127. procedure TMainFormToolsHelper.ShowSignToolsForm;
  128. var
  129. SignToolsForm: TSignToolsForm;
  130. Ini: TConfigIniFile;
  131. I: Integer;
  132. begin
  133. SignToolsForm := TSignToolsForm.Create(Application);
  134. try
  135. SignToolsForm.SignTools := FSignTools;
  136. if SignToolsForm.ShowModal = mrOk then begin
  137. FSignTools.Assign(SignToolsForm.SignTools);
  138. { Save new options }
  139. Ini := TConfigIniFile.Create;
  140. try
  141. Ini.EraseSection('SignTools');
  142. for I := 0 to FSignTools.Count-1 do
  143. Ini.WriteString('SignTools', 'SignTool' + IntToStr(I), FSignTools[I]);
  144. finally
  145. Ini.Free;
  146. end;
  147. end;
  148. finally
  149. SignToolsForm.Free;
  150. end;
  151. end;
  152. end.