diff --git a/components/common/cpp/include/ftl/configuration.hpp b/components/common/cpp/include/ftl/configuration.hpp index 9010858c4a0c268c4b7603880eef79ad2d2a974d..18ce61f4c9bcfcca73a3ba05a690f18489a06f66 100644 --- a/components/common/cpp/include/ftl/configuration.hpp +++ b/components/common/cpp/include/ftl/configuration.hpp @@ -27,6 +27,8 @@ namespace config { typedef nlohmann::json json_t; +void addPath(const std::string &path); + std::optional<std::string> locateFile(const std::string &name); std::map<std::string, std::string> read_options(char ***argv, int *argc); diff --git a/components/common/cpp/src/configuration.cpp b/components/common/cpp/src/configuration.cpp index a10ba86e571c0844c931caa643aa668d0d9c2443..b849c6ff13376ee0e1046244b7880066546c7d7f 100644 --- a/components/common/cpp/src/configuration.cpp +++ b/components/common/cpp/src/configuration.cpp @@ -106,6 +106,11 @@ bool ftl::create_directory(const std::string &path) { #endif } +void ftl::config::addPath(const std::string &path) { + auto &paths = rootCFG->getConfig()["paths"]; + paths.push_back(path); +} + optional<string> ftl::config::locateFile(const string &name) { if (is_file(name)) return name; diff --git a/components/common/cpp/src/uri.cpp b/components/common/cpp/src/uri.cpp index fe78c9ffe115225c79119c6ff779158951fb1c71..0db7a4af505f28bd162d81eed763241ed6f5ff9d 100644 --- a/components/common/cpp/src/uri.cpp +++ b/components/common/cpp/src/uri.cpp @@ -1,4 +1,13 @@ #include <ftl/uri.hpp> +// #include <filesystem> TODO When available +#include <cstdlib> +#include <loguru.hpp> + +#ifndef WIN32 +#include <unistd.h> +#else +#include <direct.h> +#endif using ftl::URI; using ftl::uri_t; @@ -27,13 +36,28 @@ URI::URI(const URI &c) { void URI::_parse(uri_t puri) { UriUriA uri; + std::string suri = puri; + + // NOTE: Non-standard additions to allow for Unix style relative file names. + if (suri[0] == '.') { + char cwdbuf[1024]; + getcwd(cwdbuf, 1024); + suri = string("file://") + string(cwdbuf) + suri.substr(1); + } else if (suri[0] == '~') { +#ifdef WIN32 + suri = string("file://") + string(std::getenv("HOMEDRIVE")) + string(std::getenv("HOMEPATH")) + suri.substr(1); +#else + suri = string("file://") + string(std::getenv("HOME")) + suri.substr(1); +#endif + } + #ifdef HAVE_URIPARSESINGLE const char *errpos; if (uriParseSingleUriA(&uri, puri, &errpos) != URI_SUCCESS) { #else UriParserStateA uris; uris.uri = &uri; - if (uriParseUriA(&uris, puri) != URI_SUCCESS) { + if (uriParseUriA(&uris, suri.c_str()) != URI_SUCCESS) { #endif m_valid = false; m_host = "none"; diff --git a/components/rgbd-sources/src/source.cpp b/components/rgbd-sources/src/source.cpp index b3b9e82b27a54f56bd2f0242d72ad60be6f338e4..06caebb232f64fd2b244c914cb8e01a518a2f6bc 100644 --- a/components/rgbd-sources/src/source.cpp +++ b/components/rgbd-sources/src/source.cpp @@ -92,7 +92,7 @@ ftl::rgbd::detail::Source *Source::_createFileImpl(const ftl::URI &uri) { if (eix == string::npos) { // Might be a directory if (ftl::is_directory(path)) { - return new StereoVideoSource(this); + return new StereoVideoSource(this, path); } else { return nullptr; } diff --git a/components/rgbd-sources/src/stereovideo.cpp b/components/rgbd-sources/src/stereovideo.cpp index b75380746942b3af2af1c5fca11b43afa848cf6e..86a9e10b2ba6bcd0d1ca0fd2a91e1bde2406e158 100644 --- a/components/rgbd-sources/src/stereovideo.cpp +++ b/components/rgbd-sources/src/stereovideo.cpp @@ -31,12 +31,15 @@ StereoVideoSource::~StereoVideoSource() { } void StereoVideoSource::init(const string &file) { + LOG(INFO) << "STEREOSOURCE = " << file; if (ftl::is_video(file)) { // Load video file LOG(INFO) << "Using video file..."; lsrc_ = ftl::create<LocalSource>(host_, "feed", file); - } - else if (file != "") { + } else if (ftl::is_directory(file)) { + // FIXME: This is not an ideal solution... + ftl::config::addPath(file); + auto vid = ftl::locateFile("video.mp4"); if (!vid) { LOG(FATAL) << "No video.mp4 file found in provided paths (" << file << ")";