mirror of
https://github.com/ValveSoftware/Proton.git
synced 2025-03-12 05:20:21 +03:00
vrclient: Improve relative path handling in vrclient_dos_to_unix_path().
CW-Bug-Id: #24798
This commit is contained in:
parent
7b0ae2e1d1
commit
0417c5dd8d
@ -55,8 +55,10 @@ static char *get_unix_file_name( const WCHAR *path )
|
||||
|
||||
char *vrclient_dos_to_unix_path( const char *src )
|
||||
{
|
||||
WCHAR srcW[PATH_MAX] = {'\\', '?', '?', '\\', 0}, *tmp;
|
||||
char buffer[4096], *dst = buffer;
|
||||
uint32_t len;
|
||||
char *unix_path;
|
||||
uint32_t len, r;
|
||||
|
||||
TRACE( "src %s\n", debugstr_a(src) );
|
||||
|
||||
@ -65,50 +67,39 @@ char *vrclient_dos_to_unix_path( const char *src )
|
||||
*dst = 0;
|
||||
if (!*src) goto done;
|
||||
|
||||
if (IS_ABSOLUTE( src ))
|
||||
len = 4;
|
||||
if (!IS_ABSOLUTE( src ))
|
||||
{
|
||||
/* absolute path, use wine conversion */
|
||||
WCHAR srcW[PATH_MAX] = {'\\', '?', '?', '\\', 0}, *tmp;
|
||||
char *unix_path;
|
||||
uint32_t r;
|
||||
CURDIR *curdir = &NtCurrentTeb()->Peb->ProcessParameters->CurrentDirectory;
|
||||
|
||||
r = ntdll_umbstowcs( src, strlen( src ) + 1, srcW + 4, PATH_MAX - 4 );
|
||||
if (r == 0) unix_path = NULL;
|
||||
else
|
||||
{
|
||||
for (tmp = srcW; *tmp; ++tmp) if (*tmp == '/') *tmp = '\\';
|
||||
unix_path = get_unix_file_name( srcW );
|
||||
}
|
||||
|
||||
if (!unix_path)
|
||||
{
|
||||
WARN( "Unable to convert DOS filename to unix: %s\n", src );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!realpath( unix_path, dst ))
|
||||
{
|
||||
ERR( "Could not get real path for %s.\n", unix_path );
|
||||
lstrcpynA( dst, unix_path, PATH_MAX );
|
||||
}
|
||||
|
||||
free( unix_path );
|
||||
memcpy( srcW + len, curdir->DosPath.Buffer, curdir->DosPath.Length );
|
||||
len += curdir->DosPath.Length / 2;
|
||||
TRACE("relative, srcW %s.\n", debugstr_w(srcW));
|
||||
}
|
||||
|
||||
r = ntdll_umbstowcs( src, strlen( src ) + 1, srcW + len, PATH_MAX - len );
|
||||
|
||||
if (r == 0) unix_path = NULL;
|
||||
else
|
||||
{
|
||||
/* relative path, just fix up backslashes */
|
||||
const char *s;
|
||||
char *d;
|
||||
|
||||
for (s = src, d = dst; *src; ++s, ++d)
|
||||
{
|
||||
if (*s == '\\') *d = '/';
|
||||
else *d = *s;
|
||||
}
|
||||
|
||||
*d = 0;
|
||||
for (tmp = srcW; *tmp; ++tmp) if (*tmp == '/') *tmp = '\\';
|
||||
unix_path = get_unix_file_name( srcW );
|
||||
}
|
||||
|
||||
if (!unix_path)
|
||||
{
|
||||
WARN( "Unable to convert DOS filename to unix: %s\n", src );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!realpath( unix_path, dst ))
|
||||
{
|
||||
ERR( "Could not get real path for %s.\n", unix_path );
|
||||
lstrcpynA( dst, unix_path, PATH_MAX );
|
||||
}
|
||||
|
||||
free( unix_path );
|
||||
|
||||
done:
|
||||
len = strlen( buffer ) + 1;
|
||||
if (!(dst = (char *)malloc( len ))) return NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user