Browse Source

/LOG: Now logs registry entries.

Martijn Laan 7 years ago
parent
commit
0e0d5e75f6
2 changed files with 64 additions and 28 deletions
  1. 63 28
      Projects/Install.pas
  2. 1 0
      whatsnew.htm

+ 63 - 28
Projects/Install.pas

@@ -2054,7 +2054,7 @@ var
   end;
   end;
 
 
   procedure CreateRegistryEntries;
   procedure CreateRegistryEntries;
-
+  
     function IsDeletableSubkey(const S: String): Boolean;
     function IsDeletableSubkey(const S: String): Boolean;
     { A sanity check to prevent people from shooting themselves in the foot by
     { A sanity check to prevent people from shooting themselves in the foot by
       using
       using
@@ -2080,18 +2080,16 @@ var
     var
     var
       P: PSetupPermissionEntry;
       P: PSetupPermissionEntry;
     begin
     begin
-      if PermsEntry <> -1 then begin
-        LogFmt('Setting permissions on registry key: %s\%s',
-          [GetRegRootKeyName(RootKey), Subkey]);
-        P := Entries[sePermission][PermsEntry];
-        if not GrantPermissionOnKey(RegView, RootKey, Subkey,
-           TGrantPermissionEntry(Pointer(P.Permissions)^),
-           Length(P.Permissions) div SizeOf(TGrantPermissionEntry)) then begin
-          if GetLastError = ERROR_FILE_NOT_FOUND then
-            Log('Could not set permissions on the registry key because it currently does not exist.')
-          else
-            LogFmt('Failed to set permissions on registry key (%d).', [GetLastError]);
-        end;
+      LogFmt('Setting permissions on key: %s\%s',
+        [GetRegRootKeyName(RootKey), Subkey]);
+      P := Entries[sePermission][PermsEntry];
+      if not GrantPermissionOnKey(RegView, RootKey, Subkey,
+         TGrantPermissionEntry(Pointer(P.Permissions)^),
+         Length(P.Permissions) div SizeOf(TGrantPermissionEntry)) then begin
+        if GetLastError = ERROR_FILE_NOT_FOUND then
+          Log('Could not set permissions on the key because it currently does not exist.')
+        else
+          LogFmt('Failed to set permissions on the key (%d).', [GetLastError]);
       end;
       end;
     end;
     end;
 
 
@@ -2105,7 +2103,7 @@ var
     S: String;
     S: String;
     RV: TRegView;
     RV: TRegView;
     CurRegNumber: Integer;
     CurRegNumber: Integer;
-    NeedToRetry: Boolean;
+    NeedToRetry, DidDeleteKey: Boolean;
     ErrorCode: Longint;
     ErrorCode: Longint;
     QV: Integer64;
     QV: Integer64;
 {$IFDEF UNICODE}
 {$IFDEF UNICODE}
@@ -2118,49 +2116,74 @@ var
         if ShouldProcessEntry(WizardComponents, WizardTasks, Components, Tasks, Languages, Check) then begin
         if ShouldProcessEntry(WizardComponents, WizardTasks, Components, Tasks, Languages, Check) then begin
           DebugNotifyEntry(seRegistry, CurRegNumber);
           DebugNotifyEntry(seRegistry, CurRegNumber);
           NotifyBeforeInstallEntry(BeforeInstall);
           NotifyBeforeInstallEntry(BeforeInstall);
+          Log('-- Registry entry --');
           S := ExpandConst(Subkey);
           S := ExpandConst(Subkey);
+          LogFmt('Key: %s\%s', [GetRegRootKeyName(RootKey), Subkey]); {LOG rootkey}
           N := ExpandConst(ValueName);
           N := ExpandConst(ValueName);
+          if N <> '' then
+            LogFmt('Value name: %s', [N]);
           RV := InstallDefaultRegView;
           RV := InstallDefaultRegView;
-          if ro32Bit in Options then
+          if (ro32Bit in Options) and (RV <> rv32Bit) then begin
+            Log('Non-default bitness: 32-bit');
             RV := rv32Bit;
             RV := rv32Bit;
+          end;
           if ro64Bit in Options then begin
           if ro64Bit in Options then begin
             if not IsWin64 then
             if not IsWin64 then
               InternalError('Cannot access 64-bit registry keys on this version of Windows');
               InternalError('Cannot access 64-bit registry keys on this version of Windows');
-            RV := rv64Bit;
+            if RV <> rv64Bit then begin
+              Log('Non-default bitness: 64-bit');
+              RV := rv64Bit;
+            end;
           end;
           end;
 
 
           repeat
           repeat
             NeedToRetry := False;
             NeedToRetry := False;
 
 
             try
             try
-              if roDeleteKey in Options then
-                if IsDeletableSubkey(S) then
+              DidDeleteKey := False;
+              if roDeleteKey in Options then begin
+                if IsDeletableSubkey(S) then begin
+                  Log('Deleting the key. ');
                   RegDeleteKeyIncludingSubkeys(RV, RootKey, PChar(S));
                   RegDeleteKeyIncludingSubkeys(RV, RootKey, PChar(S));
-              if (roDeleteKey in Options) and (Typ = rtNone) then
+                  DidDeleteKey := True;
+                end else
+                  Log('Key to delete is not deletable.');
+              end;
+              if (roDeleteKey in Options) and (Typ = rtNone) then begin
                 { We've deleted the key, and no value is to be created.
                 { We've deleted the key, and no value is to be created.
                   Our work is done. }
                   Our work is done. }
-              else if (roDeleteValue in Options) and (Typ = rtNone) then begin
+                if DidDeleteKey then
+                  Log('Successfully deleted the key.');
+              end else if (roDeleteValue in Options) and (Typ = rtNone) then begin
                 { We're going to delete a value with no intention of creating
                 { We're going to delete a value with no intention of creating
                   another, so don't create the key if it didn't exist. }
                   another, so don't create the key if it didn't exist. }
                 if RegOpenKeyExView(RV, RootKey, PChar(S), 0, KEY_SET_VALUE, K) = ERROR_SUCCESS then begin
                 if RegOpenKeyExView(RV, RootKey, PChar(S), 0, KEY_SET_VALUE, K) = ERROR_SUCCESS then begin
+                  Log('Deleting the value.');
                   RegDeleteValue(K, PChar(N));
                   RegDeleteValue(K, PChar(N));
                   RegCloseKey(K);
                   RegCloseKey(K);
-                end;
+                  Log('Successfully deleted the value.');
+                  { Our work is done. }
+                end else
+                  Log('Key of value to delete does not exist.');
               end
               end
               else begin
               else begin
                 { Apply any permissions *before* calling RegCreateKeyExView or
                 { Apply any permissions *before* calling RegCreateKeyExView or
                   RegOpenKeyExView, since we may (in a rather unlikely scenario)
                   RegOpenKeyExView, since we may (in a rather unlikely scenario)
                   need those permissions in order for those calls to succeed }
                   need those permissions in order for those calls to succeed }
-                ApplyPermissions(RV, RootKey, S, PermissionsEntry);
+                if PermissionsEntry <> -1 then
+                  ApplyPermissions(RV, RootKey, S, PermissionsEntry);
                 { Create or open the key }
                 { Create or open the key }
                 if not(roDontCreateKey in Options) then begin
                 if not(roDontCreateKey in Options) then begin
+                  Log('Creating or opening the key.');
                   ErrorCode := RegCreateKeyExView(RV, RootKey, PChar(S), 0, nil,
                   ErrorCode := RegCreateKeyExView(RV, RootKey, PChar(S), 0, nil,
                     REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE or KEY_SET_VALUE,
                     REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE or KEY_SET_VALUE,
                     nil, K, @Disp);
                     nil, K, @Disp);
                   if ErrorCode = ERROR_SUCCESS then begin
                   if ErrorCode = ERROR_SUCCESS then begin
                     { Apply permissions again if a new key was created }
                     { Apply permissions again if a new key was created }
-                    if Disp = REG_CREATED_NEW_KEY then
+                    if (Disp = REG_CREATED_NEW_KEY) and (PermissionsEntry <> -1) then begin
+                      Log('New key created, need to set permissions again.');
                       ApplyPermissions(RV, RootKey, S, PermissionsEntry);
                       ApplyPermissions(RV, RootKey, S, PermissionsEntry);
+                    end;
                   end
                   end
                   else begin
                   else begin
                     if not(roNoError in Options) then
                     if not(roNoError in Options) then
@@ -2169,6 +2192,7 @@ var
                 end
                 end
                 else begin
                 else begin
                   if Typ <> rtNone then begin
                   if Typ <> rtNone then begin
+                    Log('Opening the key.');
                     ErrorCode := RegOpenKeyExView(RV, RootKey, PChar(S), 0,
                     ErrorCode := RegOpenKeyExView(RV, RootKey, PChar(S), 0,
                       KEY_QUERY_VALUE or KEY_SET_VALUE, K);
                       KEY_QUERY_VALUE or KEY_SET_VALUE, K);
                     if (ErrorCode <> ERROR_SUCCESS) and (ErrorCode <> ERROR_FILE_NOT_FOUND) then
                     if (ErrorCode <> ERROR_SUCCESS) and (ErrorCode <> ERROR_FILE_NOT_FOUND) then
@@ -2186,11 +2210,14 @@ var
                   and/or creating the value }
                   and/or creating the value }
                 if ErrorCode = ERROR_SUCCESS then
                 if ErrorCode = ERROR_SUCCESS then
                 try
                 try
-                  if roDeleteValue in Options then
+                  if roDeleteValue in Options then begin
+                    Log('Deleting the value.');
                     RegDeleteValue(K, PChar(N));
                     RegDeleteValue(K, PChar(N));
+                  end;
                   if (Typ <> rtNone) and
                   if (Typ <> rtNone) and
                      (not(roCreateValueIfDoesntExist in Options) or
                      (not(roCreateValueIfDoesntExist in Options) or
-                      not RegValueExists(K, PChar(N))) then
+                      not RegValueExists(K, PChar(N))) then begin
+                    Log('Creating or setting the value.');
                     case Typ of
                     case Typ of
                       rtString, rtExpandString, rtMultiString: begin
                       rtString, rtExpandString, rtMultiString: begin
                           NewType := REG_SZ;
                           NewType := REG_SZ;
@@ -2264,17 +2291,25 @@ var
                              not(roNoError in Options) then
                              not(roNoError in Options) then
                             RegError(reRegSetValueEx, RootKey, S, ErrorCode);
                             RegError(reRegSetValueEx, RootKey, S, ErrorCode);
                         end;
                         end;
-                    end;
+                      end;
+                    Log('Succesfully created or set the value.');
+                  end else if roDeleteValue in Options then
+                    Log('Successully deleted the value.')
+                  else
+                    Log('Successully created the key.')
+                  { Our work is done. }
                 finally
                 finally
                   RegCloseKey(K);
                   RegCloseKey(K);
                 end;
                 end;
               end;
               end;
             except
             except
-              if not AbortRetryIgnoreMsgBox(GetExceptMessage, SetupMessages[msgEntryAbortRetryIgnore]) then
+              if not AbortRetryIgnoreMsgBox(GetExceptMessage, SetupMessages[msgEntryAbortRetryIgnore]) then begin
+                Log('Retrying.');
                 NeedToRetry := True;
                 NeedToRetry := True;
+              end;
             end;
             end;
           until not NeedToRetry;
           until not NeedToRetry;
-
+          
           if roUninsDeleteEntireKey in Options then
           if roUninsDeleteEntireKey in Options then
             if IsDeletableSubkey(S) then
             if IsDeletableSubkey(S) then
               UninstLog.AddReg(utRegDeleteEntireKey, RV, RootKey, [S]);
               UninstLog.AddReg(utRegDeleteEntireKey, RV, RootKey, [S]);

+ 1 - 0
whatsnew.htm

@@ -28,6 +28,7 @@ For conditions of distribution and use, see <a href="http://www.jrsoftware.org/f
 
 
 <p><a name="5.5.10"></a><span class="ver">5.5.10 </span><span class="date">(?)</span></p>
 <p><a name="5.5.10"></a><span class="ver">5.5.10 </span><span class="date">(?)</span></p>
 <ul>
 <ul>
+<li>/LOG: Now logs registry entries.</li>
 <li>Compiler IDE change: Syntax highlighting and syntax error underlining support for <tt>#include</tt> and ISPP has been significantly improved (with ISPP installed: <a href="https://i.imgur.com/nPiun9k.png">before</a> and <a href="https://i.imgur.com/HoJaBRP.png">after</a>, without ISPP installed: <a href="https://i.imgur.com/nPiun9k.png">before</a> and <a href="https://i.imgur.com/ro0ejL3.png">after</a>. Based on a contribution by <a href="https://github.com/KngStr" target="_blank">KngStr</a> via <a href="https://github.com/jrsoftware" target="_blank">GitHub</a>.</li>
 <li>Compiler IDE change: Syntax highlighting and syntax error underlining support for <tt>#include</tt> and ISPP has been significantly improved (with ISPP installed: <a href="https://i.imgur.com/nPiun9k.png">before</a> and <a href="https://i.imgur.com/HoJaBRP.png">after</a>, without ISPP installed: <a href="https://i.imgur.com/nPiun9k.png">before</a> and <a href="https://i.imgur.com/ro0ejL3.png">after</a>. Based on a contribution by <a href="https://github.com/KngStr" target="_blank">KngStr</a> via <a href="https://github.com/jrsoftware" target="_blank">GitHub</a>.</li>
 <li>The <tt>WizardImageFile</tt> and <tt>WizardSmallImageFile</tt> [Setup] section directives now may list multiple files. This can be used to include multiple sizes of the wizard images to avoid blurred images on high DPI systems. See the help file for a list of recommended sizes. Note: when you test this be sure to first log out and back in after any DPI change.</li>
 <li>The <tt>WizardImageFile</tt> and <tt>WizardSmallImageFile</tt> [Setup] section directives now may list multiple files. This can be used to include multiple sizes of the wizard images to avoid blurred images on high DPI systems. See the help file for a list of recommended sizes. Note: when you test this be sure to first log out and back in after any DPI change.</li>
 <li><b>Change in default behavior:</b> If [Setup] section directive <tt>DisableWelcomePage</tt> is set (which it is by default), then the title of the wizard now includes <tt>AppVerName</tt> instead of <tt>AppName</tt>, in other words: it now includes the version number of the application. If <tt>WindowVisible</tt> is set to <tt>yes</tt> this applies to the background window instead.</li>
 <li><b>Change in default behavior:</b> If [Setup] section directive <tt>DisableWelcomePage</tt> is set (which it is by default), then the title of the wizard now includes <tt>AppVerName</tt> instead of <tt>AppName</tt>, in other words: it now includes the version number of the application. If <tt>WindowVisible</tt> is set to <tt>yes</tt> this applies to the background window instead.</li>