Alexandre Julliard : setupapi: Add support for creating directories from the FakeDlls section.

Alexandre Julliard julliard at winehq.org
Thu Apr 17 14:43:45 CDT 2008


Module: wine
Branch: master
Commit: 0ed9db27c55b666b3ab80e281cc30a06f576729a
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=0ed9db27c55b666b3ab80e281cc30a06f576729a

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Apr 17 20:34:06 2008 +0200

setupapi: Add support for creating directories from the FakeDlls section.

---

 dlls/setupapi/fakedll.c |   50 +++++++++++++++++++++++++++-------------------
 1 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/dlls/setupapi/fakedll.c b/dlls/setupapi/fakedll.c
index ca9e069..e46a821 100644
--- a/dlls/setupapi/fakedll.c
+++ b/dlls/setupapi/fakedll.c
@@ -276,6 +276,27 @@ static BOOL is_fake_dll( HANDLE h )
     return !memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) );
 }
 
+/* create directories leading to a given file */
+static void create_directories( const WCHAR *name )
+{
+    WCHAR *path, *p;
+
+    /* create the directory/directories */
+    path = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1)*sizeof(WCHAR));
+    strcpyW(path, name);
+
+    p = strchrW(path, '\\');
+    while (p != NULL)
+    {
+        *p = 0;
+        if (!CreateDirectoryW(path, NULL))
+            TRACE("Couldn't create directory %s - error: %d\n", wine_dbgstr_w(path), GetLastError());
+        *p = '\\';
+        p = strchrW(p+1, '\\');
+    }
+    HeapFree(GetProcessHeap(), 0, path);
+}
+
 /***********************************************************************
  *            create_fake_dll
  */
@@ -285,6 +306,13 @@ BOOL create_fake_dll( const WCHAR *name, const WCHAR *source )
     HMODULE module;
     BOOL ret;
 
+    /* check for empty name which means to only create the directory */
+    if (name[strlenW(name) - 1] == '\\')
+    {
+        create_directories( name );
+        return TRUE;
+    }
+
     /* first check for an existing file */
     h = CreateFileW( name, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL );
     if (h != INVALID_HANDLE_VALUE)
@@ -301,27 +329,7 @@ BOOL create_fake_dll( const WCHAR *name, const WCHAR *source )
     }
     else
     {
-        if (GetLastError() == ERROR_PATH_NOT_FOUND)
-        {
-            WCHAR *path;
-            WCHAR *pathel;
-
-            /* create the directory/directories */
-            path = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1)*sizeof(WCHAR));
-            strcpyW(path, name);
-
-            pathel = strchrW(path, '\\');
-            while (pathel != NULL)
-            {
-                *pathel = 0;
-                if (!CreateDirectoryW(path, NULL))
-                    TRACE("Couldn't create directory %s - error: %d\n", wine_dbgstr_w(path), GetLastError());
-                *pathel = '\\';
-                pathel = strchrW(pathel+1, '\\');
-            }
-
-            HeapFree(GetProcessHeap(), 0, path);
-        }
+        if (GetLastError() == ERROR_PATH_NOT_FOUND) create_directories( name );
 
         h = CreateFileW( name, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL );
         if (h == INVALID_HANDLE_VALUE)




More information about the wine-cvs mailing list