Parcourir la source

Cleanup: use proper names for INVALID_FILE_ATTRIBUTES/INVALID_SET_FILE_POINTER/INVALID_FILE_SIZE.

Martijn Laan il y a 5 mois
Parent
commit
706368a861

+ 1 - 1
Projects/Src/Compiler.SetupCompiler.pas

@@ -518,7 +518,7 @@ begin
 {$IFNDEF STATICPREPROC}
   Filename := CompilerDir + 'ISPP.dll';
   Attr := GetFileAttributes(PChar(Filename));
-  if (Attr = $FFFFFFFF) and (GetLastError = ERROR_FILE_NOT_FOUND) then begin
+  if (Attr = INVALID_FILE_ATTRIBUTES) and (GetLastError = ERROR_FILE_NOT_FOUND) then begin
     { ISPP unavailable; fall back to built-in preprocessor }
   end
   else begin

+ 5 - 6
Projects/Src/Setup.Install.pas

@@ -300,7 +300,7 @@ var
 begin
   if Attribs <> 0 then begin
     ExistingAttr := GetFileAttributesRedir(DisableFsRedir, Filename);
-    if ExistingAttr <> $FFFFFFFF then
+    if ExistingAttr <> INVALID_FILE_ATTRIBUTES then
       SetFileAttributesRedir(DisableFsRedir, Filename,
         (ExistingAttr and not FILE_ATTRIBUTE_NORMAL) or DWORD(Attribs));
   end;
@@ -994,7 +994,7 @@ var
     begin
       if PermsEntry <> -1 then begin
         Attr := GetFileAttributesRedir(DisableFsRedir, Filename);
-        if (Attr <> $FFFFFFFF) and (Attr and FILE_ATTRIBUTE_DIRECTORY = 0) then begin
+        if (Attr <> INVALID_FILE_ATTRIBUTES) and (Attr and FILE_ATTRIBUTE_DIRECTORY = 0) then begin
           LogFmt('Setting permissions on file: %s', [Filename]);
           P := Entries[sePermission][PermsEntry];
           if not GrantPermissionOnFile(DisableFsRedir, Filename,
@@ -1075,7 +1075,6 @@ var
     DestFileExists, DestFileExistedBefore, CheckedDestFileExistedBefore,
       TempFileLeftOver, AllowFileToBeDuplicated, ReplaceOnRestart, DoBreak,
       DoContinue: Boolean;
-    ExistingFileAttr: Integer;
     Failed: String;
     CurFileVersionInfoValid: Boolean;
     CurFileVersionInfo, ExistingVersionInfo: TFileVersionNumbers;
@@ -1363,8 +1362,8 @@ var
 
           { Check if existing file is read-only }
           while True do begin
-            ExistingFileAttr := GetFileAttributesRedir(DisableFsRedir, DestFile);
-            if (ExistingFileAttr <> -1) and
+            var ExistingFileAttr := GetFileAttributesRedir(DisableFsRedir, DestFile);
+            if (ExistingFileAttr <> INVALID_FILE_ATTRIBUTES) and
                (ExistingFileAttr and FILE_ATTRIBUTE_READONLY <> 0) then begin
               if not(foOverwriteReadOnly in CurFile^.Options) and
                  AbortRetryIgnoreTaskDialogMsgBox(
@@ -1953,7 +1952,7 @@ var
       DesktopIniFilename, S: String;
     begin
       Attr := GetFileAttributes(PChar(Dir));
-      if (Attr <> $FFFFFFFF) and (Attr and FILE_ATTRIBUTE_DIRECTORY <> 0) then begin
+      if (Attr <> INVALID_FILE_ATTRIBUTES) and (Attr and FILE_ATTRIBUTE_DIRECTORY <> 0) then begin
         { To be sure this is really a folder shortcut and not a regular folder,
           look for a desktop.ini file specifying CLSID_FolderShortcut }
         DesktopIniFilename := PathCombine(Dir, 'desktop.ini');

+ 1 - 1
Projects/Src/Setup.RegSvr.pas

@@ -66,7 +66,7 @@ begin
   for I := 0 to 999 do begin
     NewFilename := Path + Format('isRS-%.3u.tmp', [I]);
     Attribs := GetFileAttributes(PChar(NewFilename));
-    if Attribs <> $FFFFFFFF then begin
+    if Attribs <> INVALID_FILE_ATTRIBUTES then begin
       { Skip any directories that happen to named NewFilename }
       if Attribs and FILE_ATTRIBUTE_DIRECTORY <> 0 then
         Continue;

+ 1 - 1
Projects/Src/Setup.SecurityFunc.pas

@@ -170,7 +170,7 @@ begin
     current directory as us }
   Filename := PathExpand(Filename);
   Attr := GetFileAttributesRedir(DisableFsRedir, Filename);
-  if Attr = $FFFFFFFF then begin
+  if Attr = INVALID_FILE_ATTRIBUTES then begin
     Result := False;
     Exit;
   end;

+ 1 - 1
Projects/Src/Setup.SpawnServer.pas

@@ -188,7 +188,7 @@ begin
     'GetFinalPathNameByHandleW');
   if Assigned(GetFinalPathNameByHandleFunc) then begin
     Attr := GetFileAttributes(PChar(Filename));
-    if Attr <> $FFFFFFFF then begin
+    if Attr <> INVALID_FILE_ATTRIBUTES then begin
       { Backup semantics must be requested in order to open a directory }
       if Attr and FILE_ATTRIBUTE_DIRECTORY <> 0 then
         FlagsAndAttributes := FILE_FLAG_BACKUP_SEMANTICS

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

@@ -272,7 +272,7 @@ var
 begin
   Attribs := GetFileAttributesRedir(DisableFsRedir, DirName);
   { Does the directory exist? }
-  if (Attribs <> $FFFFFFFF) and
+  if (Attribs <> INVALID_FILE_ATTRIBUTES) and
      (Attribs and FILE_ATTRIBUTE_DIRECTORY <> 0) then begin
     LogFmt('Deleting directory: %s', [DirName]);
     { If the directory has the read-only attribute, strip it first }
@@ -592,7 +592,7 @@ var
       LogFmt('Deleting file: %s', [FileName]);
       if RemoveReadOnly then begin
         ExistingAttr := GetFileAttributesRedir(DisableFsRedir, Filename);
-        if (ExistingAttr <> $FFFFFFFF) and
+        if (ExistingAttr <> INVALID_FILE_ATTRIBUTES) and
            (ExistingAttr and FILE_ATTRIBUTE_READONLY <> 0) then
           if SetFileAttributesRedir(DisableFsRedir, Filename,
              ExistingAttr and not FILE_ATTRIBUTE_READONLY) then

+ 1 - 1
Projects/Src/SetupLdrAndSetup.RedirFunc.pas

@@ -300,7 +300,7 @@ var
   ErrorCode: DWORD;
 begin
   if not DisableFsRedirectionIf(DisableFsRedir, PrevState) then begin
-    Result := $FFFFFFFF;
+    Result := INVALID_FILE_ATTRIBUTES;
     Exit;
   end;
   try

+ 7 - 11
Projects/Src/Shared.CommonFunc.pas

@@ -194,7 +194,7 @@ function SHGetPathFromIDList(pidl: PItemIDList; pszPath: PChar): BOOL; stdcall;
   external shell32 name 'SHGetPathFromIDListW';
 
 
-function InternalGetFileAttr(const Name: String): Integer;
+function InternalGetFileAttr(const Name: String): DWORD;
 begin
   Result := GetFileAttributes(PChar(RemoveBackslashUnlessRoot(Name)));
 end;
@@ -205,11 +205,9 @@ function NewFileExists(const Name: String): Boolean;
   on files in directories that don't have "list" permission. There is, however,
   one other difference: FileExists allows wildcards, but this function does
   not. }
-var
-  Attr: Integer;
 begin
-  Attr := GetFileAttributes(PChar(Name));
-  Result := (Attr <> -1) and (Attr and faDirectory = 0);
+  var Attr := GetFileAttributes(PChar(Name));
+  Result := (Attr <> INVALID_FILE_ATTRIBUTES) and (Attr and faDirectory = 0);
 end;
 
 function DirExists(const Name: String): Boolean;
@@ -218,18 +216,16 @@ function DirExists(const Name: String): Boolean;
   NOTE: Delphi's FileCtrl unit has a similar function called DirectoryExists.
   However, the implementation is different between Delphi 1 and 2. (Delphi 1
   does not count hidden or system directories as existing.) }
-var
-  Attr: Integer;
 begin
-  Attr := InternalGetFileAttr(Name);
-  Result := (Attr <> -1) and (Attr and faDirectory <> 0);
+  var Attr := InternalGetFileAttr(Name);
+  Result := (Attr <> INVALID_FILE_ATTRIBUTES) and (Attr and faDirectory <> 0);
 end;
 
 function FileOrDirExists(const Name: String): Boolean;
 { Returns True if the specified directory or file name exists. The specified
   name may include a trailing backslash. }
 begin
-  Result := InternalGetFileAttr(Name) <> -1;
+  Result := InternalGetFileAttr(Name) <> INVALID_FILE_ATTRIBUTES;
 end;
 
 function IsDirectoryAndNotReparsePoint(const Name: String): Boolean;
@@ -240,7 +236,7 @@ var
   Attr: DWORD;
 begin
   Attr := GetFileAttributes(PChar(Name));
-  Result := (Attr <> $FFFFFFFF) and
+  Result := (Attr <> INVALID_FILE_ATTRIBUTES) and
     (Attr and FILE_ATTRIBUTE_DIRECTORY <> 0) and
     (Attr and FILE_ATTRIBUTE_REPARSE_POINT = 0);
 end;

+ 7 - 4
Projects/Src/Shared.FileClass.pas

@@ -252,18 +252,21 @@ begin
     FILE_ATTRIBUTE_NORMAL, 0);
 end;
 
+const
+  INVALID_SET_FILE_POINTER = DWORD($FFFFFFFF);
+
 function TFile.GetPosition: Integer64;
 begin
   Result.Hi := 0;
   Result.Lo := SetFilePointer(FHandle, 0, @Result.Hi, FILE_CURRENT);
-  if (Result.Lo = $FFFFFFFF) and (GetLastError <> 0) then
+  if (Result.Lo = INVALID_SET_FILE_POINTER) and (GetLastError <> 0) then
     RaiseLastError;
 end;
 
 function TFile.GetSize: Integer64;
 begin
   Result.Lo := GetFileSize(FHandle, @Result.Hi);
-  if (Result.Lo = $FFFFFFFF) and (GetLastError <> 0) then
+  if (Result.Lo = INVALID_FILE_SIZE) and (GetLastError <> 0) then
     RaiseLastError;
 end;
 
@@ -277,7 +280,7 @@ end;
 procedure TFile.Seek64(Offset: Integer64);
 begin
   if (SetFilePointer(FHandle, Integer(Offset.Lo), @Offset.Hi,
-      FILE_BEGIN) = $FFFFFFFF) and (GetLastError <> 0) then
+      FILE_BEGIN) = INVALID_SET_FILE_POINTER) and (GetLastError <> 0) then
     RaiseLastError;
 end;
 
@@ -286,7 +289,7 @@ var
   DistanceHigh: Integer;
 begin
   DistanceHigh := 0;
-  if (SetFilePointer(FHandle, 0, @DistanceHigh, FILE_END) = $FFFFFFFF) and
+  if (SetFilePointer(FHandle, 0, @DistanceHigh, FILE_END) = INVALID_SET_FILE_POINTER) and
      (GetLastError <> 0) then
     RaiseLastError;
 end;