Save recording status to file to reload it when gsr overlay restarts

This commit is contained in:
dec05eba
2024-09-22 18:17:46 +02:00
parent 5d6d57b881
commit 61c9b4918e
7 changed files with 270 additions and 66 deletions

View File

@@ -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;
}
}