Alexandre Julliard : winecfg: Update the drives only when they have changed , instead of trying to compare with the current setup.

Alexandre Julliard julliard at winehq.org
Thu Oct 23 08:38:10 CDT 2008


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Oct 23 12:15:43 2008 +0200

winecfg: Update the drives only when they have changed, instead of trying to compare with the current setup.

---

 programs/winecfg/drive.c   |   95 +++++++++----------------------------------
 programs/winecfg/driveui.c |    7 +++
 programs/winecfg/winecfg.h |    1 +
 3 files changed, 28 insertions(+), 75 deletions(-)

diff --git a/programs/winecfg/drive.c b/programs/winecfg/drive.c
index 1516426..bc3766c 100644
--- a/programs/winecfg/drive.c
+++ b/programs/winecfg/drive.c
@@ -103,6 +103,7 @@ BOOL add_drive(char letter, const char *targetpath, const WCHAR *label, DWORD se
     drives[driveIndex].serial   = serial;
     drives[driveIndex].type     = type;
     drives[driveIndex].in_use   = TRUE;
+    drives[driveIndex].modified = TRUE;
 
     return TRUE;
 }
@@ -116,6 +117,7 @@ void delete_drive(struct drive *d)
     d->label = NULL;
     d->serial = 0;
     d->in_use = FALSE;
+    d->modified = TRUE;
 }
 
 static void set_drive_type( char letter, DWORD type )
@@ -370,6 +372,9 @@ void load_drives(void)
         drivecount++;
     }
 
+    /* reset modified flags */
+    for (i = 0; i < 26; i++) drives[i].modified = FALSE;
+
     WINE_TRACE("found %d drives\n", drivecount);
 
     HeapFree(GetProcessHeap(), 0, path);
@@ -383,66 +388,37 @@ void apply_drive_changes(void)
     int i;
     CHAR devicename[4];
     CHAR targetpath[256];
-    BOOL foundDrive;
-    WCHAR volumeNameBuffer[512];
-    DWORD serialNumber;
-    int retval;
-    BOOL defineDevice;
 
     WINE_TRACE("\n");
 
     /* add each drive and remove as we go */
     for(i = 0; i < 26; i++)
     {
-        defineDevice = FALSE;
-        foundDrive = FALSE;
-        volumeNameBuffer[0] = 0;
-        serialNumber = 0;
-        snprintf(devicename, sizeof(devicename), "%c:", 'A' + i);
+        if (!drives[i].modified) continue;
+        drives[i].modified = FALSE;
 
-        /* get a drive */
-        if(QueryDosDevice(devicename, targetpath, sizeof(targetpath)))
-        {
-            char *cursor;
-            
-            /* correct the slashes in the path to be UNIX style */
-            while ((cursor = strchr(targetpath, '\\'))) *cursor = '/';
-
-            foundDrive = TRUE;
-        }
+        snprintf(devicename, sizeof(devicename), "%c:", 'A' + i);
 
-        /* if we found a drive and have a drive then compare things */
-        if(foundDrive && drives[i].in_use)
+        if (drives[i].in_use)
         {
-            WCHAR deviceW[4] = {'a',':','\\',0};
-            WINE_TRACE("drives[i].letter: '%c'\n", drives[i].letter);
-
-            deviceW[0] = 'A' + i;
-            retval = GetVolumeInformationW(deviceW, volumeNameBuffer, sizeof(volumeNameBuffer)/sizeof(WCHAR),
-                                           &serialNumber, NULL, NULL, NULL, 0 );
-            if(!retval)
+            /* define this drive */
+            /* DefineDosDevice() requires that NO trailing slash be present */
+            if(!DefineDosDevice(DDD_RAW_TARGET_PATH, devicename, drives[i].unixpath))
             {
-                WINE_TRACE("  GetVolumeInformation() for '%s' failed\n", devicename);
+                WINE_ERR("  unable to define devicename of '%s', targetpath of '%s'\n",
+                    devicename, drives[i].unixpath);
                 PRINTERROR();
-                volumeNameBuffer[0] = '\0';
-            }
-
-            WINE_TRACE("  current path:   '%s', new path:   '%s'\n",
-                       targetpath, drives[i].unixpath);
-
-            /* compare to what we have */
-            /* do we have the same targetpath? */
-            if(strcmp(drives[i].unixpath, targetpath))
-            {
-                defineDevice = TRUE;
-                WINE_TRACE("  making changes to drive '%s'\n", devicename);
             }
             else
             {
-                WINE_TRACE("  no changes to drive '%s'\n", devicename);
+                WINE_TRACE("  added devicename of '%s', targetpath of '%s'\n",
+                           devicename, drives[i].unixpath);
             }
+            set_drive_label( drives[i].letter, drives[i].label );
+            set_drive_serial( drives[i].letter, drives[i].serial );
+            set_drive_type( drives[i].letter, drives[i].type );
         }
-        else if(foundDrive && !drives[i].in_use)
+        else if (QueryDosDevice(devicename, targetpath, sizeof(targetpath)))
         {
             /* remove this drive */
             if(!DefineDosDevice(DDD_REMOVE_DEFINITION, devicename, drives[i].unixpath))
@@ -460,36 +436,5 @@ void apply_drive_changes(void)
             set_drive_type( drives[i].letter, DRIVE_UNKNOWN );
             continue;
         }
-        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)
-        {
-            /* define this drive */
-            /* DefineDosDevice() requires that NO trailing slash be present */
-            snprintf(devicename, sizeof(devicename), "%c:", 'A' + i);
-            if(!DefineDosDevice(DDD_RAW_TARGET_PATH, devicename, drives[i].unixpath))
-            {
-                WINE_ERR("  unable to define devicename of '%s', targetpath of '%s'\n",
-                    devicename, drives[i].unixpath);
-                PRINTERROR();
-            }
-            else
-            {
-                WINE_TRACE("  added devicename of '%s', targetpath of '%s'\n",
-                           devicename, drives[i].unixpath);
-            }
-        }
-
-        if (!drives[i].label || lstrcmpW(drives[i].label, volumeNameBuffer))
-            set_drive_label( drives[i].letter, drives[i].label );
-
-        if (drives[i].serial != serialNumber)
-            set_drive_serial( drives[i].letter, drives[i].serial );
-
-        set_drive_type( drives[i].letter, drives[i].type );
     }
 }
diff --git a/programs/winecfg/driveui.c b/programs/winecfg/driveui.c
index 61fba5f..8443537 100644
--- a/programs/winecfg/driveui.c
+++ b/programs/winecfg/driveui.c
@@ -334,6 +334,7 @@ static void on_add_click(HWND dialog)
     SetFocus(GetDlgItem(dialog, IDC_LIST_DRIVES));
 
     update_controls(dialog);
+    SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
 }
 
 static void on_remove_click(HWND dialog)
@@ -372,6 +373,7 @@ static void on_remove_click(HWND dialog)
     SetFocus(GetDlgItem(dialog, IDC_LIST_DRIVES));
 
     update_controls(dialog);
+    SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
 }
 
 static void update_controls(HWND dialog)
@@ -485,6 +487,7 @@ static void on_edit_changed(HWND dialog, WORD id)
             WCHAR *label = get_textW(dialog, id);
             HeapFree(GetProcessHeap(), 0, current_drive->label);
             current_drive->label = label;
+            current_drive->modified = TRUE;
 
             WINE_TRACE("set label to %s\n", wine_dbgstr_w(current_drive->label));
 
@@ -500,6 +503,7 @@ static void on_edit_changed(HWND dialog, WORD id)
             path = get_text(dialog, id);
             HeapFree(GetProcessHeap(), 0, current_drive->unixpath);
             current_drive->unixpath = path ? path : strdupA("drive_c");
+            current_drive->modified = TRUE;
 
             WINE_TRACE("set path to %s\n", current_drive->unixpath);
 
@@ -517,6 +521,7 @@ static void on_edit_changed(HWND dialog, WORD id)
 
             serial = get_text(dialog, id);
             current_drive->serial = strtoul( serial, NULL, 16 );
+            current_drive->modified = TRUE;
 
             WINE_TRACE("set serial to %08x\n", current_drive->serial);
 
@@ -756,6 +761,7 @@ DriveDlgProc (HWND dialog, UINT msg, WPARAM wParam, LPARAM lParam)
 
                     str = get_textW(dialog, IDC_EDIT_SERIAL);
                     current_drive->serial = strtoulW( str, NULL, 16 );
+                    current_drive->modified = TRUE;
 
                     /* TODO: we don't have a device at this point */
 
@@ -787,6 +793,7 @@ DriveDlgProc (HWND dialog, UINT msg, WPARAM wParam, LPARAM lParam)
                     enable_labelserial_box(dialog, mode);
 
                     current_drive->type = type_pairs[selection].sCode;
+                    current_drive->modified = TRUE;
                     break;
                 }
 
diff --git a/programs/winecfg/winecfg.h b/programs/winecfg/winecfg.h
index 91cb7b3..807caf7 100644
--- a/programs/winecfg/winecfg.h
+++ b/programs/winecfg/winecfg.h
@@ -102,6 +102,7 @@ struct drive
     DWORD type; /* one of the DRIVE_ constants from winbase.h  */
 
     BOOL in_use;
+    BOOL modified;
 };
 
 #define DRIVE_MASK_BIT(B) (1 << (toupper(B) - 'A'))




More information about the wine-cvs mailing list