winecfg: fix bug 3096, make drive type an advanced option.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

winecfg: fix bug 3096, make drive type an advanced option.

ivanleo
This patch makes the drive type an advanced option. It also allows the
setting to be saved when the user clicks ok.

Ivan.

diff -urN cvs/programs/winecfg/drive.c wine/programs/winecfg/drive.c
--- cvs/programs/winecfg/drive.c 2005-09-09 09:28:49.000000000 +0100
+++ wine/programs/winecfg/drive.c 2005-10-12 21:09:50.000000000 +0100
@@ -4,6 +4,7 @@
  * Copyright 2003 Mark Westcott
  * Copyright 2003-2004 Mike Hearn
  * Copyright 2004 Chris Morgan
+ * Copyright 2005 Ivan Leo Puoti
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -290,6 +291,8 @@
     /* add each drive and remove as we go */
     for(i = 0; i < 26; i++)
     {
+        HKEY hKey;
+        char driveValue[256];
         defineDevice = FALSE;
         foundDrive = FALSE;
         snprintf(devicename, sizeof(devicename), "%c:", 'A' + i);
@@ -323,7 +326,7 @@
                          &fileSystemFlags,
                          fileSystemName,
                          sizeof(fileSystemName));
-            if(!retval)
+            if(!retval && GetLastError() != ERROR_NOT_READY)
             {
                 WINE_TRACE("  GetVolumeInformation() for '%s' failed\n", devicename);
                 WINE_TRACE("  Skipping this drive\n");
@@ -340,6 +343,35 @@
             WINE_TRACE("  current serial: '%s', new serial: '%s'\n",
                        newSerialNumberText, drives[i].serial);
 
+            /* Check if the drive type is being changed or is missing */
+            snprintf(driveValue, sizeof(driveValue), "%c:", toupper(drives[i].letter));
+            retval = RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Wine", &hKey);
+            if(retval == ERROR_SUCCESS)
+            {
+                char current_value[8];
+                char *new_value;
+                DWORD data_size;
+                retval = RegGetValue(hKey, "Drives", driveValue, RRF_RT_REG_SZ, NULL,
+                                     current_value, &data_size);
+                if(retval == ERROR_SUCCESS)
+                {
+                    switch(drives[i].type)
+                    {
+                        case DRIVE_FIXED  : new_value = "hd"; break;
+                        case DRIVE_REMOTE : new_value = "network"; break;
+                        case DRIVE_REMOVABLE : new_value = "floppy"; break;
+                        default : new_value = "cdrom";
+                    }
+                    if(strcmp(current_value, new_value))
+                        defineDevice = TRUE;
+                    RegCloseKey(hKey);
+                }
+                else
+                    defineDevice = TRUE;
+            }
+            else
+                defineDevice = TRUE;
+
             /* compare to what we have */
             /* do we have the same targetpath? */
             if(strcmp(drives[i].unixpath, targetpath) ||
@@ -356,9 +388,6 @@
         }
         else if(foundDrive && !drives[i].in_use)
         {
-            HKEY hKey;
-            char driveValue[256];
-
             /* remove this drive */
             if(!DefineDosDevice(DDD_REMOVE_DEFINITION, devicename, drives[i].unixpath))
             {
@@ -367,37 +396,24 @@
                 PRINTERROR();
             }
             else
-            {
                 WINE_TRACE("removed devicename of '%s', targetpath of '%s'\n",
                            devicename, drives[i].unixpath);
-            }
 
             retval = RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Wine\\Drives", &hKey);
             if (retval != ERROR_SUCCESS)
-            {
                 WINE_TRACE("Unable to open '%s'\n", "Software\\Wine\\Drives");
-            }
             else
-            {
-                snprintf(driveValue, sizeof(driveValue), "%c:", toupper(drives[i].letter));    
-
                 retval = RegDeleteValue(hKey, driveValue);
-            }
         }
         else if(drives[i].in_use) /* foundDrive must be false from the above check */
-        {
             defineDevice = TRUE;
-        }
 
         /* adding and modifying are the same steps */
         if(defineDevice)
         {
             char filename[256];
             HANDLE hFile;
-
-            HKEY hKey;
             const char *typeText;
-            char driveValue[256];
 
             /* define this drive */
             /* DefineDosDevice() requires that NO trailing slash be present */
@@ -429,27 +445,54 @@
             }
 
             /* Set the drive type in the registry */
-            if(drives[i].type == DRIVE_FIXED)
-                typeText = "hd";
-            else if(drives[i].type == DRIVE_REMOTE)
-                typeText = "network";
-            else if(drives[i].type == DRIVE_REMOVABLE)
-                typeText = "floppy";
-            else /* must be DRIVE_CDROM */
-                typeText = "cdrom";
-
-
-            snprintf(driveValue, sizeof(driveValue), "%c:", toupper(drives[i].letter));
+            switch(drives[i].type)
+            {
+                case DRIVE_FIXED  : typeText = "hd"; break;
+                case DRIVE_REMOTE : typeText = "network"; break;
+                case DRIVE_REMOVABLE : typeText = "floppy"; break;
+                default : typeText = "cdrom";
+            }
 
             retval = RegOpenKey(HKEY_LOCAL_MACHINE,
                        "Software\\Wine\\Drives",
                        &hKey);
 
+            /* Create the registry keys if they're missing */
             if(retval != ERROR_SUCCESS)
             {
-                WINE_TRACE("  Unable to open '%s'\n", "Software\\Wine\\Drives");
+                if(retval == ERROR_FILE_NOT_FOUND)
+                {
+                   retval = RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Wine", &hKey);
+                   if(retval == ERROR_FILE_NOT_FOUND)
+                   {
+                       retval = RegCreateKey(HKEY_LOCAL_MACHINE, "Software\\Wine", &hKey);
+                       if(retval != ERROR_SUCCESS)
+                           WINE_TRACE("  Unable to create '%s', error %ld\n", "Software\\Wine", GetLastError());
+                       else
+                           RegCloseKey(hKey);
+                   }
+                   else if(retval != ERROR_SUCCESS)
+                        WINE_TRACE("  Unable to open '%s', error %ld\n", "Software\\Wine", GetLastError());
+                   else
+                       RegCloseKey(hKey);
+                }
+                else if(retval != ERROR_SUCCESS)
+                    WINE_TRACE("  Unable to open '%s', error %ld\n", "Software\\Wine\\", GetLastError());
+
+                if(retval == ERROR_SUCCESS)
+                {
+                    retval = RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Wine\\Drives", &hKey);
+                    if(retval == ERROR_FILE_NOT_FOUND)
+                    {
+                        retval = RegCreateKey(HKEY_LOCAL_MACHINE, "Software\\Wine\\Drives", &hKey);
+                        if(retval != ERROR_SUCCESS)
+                            WINE_TRACE("  Unable to create '%s', error %ld\n", "Software\\Wine\\Drives", GetLastError());
+                    }
+                    else if(retval != ERROR_SUCCESS)
+                         WINE_TRACE("  Unable to open '%s', error %ld\n", "Software\\Wine\\Drives", GetLastError());
+                }
             }
-            else
+            if(retval == ERROR_SUCCESS)
             {
                 retval = RegSetValueEx(
                               hKey,
diff -urN cvs/programs/winecfg/driveui.c wine/programs/winecfg/driveui.c
--- cvs/programs/winecfg/driveui.c 2005-09-09 11:21:06.000000000 +0100
+++ wine/programs/winecfg/driveui.c 2005-10-14 22:21:05.000000000 +0100
@@ -121,6 +121,8 @@
     ShowWindow(GetDlgItem(dialog, IDC_EDIT_SERIAL), state);
     ShowWindow(GetDlgItem(dialog, IDC_STATIC_SERIAL), state);
     ShowWindow(GetDlgItem(dialog, IDC_LABELSERIAL_STATIC), state);
+    ShowWindow(GetDlgItem(dialog, IDC_COMBO_TYPE), state);
+    ShowWindow(GetDlgItem(dialog, IDC_STATIC_TYPE), state);
 
     /* update the button text based on the state */
     SetWindowText(GetDlgItem(dialog, IDC_BUTTON_SHOW_HIDE_ADVANCED), text);