Explorar el Código

Cleanup: remove unused DisableFsRedir parameters from GetSpaceOnDisk and GetSpaceOnNearestMountPoint.

Martijn Laan hace 3 semanas
padre
commit
f287285a4d

+ 19 - 28
Projects/Src/Setup.InstFunc.pas

@@ -76,10 +76,10 @@ function GetSHA256OfFile(const F: TFile): TSHA256Digest; overload;
 function GetSHA256OfAnsiString(const S: AnsiString): TSHA256Digest;
 function GetSHA256OfUnicodeString(const S: UnicodeString): TSHA256Digest;
 function GetRegRootKeyName(const RootKey: HKEY): String;
-function GetSpaceOnDisk(const DisableFsRedir: Boolean; const DriveRoot: String;
+function GetSpaceOnDisk(const DriveRoot: String;
+  var FreeBytes, TotalBytes: Int64): Boolean;
+function GetSpaceOnNearestMountPoint(const StartDir: String;
   var FreeBytes, TotalBytes: Int64): Boolean;
-function GetSpaceOnNearestMountPoint(const DisableFsRedir: Boolean;
-  const StartDir: String; var FreeBytes, TotalBytes: Int64): Boolean;
 function GetUserNameString: String;
 procedure IncrementSharedCount(const RegView: TRegView; const Filename: String;
   const AlreadyExisted: Boolean);
@@ -929,13 +929,12 @@ begin
     SendNotifyMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
 end;
 
-function GetSpaceOnDisk(const DisableFsRedir: Boolean; const DriveRoot: String;
+function GetSpaceOnDisk(const DriveRoot: String;
   var FreeBytes, TotalBytes: Int64): Boolean;
 var
   GetDiskFreeSpaceExFunc: function(lpDirectoryName: PChar;
     lpFreeBytesAvailable: PLargeInteger; lpTotalNumberOfBytes: PLargeInteger;
     lpTotalNumberOfFreeBytes: PLargeInteger): BOOL; stdcall;
-  PrevState: TPreviousFsRedirectionState;
   SectorsPerCluster, BytesPerSector, FreeClusters, TotalClusters: Cardinal;
 begin
   { NOTE: The docs claim that GetDiskFreeSpace supports UNC paths on
@@ -945,32 +944,24 @@ begin
     if available. }
   GetDiskFreeSpaceExFunc := GetProcAddress(GetModuleHandle(kernel32),
     'GetDiskFreeSpaceExW');
-  if not DisableFsRedirectionIf(DisableFsRedir, PrevState) then begin
-    Result := False;
-    Exit;
-  end;
-  try
-    if Assigned(@GetDiskFreeSpaceExFunc) then begin
-      Result := GetDiskFreeSpaceExFunc(PChar(AddBackslash(PathExpand(DriveRoot))),
-        @FreeBytes, @TotalBytes, nil);
-    end
-    else begin
-      Result := GetDiskFreeSpace(PChar(AddBackslash(PathExtractDrive(PathExpand(DriveRoot)))),
-        SectorsPerCluster, BytesPerSector, FreeClusters, TotalClusters);
-      if Result then begin
-        { The result of GetDiskFreeSpace does not cap at 2GB, so we must use a
-          64-bit multiply operation to avoid an overflow. }
-        FreeBytes := Int64(BytesPerSector * SectorsPerCluster) * FreeClusters;
-        TotalBytes := Int64(BytesPerSector * SectorsPerCluster) * TotalClusters;
-      end;
+  if Assigned(@GetDiskFreeSpaceExFunc) then begin
+    Result := GetDiskFreeSpaceExFunc(PChar(AddBackslash(PathExpand(DriveRoot))),
+      @FreeBytes, @TotalBytes, nil);
+  end
+  else begin
+    Result := GetDiskFreeSpace(PChar(AddBackslash(PathExtractDrive(PathExpand(DriveRoot)))),
+      SectorsPerCluster, BytesPerSector, FreeClusters, TotalClusters);
+    if Result then begin
+      { The result of GetDiskFreeSpace does not cap at 2GB, so we must use a
+        64-bit multiply operation to avoid an overflow. }
+      FreeBytes := Int64(BytesPerSector * SectorsPerCluster) * FreeClusters;
+      TotalBytes := Int64(BytesPerSector * SectorsPerCluster) * TotalClusters;
     end;
-  finally
-    RestoreFsRedirection(PrevState);
   end;
 end;
 
-function GetSpaceOnNearestMountPoint(const DisableFsRedir: Boolean;
-  const StartDir: String; var FreeBytes, TotalBytes: Int64): Boolean;
+function GetSpaceOnNearestMountPoint(const StartDir: String;
+  var FreeBytes, TotalBytes: Int64): Boolean;
 { Gets the free and total space available on the specified directory. If that
   fails (e.g. if the directory does not exist), then it strips off the last
   component of the path and tries again. This repeats until it reaches the
@@ -983,7 +974,7 @@ begin
   Dir := RemoveBackslashUnlessRoot(StartDir);
   LastLen := 0;
   while Length(Dir) <> LastLen do begin
-    if GetSpaceOnDisk(DisableFsRedir, Dir, FreeBytes, TotalBytes) then begin
+    if GetSpaceOnDisk(Dir, FreeBytes, TotalBytes) then begin
       Result := True;
       Break;
     end;

+ 2 - 2
Projects/Src/Setup.ScriptFunc.pas

@@ -1007,7 +1007,7 @@ var
     RegisterScriptFunc('GETSPACEONDISK', procedure(const Caller: TPSExec; const OrgName: AnsiString; const Stack: TPSStack; const PStart: Integer)
     begin
       var FreeBytes, TotalBytes: Int64;
-      if GetSpaceOnDisk(False, Stack.GetString(PStart-1), FreeBytes, TotalBytes) then begin
+      if GetSpaceOnDisk(Stack.GetString(PStart-1), FreeBytes, TotalBytes) then begin
         if Stack.GetBool(PStart-2) then begin
           FreeBytes := FreeBytes div (1024*1024);
           TotalBytes := TotalBytes div (1024*1024);
@@ -1027,7 +1027,7 @@ var
     RegisterScriptFunc('GETSPACEONDISK64', procedure(const Caller: TPSExec; const OrgName: AnsiString; const Stack: TPSStack; const PStart: Integer)
     begin
       var FreeBytes, TotalBytes: Int64;
-      if GetSpaceOnDisk(False, Stack.GetString(PStart-1), FreeBytes, TotalBytes) then begin
+      if GetSpaceOnDisk(Stack.GetString(PStart-1), FreeBytes, TotalBytes) then begin
         Stack.SetInt64(PStart-2, FreeBytes);
         Stack.SetInt64(PStart-3, TotalBytes);
         Stack.SetBool(PStart, True);

+ 2 - 2
Projects/Src/Setup.WizardForm.pas

@@ -2505,7 +2505,7 @@ procedure TWizardForm.NextButtonClick(Sender: TObject);
 
     if InstallMode = imNormal then begin
       { Check if there's enough free disk space }
-      if GetSpaceOnNearestMountPoint(False, T, FreeSpace, TotalSpace) then begin
+      if GetSpaceOnNearestMountPoint(T, FreeSpace, TotalSpace) then begin
         if FreeSpace < MinimumSpace then
           { If not, show warning }
           if LoggedMsgBox(FmtSetupMessage(msgDiskSpaceWarning,
@@ -2545,7 +2545,7 @@ procedure TWizardForm.NextButtonClick(Sender: TObject);
     Result := False;
 
     if InstallMode = imNormal then begin
-      if GetSpaceOnNearestMountPoint(False, DirEdit.Text, FreeSpace, TotalSpace) then begin
+      if GetSpaceOnNearestMountPoint(DirEdit.Text, FreeSpace, TotalSpace) then begin
         if FreeSpace < CurrentComponentsSpace then
           if LoggedMsgBox(FmtSetupMessage(msgDiskSpaceWarning,
                [IntToKBStr(CurrentComponentsSpace), IntToKBStr(FreeSpace)]),