diff --git a/CMakePresets.json b/CMakePresets.json index 7207774d3..3856a0150 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -1,7 +1,8 @@ { "version": 3, "configurePresets": [ - { "name": "windows-base", + { + "name": "windows-base", "condition": { "type": "equals", "lhs": "${hostSystemName}", diff --git a/include/xstudio/utility/helpers.hpp b/include/xstudio/utility/helpers.hpp index 952298eae..7b6aa1736 100644 --- a/include/xstudio/utility/helpers.hpp +++ b/include/xstudio/utility/helpers.hpp @@ -25,6 +25,7 @@ #ifdef _WIN32 #include +#include #endif namespace xstudio { @@ -378,14 +379,32 @@ inline std::string snippets_path(const std::string &append_path = "") { return get_file_mtime(uri_to_posix_path(path)); } - - inline bool is_file_supported(const caf::uri &uri) { - fs::path p(uri_to_posix_path(uri)); + inline std::string get_path_extension(const fs::path p) + { + const std::string sp = p.string(); #ifdef _WIN32 - std::string ext = to_upper(p.extension().string()); // Convert path extension to string + std::string sanitized; + + try { + sanitized = fmt::format(sp, 0); + + } catch (...) { + // If we are here, the path likely doesn't have a format string. + sanitized = sp; + } + fs::path pth(sanitized); + std::string ext = pth.extension().string(); // Convert path extension to string + return ext; #else - std::string ext = to_upper(p.extension()); + return sp.extension().string(); #endif + } + + + inline bool is_file_supported(const caf::uri &uri) { + const std::string sp = uri_to_posix_path(uri); + std::string ext = to_upper(get_path_extension(fs::path(sp))); + for (const auto &i : supported_extensions) if (i == ext) return true; @@ -394,7 +413,7 @@ inline std::string snippets_path(const std::string &append_path = "") { inline bool is_session(const std::string &path) { fs::path p(path); - std::string ext = to_upper(path_to_string(p.extension())); + std::string ext = to_upper(path_to_string(get_path_extension(p))); for (const auto &i : session_extensions) if (i == ext) return true; @@ -405,11 +424,9 @@ inline std::string snippets_path(const std::string &append_path = "") { inline bool is_timeline_supported(const caf::uri &uri) { fs::path p(uri_to_posix_path(uri)); -#ifdef _WIN32 - std::string ext = to_upper_path(p.extension()); -#else - std::string ext = to_upper(p.extension()); -#endif + spdlog::error(p.string()); + std::string ext = to_upper(get_path_extension(p)); + for (const auto &i : supported_timeline_extensions) if (i == ext) return true; diff --git a/src/global_store/src/global_store.cpp b/src/global_store/src/global_store.cpp index e7ebc3bb7..247ff8d1a 100644 --- a/src/global_store/src/global_store.cpp +++ b/src/global_store/src/global_store.cpp @@ -72,7 +72,7 @@ bool xstudio::global_store::preference_load_defaults( try { for (const auto &entry : fs::directory_iterator(path)) { if (not fs::is_regular_file(entry.status()) or - not(entry.path().extension() == ".json")) { + not(get_path_extension(entry.path()) == ".json")) { continue; } @@ -124,7 +124,8 @@ void load_from_list(const std::string &path, std::vector &overrides) { tmp = fs::canonical(rpath / tmp); } - if (fs::is_regular_file(tmp) and tmp.extension() == ".json") { + if (fs::is_regular_file(tmp) and + get_path_extension(tmp) == ".json") { overrides.push_back(tmp); } else { spdlog::warn("Invalid pref entry {}", tmp.string()); @@ -213,9 +214,9 @@ void xstudio::global_store::preference_load_overrides( try { fs::path p(i); if (fs::is_regular_file(p)) { - if (p.extension() == ".json") + if (get_path_extension(p) == ".json") overrides.push_back(p); - else if (p.extension() == ".lst") + else if (get_path_extension(p) == ".lst") load_from_list(i, overrides); else throw std::runtime_error("Unrecognised extension"); @@ -223,7 +224,7 @@ void xstudio::global_store::preference_load_overrides( std::set tmp; for (const auto &entry : fs::directory_iterator(p)) { if (not fs::is_regular_file(entry.status()) or - not(entry.path().extension() == ".json")) { + not(get_path_extension(entry.path()) == ".json")) { continue; } tmp.insert(entry.path()); diff --git a/src/media/src/media_actor.cpp b/src/media/src/media_actor.cpp index fbe8ff682..d3fb2f313 100644 --- a/src/media/src/media_actor.cpp +++ b/src/media/src/media_actor.cpp @@ -330,13 +330,9 @@ void MediaActor::init() { const FrameList &frame_list, const utility::FrameRate &rate) -> result { auto rp = make_response_promise(); -#ifdef _WIN32 - std::string ext = - ltrim_char(to_upper_path(fs::path(uri_to_posix_path(uri)).extension()), '.'); -#else - std::string ext = - ltrim_char(to_upper(fs::path(uri_to_posix_path(uri)).extension()), '.'); -#endif + + std::string ext = ltrim_char( + to_upper(get_path_extension(fs::path(uri_to_posix_path(uri)))), '.'); const auto source_uuid = Uuid::generate(); auto source = diff --git a/src/playlist/src/playlist_actor.cpp b/src/playlist/src/playlist_actor.cpp index 5274649ee..dce679634 100644 --- a/src/playlist/src/playlist_actor.cpp +++ b/src/playlist/src/playlist_actor.cpp @@ -76,9 +76,10 @@ void blocking_loader( const FrameList &frame_list = i.second; const auto uuid = Uuid::generate(); + #ifdef _WIN32 - std::string ext = - ltrim_char(to_upper_path(fs::path(uri_to_posix_path(uri)).extension()), '.'); + std::string ext = ltrim_char( + get_path_extension(to_upper_path(fs::path(uri_to_posix_path(uri)))), '.'); #else std::string ext = ltrim_char(to_upper(fs::path(uri_to_posix_path(uri)).extension()), '.'); diff --git a/src/utility/src/helpers.cpp b/src/utility/src/helpers.cpp index 41f401258..4f2cf3809 100644 --- a/src/utility/src/helpers.cpp +++ b/src/utility/src/helpers.cpp @@ -252,10 +252,6 @@ std::string xstudio::utility::uri_to_posix_path(const caf::uri &uri) { if (pos != std::string::npos) { path.erase(0, pos + 1); // +1 to erase the colon } - - - // Now, replace forward slashes with backslashes - std::replace(path.begin(), path.end(), '/', '\\'); */ #endif return path; @@ -507,7 +503,8 @@ xstudio::utility::scan_posix_path(const std::string &path, const int depth) { items.insert(items.end(), more.begin(), more.end()); } else if (fs::is_regular_file(entry)) #ifdef _WIN32 - files.push_back(entry.path().string()); + files.push_back( + std::regex_replace(entry.path().string(), std::regex("[\]"), "/")); #else files.push_back(entry.path()); #endif