MCPcopy Create free account
hub / github.com/OpenHD/OpenHD / getVideoPath

Function getVideoPath

OpenHD/ohd_common/src/config_paths.cpp:51–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51const char* getVideoPath() {
52 static std::string cachedPath;
53 static const char* CACHE_FILE = "/usr/local/share/openhd/recording.txt";
54 static const char* FILENAME1 = "/Videos/external_video_part.txt";
55 static const char* FILENAME2 = "/external/Videos/external_video_part.txt";
56
57 if (!cachedPath.empty()) {
58 return cachedPath.c_str();
59 }
60
61 if (OHDFilesystemUtil::exists(CACHE_FILE)) {
62 std::ifstream infile(CACHE_FILE);
63 if (infile) {
64 std::getline(infile, cachedPath);
65 return cachedPath.c_str();
66 }
67 }
68
69 const char* selectedPath = nullptr;
70
71 if (OHDFilesystemUtil::exists(FILENAME1)) {
72 selectedPath = VIDEO_PATH ? VIDEO_PATH : "/Videos/";
73 OHDFilesystemUtil::remove_if_existing(FILENAME1);
74 } else if (OHDFilesystemUtil::exists(FILENAME2)) {
75 selectedPath = VIDEO_PATH ? VIDEO_PATH : "/external/Videos/";
76 OHDFilesystemUtil::remove_if_existing(FILENAME2);
77 } else {
78 selectedPath = "/home/openhd/Videos/";
79 OHDFilesystemUtil::create_directories(selectedPath);
80 }
81
82 cachedPath = selectedPath;
83 OHDFilesystemUtil::create_directories("/usr/local/share/openhd/");
84 std::ofstream outfile(CACHE_FILE);
85 if (outfile) {
86 outfile << cachedPath;
87 }
88
89 return cachedPath.c_str();
90}
91
92void setConfigBasePath(const char* path) {
93 if (CONFIG_BASE_PATH) {

Calls

no outgoing calls

Tested by

no test coverage detected