Rob Shearman : setupapi: SetupCopyOEMInfW should preserve the basename when copying the inf file to the inf directory if possible .

Alexandre Julliard julliard at wine.codeweavers.com
Wed May 2 08:14:56 CDT 2007


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

Author: Rob Shearman <rob at codeweavers.com>
Date:   Wed May  2 13:20:47 2007 +0100

setupapi: SetupCopyOEMInfW should preserve the basename when copying the inf file to the inf directory if possible.

If the file already exists, then it should use a name with the form oem%u.inf instead.

---

 dlls/setupapi/misc.c |   34 ++++++++++++++++++++++++++++++++--
 1 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/dlls/setupapi/misc.c b/dlls/setupapi/misc.c
index a9e1e82..b79c0e6 100644
--- a/dlls/setupapi/misc.c
+++ b/dlls/setupapi/misc.c
@@ -37,6 +37,8 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
 
+/* arbitrary limit not related to what native actually uses */
+#define OEM_INDEX_LIMIT 999
 
 /**************************************************************************
  * MyFree [SETUPAPI.@]
@@ -926,7 +928,7 @@ BOOL WINAPI SetupCopyOEMInfW( PCWSTR source, PCWSTR location,
 {
     BOOL ret = FALSE;
     WCHAR target[MAX_PATH], *p;
-    static const WCHAR inf_oem[] = { '\\','i','n','f','\\','O','E','M',0 };
+    static const WCHAR inf[] = { '\\','i','n','f','\\',0 };
     DWORD size;
 
     TRACE("%s, %s, %d, %d, %p, %d, %p, %p\n", debugstr_w(source), debugstr_w(location),
@@ -947,10 +949,38 @@ BOOL WINAPI SetupCopyOEMInfW( PCWSTR source, PCWSTR location,
 
     if (!GetWindowsDirectoryW( target, sizeof(target)/sizeof(WCHAR) )) return FALSE;
 
-    strcatW( target, inf_oem );
+    strcatW( target, inf );
     if ((p = strrchrW( source, '\\' )))
         strcatW( target, p + 1 );
 
+    /* does the file exist already? */
+    if ((GetFileAttributesW( target ) != INVALID_FILE_ATTRIBUTES) &&
+        !(style & SP_COPY_NOOVERWRITE))
+    {
+        static const WCHAR oem[] = { 'o','e','m',0 };
+        unsigned int i;
+
+        p = strrchrW( target, '\\' ) + 1;
+        memcpy( p, oem, sizeof(oem) );
+        p += sizeof(oem)/sizeof(oem[0]) - 1;
+
+        /* generate OEMnnn.inf ending */
+        for (i = 0; i < OEM_INDEX_LIMIT; i++)
+        {
+            static const WCHAR format[] = { '%','u','.','i','n','f',0 };
+            wsprintfW( p, format, i );
+            /* if we found a file name that doesn't exist then we're done */
+            if (GetFileAttributesW( target ) == INVALID_FILE_ATTRIBUTES)
+                break;
+        }
+
+        if (i == OEM_INDEX_LIMIT)
+        {
+            SetLastError( ERROR_FILENAME_EXCED_RANGE );
+            return FALSE;
+        }
+    }
+
     if (!(ret = CopyFileW( source, target, (style & SP_COPY_NOOVERWRITE) != 0 )))
         return ret;
 




More information about the wine-cvs mailing list