Changeset View
Changeset View
Standalone View
Standalone View
files/0001-use-xdg-config-dir-for-profiles-on-linux.patch
- This file was added.
| From f10be3aebd88e197701b55c2b34c11e408073217 Mon Sep 17 00:00:00 2001 | |||||
| From: Campbell Jones <git@serebit.com> | |||||
| Date: Wed, 2 Sep 2020 17:55:31 -0400 | |||||
| Subject: [PATCH] use xdg config dir for profiles on linux | |||||
| --- | |||||
| ProfileManager.cpp | 42 +++++++++++++++++++++++++++++++++++------- | |||||
| 1 file changed, 35 insertions(+), 7 deletions(-) | |||||
| diff --git a/ProfileManager.cpp b/ProfileManager.cpp | |||||
| index c4f26a4..5479652 100644 | |||||
| --- a/ProfileManager.cpp | |||||
| +++ b/ProfileManager.cpp | |||||
| @@ -5,9 +5,39 @@ | |||||
| #include <fstream> | |||||
| #include <iostream> | |||||
| #include <cstring> | |||||
| +#include <unistd.h> | |||||
| +#include <pwd.h> | |||||
| namespace fs = std::experimental::filesystem; | |||||
| +static std::string GetProfileDir() | |||||
| +{ | |||||
| +#ifdef __linux__ | |||||
| + std::string profile_dir; | |||||
| + | |||||
| + const char* xdg_dir = getenv("XDG_CONFIG_DIR"); | |||||
| + if (xdg_dir == NULL) | |||||
| + { | |||||
| + const char* home_dir = getenv("HOME"); | |||||
| + if (home_dir == NULL) | |||||
| + { | |||||
| + home_dir = getpwuid(getuid())->pw_dir; | |||||
| + } | |||||
| + profile_dir = std::string(home_dir).append("/.config"); | |||||
| + } | |||||
| + else | |||||
| + { | |||||
| + profile_dir = std::string(xdg_dir); | |||||
| + } | |||||
| + | |||||
| + profile_dir = profile_dir.append("/openrgb/"); | |||||
| + fs::create_directory(profile_dir); | |||||
| + return profile_dir; | |||||
| +#else | |||||
| + return "./"; | |||||
| +#endif | |||||
| +} | |||||
| + | |||||
| ProfileManager::ProfileManager(std::vector<RGBController *>& control) : controllers(control) | |||||
| { | |||||
| UpdateProfileList(); | |||||
| @@ -28,7 +58,7 @@ bool ProfileManager::SaveProfile(std::string profile_name) | |||||
| /*---------------------------------------------------------*\ | |||||
| | Open an output file in binary mode | | |||||
| \*---------------------------------------------------------*/ | |||||
| - std::ofstream controller_file(profile_name, std::ios::out | std::ios::binary); | |||||
| + std::ofstream controller_file(GetProfileDir().append(profile_name), std::ios::out | std::ios::binary); | |||||
| /*---------------------------------------------------------*\ | |||||
| | Write header | | |||||
| @@ -93,12 +123,10 @@ bool ProfileManager::LoadProfileWithOptions | |||||
| unsigned int controller_offset = 0; | |||||
| bool ret_val = false; | |||||
| - std::string filename = profile_name; | |||||
| - | |||||
| /*---------------------------------------------------------*\ | |||||
| | Open input file in binary mode | | |||||
| \*---------------------------------------------------------*/ | |||||
| - std::ifstream controller_file(filename, std::ios::in | std::ios::binary); | |||||
| + std::ifstream controller_file(GetProfileDir().append(profile_name), std::ios::in | std::ios::binary); | |||||
| /*---------------------------------------------------------*\ | |||||
| | Read and verify file header | | |||||
| @@ -251,7 +279,7 @@ bool ProfileManager::LoadProfileWithOptions | |||||
| void ProfileManager::DeleteProfile(std::string profile_name) | |||||
| { | |||||
| - remove(profile_name.c_str()); | |||||
| + remove(GetProfileDir().append(profile_name).c_str()); | |||||
| UpdateProfileList(); | |||||
| } | |||||
| @@ -263,7 +291,7 @@ void ProfileManager::UpdateProfileList() | |||||
| /*---------------------------------------------------------*\ | |||||
| | Load profiles by looking for .orp files in current dir | | |||||
| \*---------------------------------------------------------*/ | |||||
| - for(const auto & entry : fs::directory_iterator(".")) | |||||
| + for(const auto & entry : fs::directory_iterator(GetProfileDir())) | |||||
| { | |||||
| std::string filename = entry.path().filename().string(); | |||||
| @@ -272,7 +300,7 @@ void ProfileManager::UpdateProfileList() | |||||
| /*---------------------------------------------------------*\ | |||||
| | Open input file in binary mode | | |||||
| \*---------------------------------------------------------*/ | |||||
| - std::ifstream profile_file(filename, std::ios::in | std::ios::binary); | |||||
| + std::ifstream profile_file(entry.path().string(), std::ios::in | std::ios::binary); | |||||
| /*---------------------------------------------------------*\ | |||||
| | Read and verify file header | | |||||
| -- | |||||
| 2.27.0 | |||||
Copyright © 2015-2021 Solus Project. The Solus logo is Copyright © 2016-2021 Solus Project. All Rights Reserved.