2003-08-30 02:49:00 +02:00
|
|
|
/*
|
2004-11-23 14:50:23 +01:00
|
|
|
* Drive management code
|
2003-08-30 02:49:00 +02:00
|
|
|
*
|
|
|
|
* Copyright 2003 Mark Westcott
|
2004-11-23 14:50:23 +01:00
|
|
|
* Copyright 2003-2004 Mike Hearn
|
2004-05-04 04:56:46 +02:00
|
|
|
* Copyright 2004 Chris Morgan
|
2003-08-30 02:49:00 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdarg.h>
|
2003-08-30 02:49:00 +02:00
|
|
|
#include <stdio.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <winreg.h>
|
|
|
|
#include <wine/debug.h>
|
2003-08-30 02:49:00 +02:00
|
|
|
#include <shellapi.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <objbase.h>
|
2003-08-30 02:49:00 +02:00
|
|
|
#include <shlguid.h>
|
|
|
|
#include <shlwapi.h>
|
|
|
|
#include <shlobj.h>
|
|
|
|
|
|
|
|
#include "winecfg.h"
|
|
|
|
#include "resource.h"
|
|
|
|
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2003-08-30 02:49:00 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
struct drive drives[26]; /* one for each drive letter */
|
|
|
|
|
|
|
|
static inline int letter_to_index(char letter)
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
2004-11-23 14:50:23 +01:00
|
|
|
return (toupper(letter) - 'A');
|
|
|
|
}
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* This function produces a mask for each drive letter that isn't
|
|
|
|
* currently used. Each bit of the long result represents a letter,
|
|
|
|
* with A being the least significant bit, and Z being the most
|
|
|
|
* significant.
|
|
|
|
*
|
|
|
|
* To calculate this, we loop over each letter, and see if we can get
|
|
|
|
* a drive entry for it. If so, we set the appropriate bit. At the
|
|
|
|
* end, we flip each bit, to give the desired result.
|
|
|
|
*
|
|
|
|
* The letter parameter is always marked as being available. This is
|
|
|
|
* so the edit dialog can display the currently used drive letter
|
|
|
|
* alongside the available ones.
|
|
|
|
*/
|
|
|
|
long drive_available_mask(char letter)
|
|
|
|
{
|
|
|
|
long result = 0;
|
|
|
|
int i;
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
WINE_TRACE("\n");
|
2003-08-30 02:49:00 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
|
|
|
|
for(i = 0; i < 26; i++)
|
|
|
|
{
|
|
|
|
if (!drives[i].in_use) continue;
|
|
|
|
result |= (1 << (toupper(drives[i].letter) - 'A'));
|
|
|
|
}
|
|
|
|
|
|
|
|
result = ~result;
|
|
|
|
if (letter) result |= DRIVE_MASK_BIT(letter);
|
|
|
|
|
|
|
|
WINE_TRACE("finished drive letter loop with %lx\n", result);
|
|
|
|
return result;
|
2004-05-04 04:56:46 +02:00
|
|
|
}
|
2003-08-30 02:49:00 +02:00
|
|
|
|
2005-06-02 17:11:32 +02:00
|
|
|
BOOL add_drive(const char letter, const char *targetpath, const char *label, const char *serial, unsigned int type)
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
2004-11-23 14:50:23 +01:00
|
|
|
int driveIndex = letter_to_index(letter);
|
2004-05-13 07:17:41 +02:00
|
|
|
|
|
|
|
if(drives[driveIndex].in_use)
|
2004-05-04 04:56:46 +02:00
|
|
|
return FALSE;
|
2003-08-30 02:49:00 +02:00
|
|
|
|
2004-05-04 04:56:46 +02:00
|
|
|
WINE_TRACE("letter == '%c', unixpath == '%s', label == '%s', serial == '%s', type == %d\n",
|
|
|
|
letter, targetpath, label, serial, type);
|
2003-08-30 02:49:00 +02:00
|
|
|
|
2004-05-13 07:17:41 +02:00
|
|
|
drives[driveIndex].letter = toupper(letter);
|
2004-11-23 14:50:23 +01:00
|
|
|
drives[driveIndex].unixpath = strdupA(targetpath);
|
|
|
|
drives[driveIndex].label = strdupA(label);
|
|
|
|
drives[driveIndex].serial = strdupA(serial);
|
2004-05-13 07:17:41 +02:00
|
|
|
drives[driveIndex].type = type;
|
|
|
|
drives[driveIndex].in_use = TRUE;
|
2003-08-30 02:49:00 +02:00
|
|
|
|
2004-05-04 04:56:46 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2003-08-30 02:49:00 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* deallocates the contents of the drive. does not free the drive itself */
|
|
|
|
void delete_drive(struct drive *d)
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
2004-11-23 14:50:23 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, d->unixpath);
|
2005-02-14 21:54:21 +01:00
|
|
|
d->unixpath = NULL;
|
2004-11-23 14:50:23 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, d->label);
|
2005-02-14 21:54:21 +01:00
|
|
|
d->label = NULL;
|
2004-11-23 14:50:23 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, d->serial);
|
2005-02-14 21:54:21 +01:00
|
|
|
d->serial = NULL;
|
2003-08-30 02:49:00 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
d->in_use = FALSE;
|
2003-09-10 05:41:44 +02:00
|
|
|
}
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
#if 0
|
2003-09-18 00:40:38 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* currently unused, but if users have this burning desire to be able to rename drives,
|
|
|
|
we can put it back in.
|
|
|
|
*/
|
2003-09-18 00:40:38 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
BOOL copyDrive(struct drive *pSrc, struct drive *pDst)
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
|
|
|
if(pDst->in_use)
|
|
|
|
{
|
|
|
|
WINE_TRACE("pDst already in use\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!pSrc->unixpath) WINE_TRACE("!pSrc->unixpath\n");
|
|
|
|
if(!pSrc->label) WINE_TRACE("!pSrc->label\n");
|
|
|
|
if(!pSrc->serial) WINE_TRACE("!pSrc->serial\n");
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
pDst->unixpath = strdupA(pSrc->unixpath);
|
|
|
|
pDst->label = strdupA(pSrc->label);
|
|
|
|
pDst->serial = strdupA(pSrc->serial);
|
2004-05-04 04:56:46 +02:00
|
|
|
pDst->type = pSrc->type;
|
|
|
|
pDst->in_use = TRUE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
BOOL moveDrive(struct drive *pSrc, struct drive *pDst)
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
|
|
|
WINE_TRACE("pSrc->letter == %c, pDst->letter == %c\n", pSrc->letter, pDst->letter);
|
|
|
|
|
|
|
|
if(!copyDrive(pSrc, pDst))
|
|
|
|
{
|
|
|
|
WINE_TRACE("copyDrive failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
delete_drive(pSrc);
|
2004-05-04 04:56:46 +02:00
|
|
|
return TRUE;
|
2003-09-18 00:40:38 +02:00
|
|
|
}
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
#endif
|
2003-09-08 21:29:28 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* Load currently defined drives into the drives array */
|
|
|
|
void load_drives()
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
2004-11-23 14:50:23 +01:00
|
|
|
char *devices, *dev;
|
|
|
|
int len;
|
|
|
|
int drivecount = 0, i;
|
|
|
|
int retval;
|
|
|
|
static const int arraysize = 512;
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
WINE_TRACE("\n");
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* FIXME: broken symlinks in $WINEPREFIX/dosdevices will not be
|
|
|
|
returned by this API, so we need to handle that */
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* setup the drives array */
|
|
|
|
dev = devices = HeapAlloc(GetProcessHeap(), 0, arraysize);
|
|
|
|
len = GetLogicalDriveStrings(arraysize, devices);
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* make all devices unused */
|
|
|
|
for (i = 0; i < 26; i++)
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
2004-11-23 14:50:23 +01:00
|
|
|
drives[i].letter = 'A' + i;
|
|
|
|
drives[i].in_use = FALSE;
|
2005-01-09 19:01:00 +01:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, drives[i].unixpath);
|
|
|
|
drives[i].unixpath = NULL;
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, drives[i].label);
|
|
|
|
drives[i].label = NULL;
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, drives[i].serial);
|
|
|
|
drives[i].serial = NULL;
|
2004-05-04 04:56:46 +02:00
|
|
|
}
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* work backwards through the result of GetLogicalDriveStrings */
|
|
|
|
while (len)
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
2004-11-23 14:50:23 +01:00
|
|
|
char volname[512]; /* volume name */
|
|
|
|
DWORD serial;
|
|
|
|
char serialstr[256];
|
|
|
|
char rootpath[256];
|
|
|
|
char simplepath[3];
|
|
|
|
int pathlen;
|
|
|
|
char targetpath[256];
|
|
|
|
char *c;
|
|
|
|
|
|
|
|
*devices = toupper(*devices);
|
|
|
|
|
|
|
|
WINE_TRACE("devices == '%s'\n", devices);
|
|
|
|
|
|
|
|
volname[0] = 0;
|
|
|
|
|
|
|
|
retval = GetVolumeInformation(devices,
|
|
|
|
volname,
|
|
|
|
sizeof(volname),
|
|
|
|
&serial,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0);
|
|
|
|
if(!retval)
|
|
|
|
{
|
|
|
|
WINE_ERR("GetVolumeInformation() for '%s' failed, setting serial to 0\n", devices);
|
|
|
|
PRINTERROR();
|
|
|
|
serial = 0;
|
|
|
|
}
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
WINE_TRACE("serial: '0x%lX'\n", serial);
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* build rootpath for GetDriveType() */
|
2005-03-28 16:17:51 +02:00
|
|
|
lstrcpynA(rootpath, devices, sizeof(rootpath));
|
2004-11-23 14:50:23 +01:00
|
|
|
pathlen = strlen(rootpath);
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* ensure that we have a backslash on the root path */
|
|
|
|
if ((rootpath[pathlen - 1] != '\\') && (pathlen < sizeof(rootpath)))
|
|
|
|
{
|
|
|
|
rootpath[pathlen] = '\\';
|
|
|
|
rootpath[pathlen + 1] = 0;
|
|
|
|
}
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2005-03-28 16:17:51 +02:00
|
|
|
/* QueryDosDevice() requires no trailing backslash */
|
|
|
|
lstrcpynA(simplepath, devices, 3);
|
2004-11-23 14:50:23 +01:00
|
|
|
QueryDosDevice(simplepath, targetpath, sizeof(targetpath));
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* targetpath may have forward slashes rather than backslashes, so correct */
|
|
|
|
c = targetpath;
|
|
|
|
do if (*c == '\\') *c = '/'; while (*c++);
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
snprintf(serialstr, sizeof(serialstr), "%lX", serial);
|
|
|
|
WINE_TRACE("serialstr: '%s'\n", serialstr);
|
|
|
|
add_drive(*devices, targetpath, volname, serialstr, GetDriveType(rootpath));
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
len -= strlen(devices);
|
|
|
|
devices += strlen(devices);
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* skip over any nulls */
|
|
|
|
while ((*devices == 0) && (len))
|
|
|
|
{
|
|
|
|
len--;
|
|
|
|
devices++;
|
|
|
|
}
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
drivecount++;
|
2004-05-04 04:56:46 +02:00
|
|
|
}
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
WINE_TRACE("found %d drives\n", drivecount);
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, dev);
|
2004-05-04 04:56:46 +02:00
|
|
|
}
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* some of this code appears to be broken by bugs in Wine: the label
|
|
|
|
* setting code has no effect, for instance */
|
2005-06-16 17:52:44 +02:00
|
|
|
void apply_drive_changes(void)
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
CHAR devicename[4];
|
|
|
|
CHAR targetpath[256];
|
|
|
|
BOOL foundDrive;
|
|
|
|
CHAR volumeNameBuffer[512];
|
|
|
|
DWORD serialNumber;
|
|
|
|
DWORD maxComponentLength;
|
|
|
|
DWORD fileSystemFlags;
|
|
|
|
CHAR fileSystemName[128];
|
|
|
|
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;
|
2004-11-23 14:50:23 +01:00
|
|
|
snprintf(devicename, sizeof(devicename), "%c:", 'A' + i);
|
2004-05-04 04:56:46 +02:00
|
|
|
|
|
|
|
/* get a drive */
|
|
|
|
if(QueryDosDevice(devicename, targetpath, sizeof(targetpath)))
|
|
|
|
{
|
2005-01-10 15:25:58 +01:00
|
|
|
char *cursor;
|
|
|
|
|
|
|
|
/* correct the slashes in the path to be UNIX style */
|
|
|
|
while ((cursor = strchr(targetpath, '\\'))) *cursor = '/';
|
|
|
|
|
2004-05-04 04:56:46 +02:00
|
|
|
foundDrive = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we found a drive and have a drive then compare things */
|
|
|
|
if(foundDrive && drives[i].in_use)
|
|
|
|
{
|
|
|
|
char newSerialNumberText[256];
|
|
|
|
|
|
|
|
volumeNameBuffer[0] = 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));
|
|
|
|
if(!retval)
|
|
|
|
{
|
|
|
|
WINE_TRACE(" GetVolumeInformation() for '%s' failed\n", devicename);
|
|
|
|
WINE_TRACE(" Skipping this drive\n");
|
|
|
|
PRINTERROR();
|
|
|
|
continue; /* skip this drive */
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(newSerialNumberText, sizeof(newSerialNumberText), "%lX", serialNumber);
|
|
|
|
|
|
|
|
WINE_TRACE(" current path: '%s', new path: '%s'\n",
|
|
|
|
targetpath, drives[i].unixpath);
|
|
|
|
WINE_TRACE(" current label: '%s', new label: '%s'\n",
|
|
|
|
volumeNameBuffer, drives[i].label);
|
|
|
|
WINE_TRACE(" current serial: '%s', new serial: '%s'\n",
|
|
|
|
newSerialNumberText, drives[i].serial);
|
|
|
|
|
|
|
|
/* compare to what we have */
|
|
|
|
/* do we have the same targetpath? */
|
|
|
|
if(strcmp(drives[i].unixpath, targetpath) ||
|
|
|
|
strcmp(drives[i].label, volumeNameBuffer) ||
|
|
|
|
strcmp(drives[i].serial, newSerialNumberText))
|
|
|
|
{
|
|
|
|
defineDevice = TRUE;
|
|
|
|
WINE_TRACE(" making changes to drive '%s'\n", devicename);
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
|
|
|
else
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
|
|
|
WINE_TRACE(" no changes to drive '%s'\n", devicename);
|
|
|
|
}
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
|
|
|
else if(foundDrive && !drives[i].in_use)
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
2005-05-04 11:47:56 +02:00
|
|
|
HKEY hKey;
|
|
|
|
char driveValue[256];
|
|
|
|
|
2004-05-04 04:56:46 +02:00
|
|
|
/* remove this drive */
|
|
|
|
if(!DefineDosDevice(DDD_REMOVE_DEFINITION, devicename, drives[i].unixpath))
|
|
|
|
{
|
|
|
|
WINE_ERR("unable to remove devicename of '%s', targetpath of '%s'\n",
|
|
|
|
devicename, drives[i].unixpath);
|
|
|
|
PRINTERROR();
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
|
|
|
else
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
|
|
|
WINE_TRACE("removed devicename of '%s', targetpath of '%s'\n",
|
|
|
|
devicename, drives[i].unixpath);
|
|
|
|
}
|
2005-05-04 11:47:56 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
|
|
|
else if(drives[i].in_use) /* foundDrive must be false from the above check */
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
|
|
|
defineDevice = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* adding and modifying are the same steps */
|
|
|
|
if(defineDevice)
|
|
|
|
{
|
|
|
|
char filename[256];
|
|
|
|
HANDLE hFile;
|
|
|
|
|
|
|
|
HKEY hKey;
|
2005-06-02 17:11:32 +02:00
|
|
|
const char *typeText;
|
2004-05-04 04:56:46 +02:00
|
|
|
char driveValue[256];
|
|
|
|
|
|
|
|
/* define this drive */
|
|
|
|
/* DefineDosDevice() requires that NO trailing slash be present */
|
2004-11-23 14:50:23 +01:00
|
|
|
snprintf(devicename, sizeof(devicename), "%c:", 'A' + i);
|
2004-05-04 04:56:46 +02:00
|
|
|
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();
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
|
|
|
else
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
|
|
|
WINE_TRACE(" added devicename of '%s', targetpath of '%s'\n",
|
|
|
|
devicename, drives[i].unixpath);
|
2004-11-23 14:50:23 +01:00
|
|
|
|
2004-05-04 04:56:46 +02:00
|
|
|
/* SetVolumeLabel() requires a trailing slash */
|
|
|
|
snprintf(devicename, sizeof(devicename), "%c:\\", 'A' + i);
|
|
|
|
if(!SetVolumeLabel(devicename, drives[i].label))
|
|
|
|
{
|
2005-01-10 15:25:58 +01:00
|
|
|
WINE_WARN("unable to set volume label for devicename of '%s', label of '%s'\n",
|
2004-05-04 04:56:46 +02:00
|
|
|
devicename, drives[i].label);
|
|
|
|
PRINTERROR();
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
|
|
|
else
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
|
|
|
WINE_TRACE(" set volume label for devicename of '%s', label of '%s'\n",
|
|
|
|
devicename, drives[i].label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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";
|
2004-11-23 14:50:23 +01:00
|
|
|
|
2004-05-04 04:56:46 +02:00
|
|
|
|
|
|
|
snprintf(driveValue, sizeof(driveValue), "%c:", toupper(drives[i].letter));
|
|
|
|
|
|
|
|
retval = RegOpenKey(HKEY_LOCAL_MACHINE,
|
|
|
|
"Software\\Wine\\Drives",
|
|
|
|
&hKey);
|
|
|
|
|
|
|
|
if(retval != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
WINE_TRACE(" Unable to open '%s'\n", "Software\\Wine\\Drives");
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
|
|
|
else
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
|
|
|
retval = RegSetValueEx(
|
|
|
|
hKey,
|
|
|
|
driveValue,
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
typeText,
|
|
|
|
strlen(typeText) + 1);
|
|
|
|
if(retval != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
WINE_TRACE(" Unable to set value of '%s' to '%s'\n",
|
|
|
|
driveValue, typeText);
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
|
|
|
else
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
|
|
|
WINE_TRACE(" Finished setting value of '%s' to '%s'\n",
|
|
|
|
driveValue, typeText);
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the drive serial number via a .windows-serial file in */
|
|
|
|
/* the targetpath directory */
|
|
|
|
snprintf(filename, sizeof(filename), "%c:\\.windows-serial", drives[i].letter);
|
|
|
|
WINE_TRACE(" Putting serial number of '%ld' into file '%s'\n",
|
|
|
|
serialNumber, filename);
|
|
|
|
hFile = CreateFile(filename,
|
|
|
|
GENERIC_WRITE,
|
|
|
|
FILE_SHARE_READ,
|
|
|
|
NULL,
|
|
|
|
CREATE_ALWAYS,
|
|
|
|
FILE_ATTRIBUTE_NORMAL,
|
|
|
|
NULL);
|
2004-11-23 14:50:23 +01:00
|
|
|
if (hFile != INVALID_HANDLE_VALUE)
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
2004-12-22 19:38:31 +01:00
|
|
|
DWORD w;
|
2004-05-04 04:56:46 +02:00
|
|
|
WINE_TRACE(" writing serial number of '%s'\n", drives[i].serial);
|
|
|
|
WriteFile(hFile,
|
|
|
|
drives[i].serial,
|
|
|
|
strlen(drives[i].serial),
|
2004-12-22 19:38:31 +01:00
|
|
|
&w,
|
2004-11-23 14:50:23 +01:00
|
|
|
NULL);
|
2004-05-04 04:56:46 +02:00
|
|
|
WriteFile(hFile,
|
|
|
|
"\n",
|
|
|
|
strlen("\n"),
|
2004-12-22 19:38:31 +01:00
|
|
|
&w,
|
2004-11-23 14:50:23 +01:00
|
|
|
NULL);
|
2004-05-04 04:56:46 +02:00
|
|
|
CloseHandle(hFile);
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
|
|
|
else
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
|
|
|
WINE_TRACE(" CreateFile() error with file '%s'\n", filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-09-10 05:41:44 +02:00
|
|
|
}
|