fix Calculate_relative_path()
This commit is contained in:
parent
d131b48274
commit
02f9d68f8e
@ -2381,11 +2381,11 @@ byte Button_Load_or_Save(T_Selector_settings *settings, byte load, T_IO_Context
|
||||
// We must enter the directory
|
||||
|
||||
if (directory_to_change_to[0] == '.' &&
|
||||
(directory_to_change_to[1] == '/' || directory_to_change_to[1] == '\\' ||
|
||||
(directory_to_change_to[1] == '\0' || directory_to_change_to[1] == '/' || directory_to_change_to[1] == '\\' ||
|
||||
(directory_to_change_to[1] == '.' &&
|
||||
(directory_to_change_to[2] == '/' || directory_to_change_to[2] == '\\')))) // Relative path
|
||||
(directory_to_change_to[2] == '\0' || directory_to_change_to[2] == '/' || directory_to_change_to[2] == '\\')))) // Relative path
|
||||
{
|
||||
GFX2_Log(GFX2_DEBUG, "Relative bookmark %s. Change to %s first\n",
|
||||
GFX2_Log(GFX2_DEBUG, "Relative bookmark \"%s\", Change to \"%s\" first.\n",
|
||||
directory_to_change_to, Data_directory);
|
||||
Change_directory(Data_directory);
|
||||
}
|
||||
|
||||
22
src/io.c
22
src/io.c
@ -960,13 +960,27 @@ const char * Calculate_relative_path(const char * ref_path, const char * path)
|
||||
last_separator = i;
|
||||
#endif
|
||||
}
|
||||
if (real_ref_path[i] == '\0' && path[i] == PATH_SEPARATOR[0])
|
||||
// at this point, all chars from index 0 to i-1 are identical in
|
||||
// real_ref_path and path.
|
||||
// real_ref_path[i] and path[i] are either different, or both '\0'
|
||||
if (real_ref_path[i] == PATH_SEPARATOR[0] && real_ref_path[i + 1] == '\0' && path[i] == '\0')
|
||||
return "."; // path are identical (real_ref_path has additional trailing separator)
|
||||
if (real_ref_path[i] == '\0')
|
||||
{
|
||||
snprintf(rel_path, MAX_PATH_CHARACTERS, ".%s", path + i); // path is under ref_path
|
||||
if (path[i] == '\0')
|
||||
return "."; // path are identical
|
||||
// path is under ref_path
|
||||
if (path[i] == PATH_SEPARATOR[0])
|
||||
{
|
||||
snprintf(rel_path, MAX_PATH_CHARACTERS, ".%s", path + i);
|
||||
return rel_path;
|
||||
}
|
||||
if (real_ref_path[i] == '\0' && path[i] == '\0')
|
||||
return "."; // path are identical
|
||||
else if (i > 0 && real_ref_path[i - 1] == PATH_SEPARATOR[0])
|
||||
{
|
||||
snprintf(rel_path, MAX_PATH_CHARACTERS, ".%s", path + i - 1);
|
||||
return rel_path;
|
||||
}
|
||||
}
|
||||
if (last_separator <= 0)
|
||||
return path; // no common part found return absolute path
|
||||
// count the number of path separators in the reference path
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user