winecfg: Store the drive label as Unicode.

This commit is contained in:
Alexandre Julliard 2008-10-17 14:11:56 +02:00
parent 6483f2f201
commit f150ddc3ed
4 changed files with 66 additions and 95 deletions

View File

@ -87,19 +87,19 @@ long drive_available_mask(char letter)
return result; return result;
} }
BOOL add_drive(const char letter, const char *targetpath, const char *label, DWORD serial, unsigned int type) BOOL add_drive(char letter, const char *targetpath, const WCHAR *label, DWORD serial, DWORD type)
{ {
int driveIndex = letter_to_index(letter); int driveIndex = letter_to_index(letter);
if(drives[driveIndex].in_use) if(drives[driveIndex].in_use)
return FALSE; return FALSE;
WINE_TRACE("letter == '%c', unixpath == '%s', label == '%s', serial == %08x, type == %d\n", WINE_TRACE("letter == '%c', unixpath == '%s', label == %s, serial == %08x, type == %d\n",
letter, targetpath, label, serial, type); letter, targetpath, wine_dbgstr_w(label), serial, type);
drives[driveIndex].letter = toupper(letter); drives[driveIndex].letter = toupper(letter);
drives[driveIndex].unixpath = strdupA(targetpath); drives[driveIndex].unixpath = strdupA(targetpath);
drives[driveIndex].label = strdupA(label); drives[driveIndex].label = strdupW(label);
drives[driveIndex].serial = serial; drives[driveIndex].serial = serial;
drives[driveIndex].type = type; drives[driveIndex].type = type;
drives[driveIndex].in_use = TRUE; drives[driveIndex].in_use = TRUE;
@ -177,21 +177,23 @@ static DWORD get_drive_type( char letter )
} }
static void set_drive_label( char letter, const char *label ) static void set_drive_label( char letter, const WCHAR *label )
{ {
char device[] = "a:\\"; /* SetVolumeLabel() requires a trailing slash */ static const WCHAR emptyW[1];
WCHAR device[] = {'a',':','\\',0}; /* SetVolumeLabel() requires a trailing slash */
device[0] = letter; device[0] = letter;
if(!SetVolumeLabel(device, label)) if (!label) label = emptyW;
if(!SetVolumeLabelW(device, label))
{ {
WINE_WARN("unable to set volume label for devicename of '%s', label of '%s'\n", WINE_WARN("unable to set volume label for devicename of %s, label of %s\n",
device, label); wine_dbgstr_w(device), wine_dbgstr_w(label));
PRINTERROR(); PRINTERROR();
} }
else else
{ {
WINE_TRACE(" set volume label for devicename of '%s', label of '%s'\n", WINE_TRACE(" set volume label for devicename of %s, label of %s\n",
device, label); wine_dbgstr_w(device), wine_dbgstr_w(label));
} }
} }
@ -262,7 +264,7 @@ BOOL moveDrive(struct drive *pSrc, struct drive *pDst)
/* Load currently defined drives into the drives array */ /* Load currently defined drives into the drives array */
void load_drives(void) void load_drives(void)
{ {
char *devices, *dev; WCHAR *devices, *dev;
int len; int len;
int drivecount = 0, i; int drivecount = 0, i;
int retval; int retval;
@ -273,8 +275,8 @@ void load_drives(void)
WINE_TRACE("\n"); WINE_TRACE("\n");
/* setup the drives array */ /* setup the drives array */
dev = devices = HeapAlloc(GetProcessHeap(), 0, arraysize); dev = devices = HeapAlloc(GetProcessHeap(), 0, arraysize * sizeof(WCHAR));
len = GetLogicalDriveStrings(arraysize, devices); len = GetLogicalDriveStringsW(arraysize, devices);
/* make all devices unused */ /* make all devices unused */
for (i = 0; i < 26; i++) for (i = 0; i < 26; i++)
@ -293,50 +295,32 @@ void load_drives(void)
/* work backwards through the result of GetLogicalDriveStrings */ /* work backwards through the result of GetLogicalDriveStrings */
while (len) while (len)
{ {
char volname[512]; /* volume name */ WCHAR volname[512]; /* volume name */
DWORD serial; DWORD serial;
char rootpath[256];
char simplepath[3]; char simplepath[3];
int pathlen;
char targetpath[256]; char targetpath[256];
char *c; char *c;
*devices = toupper(*devices); WINE_TRACE("devices == %s\n", wine_dbgstr_w(devices));
WINE_TRACE("devices == '%s'\n", devices);
volname[0] = 0; volname[0] = 0;
retval = GetVolumeInformation(devices, retval = GetVolumeInformationW(devices, volname, sizeof(volname)/sizeof(WCHAR),
volname, &serial, NULL, NULL, NULL, 0);
sizeof(volname),
&serial,
NULL,
NULL,
NULL,
0);
if(!retval) if(!retval)
{ {
WINE_ERR("GetVolumeInformation() for '%s' failed, setting serial to 0\n", devices); WINE_ERR("GetVolumeInformation() for %s failed, setting serial to 0\n",
wine_dbgstr_w(devices));
PRINTERROR(); PRINTERROR();
serial = 0; serial = 0;
} }
WINE_TRACE("serial: '0x%X'\n", serial); WINE_TRACE("serial: '0x%X'\n", serial);
/* build rootpath for GetDriveType() */
lstrcpynA(rootpath, devices, sizeof(rootpath));
pathlen = strlen(rootpath);
/* ensure that we have a backslash on the root path */
if ((rootpath[pathlen - 1] != '\\') && (pathlen < sizeof(rootpath)))
{
rootpath[pathlen] = '\\';
rootpath[pathlen + 1] = 0;
}
/* QueryDosDevice() requires no trailing backslash */ /* QueryDosDevice() requires no trailing backslash */
lstrcpynA(simplepath, devices, 3); simplepath[0] = devices[0];
simplepath[1] = ':';
simplepath[2] = 0;
QueryDosDevice(simplepath, targetpath, sizeof(targetpath)); QueryDosDevice(simplepath, targetpath, sizeof(targetpath));
/* targetpath may have forward slashes rather than backslashes, so correct */ /* targetpath may have forward slashes rather than backslashes, so correct */
@ -345,8 +329,8 @@ void load_drives(void)
add_drive(*devices, targetpath, volname, serial, get_drive_type(devices[0]) ); add_drive(*devices, targetpath, volname, serial, get_drive_type(devices[0]) );
len -= strlen(devices); len -= lstrlenW(devices);
devices += strlen(devices); devices += lstrlenW(devices);
/* skip over any nulls */ /* skip over any nulls */
while ((*devices == 0) && (len)) while ((*devices == 0) && (len))
@ -381,7 +365,7 @@ void load_drives(void)
buff[cnt] = '\0'; buff[cnt] = '\0';
WINE_TRACE("found broken symlink %s -> %s\n", path, buff); WINE_TRACE("found broken symlink %s -> %s\n", path, buff);
add_drive('A' + i, buff, "", 0, DRIVE_UNKNOWN); add_drive('A' + i, buff, NULL, 0, DRIVE_UNKNOWN);
drivecount++; drivecount++;
} }
@ -400,11 +384,8 @@ void apply_drive_changes(void)
CHAR devicename[4]; CHAR devicename[4];
CHAR targetpath[256]; CHAR targetpath[256];
BOOL foundDrive; BOOL foundDrive;
CHAR volumeNameBuffer[512]; WCHAR volumeNameBuffer[512];
DWORD serialNumber; DWORD serialNumber;
DWORD maxComponentLength;
DWORD fileSystemFlags;
CHAR fileSystemName[128];
int retval; int retval;
BOOL defineDevice; BOOL defineDevice;
@ -433,17 +414,12 @@ void apply_drive_changes(void)
/* if we found a drive and have a drive then compare things */ /* if we found a drive and have a drive then compare things */
if(foundDrive && drives[i].in_use) if(foundDrive && drives[i].in_use)
{ {
WCHAR deviceW[4] = {'a',':','\\',0};
WINE_TRACE("drives[i].letter: '%c'\n", drives[i].letter); WINE_TRACE("drives[i].letter: '%c'\n", drives[i].letter);
snprintf(devicename, sizeof(devicename), "%c:\\", 'A' + i); deviceW[0] = 'A' + i;
retval = GetVolumeInformation(devicename, retval = GetVolumeInformationW(deviceW, volumeNameBuffer, sizeof(volumeNameBuffer)/sizeof(WCHAR),
volumeNameBuffer, &serialNumber, NULL, NULL, NULL, 0 );
sizeof(volumeNameBuffer),
&serialNumber,
&maxComponentLength,
&fileSystemFlags,
fileSystemName,
sizeof(fileSystemName));
if(!retval) if(!retval)
{ {
WINE_TRACE(" GetVolumeInformation() for '%s' failed\n", devicename); WINE_TRACE(" GetVolumeInformation() for '%s' failed\n", devicename);
@ -508,7 +484,7 @@ void apply_drive_changes(void)
} }
} }
if (drives[i].label && strcmp(drives[i].label, volumeNameBuffer)) if (!drives[i].label || lstrcmpW(drives[i].label, volumeNameBuffer))
set_drive_label( drives[i].letter, drives[i].label ); set_drive_label( drives[i].letter, drives[i].label );
if (drives[i].serial != serialNumber) if (drives[i].serial != serialNumber)

View File

@ -22,21 +22,22 @@
#include "config.h" #include "config.h"
#include "wine/port.h" #include "wine/port.h"
#include <wine/debug.h>
#include <wine/library.h>
#include "winecfg.h"
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_MNTENT_H #ifdef HAVE_MNTENT_H
#include <mntent.h> #include <mntent.h>
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <windef.h>
#include <winbase.h> #include <winbase.h>
#include <wine/debug.h>
#include <wine/library.h>
#include "winecfg.h"
#include "resource.h"
WINE_DEFAULT_DEBUG_CHANNEL(winecfg); WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
@ -233,7 +234,7 @@ static void ensure_root_is_mapped(void)
{ {
if (!drives[letter - 'A'].in_use) if (!drives[letter - 'A'].in_use)
{ {
add_drive(letter, "/", "System", 0, DRIVE_FIXED); add_drive(letter, "/", NULL, 0, DRIVE_FIXED);
WINE_TRACE("allocated drive %c as the root drive\n", letter); WINE_TRACE("allocated drive %c as the root drive\n", letter);
break; break;
} }
@ -262,7 +263,7 @@ static void ensure_home_is_mapped(void)
{ {
if (!drives[letter - 'A'].in_use) if (!drives[letter - 'A'].in_use)
{ {
add_drive(letter, home, "Home", 0, DRIVE_FIXED); add_drive(letter, home, NULL, 0, DRIVE_FIXED);
WINE_TRACE("allocated drive %c as the user's home directory\n", letter); WINE_TRACE("allocated drive %c as the user's home directory\n", letter);
break; break;
} }
@ -287,7 +288,10 @@ static void ensure_drive_c_is_mapped(void)
if (stat(drive_c_dir, &buf) == 0) if (stat(drive_c_dir, &buf) == 0)
{ {
add_drive('C', "../drive_c", "Virtual Windows Drive", 0, DRIVE_FIXED); WCHAR label[64];
LoadStringW (GetModuleHandle (NULL), IDS_SYSTEM_DRIVE_LABEL, label,
sizeof(label)/sizeof(label[0]));
add_drive('C', "../drive_c", label, 0, DRIVE_FIXED);
} }
else else
{ {
@ -324,7 +328,6 @@ int autodetect_drives(void)
while ((ent = getmntent(fstab))) while ((ent = getmntent(fstab)))
{ {
char letter; char letter;
char label[256];
int type; int type;
WINE_TRACE("ent->mnt_dir=%s\n", ent->mnt_dir); WINE_TRACE("ent->mnt_dir=%s\n", ent->mnt_dir);
@ -351,12 +354,8 @@ int autodetect_drives(void)
return FALSE; return FALSE;
} }
strcpy(label, "Drive X"); WINE_TRACE("adding drive %c for %s, type %s\n", letter, ent->mnt_dir, ent->mnt_type);
label[6] = letter; add_drive(letter, ent->mnt_dir, NULL, 0, type);
WINE_TRACE("adding drive %c for %s, type %s with label %s\n", letter, ent->mnt_dir, ent->mnt_type,label);
add_drive(letter, ent->mnt_dir, label, 0, type);
/* working_mask is a map of the drive letters still available. */ /* working_mask is a map of the drive letters still available. */
working_mask &= ~DRIVE_MASK_BIT(letter); working_mask &= ~DRIVE_MASK_BIT(letter);

View File

@ -33,6 +33,7 @@
#include <shlwapi.h> #include <shlwapi.h>
#include <shlobj.h> #include <shlobj.h>
#include <wine/unicode.h>
#include <wine/debug.h> #include <wine/debug.h>
#include "winecfg.h" #include "winecfg.h"
@ -311,12 +312,12 @@ static void on_add_click(HWND dialog)
if (new == 'C') if (new == 'C')
{ {
char label[64]; WCHAR label[64];
LoadStringA (GetModuleHandle (NULL), IDS_SYSTEM_DRIVE_LABEL, label, LoadStringW (GetModuleHandle (NULL), IDS_SYSTEM_DRIVE_LABEL, label,
sizeof(label)/sizeof(label[0])); sizeof(label)/sizeof(label[0]));
add_drive(new, "../drive_c", label, 0, DRIVE_FIXED); add_drive(new, "../drive_c", label, 0, DRIVE_FIXED);
} }
else add_drive(new, "/", "", 0, DRIVE_UNKNOWN); else add_drive(new, "/", NULL, 0, DRIVE_UNKNOWN);
fill_drives_list(dialog); fill_drives_list(dialog);
@ -375,9 +376,9 @@ static void on_remove_click(HWND dialog)
static void update_controls(HWND dialog) static void update_controls(HWND dialog)
{ {
static const WCHAR emptyW[1];
char *path; char *path;
unsigned int type; unsigned int type;
char *label;
char serial[16]; char serial[16];
const char *device; const char *device;
int i, selection = -1; int i, selection = -1;
@ -433,8 +434,7 @@ static void update_controls(HWND dialog)
EnableWindow( GetDlgItem( dialog, IDC_COMBO_TYPE ), (current_drive->letter != 'C') ); EnableWindow( GetDlgItem( dialog, IDC_COMBO_TYPE ), (current_drive->letter != 'C') );
/* removeable media properties */ /* removeable media properties */
label = current_drive->label; set_textW(dialog, IDC_EDIT_LABEL, current_drive->label ? current_drive->label : emptyW);
set_text(dialog, IDC_EDIT_LABEL, label);
/* set serial edit text */ /* set serial edit text */
sprintf( serial, "%X", current_drive->serial ); sprintf( serial, "%X", current_drive->serial );
@ -482,13 +482,11 @@ static void on_edit_changed(HWND dialog, WORD id)
{ {
case IDC_EDIT_LABEL: case IDC_EDIT_LABEL:
{ {
char *label; WCHAR *label = get_textW(dialog, id);
label = get_text(dialog, id);
HeapFree(GetProcessHeap(), 0, current_drive->label); HeapFree(GetProcessHeap(), 0, current_drive->label);
current_drive->label = label ? label : strdupA(""); current_drive->label = label;
WINE_TRACE("set label to %s\n", current_drive->label); WINE_TRACE("set label to %s\n", wine_dbgstr_w(current_drive->label));
/* enable the apply button */ /* enable the apply button */
SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0); SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
@ -752,14 +750,12 @@ DriveDlgProc (HWND dialog, UINT msg, WPARAM wParam, LPARAM lParam)
case IDC_RADIO_ASSIGN: case IDC_RADIO_ASSIGN:
{ {
char *str; WCHAR *str = get_textW(dialog, IDC_EDIT_LABEL);
str = get_text(dialog, IDC_EDIT_LABEL);
HeapFree(GetProcessHeap(), 0, current_drive->label); HeapFree(GetProcessHeap(), 0, current_drive->label);
current_drive->label = str ? str : strdupA(""); current_drive->label = str;
str = get_text(dialog, IDC_EDIT_SERIAL); str = get_textW(dialog, IDC_EDIT_SERIAL);
current_drive->serial = strtoul( str, NULL, 16 ); current_drive->serial = strtoulW( str, NULL, 16 );
/* TODO: we don't have a device at this point */ /* TODO: we don't have a device at this point */

View File

@ -97,7 +97,7 @@ struct drive
{ {
char letter; char letter;
char *unixpath; char *unixpath;
char *label; WCHAR *label;
DWORD serial; DWORD serial;
DWORD type; /* one of the DRIVE_ constants from winbase.h */ DWORD type; /* one of the DRIVE_ constants from winbase.h */
@ -107,7 +107,7 @@ struct drive
#define DRIVE_MASK_BIT(B) (1 << (toupper(B) - 'A')) #define DRIVE_MASK_BIT(B) (1 << (toupper(B) - 'A'))
long drive_available_mask(char letter); long drive_available_mask(char letter);
BOOL add_drive(const char letter, const char *targetpath, const char *label, DWORD serial, unsigned int type); BOOL add_drive(char letter, const char *targetpath, const WCHAR *label, DWORD serial, DWORD type);
void delete_drive(struct drive *pDrive); void delete_drive(struct drive *pDrive);
void apply_drive_changes(void); void apply_drive_changes(void);
BOOL browse_for_unix_folder(HWND dialog, WCHAR *pszPath); BOOL browse_for_unix_folder(HWND dialog, WCHAR *pszPath);