From 1458e8459cfd505d763852fc1a18d8d150723c93 Mon Sep 17 00:00:00 2001 From: Sagi Amangeldi <101683689+capCafu@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:51:15 +0900 Subject: [PATCH 1/3] Add resolveProjectPath for step 3 project files --- shared/include/HDMapping/SessionPaths.h | 49 +++++++++++++++++++------ 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/shared/include/HDMapping/SessionPaths.h b/shared/include/HDMapping/SessionPaths.h index 5ecf35fd..92d3a8be 100644 --- a/shared/include/HDMapping/SessionPaths.h +++ b/shared/include/HDMapping/SessionPaths.h @@ -8,7 +8,8 @@ // store the paths of the files they reference relative to the session file's // folder, so a session keeps working after its folder is moved or copied to // another computer. In memory the paths stay absolute: writers convert with -// toSessionPath(), readers with resolveSessionPath(). +// toSessionPath(), readers with resolveSessionPath(). Step 3 projects (.mjp) +// store their session files the same way and read them with resolveProjectPath(). // Path to write into session_file for `path`: relative to the session file's // folder with '/' separators, or absolute when there is no relative path (e.g. @@ -32,25 +33,51 @@ inline std::string toSessionPath(const std::string& path, const std::string& ses return (relative_path.empty() ? absolute_path : relative_path).generic_string(); } -// Absolute path for a path read from session_file. Relative paths resolve -// against the session file's folder, absolute ones (older sessions) are used as -// they are. If the result doesn't exist, the file of the same name next to the -// session file is used instead, so sessions moved together with their data keep -// loading. -inline std::string resolveSessionPath(const std::string& stored_path, const std::string& session_file) +//! Absolute path for a path read from `file`: relative paths resolve against the +//! folder of `file`, absolute ones (older files) are used as they are. +inline std::string resolveStoredPath(const std::string& stored_path, const std::string& file) { namespace fs = std::filesystem; - // Sessions written on Windows use '\' separators + // Files written on Windows use '\' separators std::string normalized = stored_path; std::replace(normalized.begin(), normalized.end(), '\\', '/'); const fs::path path(normalized); std::error_code ec; - const fs::path session_dir = fs::absolute(session_file, ec).parent_path(); - const fs::path resolved = path.is_absolute() ? path : (session_dir / path).lexically_normal(); + const fs::path dir = fs::absolute(file, ec).parent_path(); + return (path.is_absolute() ? path : (dir / path).lexically_normal()).string(); +} + +// Absolute path for a path read from session_file, see resolveStoredPath(). If +// the result doesn't exist, the file of the same name next to the session file +// is used instead, so sessions moved together with their data keep loading. +inline std::string resolveSessionPath(const std::string& stored_path, const std::string& session_file) +{ + namespace fs = std::filesystem; + const fs::path resolved = resolveStoredPath(stored_path, session_file); + + std::error_code ec; if (fs::exists(resolved, ec)) { return resolved.string(); } - return (session_dir / path.filename()).string(); + return (fs::absolute(session_file, ec).parent_path() / resolved.filename()).string(); +} + +//! Absolute path of a session file read from a step 3 project, see +//! resolveStoredPath(). Older projects kept paths given on the command line as +//! they were, relative to the current folder; such a path is used when the +//! project-relative one doesn't exist. +inline std::string resolveProjectPath(const std::string& stored_path, const std::string& project_file) +{ + namespace fs = std::filesystem; + const std::string resolved = resolveStoredPath(stored_path, project_file); + + std::error_code ec; + if (!fs::exists(resolved, ec) && fs::exists(stored_path, ec)) + { + const fs::path absolute_path = fs::absolute(stored_path, ec); + return ec ? stored_path : absolute_path.string(); + } + return resolved; } From e8ef8bc70f7ac51bae2b02b9d55c15237e7ff671 Mon Sep 17 00:00:00 2001 From: Sagi Amangeldi <101683689+capCafu@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:51:15 +0900 Subject: [PATCH 2/3] Store step 3 project paths relative to the project file --- .../multi_session_registration.cpp | 5 +++-- .../multi_session_registration_no_gui.cpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/multi_session_registration/multi_session_registration.cpp b/apps/multi_session_registration/multi_session_registration.cpp index db0e97c2..ce206194 100644 --- a/apps/multi_session_registration/multi_session_registration.cpp +++ b/apps/multi_session_registration/multi_session_registration.cpp @@ -37,6 +37,7 @@ #include #include +#include #ifdef _WIN32 #include "resource.h" @@ -1293,7 +1294,7 @@ bool save_project_settings(const std::string& file_name, const ProjectSettings& nlohmann::json jsession_file_names; for (const auto& pc : _project_settings.session_file_names) { - nlohmann::json jfn{ { "session_file_name", pc } }; + nlohmann::json jfn{ { "session_file_name", toSessionPath(pc, file_name) } }; jsession_file_names.push_back(jfn); } jj["session_file_names"] = jsession_file_names; @@ -1481,7 +1482,7 @@ bool loadProject(const std::string& file_name, ProjectSettings& _project_setting for (const auto& fn_json : data["session_file_names"]) { - const std::string fn = fn_json["session_file_name"]; + const std::string fn = resolveProjectPath(fn_json["session_file_name"].get(), file_name); _project_settings.session_file_names.push_back(fn); std::cout << "'" << fn << "'"; if (!fs::exists(fn)) diff --git a/apps/multi_session_registration/multi_session_registration_no_gui.cpp b/apps/multi_session_registration/multi_session_registration_no_gui.cpp index 08328baa..7e85bf79 100644 --- a/apps/multi_session_registration/multi_session_registration_no_gui.cpp +++ b/apps/multi_session_registration/multi_session_registration_no_gui.cpp @@ -19,6 +19,7 @@ #include #include +#include #ifdef _WIN32 #include "resource.h" @@ -326,7 +327,7 @@ bool save_project_settings(const std::string& file_name, const ProjectSettings& nlohmann::json jsession_file_names; for (const auto& pc : _project_settings.session_file_names) { - nlohmann::json jfn{ { "session_file_name", pc } }; + nlohmann::json jfn{ { "session_file_name", toSessionPath(pc, file_name) } }; jsession_file_names.push_back(jfn); } jj["session_file_names"] = jsession_file_names; @@ -443,7 +444,7 @@ bool loadProject(const std::string& file_name, ProjectSettings& _project_setting for (const auto& fn_json : data["session_file_names"]) { - const std::string fn = fn_json["session_file_name"]; + const std::string fn = resolveProjectPath(fn_json["session_file_name"].get(), file_name); _project_settings.session_file_names.push_back(fn); std::cout << "'" << fn << "'"; if (!fs::exists(fn)) From 67d79ee659220215ba2881930f2b4609440a30bf Mon Sep 17 00:00:00 2001 From: Sagi Amangeldi <101683689+capCafu@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:51:15 +0900 Subject: [PATCH 3/3] Store legacy step 3 project paths relative to the project file --- .../multi_session_registration.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/multi_session_registration_legacy/multi_session_registration.cpp b/apps/multi_session_registration_legacy/multi_session_registration.cpp index bed35aa8..eae68a79 100644 --- a/apps/multi_session_registration_legacy/multi_session_registration.cpp +++ b/apps/multi_session_registration_legacy/multi_session_registration.cpp @@ -28,6 +28,7 @@ #include #include +#include #ifdef _WIN32 #include "resource.h" @@ -1617,7 +1618,7 @@ bool save_project_settings(const std::string& file_name, const ProjectSettings& nlohmann::json jsession_file_names; for (const auto& pc : _project_settings.session_file_names) { - nlohmann::json jfn{ { "session_file_name", pc } }; + nlohmann::json jfn{ { "session_file_name", toSessionPath(pc, file_name) } }; jsession_file_names.push_back(jfn); } jj["session_file_names"] = jsession_file_names; @@ -1749,7 +1750,7 @@ bool loadProject(const std::string& file_name, ProjectSettings& _project_setting for (const auto& fn_json : data["session_file_names"]) { - const std::string fn = fn_json["session_file_name"]; + const std::string fn = resolveProjectPath(fn_json["session_file_name"].get(), file_name); _project_settings.session_file_names.push_back(fn); std::cout << "'" << fn << "'"; if (!fs::exists(fn))