Merge pull request #3965 from akallabeth/drive_fixes_unicode

Drive fixes unicode
This commit is contained in:
David Fort 2017-05-22 11:08:10 +02:00 committed by GitHub
commit 25a3b23013
2 changed files with 17 additions and 17 deletions

View File

@ -59,24 +59,24 @@ static void drive_file_fix_path(WCHAR* path)
for (i = 0; i < length; i++)
{
if (path[i] == '\\')
path[i] = '/';
if (path[i] == L'\\')
path[i] = L'/';
}
#ifdef WIN32
if ((length == 3) && (path[1] == ':') && (path[2] == '/'))
if ((length == 3) && (path[1] == L':') && (path[2] == L'/'))
return;
#else
if ((length == 1) && (path[0] == '/'))
if ((length == 1) && (path[0] == L'/'))
return;
#endif
if ((length > 0) && (path[length - 1] == '/'))
path[length - 1] = '\0';
if ((length > 0) && (path[length - 1] == L'/'))
path[length - 1] = L'\0';
}
static WCHAR* drive_file_combine_fullpath(const WCHAR* base_path, const WCHAR* path,
@ -126,8 +126,8 @@ static BOOL drive_file_remove_dir(const WCHAR* path)
}
CopyMemory(path_slash, path, base_path_length);
path_slash[base_path_length / 2] = '/';
path_slash[base_path_length / 2 + 1] = '*';
path_slash[base_path_length / 2] = L'/';
path_slash[base_path_length / 2 + 1] = L'*';
DEBUG_WSTR("Search in %s", path_slash);
dir = FindFirstFileW(path_slash, &findFileData);
path_slash[base_path_length / 2 + 1] = 0;
@ -142,8 +142,8 @@ static BOOL drive_file_remove_dir(const WCHAR* path)
{
len = _wcslen(findFileData.cFileName);
if ((len == 1 && findFileData.cFileName[0] == '.') || (len == 2 &&
findFileData.cFileName[0] == '.' && findFileData.cFileName[1] == '.'))
if ((len == 1 && findFileData.cFileName[0] == L'.') || (len == 2 &&
findFileData.cFileName[0] == L'.' && findFileData.cFileName[1] == L'.'))
{
continue;
}
@ -181,11 +181,11 @@ static BOOL drive_file_remove_dir(const WCHAR* path)
return ret;
}
static void drive_file_set_fullpath(DRIVE_FILE* file, WCHAR* fullpath)
static void drive_file_set_fullpath(DRIVE_FILE* file, const WCHAR* fullpath)
{
free(file->fullpath);
file->fullpath = fullpath;
file->filename = _wcsrchr(file->fullpath, 0x5c);
file->filename = _wcsrchr(file->fullpath, L'/');
if (file->filename == NULL)
file->filename = file->fullpath;
@ -852,7 +852,3 @@ out_fail:
Stream_Write_UINT8(output, 0); /* Padding */
return FALSE;
}
#ifdef _WIN32
#pragma warning(pop)
#endif

View File

@ -790,6 +790,7 @@ UINT drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints,
if (name[0] && path[0])
{
size_t pathLength = strnlen(path, MAX_PATH);
drive = (DRIVE_DEVICE*) calloc(1, sizeof(DRIVE_DEVICE));
if (!drive)
@ -816,7 +817,10 @@ UINT drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints,
for (i = 0; i <= length; i++)
Stream_Write_UINT8(drive->device.data, name[i] < 0 ? '_' : name[i]);
if (ConvertToUnicode(sys_code_page, 0, path, -1, &drive->path, 0) <= 0)
if ((pathLength > 0) && (path[pathLength-1] == '/'))
pathLength --;
if (ConvertToUnicode(sys_code_page, 0, path, pathLength, &drive->path, 0) <= 0)
{
WLog_ERR(TAG, "ConvertToUnicode failed!");
error = CHANNEL_RC_NO_MEMORY;