Compil32.dpr 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. program Compil32;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2019 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. Compiler
  8. }
  9. {$SetPEFlags 1}
  10. {$SETPEOSVERSION 6.0}
  11. {$SETPESUBSYSVERSION 6.0}
  12. {$WEAKLINKRTTI ON}
  13. uses
  14. SafeDLLPath in 'SafeDLLPath.pas',
  15. Windows,
  16. SysUtils,
  17. Forms,
  18. PathFunc,
  19. CompForm in 'CompForm.pas' {CompileForm},
  20. CmnFunc in 'CmnFunc.pas',
  21. CmnFunc2 in 'CmnFunc2.pas',
  22. CompFunc in 'CompFunc.pas',
  23. CompMsgs in 'CompMsgs.pas',
  24. CompInt in 'CompInt.pas',
  25. CompOptions in 'CompOptions.pas' {OptionsForm},
  26. CompStartup in 'CompStartup.pas' {StartupForm},
  27. CompWizard in 'CompWizard.pas' {WizardForm},
  28. CompWizardFile in 'CompWizardFile.pas' {WizardFileForm},
  29. CompFileAssoc in 'CompFileAssoc.pas',
  30. TmSchema in '..\Components\TmSchema.pas',
  31. UxTheme in '..\Components\UxTheme.pas',
  32. DebugStruct in 'DebugStruct.pas',
  33. BrowseFunc in 'BrowseFunc.pas',
  34. CompSignTools in 'CompSignTools.pas' {SignToolsForm},
  35. CompInputQueryCombo in 'CompInputQueryCombo.pas',
  36. ScintInt in '..\Components\ScintInt.pas',
  37. ScintEdit in '..\Components\ScintEdit.pas',
  38. ScintStylerInnoSetup in '..\Components\ScintStylerInnoSetup.pas',
  39. ModernColors in '..\Components\ModernColors.pas',
  40. CompMessageBoxDesigner in 'CompMessageBoxDesigner.pas' {MBDForm},
  41. CompScintEdit in 'CompScintEdit.pas';
  42. {$R Compil32.docicon.res}
  43. {$R Compil32.manifest.res}
  44. {$R Compil32.versionandicon.res}
  45. procedure SetAppUserModelID;
  46. var
  47. Func: function(AppID: PWideChar): HRESULT; stdcall;
  48. begin
  49. { On Windows 7, for the IDE to be pinnable and show a Jump List, it is
  50. necessary to explicitly assign an AppUserModelID because by default the
  51. taskbar excludes applications that have "Setup" in their name. }
  52. Func := GetProcAddress(GetModuleHandle('shell32.dll'),
  53. 'SetCurrentProcessExplicitAppUserModelID');
  54. if Assigned(Func) then
  55. Func('JR.InnoSetup.IDE.6');
  56. end;
  57. procedure RegisterApplicationRestart;
  58. const
  59. RESTART_MAX_CMD_LINE = 1024;
  60. RESTART_NO_CRASH = $1;
  61. RESTART_NO_HANG = $2;
  62. RESTART_NO_PATCH = $4;
  63. RESTART_NO_REBOOT = $8;
  64. var
  65. Func: function(pwzCommandLine: PWideChar; dwFlags: DWORD): HRESULT; stdcall;
  66. CommandLine: WideString;
  67. begin
  68. { Allow Restart Manager to restart us after updates. }
  69. Func := GetProcAddress(GetModuleHandle('kernel32.dll'),
  70. 'RegisterApplicationRestart');
  71. if Assigned(Func) then begin
  72. { Rebuild the command line, can't just use an exact copy since it might contain
  73. relative path names but Restart Manager doesn't restore the working
  74. directory. }
  75. if CommandLineWizard then
  76. CommandLine := '/WIZARD'
  77. else begin
  78. CommandLine := CommandLineFilename;
  79. if CommandLine <> '' then
  80. CommandLine := '"' + CommandLine + '"';
  81. if CommandLineCompile then
  82. CommandLine := '/CC ' + CommandLine;
  83. end;
  84. if Length(CommandLine) > RESTART_MAX_CMD_LINE then
  85. CommandLine := '';
  86. Func(PWideChar(CommandLine), RESTART_NO_CRASH or RESTART_NO_HANG or RESTART_NO_REBOOT);
  87. end;
  88. end;
  89. procedure CreateMutexes;
  90. { Creates the two mutexes used by the Inno Setup's own installer/uninstaller to
  91. see if the compiler is still running.
  92. One of the mutexes is created in the global name space (which makes it
  93. possible to access the mutex across user sessions in Windows XP); the other
  94. is created in the session name space (because versions of Windows NT prior
  95. to 4.0 TSE don't have a global name space and don't support the 'Global\'
  96. prefix). }
  97. const
  98. MutexName = 'InnoSetupCompilerAppMutex';
  99. begin
  100. CreateMutex(MutexName);
  101. CreateMutex('Global\' + MutexName); { don't localize }
  102. end;
  103. var
  104. InitialCurDir: String;
  105. procedure CheckParams;
  106. procedure Error;
  107. begin
  108. MessageBox(0, SCompilerCommandLineHelp3, SCompilerFormCaption,
  109. MB_OK or MB_ICONEXCLAMATION);
  110. Halt(1);
  111. end;
  112. var
  113. P, I: Integer;
  114. S: String;
  115. Dummy: Boolean;
  116. begin
  117. P := NewParamCount;
  118. I := 1;
  119. while I <= P do begin
  120. S := NewParamStr(I);
  121. if CompareText(S, '/CC') = 0 then
  122. CommandLineCompile := True
  123. else if CompareText(S, '/WIZARD') = 0 then begin
  124. if I = P then
  125. Error;
  126. CommandLineWizard := True;
  127. CommandLineWizardName := NewParamStr(I+1);
  128. Inc(I);
  129. end
  130. else if CompareText(S, '/ASSOC') = 0 then begin
  131. try
  132. RegisterISSFileAssociation(False, Dummy);
  133. except
  134. MessageBox(0, PChar(GetExceptMessage), nil, MB_OK or MB_ICONSTOP);
  135. Halt(2);
  136. end;
  137. Halt;
  138. end
  139. else if CompareText(S, '/UNASSOC') = 0 then begin
  140. try
  141. UnregisterISSFileAssociation;
  142. except
  143. MessageBox(0, PChar(GetExceptMessage), nil, MB_OK or MB_ICONSTOP);
  144. Halt(2);
  145. end;
  146. Halt;
  147. end
  148. else if (S = '') or (S[1] = '/') or (CommandLineFilename <> '') then
  149. Error
  150. else
  151. CommandLineFilename := PathExpand(PathCombine(InitialCurDir, S));
  152. Inc(I);
  153. end;
  154. if (CommandLineCompile or CommandLineWizard) and (CommandLineFilename = '') then
  155. Error;
  156. end;
  157. begin
  158. InitialCurDir := GetCurrentDir;
  159. if not SetCurrentDir(PathExtractDir(NewParamStr(0))) then
  160. SetCurrentDir(GetSystemDir);
  161. SetAppUserModelID;
  162. CreateMutexes;
  163. Application.Initialize;
  164. CheckParams;
  165. RegisterApplicationRestart;
  166. { The 'with' is so that the Delphi IDE doesn't mess with these }
  167. with Application do begin
  168. if CommandLineWizard then
  169. Title := CommandLineWizardName
  170. else
  171. Title := SCompilerFormCaption;
  172. end;
  173. Application.CreateForm(TCompileForm, CompileForm);
  174. Application.Run;
  175. end.