Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 5edeb70

Browse files
[[ Bug 15814 ]] Merge bugfix-15814 up to develop-7.0
Now, MCWindowsDesktop::ResolvePath also returns an absolute path, as MCLinuxDesktop and MCMacDestop do. One change only from the fix in 6.7: in 7.0, the paths given to MCSystemInterface functions are always native, so when needed, ResolvePath will add \, not / as it does in 6.7
1 parent 0504b9b commit 5edeb70

1 file changed

Lines changed: 61 additions & 7 deletions

File tree

engine/src/dskw32.cpp

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3650,13 +3650,67 @@ struct MCWindowsDesktop: public MCSystemInterface, public MCWindowsSystemService
36503650
if (MCStringGetLength(p_path) == 0)
36513651
return MCS_getcurdir_native(r_resolved_path);
36523652

3653-
MCAutoStringRef t_native;
3654-
MCAutoStringRef t_native_resolved;
3655-
3656-
MCS_pathtonative(p_path, &t_native);
3657-
MCU_fix_path(*t_native, &t_native_resolved);
3658-
MCS_pathfromnative(*t_native_resolved, r_resolved_path);
3659-
return true;
3653+
MCAutoStringRef t_canonised_path;
3654+
bool t_success;
3655+
t_success = true;
3656+
3657+
// Taken from LiveCode 6.7's w32spec.cpp MCS_get_canonical_path
3658+
// The following rules are used to process paths on Windows:
3659+
// - an absolute UNIX path is mapped to an absolute windows path using the drive of the CWD:
3660+
// /foo/bar -> CWD-DRIVE:/foo/bar
3661+
// - an absolute windows path is left as is:
3662+
// //foo/bar -> //foo/bar
3663+
// C:/foo/bar -> C:/foo/bar
3664+
// - a relative path is prefixed by the CWD:
3665+
// foo/bar -> CWD/foo/bar
3666+
// Note: / and \ are treated the same, but not changed.
3667+
// Note: When adding a path separator \ is used in LiveCode 7.0
3668+
// since we are suppose to have a native path as input for MCSystem functions
3669+
3670+
// We store the first chars in this static to make the if
3671+
// statements more readable
3672+
char_t t_first_chars[2];
3673+
t_first_chars[0] = MCStringGetNativeCharAtIndex(p_path, 0);
3674+
t_first_chars[1] = MCStringGetNativeCharAtIndex(p_path, 1);
3675+
3676+
if ((t_first_chars[0] == '/' && t_first_chars[1] != '/')
3677+
|| (t_first_chars[0] == '\\' && t_first_chars[1] != '\\'))
3678+
{
3679+
// path in root of current drive
3680+
MCAutoStringRef t_curdir;
3681+
if (t_success)
3682+
t_success = MCS_getcurdir_native(&t_curdir);
3683+
3684+
if (t_success)
3685+
t_success = MCStringFormat(&t_canonised_path,
3686+
"%c:%@",
3687+
MCStringGetNativeCharAtIndex(*t_curdir, 0),
3688+
p_path);
3689+
}
3690+
else if ((is_legal_drive(t_first_chars[0]) && t_first_chars[1] == ':')
3691+
|| (t_first_chars[0] == '/' && t_first_chars[1] == '/')
3692+
|| (t_first_chars[0] == '\\' && t_first_chars[1] == '\\'))
3693+
{
3694+
// absolute path
3695+
t_canonised_path = p_path;
3696+
}
3697+
else
3698+
{
3699+
// relative to current folder
3700+
MCAutoStringRef t_curdir;
3701+
t_success = MCS_getcurdir_native(&t_curdir);
3702+
3703+
if (t_success)
3704+
t_success = MCStringFormat(&t_canonised_path,
3705+
"%@\\%@",
3706+
*t_curdir,
3707+
p_path);
3708+
}
3709+
3710+
if (t_success)
3711+
r_resolved_path = MCValueRetain(*t_canonised_path);
3712+
3713+
return t_success;
36603714
}
36613715

36623716
virtual bool LongFilePath(MCStringRef p_path, MCStringRef& r_long_path)

0 commit comments

Comments
 (0)