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;
}
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);
if(drives[driveIndex].in_use)
return FALSE;
WINE_TRACE("letter == '%c', unixpath == '%s', label == '%s', serial == %08x, type == %d\n",
letter, targetpath, label, serial, type);
WINE_TRACE("letter == '%c', unixpath == '%s', label == %s, serial == %08x, type == %d\n",
letter, targetpath, wine_dbgstr_w(label), serial, type);
drives[driveIndex].letter = toupper(letter);
drives[driveIndex].unixpath = strdupA(targetpath);
drives[driveIndex].label = strdupA(label);
drives[driveIndex].label = strdupW(label);
drives[driveIndex].serial = serial;
drives[driveIndex].type = type;
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;
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",
device, label);
WINE_WARN("unable to set volume label for devicename of %s, label of %s\n",
wine_dbgstr_w(device), wine_dbgstr_w(label));
PRINTERROR();
}
else
{
WINE_TRACE(" set volume label for devicename of '%s', label of '%s'\n",
device, label);
WINE_TRACE(" set volume label for devicename of %s, label of %s\n",
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 */
void load_drives(void)
{
char *devices, *dev;
WCHAR *devices, *dev;
int len;
int drivecount = 0, i;
int retval;
@ -273,8 +275,8 @@ void load_drives(void)
WINE_TRACE("\n");
/* setup the drives array */
dev = devices = HeapAlloc(GetProcessHeap(), 0, arraysize);
len = GetLogicalDriveStrings(arraysize, devices);
dev = devices = HeapAlloc(GetProcessHeap(), 0, arraysize * sizeof(WCHAR));
len = GetLogicalDriveStringsW(arraysize, devices);
/* make all devices unused */
for (i = 0; i < 26; i++)
@ -293,50 +295,32 @@ void load_drives(void)
/* work backwards through the result of GetLogicalDriveStrings */
while (len)
{
char volname[512]; /* volume name */
WCHAR volname[512]; /* volume name */
DWORD serial;
char rootpath[256];
char simplepath[3];
int pathlen;
char targetpath[256];
char *c;
*devices = toupper(*devices);
WINE_TRACE("devices == '%s'\n", devices);
WINE_TRACE("devices == %s\n", wine_dbgstr_w(devices));
volname[0] = 0;
retval = GetVolumeInformation(devices,
volname,
sizeof(volname),
&serial,
NULL,
NULL,
NULL,
0);
retval = GetVolumeInformationW(devices, volname, sizeof(volname)/sizeof(WCHAR),
&serial, NULL, NULL, NULL, 0);
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();
serial = 0;
}
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 */
lstrcpynA(simplepath, devices, 3);
simplepath[0] = devices[0];
simplepath[1] = ':';
simplepath[2] = 0;
QueryDosDevice(simplepath, targetpath, sizeof(targetpath));
/* 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]) );
len -= strlen(devices);
devices += strlen(devices);
len -= lstrlenW(devices);
devices += lstrlenW(devices);
/* skip over any nulls */
while ((*devices == 0) && (len))
@ -381,7 +365,7 @@ void load_drives(void)
buff[cnt] = '\0';
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++;
}
@ -400,11 +384,8 @@ void apply_drive_changes(void)
CHAR devicename[4];
CHAR targetpath[256];
BOOL foundDrive;
CHAR volumeNameBuffer[512];
WCHAR volumeNameBuffer[512];
DWORD serialNumber;
DWORD maxComponentLength;
DWORD fileSystemFlags;
CHAR fileSystemName[128];
int retval;
BOOL defineDevice;
@ -433,17 +414,12 @@ void apply_drive_changes(void)
/* if we found a drive and have a drive then compare things */
if(foundDrive && drives[i].in_use)
{
WCHAR deviceW[4] = {'a',':','\\',0};
WINE_TRACE("drives[i].letter: '%c'\n", drives[i].letter);
snprintf(devicename, sizeof(devicename), "%c:\\", 'A' + i);
retval = GetVolumeInformation(devicename,
volumeNameBuffer,
sizeof(volumeNameBuffer),
&serialNumber,
&maxComponentLength,
&fileSystemFlags,
fileSystemName,
sizeof(fileSystemName));
deviceW[0] = 'A' + i;
retval = GetVolumeInformationW(deviceW, volumeNameBuffer, sizeof(volumeNameBuffer)/sizeof(WCHAR),
&serialNumber, NULL, NULL, NULL, 0 );
if(!retval)
{
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 );
if (drives[i].serial != serialNumber)

View file

@ -22,21 +22,22 @@
#include "config.h"
#include "wine/port.h"
#include <wine/debug.h>
#include <wine/library.h>
#include "winecfg.h"
#include <stdio.h>
#ifdef HAVE_MNTENT_H
#include <mntent.h>
#endif
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include <windef.h>
#include <winbase.h>
#include <wine/debug.h>
#include <wine/library.h>
#include "winecfg.h"
#include "resource.h"
WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
@ -233,7 +234,7 @@ static void ensure_root_is_mapped(void)
{
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);
break;
}
@ -262,7 +263,7 @@ static void ensure_home_is_mapped(void)
{
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);
break;
}
@ -287,7 +288,10 @@ static void ensure_drive_c_is_mapped(void)
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
{
@ -324,7 +328,6 @@ int autodetect_drives(void)
while ((ent = getmntent(fstab)))
{
char letter;
char label[256];
int type;
WINE_TRACE("ent->mnt_dir=%s\n", ent->mnt_dir);
@ -350,14 +353,10 @@ int autodetect_drives(void)
fclose(fstab);
return FALSE;
}
strcpy(label, "Drive X");
label[6] = letter;
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);
WINE_TRACE("adding drive %c for %s, type %s\n", letter, ent->mnt_dir, ent->mnt_type);
add_drive(letter, ent->mnt_dir, NULL, 0, type);
/* working_mask is a map of the drive letters still available. */
working_mask &= ~DRIVE_MASK_BIT(letter);
}

View file

@ -33,6 +33,7 @@
#include <shlwapi.h>
#include <shlobj.h>
#include <wine/unicode.h>
#include <wine/debug.h>
#include "winecfg.h"
@ -311,12 +312,12 @@ static void on_add_click(HWND dialog)
if (new == 'C')
{
char label[64];
LoadStringA (GetModuleHandle (NULL), IDS_SYSTEM_DRIVE_LABEL, label,
sizeof(label)/sizeof(label[0]));
WCHAR label[64];
LoadStringW (GetModuleHandle (NULL), IDS_SYSTEM_DRIVE_LABEL, label,
sizeof(label)/sizeof(label[0]));
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);
@ -375,9 +376,9 @@ static void on_remove_click(HWND dialog)
static void update_controls(HWND dialog)
{
static const WCHAR emptyW[1];
char *path;
unsigned int type;
char *label;
char serial[16];
const char *device;
int i, selection = -1;
@ -433,8 +434,7 @@ static void update_controls(HWND dialog)
EnableWindow( GetDlgItem( dialog, IDC_COMBO_TYPE ), (current_drive->letter != 'C') );
/* removeable media properties */
label = current_drive->label;
set_text(dialog, IDC_EDIT_LABEL, label);
set_textW(dialog, IDC_EDIT_LABEL, current_drive->label ? current_drive->label : emptyW);
/* set serial edit text */
sprintf( serial, "%X", current_drive->serial );
@ -482,13 +482,11 @@ static void on_edit_changed(HWND dialog, WORD id)
{
case IDC_EDIT_LABEL:
{
char *label;
label = get_text(dialog, id);
WCHAR *label = get_textW(dialog, id);
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 */
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:
{
char *str;
str = get_text(dialog, IDC_EDIT_LABEL);
WCHAR *str = get_textW(dialog, IDC_EDIT_LABEL);
HeapFree(GetProcessHeap(), 0, current_drive->label);
current_drive->label = str ? str : strdupA("");
current_drive->label = str;
str = get_text(dialog, IDC_EDIT_SERIAL);
current_drive->serial = strtoul( str, NULL, 16 );
str = get_textW(dialog, IDC_EDIT_SERIAL);
current_drive->serial = strtoulW( str, NULL, 16 );
/* TODO: we don't have a device at this point */

View file

@ -97,7 +97,7 @@ struct drive
{
char letter;
char *unixpath;
char *label;
WCHAR *label;
DWORD serial;
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'))
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 apply_drive_changes(void);
BOOL browse_for_unix_folder(HWND dialog, WCHAR *pszPath);