Selaa lähdekoodia

Links displayed by [Setup] section directives LicenseFile, InfoBeforeFile and InfoAfterFile are now executed as the original user if possible when clicked.

Martijn Laan 4 vuotta sitten
vanhempi
commit
a919591beb
4 muutettua tiedostoa jossa 21 lisäystä ja 2 poistoa
  1. 10 2
      Components/RichEditViewer.pas
  2. 8 0
      Projects/Main.pas
  3. 2 0
      Projects/Setup.dpr
  4. 1 0
      whatsnew.htm

+ 10 - 2
Components/RichEditViewer.pas

@@ -37,11 +37,14 @@ type
       const chrg: TCharRange; out menu: HMENU): HResult; stdcall;
   end;
   
+  TRichEditViewerCustomShellExecute = procedure(hWnd: HWND; Operation, FileName, Parameters, Directory: LPWSTR; ShowCmd: Integer); stdcall;
+  
   TRichEditViewer = class(TMemo)
   private
     FUseRichEdit: Boolean;
     FRichEditLoaded: Boolean;
     FCallback: IRichEditOleCallback;
+    class var FCustomShellExecute: TRichEditViewerCustomShellExecute;
     procedure SetRTFTextProp(const Value: AnsiString);
     procedure SetUseRichEdit(Value: Boolean);
     procedure UpdateBackgroundColor;
@@ -56,6 +59,7 @@ type
     destructor Destroy; override;
     function SetRTFText(const Value: AnsiString): Integer;
     property RTFText: AnsiString write SetRTFTextProp;
+    class property CustomShellExecute: TRichEditViewerCustomShellExecute read FCustomShellExecute write FCustomShellExecute;
   published
     property UseRichEdit: Boolean read FUseRichEdit write SetUseRichEdit default True;
   end;
@@ -411,8 +415,12 @@ begin
             TextRange.chrg := CharRange;
             TextRange.lpstrText := PChar(URL);
             SetLength(URL, SendMessage(Handle, EM_GETTEXTRANGE, 0, LParam(@TextRange)));
-            if URL <> '' then
-              ShellExecute(Handle, 'open', PChar(URL), nil, nil, SW_SHOWNORMAL);
+            if URL <> '' then begin
+              if Assigned(FCustomShellExecute) then
+                FCustomShellExecute(Handle, 'open', PChar(URL), nil, nil, SW_SHOWNORMAL)
+              else
+                ShellExecute(Handle, 'open', PChar(URL), nil, nil, SW_SHOWNORMAL);
+            end;
           end;
         end;
       end;

+ 8 - 0
Projects/Main.pas

@@ -242,6 +242,7 @@ procedure RemoveTempInstallDir;
 procedure SaveResourceToTempFile(const ResName, Filename: String);
 procedure SetActiveLanguage(const I: Integer);
 procedure SetTaskbarButtonVisibility(const AVisible: Boolean);
+procedure ShellExecuteAsOriginalUser(hWnd: HWND; Operation, FileName, Parameters, Directory: LPWSTR; ShowCmd: Integer); stdcall;
 function ShouldDisableFsRedirForFileEntry(const FileEntry: PSetupFileEntry): Boolean;
 function ShouldDisableFsRedirForRunEntry(const RunEntry: PSetupRunEntry): Boolean;
 function EvalDirectiveCheck(const Expression: String): Boolean;
@@ -3987,6 +3988,13 @@ begin
   end;
 end;
 
+procedure ShellExecuteAsOriginalUser(hWnd: HWND; Operation, FileName, Parameters, Directory: LPWSTR; ShowCmd: Integer); stdcall;
+var
+  ErrorCode: Integer;
+begin
+  InstShellExecEx(True, Operation, Filename, Parameters, Directory, ewNoWait, ShowCmd, ProcessMessagesProc, ErrorCode);
+end;
+
 function TMainForm.Install: Boolean;
 
   procedure ProcessRunEntries;

+ 2 - 0
Projects/Setup.dpr

@@ -21,6 +21,7 @@ uses
   Windows,
   SysUtils,
   Messages,
+  RichEditViewer,
   CmnFunc in 'CmnFunc.pas',
   CmnFunc2 in 'CmnFunc2.pas',
   Main in 'Main.pas' {MainForm},
@@ -272,6 +273,7 @@ begin
     SetErrorMode(SEM_FAILCRITICALERRORS);
     DisableWindowGhosting;
     Application.HookMainWindow(TDummyClass.AntiShutdownHook);
+    TRichEditViewer.CustomShellExecute := ShellExecuteAsOriginalUser;
     SelectMode; { Only returns if we should run as Setup }
   except
     { Halt on any exception }

+ 1 - 0
whatsnew.htm

@@ -30,6 +30,7 @@ For conditions of distribution and use, see <a href="https://jrsoftware.org/file
 
 <p><a name="6.1.3"></a><span class="ver">6.1.3-dev </span><span class="date">(?)</span></p>
 <ul>
+  <li>Links displayed by [Setup] section directives <tt>LicenseFile</tt>, <tt>InfoBeforeFile</tt> and <tt>InfoAfterFile</tt> are now executed as the original user if possible when clicked.</li>
   <li>/LOG: Now logs more uninstaller actions.</li>
   <li>Compiler IDE change: <i>Fix:</i> Autocomplete support for event functions listed some procedures as functions.</li>
   <li>Pascal Scripting changes: