Skip to content

Commit

Permalink
Support getting extensions from frame sequences. Resolves AcademySoft…
Browse files Browse the repository at this point in the history
…wareFoundation#106

Signed-off-by: Michael Kessler <[email protected]>
  • Loading branch information
mpkepic committed Jul 19, 2024
1 parent ecb42d4 commit ad7c8bf
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 31 deletions.
3 changes: 2 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"version": 3,
"configurePresets": [
{ "name": "windows-base",
{
"name": "windows-base",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
Expand Down
39 changes: 28 additions & 11 deletions include/xstudio/utility/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#ifdef _WIN32
#include <windows.h>
#include <fmt/format.h>
#endif

namespace xstudio {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions src/global_store/src/global_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -124,7 +124,8 @@ void load_from_list(const std::string &path, std::vector<fs::path> &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());
Expand Down Expand Up @@ -213,17 +214,17 @@ 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");
} else if (fs::is_directory(p)) {
std::set<fs::path> 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());
Expand Down
10 changes: 3 additions & 7 deletions src/media/src/media_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,9 @@ void MediaActor::init() {
const FrameList &frame_list,
const utility::FrameRate &rate) -> result<UuidActor> {
auto rp = make_response_promise<UuidActor>();
#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 =
Expand Down
5 changes: 3 additions & 2 deletions src/playlist/src/playlist_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()), '.');
Expand Down
7 changes: 2 additions & 5 deletions src/utility/src/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ad7c8bf

Please sign in to comment.