[winecfg 3] Merge drive editing code

Mike Hearn mike at theoretic.com
Thu Aug 28 10:39:33 CDT 2003


Yes, it's a bigass patch. Sorry about that. No way around it. I think I
got all of the C99isms, yell if I missed some.

Mark Westcott <mark at houseoffish.org>
Mike Hearn <mike at theoretic.com>
* Merge drive code from Mark
* Rename saveX11DrvDlgSettings to fetchX11DrvDlgSettings
* Make the listbox display drive title, not letter


diff -ur --exclude-from=diff-exclusions ../head/programs/winecfg/En.rc programs/winecfg/En.rc
--- ../head/programs/winecfg/En.rc	2003-08-28 16:13:21.000000000 +0100
+++ programs/winecfg/En.rc	2003-08-28 15:28:30.000000000 +0100
@@ -102,6 +102,93 @@
     LTEXT           "Load order:",IDC_STATIC,16,144,37,8
 END
 
+IDD_SYSTEMCFG DIALOG DISCARDABLE  0, 0, 260, 250
+STYLE WS_CHILD
+FONT 8, "MS Sans Serif"
+BEGIN
+    GROUPBOX        "Drives",IDC_STATIC,8,4,244,120
+    LISTBOX         IDC_LIST_DRIVES,15,23,179,90,WS_VSCROLL
+    PUSHBUTTON      "&Add",IDC_DRIVE_ADD,197,22,50,22
+    PUSHBUTTON      "&Remove",IDC_DRIVE_REMOVE,197,51,50,22
+    PUSHBUTTON      "&Edit",IDC_DRIVE_EDIT,197,80,50,22
+END
+
+IDD_DRIVE_EDIT DIALOG DISCARDABLE  0, 0, 207, 110
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Drive Configuration"
+FONT 8, "MS Sans Serif"
+BEGIN
+    DEFPUSHBUTTON   "OK",ID_DRIVE_OK,150,7,50,14
+    PUSHBUTTON      "Cancel",ID_DRIVE_CANCEL,150,24,50,14
+    EDITTEXT        IDC_DRIVE_EDIT_NAME,42,8,78,13,ES_AUTOHSCROLL
+    LTEXT           "Drive:",-1,11,10,29,12
+    EDITTEXT        IDC_DRIVE_EDIT_LABEL,42,23,78,13,ES_AUTOHSCROLL
+    LTEXT           "Label:",-1,11,25,29,12
+    EDITTEXT        IDC_DRIVE_EDIT_TYPE,42,38,78,13,ES_AUTOHSCROLL
+    LTEXT           "Type:",-1,11,40,29,12
+    EDITTEXT        IDC_DRIVE_EDIT_PATH,42,53,78,13,ES_AUTOHSCROLL
+    LTEXT           "Path:",-1,11,55,29,12
+    EDITTEXT        IDC_DRIVE_EDIT_FS,42,68,78,13,ES_AUTOHSCROLL
+    LTEXT           "FS:",-1,11,70,29,12
+    EDITTEXT        IDC_DRIVE_EDIT_DEVICE,42,83,78,13,ES_AUTOHSCROLL
+    LTEXT           "Device:",-1,11,85,29,12
+END
+
+IDD_DRIVECFG DIALOG DISCARDABLE  0, 0, 260, 250
+STYLE WS_CHILD | WS_DISABLED
+FONT 8, "MS Sans Serif"
+BEGIN
+    GROUPBOX        "Windows Drive",IDC_STATIC,7,7,246,99
+    CONTROL         "Create a virtual Windows drive",IDC_RADIO_VIRTUAL,
+                    "Button",BS_AUTORADIOBUTTON,14,18,112,10
+    EDITTEXT        IDC_EDIT_VIRTUAL,25,30,169,14,ES_AUTOHSCROLL
+    PUSHBUTTON      "Browse...",IDC_BUTTON_VIRTUAL,202,30,44,14
+    CONTROL         "Use a real Windows drive",IDC_RADIO_REAL,"Button",
+                    BS_AUTORADIOBUTTON,14,48,97,10
+    EDITTEXT        IDC_EDIT_REAL,25,60,169,14,ES_AUTOHSCROLL
+    PUSHBUTTON      "Browse...",IDC_BUTTON_REAL,202,60,44,14
+    PUSHBUTTON      "Important Folders...",IDC_BUTTON_FOLDERS,173,85,73,14
+    GROUPBOX        "Other Drives",IDC_STATIC,7,107,246,112
+    LISTBOX         IDC_LIST_DRIVES,14,118,232,76,LBS_SORT | LBS_NOINTEGRALHEIGHT | 
+                    LBS_MULTICOLUMN | WS_VSCROLL | WS_TABSTOP
+    PUSHBUTTON      "Add...",IDC_BUTTON_ADD,14,199,37,14
+    PUSHBUTTON      "Remove",IDC_BUTTON_REMOVE,55,199,37,14
+    PUSHBUTTON      "Edit...",IDC_BUTTON_EDIT,97,199,37,14
+    PUSHBUTTON      "Autodetect...",IDC_BUTTON_AUTODETECT,197,199,49,14
+END
+
+IDD_DRIVE_EDIT2 DIALOG DISCARDABLE  0, 0, 272, 153
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Drive Configuration"
+FONT 8, "MS Sans Serif"
+BEGIN
+    DEFPUSHBUTTON   "OK",ID_BUTTON_OK,217,5,50,14
+    PUSHBUTTON      "Cancel",ID_BUTTON_CANCEL,217,22,50,14
+    LTEXT           "Letter:",IDC_STATIC,5,23,26,9
+    EDITTEXT        IDC_EDIT_LABEL,63,114,78,13,ES_AUTOHSCROLL
+    LTEXT           "Label:",IDC_STATIC_LABEL,33,117,29,12
+    LTEXT           "Type:",IDC_STATIC,5,54,21,10
+    EDITTEXT        IDC_EDIT_PATH,31,5,117,13,ES_AUTOHSCROLL
+    LTEXT           "Path:",IDC_STATIC,5,9,20,9
+    LTEXT           "Names:",IDC_STATIC,5,39,25,9
+    EDITTEXT        IDC_EDIT_SERIAL,63,129,78,13,ES_AUTOHSCROLL
+    LTEXT           "Serial:",IDC_STATIC_SERIAL,33,133,29,12
+    COMBOBOX        IDC_COMBO_LETTER,31,20,78,60,CBS_DROPDOWNLIST  | 
+                    WS_VSCROLL | WS_TABSTOP
+    PUSHBUTTON      "Browse...",IDC_BUTTON_BROWSE_PATH,154,5,40,13
+    COMBOBOX        IDC_COMBO_NAMES,31,36,78,60,CBS_DROPDOWNLIST  | 
+                    WS_VSCROLL | WS_TABSTOP
+    COMBOBOX        IDC_COMBO_TYPE,31,52,78,60,CBS_DROPDOWNLIST | 
+                    WS_VSCROLL | WS_TABSTOP
+    CONTROL         "Autodetect from Device:",IDC_RADIO_AUTODETECT,"Button",
+                    BS_AUTORADIOBUTTON,21,79,93,10
+    EDITTEXT        IDC_EDIT_DEVICE,33,89,108,13,ES_AUTOHSCROLL
+    PUSHBUTTON      "Browse...",IDC_BUTTON_BROWSE_DEVICE,148,89,40,13
+    CONTROL         "Manually Assign:",IDC_RADIO_ASSIGN,"Button",
+                    BS_AUTORADIOBUTTON,21,104,69,10
+    GROUPBOX        "Label and Serial Number",IDC_BOX_CDROM,15,68,180,79
+END
+
 STRINGTABLE DISCARDABLE 
 BEGIN
     IDS_WINE_VERSION        "CVS"
diff -ur --exclude-from=diff-exclusions ../head/programs/winecfg/main.c programs/winecfg/main.c
--- ../head/programs/winecfg/main.c	2003-08-28 16:20:41.000000000 +0100
+++ programs/winecfg/main.c	2003-08-28 15:23:31.000000000 +0100
@@ -160,7 +160,7 @@
     return FALSE;
 }
 
-#define NUM_PROPERTY_PAGES 4
+#define NUM_PROPERTY_PAGES 5
 INT_PTR
 doPropertySheet (HINSTANCE hInstance, HWND hOwner)
 {
@@ -219,6 +219,15 @@
     psp[3].pszTitle = "X11 Driver";
     psp[3].lParam = 0;
 
+    psp[4].dwSize = sizeof (PROPSHEETPAGE);
+    psp[4].dwFlags = PSP_USETITLE;
+    psp[4].hInstance = hInstance;
+    psp[4].u.pszTemplate = MAKEINTRESOURCE (IDD_DRIVECFG);
+    psp[4].u2.pszIcon = NULL;
+    psp[4].pfnDlgProc = DriveDlgProc;
+    psp[4].pszTitle = "Drives";
+    psp[4].lParam = 0;
+    
     /*
      * Fill out the PROPSHEETHEADER
      */
diff -ur --exclude-from=diff-exclusions ../head/programs/winecfg/Makefile.in programs/winecfg/Makefile.in
--- ../head/programs/winecfg/Makefile.in	2003-08-28 16:20:41.000000000 +0100
+++ programs/winecfg/Makefile.in	2003-08-28 14:38:41.000000000 +0100
@@ -10,7 +10,8 @@
 	main.c \
 	properties.c \
 	winecfg.c \
-	x11drvdlg.c
+	x11drvdlg.c \
+	drive.c
 
 RC_SRCS = winecfg.rc
 
diff -ur --exclude-from=diff-exclusions ../head/programs/winecfg/properties.h programs/winecfg/properties.h
--- ../head/programs/winecfg/properties.h	2003-08-28 16:20:41.000000000 +0100
+++ programs/winecfg/properties.h	2003-08-28 14:41:38.000000000 +0100
@@ -3,6 +3,7 @@
  *
  * Copyright 2002 Jaco Greeff
  * Copyright 2003 Dimitrie O. Paun
+ * Copyright 2003 Mark Westcott
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -52,6 +53,18 @@
     HDPA  DLLs;
 } APP_DESC;
 
+
+typedef struct
+{
+    char szName[MAX_NAME_LENGTH];
+    char szPath[MAX_NAME_LENGTH];
+    char szType[MAX_NAME_LENGTH];
+    char szFS[MAX_NAME_LENGTH];
+    char szLabel[MAX_NAME_LENGTH];
+    char szDevice[MAX_NAME_LENGTH];
+    char szSerial[MAX_NAME_LENGTH];
+} DRIVE_DESC;
+
 typedef struct
 {
     char   szX11Display[MAX_NAME_LENGTH];
diff -ur --exclude-from=diff-exclusions ../head/programs/winecfg/resource.h programs/winecfg/resource.h
--- ../head/programs/winecfg/resource.h	2003-03-31 20:41:55.000000000 +0100
+++ programs/winecfg/resource.h	2003-08-28 15:26:50.000000000 +0100
@@ -3,6 +3,7 @@
  *
  * Copyright 2002 Jaco Greeff
  * Copyright 2003 Dimitrie O. Paun
+ * Copyright 2003 Mark Westcott
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -31,6 +32,11 @@
 #define IDD_APPCFG                      108
 #define IDD_X11DRVCFG                   109
 #define IDD_DLLCFG                      110
+#define IDD_DRIVECFG                    111
+#define IDD_SYSTEMCFG                   112
+#define IDD_DRIVE_EDIT                  113
+#define IDD_DRIVE_EDIT2                 114
+#define IDB_WINE_LOGO                   200
 #define IDC_TABABOUT                    1001
 #define IDC_APPLYBTN                    1002
 #define IDC_WINEVER                     1011
@@ -51,3 +57,47 @@
 #define IDC_RAD_BUILTIN                 1029
 #define IDC_RAD_NATIVE                  1030
 #define IDC_LIST_DLLS                   1031
+#define IDC_LIST_BUILTIN_DLLS           1031
+#define IDC_LIST_NATIVE_DLLS            1032
+#define IDC_RADIO_DEFAULT_BUILTIN       1033
+#define IDC_RADIO_DEFAULT_NATIVE        1034
+#define IDC_RADIO_VIRTUAL               1035
+#define IDC_EDIT_VIRTUAL                1036
+#define IDC_BUTTON_VIRTUAL              1037
+#define IDC_RADIO_REAL                  1038
+#define IDC_EDIT_REAL                   1039
+#define IDC_BUTTON_REAL                 1040
+#define IDC_BUTTON_FOLDERS              1041
+#define IDC_LIST_DRIVES                 1042
+#define IDC_BUTTON_ADD                  1043
+#define IDC_BUTTON_REMOVE               1044
+#define IDC_BUTTON_EDIT                 1045
+#define IDC_BUTTON7                     1046
+#define IDC_BUTTON_AUTODETECT           1046
+#define IDC_DRIVE_ADD                   1047
+#define IDC_DRIVE_REMOVE                1048
+#define IDC_DRIVE_EDIT                  1049
+#define IDC_DRIVE_EDIT_NAME             1050
+#define IDC_DRIVE_EDIT_LABEL            1051
+#define IDC_DRIVE_EDIT_TYPE             1052
+#define IDC_DRIVE_EDIT_FS               1053
+#define IDC_DRIVE_EDIT_PATH             1054
+#define IDC_DRIVE_EDIT_DEVICE           1055
+#define ID_DRIVE_OK                     1056
+#define ID_DRIVE_CANCEL                 1057
+#define ID_BUTTON_CANCEL                1058
+#define ID_BUTTON_OK                    1059
+#define IDC_EDIT_LABEL                  1060
+#define IDC_EDIT_PATH                   1061
+#define IDC_EDIT_SERIAL                 1062
+#define IDC_COMBO_LETTER                1063
+#define IDC_COMBO_NAMES                 1064
+#define IDC_COMBO_TYPE                  1065
+#define IDC_EDIT_DEVICE                 1066
+#define IDC_BUTTON_BROWSE_PATH          1067
+#define IDC_RADIO_AUTODETECT            1068
+#define IDC_RADIO_ASSIGN                1069
+#define IDC_BUTTON_BROWSE_DEVICE        1070
+#define IDC_BOX_CDROM                   1071
+#define IDC_STATIC_SERIAL               1072
+#define IDC_STATIC_LABEL                1073
Only in programs/winecfg: TODO
diff -ur --exclude-from=diff-exclusions ../head/programs/winecfg/winecfg.c programs/winecfg/winecfg.c
--- ../head/programs/winecfg/winecfg.c	2003-08-28 16:20:41.000000000 +0100
+++ programs/winecfg/winecfg.c	2003-08-28 16:01:32.000000000 +0100
@@ -190,9 +190,10 @@
 int loadConfig (WINECFG_DESC* pCfg)
 {
     const DLL_DESC *pDllDefaults;
-    char buffer[MAX_PATH];    
-    DWORD res;
-
+    char buffer[MAX_PATH];
+    char subKeyName[51];    
+    DWORD res, i, sizeOfSubKeyName = 50;
+    
     WINE_TRACE("\n");
 
     res = RegCreateKey(HKEY_LOCAL_MACHINE, WINEHQ_KEY_ROOT, &configKey);
@@ -265,7 +266,100 @@
     pCfg->sX11Drv.nDXGrab = 0;
     pCfg->sX11Drv.nDoubleBuffered = 0;
     pCfg->sX11Drv.nSynchronous = 1;
-    
+
+
+    /*
+     * Drive mappings
+     */
+    pCfg->pDrives = DPA_Create(26);
+    for (i = 0;
+	 RegEnumKeyExA(configKey, i, subKeyName, &sizeOfSubKeyName, NULL, NULL, NULL, NULL ) != ERROR_NO_MORE_ITEMS;
+         ++i, sizeOfSubKeyName=50) {
+	HKEY hkDrive;
+	DWORD returnType;
+	char returnBuffer[MAX_NAME_LENGTH];
+	DWORD sizeOfReturnBuffer = sizeof(returnBuffer);
+	LONG r;
+
+	if (!strncmp("Drive ", subKeyName, 5)) {
+	    DRIVE_DESC *pDrive = malloc(sizeof(DRIVE_DESC));
+
+	    WINE_TRACE("Loading %s\n", subKeyName);
+	    
+	    ZeroMemory(pDrive, sizeof(*pDrive));
+	    sizeOfReturnBuffer = sizeof(returnBuffer);
+	    if (RegOpenKeyExA (configKey, subKeyName, 0, KEY_READ, &hkDrive) != ERROR_SUCCESS)	{
+		WINE_ERR("unable to open drive registry key");
+		RegCloseKey(configKey);
+		return 1;
+	    }
+	   
+	    strncpy(pDrive->szName, &subKeyName[strlen(subKeyName)-1],1);
+	    if(pDrive->szName) {
+		pDrive->szName[0] = toupper(pDrive->szName[0]);
+	    }
+	    
+	    ZeroMemory(returnBuffer, sizeof(*returnBuffer));
+	    sizeOfReturnBuffer = sizeof(returnBuffer);
+	    r = RegQueryValueExA(hkDrive, "Label", NULL, &returnType, returnBuffer, &sizeOfReturnBuffer);
+	    if (r == ERROR_SUCCESS) {
+		strncpy(pDrive->szLabel, returnBuffer, sizeOfReturnBuffer);
+	    } else {
+		WINE_WARN("pDrive->szLabel not loaded: %ld\n", r);
+	    }
+	    
+	    ZeroMemory(returnBuffer, sizeof(*returnBuffer));
+	    sizeOfReturnBuffer = sizeof(returnBuffer);
+	    r = RegQueryValueExA(hkDrive, "Serial", NULL, &returnType, returnBuffer, &sizeOfReturnBuffer);
+	    if (r == ERROR_SUCCESS) {
+		strncpy(pDrive->szSerial, returnBuffer, sizeOfReturnBuffer);
+	    } else {
+		WINE_WARN("pDrive->szSerial not loaded: %ld\n", r);
+	    }
+	    
+	    
+	    ZeroMemory(returnBuffer, sizeof(*returnBuffer));
+	    sizeOfReturnBuffer = sizeof(returnBuffer);
+	    r = RegQueryValueExA(hkDrive, "Type", NULL, &returnType, returnBuffer, &sizeOfReturnBuffer);
+	    if (r == ERROR_SUCCESS) {
+		strncpy(pDrive->szType, returnBuffer, sizeOfReturnBuffer);
+	    } else {
+		WINE_WARN("pDrive->szType not loaded: %ld", r);
+	    }
+	    
+	    ZeroMemory(returnBuffer, sizeof(*returnBuffer));
+	    sizeOfReturnBuffer = sizeof(returnBuffer);
+	    if (RegQueryValueExA(hkDrive, "Path", NULL, &returnType, returnBuffer, &sizeOfReturnBuffer) == ERROR_SUCCESS) {
+		strncpy(pDrive->szPath, returnBuffer, sizeOfReturnBuffer);
+	    } else {
+		WINE_WARN("pDrive->szPath not loaded: %ld\n", GetLastError());
+	    }
+	    
+	    ZeroMemory(returnBuffer, sizeof(*returnBuffer));
+	    sizeOfReturnBuffer = sizeof(returnBuffer);
+	    if (RegQueryValueExA(hkDrive, "FileSystem", NULL, &returnType, returnBuffer, &sizeOfReturnBuffer) == ERROR_SUCCESS) {
+		strncpy(pDrive->szFS, returnBuffer, sizeOfReturnBuffer);
+	    } else {
+		WINE_WARN("pDrive->szFS not loaded: %ld\n", GetLastError());
+	    }
+
+	    ZeroMemory(returnBuffer, sizeof(*returnBuffer));
+	    sizeOfReturnBuffer = sizeof(returnBuffer);
+	    if (RegQueryValueExA(hkDrive, "Device", NULL, &returnType, returnBuffer, &sizeOfReturnBuffer) == ERROR_SUCCESS) {
+		strncpy(pDrive->szDevice, returnBuffer, sizeOfReturnBuffer);
+	    } else {
+		WINE_WARN("pDrive->szDevice not found: %ld\n", GetLastError());
+	    }
+
+	    if (DPA_InsertPtr(pCfg->pDrives, pCfg->driveCount, pDrive) == -1)
+		WINE_ERR("Failed to insert pDrive into DPA\n");
+	    else
+		pCfg->driveCount++;
+	    
+	}
+    }
+    WINE_TRACE("loaded %d drives\n", pCfg->driveCount);
+
     RegCloseKey( configKey );
     return 0;
 }
diff -ur --exclude-from=diff-exclusions ../head/programs/winecfg/winecfg.h programs/winecfg/winecfg.h
--- ../head/programs/winecfg/winecfg.h	2003-08-28 16:20:41.000000000 +0100
+++ programs/winecfg/winecfg.h	2003-08-28 15:31:48.000000000 +0100
@@ -44,8 +44,11 @@
 
     char   szGraphDriver[MAX_NAME_LENGTH];
 
-    HDPA     pDlls;
-    HDPA     pApps;
+    HDPA   pDlls;
+    HDPA   pApps;
+    HDPA   pDrives;
+
+    int    driveCount;
 
     X11DRV_DESC sX11Drv;
 } WINECFG_DESC;
@@ -61,10 +64,20 @@
 int setConfigValue (HKEY hCurrent, char *subkey, char *valueName, const char *value);
 int getConfigValue (HKEY hCurrent, char *subkey, char *valueName, char *retVal, int length, char *defaultResult);
 
+
+/* X11DRV */
+
 void initX11DrvDlg (HWND hDlg);
 void saveX11DrvDlgSettings (HWND hDlg);
 INT_PTR CALLBACK X11DrvDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
+/* Drive management */
+void initDriveDlg (HWND hDlg);
+void saveDriveSettings (HWND hDlg);
+
+INT_PTR CALLBACK DriveDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
+INT_PTR CALLBACK DriveEditDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
+
 #define WINEHQ_KEY_ROOT "Software\\Wine\\Wine\\Config"
 
 #endif
--- /dev/null	2003-01-30 10:24:37.000000000 +0000
+++ programs/winecfg/drive.c	2003-08-28 16:10:15.000000000 +0100
@@ -0,0 +1,423 @@
+/*
+ * Drive management UI code
+ *
+ * Copyright 2003 Mark Westcott
+ * Copyright 2003 Mike Hearn
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include <winreg.h>
+#include <wine/debug.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <shellapi.h>
+#include <shlguid.h>
+#include <shlwapi.h>
+#include <shlobj.h>
+#include <string.h>
+#include <assert.h>
+
+#include "winecfg.h"
+#include "resource.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
+
+/*******************************************************************/
+/*  the configuration properties affected by this code             */
+/*******************************************************************/
+static BOOL initialized = FALSE;
+
+void initDriveDlg (HWND hDlg)
+{
+    int i;
+    for (i = 0; i < config.driveCount; i++) {
+	int itemIndex;
+	DRIVE_DESC *drive = DPA_GetPtr(config.pDrives, i);
+	char *title = malloc(MAX_NAME_LENGTH);
+	
+	WINE_TRACE("Iterating, item %d of %d, drive=%p\n", i, config.driveCount, drive);
+	assert(drive);
+
+	WINE_TRACE("Adding %s to the listbox\n", drive->szName);
+
+	/* the first SendMessage call adds the string and returns the index, the second associates that index with it */
+	snprintf(title, MAX_NAME_LENGTH, "Drive %s (%s)", drive->szName, drive->szLabel);
+	itemIndex = SendMessageA(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_ADDSTRING ,(WPARAM) -1, (LPARAM) title);
+	SendMessageA(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_SETITEMDATA, itemIndex, (LPARAM) itemIndex);
+	free(title);
+    }
+    
+    initialized = TRUE;
+}
+
+
+void saveDriveDlgSettings (HWND hDlg)
+{
+
+}
+
+
+
+/******************************************************************************/
+/*  The Drive Editing Dialog                                                  */
+/******************************************************************************/
+#define DRIVE_MASK_BIT(B) 1<<(toupper(B)-'A')
+
+typedef struct{
+  char *sCode;
+  char *sDesc;
+} code_desc_pair;
+
+static code_desc_pair type_pairs[] = {
+  {"hd", "Local hard disk"},
+  {"network", "Network share" },
+  {"floppy", "Floppy disk"},
+  {"cdrom", "CD-ROM"}
+};
+#define DRIVE_TYPE_DEFAULT 1
+
+static code_desc_pair fs_pairs[] = {
+  {"win95", "Long file names"},
+  {"msdos", "MS-DOS 8 character file names"},
+  {"unix", "UNIX file names"}
+};
+#define DRIVE_FS_DEFAULT 0
+
+long drive_available_mask(DRIVE_DESC *pCurrentDrive)
+{
+  int i;
+  DRIVE_DESC *pDrive;
+  long result = 0;
+  
+  for( i=0; i < config.pDrives->nItemCount; ++i) {
+    pDrive = (DRIVE_DESC *) DPA_GetPtr( config.pDrives, i );
+    if(pDrive) {
+      result |= DRIVE_MASK_BIT(pDrive->szName[0]);
+    }
+  }
+  
+  result = ~result; /*flag unused, not used*/
+  result |= DRIVE_MASK_BIT(pCurrentDrive->szName[0]);
+  WINE_TRACE( "finished drive letter loop with %ld\n", result );
+
+  return result;
+}
+
+void fill_drive_droplist(long mask, DRIVE_DESC *pCurrentDrive, HWND hDlg)
+{
+  int i;
+  int selection;
+  int count;
+  int next_letter;
+  char sName[4] = "A:";
+
+  for( i=0, count=0, selection=-1, next_letter=-1; i <= 'Z'-'A'; ++i ) {
+    if( mask & DRIVE_MASK_BIT('A'+i) ) {
+      sName[0] = 'A' + i;
+      SendDlgItemMessage( hDlg, IDC_COMBO_LETTER, CB_ADDSTRING, 0, (LPARAM) sName );
+      
+      if( toupper(pCurrentDrive->szName[0]) == 'A' + i ) {
+	selection = count;
+      }
+      
+      if( i >= 2 && next_letter == -1){ /*default drive is first one of C-Z */
+	next_letter = count;
+      }
+      
+      count++;
+    }
+  }
+  
+  if( selection == -1 ) {
+    selection = next_letter;
+  }
+  
+  SendDlgItemMessage( hDlg, IDC_COMBO_LETTER, CB_SETCURSEL, selection, 0 );
+}
+
+
+void enable_cdrom_box(HWND hDlg, int bEnable)
+{
+  EnableWindow( GetDlgItem( hDlg, IDC_BOX_CDROM ), bEnable );
+  EnableWindow( GetDlgItem( hDlg, IDC_RADIO_AUTODETECT ), bEnable );
+  EnableWindow( GetDlgItem( hDlg, IDC_RADIO_ASSIGN ), bEnable );
+  EnableWindow( GetDlgItem( hDlg, IDC_EDIT_DEVICE ), bEnable );
+  EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_BROWSE_DEVICE ), bEnable );
+  EnableWindow( GetDlgItem( hDlg, IDC_EDIT_SERIAL ), bEnable );
+  EnableWindow( GetDlgItem( hDlg, IDC_EDIT_LABEL ), bEnable );
+  EnableWindow( GetDlgItem( hDlg, IDC_STATIC_SERIAL ), bEnable );
+  EnableWindow( GetDlgItem( hDlg, IDC_STATIC_LABEL ), bEnable );
+}
+
+
+INT_PTR CALLBACK DriveEditDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+  int i;
+  int selection;
+
+  switch (uMsg)  {
+    case WM_INITDIALOG: {
+	DRIVE_DESC* pDrive = (DRIVE_DESC *)lParam;
+	
+	SetProp(hDlg, "PDRIVE", pDrive);
+
+	/* Fill in the list boxes */
+	/* Drive letters */
+	fill_drive_droplist( drive_available_mask( pDrive ), pDrive, hDlg );
+
+	/* drive type*/
+	for( i=0, selection=-1; i < sizeof(type_pairs)/sizeof(code_desc_pair); i++) {
+	  SendDlgItemMessage(hDlg, IDC_COMBO_TYPE, CB_ADDSTRING, 0,
+			     (LPARAM) type_pairs[i].sDesc);
+	  if(strcasecmp(type_pairs[i].sCode, pDrive->szType) == 0){
+	    selection = i;
+	  }
+	}
+	
+	if( selection == -1 ) {
+	  selection = DRIVE_TYPE_DEFAULT;
+	}
+	SendDlgItemMessage(hDlg, IDC_COMBO_TYPE, CB_SETCURSEL, selection, 0);
+
+	/* FileSystem name handling */
+	for( i=0, selection=-1; i < sizeof(fs_pairs)/sizeof(code_desc_pair); i++) {
+	  SendDlgItemMessage(hDlg, IDC_COMBO_NAMES, CB_ADDSTRING, 0,
+			     (LPARAM) fs_pairs[i].sDesc);
+	  if(strcasecmp(fs_pairs[i].sCode, pDrive->szFS) == 0){
+	    selection = i;
+	  }
+	}
+	
+	if( selection == -1 ) {
+	  selection = DRIVE_FS_DEFAULT;
+	}
+	SendDlgItemMessage(hDlg, IDC_COMBO_NAMES, CB_SETCURSEL, selection, 0);
+
+       
+	/* removeable media properties */
+	SendDlgItemMessage(hDlg, IDC_EDIT_SERIAL, WM_SETTEXT, 0,(LPARAM)pDrive->szSerial);
+	SendDlgItemMessage(hDlg, IDC_EDIT_LABEL, WM_SETTEXT, 0,(LPARAM)pDrive->szLabel);
+	SendDlgItemMessage(hDlg, IDC_EDIT_DEVICE, WM_SETTEXT, 0,(LPARAM)pDrive->szDevice);
+	if( strcmp("cdrom", pDrive->szType) == 0 ||
+	    strcmp("floppy", pDrive->szType) == 0) {
+	  if( (strlen( pDrive->szDevice ) == 0) &&
+	      ((strlen( pDrive->szSerial ) > 0) || (strlen( pDrive->szLabel ) > 0)) ) {
+	    selection = IDC_RADIO_ASSIGN;
+	  }
+	  else {
+	    selection = IDC_RADIO_AUTODETECT;
+	  }
+	
+	  enable_cdrom_box( hDlg, 1 );
+	}
+	else {
+	  enable_cdrom_box( hDlg, 0 );
+	}
+	
+	CheckRadioButton( hDlg, IDC_RADIO_AUTODETECT, IDC_RADIO_ASSIGN, selection );
+	SendDlgItemMessage(hDlg, IDC_EDIT_PATH, WM_SETTEXT, 0,(LPARAM)pDrive->szPath);
+	break;
+      }
+
+    case WM_COMMAND:
+      switch (LOWORD(wParam))
+	{
+	case IDC_COMBO_TYPE:
+	  switch( HIWORD(wParam)) 
+	    {
+	    case CBN_SELCHANGE:
+	      selection = SendDlgItemMessage( hDlg, IDC_COMBO_TYPE, CB_GETCURSEL, 0, 0);
+	      if( selection == 2 || selection == 3 ) { /* cdrom or floppy */
+		enable_cdrom_box( hDlg, 1 );
+	      }
+	      else {
+		enable_cdrom_box( hDlg, 0 );
+	      }
+	      break;
+	    }
+	  break;
+
+	case ID_BUTTON_OK:
+	  {
+	    DRIVE_DESC *pDrive = GetProp(hDlg, "PDRIVE");
+	    char buffer[MAX_NAME_LENGTH];
+	    
+	    /* fixme: do it in a cleanup */
+	    RemoveProp(hDlg, "PDRIVE");
+
+	    ZeroMemory(&buffer[0], MAX_NAME_LENGTH);
+	    GetWindowText(GetDlgItem(hDlg, IDC_EDIT_PATH), buffer, MAX_NAME_LENGTH);
+	    if (strlen(buffer) > 0) {
+	      strncpy(pDrive->szName, buffer, MAX_NAME_LENGTH);
+	      
+	      /* only fill in the other values if we have a path */
+	      selection = SendDlgItemMessage( hDlg, IDC_COMBO_TYPE, CB_GETCURSEL, 0, 0);
+	      strncpy(pDrive->szType, type_pairs[selection].sCode, MAX_NAME_LENGTH);
+	      
+	      selection = SendDlgItemMessage( hDlg, IDC_COMBO_NAMES, CB_GETCURSEL, 0, 0);
+	      strncpy(pDrive->szFS, fs_pairs[selection].sCode, MAX_NAME_LENGTH);
+	      
+	      selection = SendDlgItemMessage( hDlg, IDC_COMBO_LETTER, CB_GETCURSEL, 0, 0);
+	      SendDlgItemMessage( hDlg, IDC_COMBO_LETTER, CB_GETLBTEXT, selection, (WPARAM)buffer);
+	      strncpy(pDrive->szName, buffer, MAX_NAME_LENGTH);
+	      pDrive->szName[1] = 0; /* truncate to only the letter */
+
+	      if( strncmp( pDrive->szType, "cdrom", MAX_NAME_LENGTH ) == 0) {
+		if( IsDlgButtonChecked( hDlg, IDC_RADIO_ASSIGN ) == BST_CHECKED ) {
+		  GetWindowText(GetDlgItem(hDlg, IDC_EDIT_LABEL), buffer, 
+				MAX_NAME_LENGTH);
+		  strncpy(pDrive->szLabel, buffer, MAX_NAME_LENGTH);
+		  GetWindowText(GetDlgItem(hDlg, IDC_EDIT_SERIAL), buffer, 
+				MAX_NAME_LENGTH);
+		  strncpy(pDrive->szSerial, buffer, MAX_NAME_LENGTH);
+		  pDrive->szDevice[0] = 0;
+		}
+		else {
+		  GetWindowText(GetDlgItem(hDlg, IDC_EDIT_DEVICE), buffer, 
+				MAX_NAME_LENGTH);
+		  strncpy(pDrive->szDevice, buffer, MAX_NAME_LENGTH);
+		  pDrive->szLabel[0] = 0;
+		  pDrive->szSerial[0] = 0;
+		}
+	      }
+	      else {
+		pDrive->szLabel[0] = 0;
+		pDrive->szSerial[0] = 0;
+		pDrive->szDevice[0] = 0;
+	      }
+	      EndDialog(hDlg, wParam);
+	    }
+	    else { /* missing a path */
+	      MessageBox( hDlg, "Please enter a valid path", "ERROR", MB_OK );
+	    }
+	    return TRUE;
+	    
+	  }
+
+	  
+	  /* Fall through. */
+	  
+	case ID_BUTTON_CANCEL:
+	  /* fixme: do it in a cleanup */
+	  RemoveProp(hDlg, "PDRIVE");
+	  EndDialog(hDlg, wParam);
+	  return TRUE;
+	}
+    }
+  return FALSE;
+}
+
+
+/***************************************************************************/
+/*  The Actual Property Sheet Page                                         */
+/***************************************************************************/
+
+INT_PTR CALLBACK
+DriveDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+  int selection = -1;
+
+  switch (uMsg)
+    {
+    case WM_INITDIALOG:
+      break;
+      
+    case WM_COMMAND:
+      switch (LOWORD(wParam))
+	{
+	case IDC_LIST_DRIVES:
+	  switch( HIWORD( wParam ) )
+	    {
+	    case LBN_DBLCLK:
+	      selection = -1;
+	      break;
+	    }
+	case IDC_BUTTON_ADD:
+	  if (HIWORD(wParam)==BN_CLICKED) {
+	    DRIVE_DESC* pDrive = malloc(sizeof(DRIVE_DESC));
+	    
+	    /* adding a new drive */
+	    ZeroMemory(pDrive, sizeof(*pDrive));
+	    DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_DRIVE_EDIT2),
+			   NULL, (DLGPROC) DriveEditDlgProc, (LPARAM) pDrive );
+	    /* if pDrive is blank, free the memory, otherwise, add the pointer to HDPA and add to listbox */
+	    if (!(pDrive->szName[0]))
+	      free(pDrive);
+	    else {
+	      char DRIVE_NAME[7];
+	      int pos;
+	      
+	      ZeroMemory(DRIVE_NAME,sizeof(DRIVE_NAME));
+	      strcat(DRIVE_NAME, "Drive \0");
+	      strncat(DRIVE_NAME, pDrive->szName, 1);
+	      pos = SendMessageA(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_ADDSTRING ,(WPARAM) -1, (LPARAM) DRIVE_NAME);
+	      SendMessageA(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_SETITEMDATA, pos, (LPARAM) pos);
+	      DPA_InsertPtr(config.pDrives, pos, pDrive);
+	    }
+	  }
+	  break;
+	case IDC_BUTTON_EDIT:
+	  if (HIWORD(wParam)==BN_CLICKED) {
+	    int nItem = SendMessage(GetDlgItem(hDlg, IDC_LIST_DRIVES),  LB_GETCURSEL, 0, 0);
+	    int i = SendMessage(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_GETITEMDATA, nItem, 0);
+	    DRIVE_DESC* pDrive = DPA_GetPtr(config.pDrives, i);
+	    
+	    if (pDrive != NULL) {
+	      DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_DRIVE_EDIT2),
+			     NULL, (DLGPROC) DriveEditDlgProc, (LPARAM) pDrive );
+	      SetProp(hDlg, "PDRIVE", pDrive);
+	    }
+	  }
+	  break;
+	case IDC_BUTTON_REMOVE:
+	  if (HIWORD(wParam)==BN_CLICKED) {
+	    int nItem = SendMessage(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_GETCURSEL, 0, 0);
+	    SendMessage(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_DELETESTRING, (WPARAM) nItem, (LPARAM) 0 );
+	    free(DPA_GetPtr(config.pDrives, nItem));
+	  }
+
+	default:
+	  /** SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0); */
+	  break;
+	}
+      break;
+
+    case WM_NOTIFY:
+      switch(((LPNMHDR)lParam)->code)
+	{
+	case PSN_KILLACTIVE: {
+	  /* validate user info.  Lets just assume everything is okay for now */
+	  SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
+	}
+	case PSN_APPLY: {
+	  /* should probably check everything is really all rosy :) */
+	  saveDriveDlgSettings (hDlg);
+	  SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
+	}
+	case PSN_SETACTIVE: {
+	  if (!initialized)
+	    initDriveDlg (hDlg);
+
+	}
+	}
+
+    default:
+      break;
+    }
+  return FALSE;
+}
+





More information about the wine-patches mailing list