diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-09-22 18:17:46 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-09-22 18:17:46 +0200 |
commit | 61c9b4918ed81a6ad439748f8bcb1c6f9b0cf65e (patch) | |
tree | 7b54793153fb8f3b608e59a0c27ddec63fb817f5 /src/Utils.cpp | |
parent | 5d6d57b8810a6ef88fb5e155d4610345f7df288d (diff) |
Save recording status to file to reload it when gsr overlay restarts
Diffstat (limited to 'src/Utils.cpp')
-rw-r--r-- | src/Utils.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/Utils.cpp b/src/Utils.cpp index ae24f7b..c3da908 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -167,6 +167,20 @@ namespace gsr { return success; } + bool file_overwrite(const char *filepath, const std::string &data) { + bool success = false; + + FILE *file = fopen(filepath, "wb"); + if(!file) + return success; + + if(fwrite(data.data(), 1, data.size(), file) == data.size()) + success = true; + + fclose(file); + return success; + } + std::string get_parent_directory(std::string_view directory) { std::string result; @@ -184,4 +198,21 @@ namespace gsr { } return result; } + + std::optional<std::string> get_gsr_runtime_dir() { + std::optional<std::string> result; + char runtime_dir_path[256]; + snprintf(runtime_dir_path, sizeof(runtime_dir_path), "/run/user/%u", (unsigned int)getuid()); + + struct stat st; + if(stat(runtime_dir_path, &st) == -1 || !S_ISDIR(st.st_mode)) + snprintf(runtime_dir_path, sizeof(runtime_dir_path), "/tmp"); + + strcat(runtime_dir_path, "/gsr-overlay"); + if(create_directory_recursive(runtime_dir_path) != 0) + return result; + + result = runtime_dir_path; + return result; + } }
\ No newline at end of file |