branch update for HEAD-2003091401
[reactos.git] / subsys / system / usetup / filesup.c
index f735dc0..2a15a16 100644 (file)
@@ -22,6 +22,7 @@
  * FILE:            subsys/system/usetup/filesup.c
  * PURPOSE:         File support functions
  * PROGRAMMER:      Eric Kohl
+ *                  Casper S. Hornstrup (chorns@users.sourceforge.net)
  */
 
 /* INCLUDES *****************************************************************/
 
 #include "usetup.h"
 #include "filesup.h"
+#include "cabinet.h"
 
 
 /* FUNCTIONS ****************************************************************/
 
 
+static BOOLEAN HasCurrentCabinet = FALSE;
+static WCHAR CurrentCabinetName[MAX_PATH];
+
 NTSTATUS
 CreateDirectory(PWCHAR DirectoryName)
 {
@@ -111,7 +116,6 @@ SetupCopyFile(PWCHAR SourceFileName,
                      FILE_SYNCHRONOUS_IO_ALERT | FILE_SEQUENTIAL_ONLY);
   if (!NT_SUCCESS(Status))
     {
-CHECKPOINT1;
       return(Status);
     }
 
@@ -122,7 +126,6 @@ CHECKPOINT1;
                                  FileStandardInformation);
   if (!NT_SUCCESS(Status))
     {
-CHECKPOINT1;
      NtClose(FileHandleSource);
      return(Status);
     }
@@ -133,7 +136,6 @@ CHECKPOINT1;
                                  FileBasicInformation);
   if (!NT_SUCCESS(Status))
     {
-CHECKPOINT1;
       NtClose(FileHandleSource);
       return(Status);
     }
@@ -160,7 +162,6 @@ CHECKPOINT1;
                        0);
   if (!NT_SUCCESS(Status))
     {
-CHECKPOINT1;
       NtClose(FileHandleSource);
       return(Status);
     }
@@ -174,7 +175,6 @@ CHECKPOINT1;
                                FilePositionInformation);
   if (!NT_SUCCESS(Status))
     {
-CHECKPOINT1;
       NtClose(FileHandleSource);
       NtClose(FileHandleDest);
       return(Status);
@@ -187,7 +187,6 @@ CHECKPOINT1;
                                FilePositionInformation);
   if (!NT_SUCCESS(Status))
     {
-CHECKPOINT1;
       NtClose(FileHandleSource);
       NtClose(FileHandleDest);
       return(Status);
@@ -206,7 +205,6 @@ CHECKPOINT1;
                                   PAGE_READWRITE);
   if (!NT_SUCCESS(Status))
     {
-CHECKPOINT1;
       NtClose(FileHandleSource);
       NtClose(FileHandleDest);
       return(Status);
@@ -234,7 +232,6 @@ CHECKPOINT1;
              DPRINT("STATUS_END_OF_FILE\n");
              break;
            }
-CHECKPOINT1;
          NtClose(FileHandleSource);
          NtClose(FileHandleDest);
          return(Status);
@@ -253,7 +250,6 @@ CHECKPOINT1;
                           NULL);
       if (!NT_SUCCESS(Status))
        {
-CHECKPOINT1;
          NtFreeVirtualMemory(NtCurrentProcess(),
                              (PVOID *)&Buffer,
                              &RegionSize,
@@ -283,6 +279,65 @@ CHECKPOINT1;
 }
 
 
+NTSTATUS
+SetupExtractFile(PWCHAR CabinetFileName,
+        PWCHAR SourceFileName,
+             PWCHAR DestinationPathName)
+{
+  ULONG CabStatus;
+
+  DPRINT("SetupExtractFile(CabinetFileName %S, SourceFileName %S, DestinationPathName %S)\n",
+    CabinetFileName, SourceFileName, DestinationPathName);
+
+  if (HasCurrentCabinet)
+    {
+      DPRINT("CurrentCabinetName: %S\n", CurrentCabinetName);
+    }
+
+  if ((HasCurrentCabinet) && (wcscmp(CabinetFileName, CurrentCabinetName) == 0))
+    {
+      DPRINT("Using same cabinet as last time\n");
+    }
+  else
+    {
+      DPRINT("Using new cabinet\n");
+
+      if (HasCurrentCabinet)
+        {
+          CabinetCleanup();
+        }
+
+      wcscpy(CurrentCabinetName, CabinetFileName); 
+
+      CabinetInitialize();
+      CabinetSetEventHandlers(NULL, NULL, NULL);
+      CabinetSetCabinetName(CabinetFileName);
+
+      CabStatus = CabinetOpen();
+      if (CabStatus == CAB_STATUS_SUCCESS)
+        {
+          DPRINT("Opened cabinet %S\n", CabinetGetCabinetName());
+          HasCurrentCabinet = TRUE;
+        }
+      else
+        {
+          DPRINT("Cannot open cabinet (%d)\n", CabStatus);
+          return STATUS_UNSUCCESSFUL;
+        }
+    }
+
+  CabinetSetDestinationPath(DestinationPathName);
+  CabStatus = CabinetExtractFile(SourceFileName);
+  if (CabStatus != CAB_STATUS_SUCCESS)
+    {
+      DPRINT("Cannot extract file %S (%d)\n", SourceFileName, CabStatus);
+      return STATUS_UNSUCCESSFUL;
+    }
+
+  return STATUS_SUCCESS;
+}
+
+
 BOOLEAN
 DoesFileExist(PWSTR PathName,
              PWSTR FileName)
@@ -319,7 +374,6 @@ DoesFileExist(PWSTR PathName,
                      FILE_SYNCHRONOUS_IO_ALERT);
   if (!NT_SUCCESS(Status))
     {
-CHECKPOINT1;
       return(FALSE);
     }