[ros-diffs] [cfinck] 32092: - Fix funky ways of checking for success, when calling SetFilePointer. The only correct and always working way is checking for INVALID_SET_FILE_POINTER. - Fix setting the file attributes. We didn't pass the destination directory before, so if the user specified another destination directory, the SetFileAttributes call failed. - Simplify GetAttributesOnFile and SetAttributesOnFile

cfinck at svn.reactos.org cfinck at svn.reactos.org
Sat Feb 2 20:21:36 CET 2008


Author: cfinck
Date: Sat Feb  2 22:21:35 2008
New Revision: 32092

URL: http://svn.reactos.org/svn/reactos?rev=32092&view=rev
Log:
- Fix funky ways of checking for success, when calling SetFilePointer.
  The only correct and always working way is checking for INVALID_SET_FILE_POINTER.
- Fix setting the file attributes.
  We didn't pass the destination directory before, so if the user specified another destination directory, the SetFileAttributes call failed.
- Simplify GetAttributesOnFile and SetAttributesOnFile

Modified:
    trunk/reactos/tools/cabman/cabinet.cxx
    trunk/reactos/tools/cabman/cabinet.h

Modified: trunk/reactos/tools/cabman/cabinet.cxx
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/cabman/cabinet.cxx?rev=32092&r1=32091&r2=32092&view=diff
==============================================================================
--- trunk/reactos/tools/cabman/cabinet.cxx (original)
+++ trunk/reactos/tools/cabman/cabinet.cxx Sat Feb  2 22:21:35 2008
@@ -189,7 +189,7 @@
  */
 {
 #if defined(WIN32)
-    if (!SetFilePointer(FileHandle, 0, NULL, FILE_BEGIN))
+    if( SetFilePointer(FileHandle, 0, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER )
         return CAB_STATUS_FAILURE;
     if (!SetEndOfFile(FileHandle))
         return CAB_STATUS_FAILURE;
@@ -231,10 +231,10 @@
  */
 {
 #if defined(WIN32)
-    if (SetFilePointer(FileHandle,
-        Position,
-        NULL,
-        FILE_BEGIN) == 0xFFFFFFFF)
+    if( SetFilePointer(FileHandle,
+                       Position,
+                       NULL,
+                       FILE_BEGIN) == INVALID_SET_FILE_POINTER )
         return CAB_STATUS_FAILURE;
     else
         return CAB_STATUS_SUCCESS;
@@ -712,10 +712,9 @@
             DataReserved    = (Size >> 24) & 0xFF;
 
 #if defined(WIN32)
-            SetFilePointer(FileHandle, CabinetReserved, NULL, FILE_CURRENT);
-            if (GetLastError() != NO_ERROR)
+            if (SetFilePointer(FileHandle, CabinetReserved, NULL, FILE_CURRENT) == INVALID_SET_FILE_POINTER)
             {
-                DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n"));
+                DPRINT(MIN_TRACE, ("SetFilePointer() failed, error code is %u.\n", GetLastError()));
                 return CAB_STATUS_FAILURE;
             }
 #else
@@ -823,7 +822,7 @@
 
 
 ULONG CCabinet::FindFirst(char* FileName,
-                             PCAB_SEARCH Search)
+                          PCAB_SEARCH Search)
 /*
  * FUNCTION: Finds the first file in the cabinet that matches a search criteria
  * ARGUMENTS:
@@ -1030,7 +1029,7 @@
 #else
     //DPRINT(MIN_TRACE, ("FIXME: DosDateTimeToFileTime\n"));
 #endif
-    SetAttributesOnFile(File);
+    SetAttributesOnFile(DestName, File->File.Attributes);
 
     Buffer = (unsigned char*)AllocateMemory(CAB_BLOCKSIZE + 12); // This should be enough
     if (!Buffer)
@@ -1049,9 +1048,9 @@
         File->DataBlock->AbsoluteOffset,
         NULL,
         FILE_BEGIN);
-    if (GetLastError() != NO_ERROR)
-    {
-        DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n"));
+    if (Offset == INVALID_SET_FILE_POINTER)
+    {
+        DPRINT(MIN_TRACE, ("SetFilePointer() failed, error code is %u.\n", GetLastError()));
         return CAB_STATUS_INVALID_CAB;
     }
 #else
@@ -1171,13 +1170,12 @@
 
                         /* Search to start of file */
 #if defined(WIN32)
-                        SetFilePointer(FileHandle,
-                            File->DataBlock->AbsoluteOffset,
-                            NULL,
-                            FILE_BEGIN);
-                        if (GetLastError() != NO_ERROR)
+                        if( SetFilePointer(FileHandle,
+                                           File->DataBlock->AbsoluteOffset,
+                                           NULL,
+                                           FILE_BEGIN) == INVALID_SET_FILE_POINTER )
                         {
-                            DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n"));
+                            DPRINT(MIN_TRACE, ("SetFilePointer() failed, error code is %u.\n", GetLastError()));
                             return CAB_STATUS_INVALID_CAB;
                         }
 #else
@@ -1247,14 +1245,13 @@
 
                 /* Go to next data block */
 #if defined(WIN32)
-                SetFilePointer(FileHandle,
-                    CurrentDataNode->AbsoluteOffset + sizeof(CFDATA) +
-                    CurrentDataNode->Data.CompSize,
-                    NULL,
-                    FILE_BEGIN);
-                if (GetLastError() != NO_ERROR)
+                if( SetFilePointer(FileHandle,
+                                   CurrentDataNode->AbsoluteOffset + sizeof(CFDATA) +
+                                   CurrentDataNode->Data.CompSize,
+                                   NULL,
+                                   FILE_BEGIN) == INVALID_SET_FILE_POINTER )
                 {
-                    DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n"));
+                    DPRINT(MIN_TRACE, ("SetFilePointer() failed, error code is %u.\n", GetLastError()));
                     return CAB_STATUS_INVALID_CAB;
                 }
 #else
@@ -2231,14 +2228,12 @@
     /* Back up some bytes */
     Size = (BytesRead - Size) - 1;
 #if defined(WIN32)
-    SetLastError(NO_ERROR);
-    (ULONG)SetFilePointer(FileHandle,
-        -(LONG)Size,
-        NULL,
-        FILE_CURRENT);
-    if (GetLastError() != NO_ERROR)
-    {
-        DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n"));
+    if( SetFilePointer(FileHandle,
+                       -(LONG)Size,
+                       NULL,
+                       FILE_CURRENT) == INVALID_SET_FILE_POINTER )
+    {
+        DPRINT(MIN_TRACE, ("SetFilePointer() failed, error code is %u.\n", GetLastError()));
         return CAB_STATUS_INVALID_CAB;
     }
 #else
@@ -2269,15 +2264,12 @@
 
     /* Seek to file table */
 #if defined(WIN32)
-    SetLastError(NO_ERROR);
-    SetFilePointer(FileHandle,
-        CABHeader.FileTableOffset,
-        NULL,
-        FILE_BEGIN);
-    if (GetLastError() != NO_ERROR)
-    {
-        DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n"));
-        DPRINT(MIN_TRACE, ("Error: %lu\n", GetLastError()));
+    if( SetFilePointer(FileHandle,
+                       CABHeader.FileTableOffset,
+                       NULL,
+                       FILE_BEGIN) == INVALID_SET_FILE_POINTER )
+    {
+        DPRINT(MIN_TRACE, ("SetFilePointer() failed, error code is %u.\n", GetLastError()));
         return CAB_STATUS_INVALID_CAB;
     }
 #else
@@ -2360,14 +2352,12 @@
 
         /* Seek to data block */
 #if defined(WIN32)
-        SetLastError(NO_ERROR);
-        SetFilePointer(FileHandle,
-            AbsoluteOffset,
-            NULL,
-            FILE_BEGIN);
-        if (GetLastError() != NO_ERROR)
-        {
-            DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n"));
+        if( SetFilePointer(FileHandle,
+                           AbsoluteOffset,
+                           NULL,
+                           FILE_BEGIN) == INVALID_SET_FILE_POINTER )
+        {
+            DPRINT(MIN_TRACE, ("SetFilePointer() failed, error code is %u.\n", GetLastError()));
             return CAB_STATUS_INVALID_CAB;
         }
 #else
@@ -3384,20 +3374,10 @@
     if (Attributes == -1)
         return CAB_STATUS_CANNOT_READ;
 
-    if (Attributes & FILE_ATTRIBUTE_READONLY)
-        File->File.Attributes |= CAB_ATTRIB_READONLY;
-
-    if (Attributes & FILE_ATTRIBUTE_HIDDEN)
-        File->File.Attributes |= CAB_ATTRIB_HIDDEN;
-
-    if (Attributes & FILE_ATTRIBUTE_SYSTEM)
-        File->File.Attributes |= CAB_ATTRIB_SYSTEM;
-
-    if (Attributes & FILE_ATTRIBUTE_DIRECTORY)
-        File->File.Attributes |= CAB_ATTRIB_DIRECTORY;
-
-    if (Attributes & FILE_ATTRIBUTE_ARCHIVE)
-        File->File.Attributes |= CAB_ATTRIB_ARCHIVE;
+    // 0x37 = READONLY | HIDDEN | SYSTEM | DIRECTORY | ARCHIVE
+    // The IDs for these attributes are the same in the CAB file and under Windows
+    // If the file has any other attributes, strip them off by the logical AND.
+    File->File.Attributes = (USHORT)(Attributes & 0x37);
 #else
     struct stat stbuf;
     char buf[MAX_PATH];
@@ -3431,34 +3411,21 @@
 }
 
 
-ULONG CCabinet::SetAttributesOnFile(PCFFILE_NODE File)
+ULONG CCabinet::SetAttributesOnFile(char* FileName, USHORT FileAttributes)
 /*
  * FUNCTION: Sets attributes on a file
  * ARGUMENTS:
- *      File = Pointer to CFFILE node for file
+ *      FileName       = File name with path
+ *      FileAttributes = Attributes of that file
  * RETURNS:
  *     Status of operation
  */
 {
 #if defined(WIN32)
-    ULONG Attributes = 0;
-
-    if (File->File.Attributes & CAB_ATTRIB_READONLY)
-        Attributes |= FILE_ATTRIBUTE_READONLY;
-
-    if (File->File.Attributes & CAB_ATTRIB_HIDDEN)
-        Attributes |= FILE_ATTRIBUTE_HIDDEN;
-
-    if (File->File.Attributes & CAB_ATTRIB_SYSTEM)
-        Attributes |= FILE_ATTRIBUTE_SYSTEM;
-
-    if (File->File.Attributes & CAB_ATTRIB_DIRECTORY)
-        Attributes |= FILE_ATTRIBUTE_DIRECTORY;
-
-    if (File->File.Attributes & CAB_ATTRIB_ARCHIVE)
-        Attributes |= FILE_ATTRIBUTE_ARCHIVE;
-
-    SetFileAttributes(File->FileName, Attributes);
+    // 0x37 = READONLY | HIDDEN | SYSTEM | DIRECTORY | ARCHIVE
+    // The IDs for these attributes are the same in the CAB file and under Windows
+    // If the file has any other attributes, strip them off by the logical AND.
+    SetFileAttributes(FileName, (DWORD)(FileAttributes & 0x37));
 
     return CAB_STATUS_SUCCESS;
 #else

Modified: trunk/reactos/tools/cabman/cabinet.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/cabman/cabinet.h?rev=32092&r1=32091&r2=32092&view=diff
==============================================================================
--- trunk/reactos/tools/cabman/cabinet.h (original)
+++ trunk/reactos/tools/cabman/cabinet.h Sat Feb  2 22:21:35 2008
@@ -416,7 +416,7 @@
     ULONG CommitDataBlocks(PCFFOLDER_NODE FolderNode);
     ULONG WriteDataBlock();
     ULONG GetAttributesOnFile(PCFFILE_NODE File);
-    ULONG SetAttributesOnFile(PCFFILE_NODE File);
+    ULONG SetAttributesOnFile(char* FileName, USHORT FileAttributes);
     ULONG GetFileTimes(FILEHANDLE FileHandle, PCFFILE_NODE File);
 #if !defined(WIN32)
     void ConvertDateAndTime(time_t* Time, PUSHORT DosDate, PUSHORT DosTime);




More information about the Ros-diffs mailing list