[CABINET] Sync with Wine Staging 3.3. CORE-14434
[reactos.git] / dll / win32 / cabinet / cabinet_main.c
index 45454f4..8af0fb1 100644 (file)
@@ -251,11 +251,9 @@ static INT_PTR CDECL fdi_notify_extract(FDINOTIFICATIONTYPE fdint, PFDINOTIFICAT
                 }
 
                 hFile = CreateFileA(szFullPath, GENERIC_READ | GENERIC_WRITE, 0, NULL,
-                                    CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
+                                    CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
 
-                if (hFile == INVALID_HANDLE_VALUE)
-                    hFile = 0;
-                else if (node)
+                if (hFile != INVALID_HANDLE_VALUE && node)
                     node->DoExtract = FALSE;
             }
 
@@ -331,9 +329,9 @@ HRESULT WINAPI Extract(SESSION *dest, LPCSTR szCabName)
 {
     HRESULT res = S_OK;
     HFDI hfdi;
-    char *str, *path, *name;
+    char *str, *end, *path = NULL, *name = NULL;
 
-    TRACE("(%p, %s)\n", dest, szCabName);
+    TRACE("(%p, %s)\n", dest, debugstr_a(szCabName));
 
     hfdi = FDICreate(mem_alloc,
                      mem_free,
@@ -363,13 +361,22 @@ HRESULT WINAPI Extract(SESSION *dest, LPCSTR szCabName)
     }
     lstrcpyA(str, szCabName);
 
-    path = str;
-    name = strrchr(path, '\\');
-    if (name)
-        *name++ = 0;
+    if ((end = strrchr(str, '\\')))
+    {
+        path = str;
+        end++;
+        name = HeapAlloc( GetProcessHeap(), 0, strlen(end) + 1 );
+        if (!name)
+        {
+            res = E_OUTOFMEMORY;
+            goto end;
+        }
+        strcpy( name, end );
+        *end = 0;
+    }
     else
     {
-        name = path;
+        name = str;
         path = NULL;
     }
 
@@ -379,10 +386,9 @@ HRESULT WINAPI Extract(SESSION *dest, LPCSTR szCabName)
          fdi_notify_extract, NULL, dest))
         res = HRESULT_FROM_WIN32(GetLastError());
 
-    HeapFree(GetProcessHeap(), 0, str);
 end:
-
+    HeapFree(GetProcessHeap(), 0, path);
+    HeapFree(GetProcessHeap(), 0, name);
     FDIDestroy(hfdi);
-
     return res;
 }