diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-06-30 19:21:29 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-06-30 19:21:29 -0400 |
commit | f7ac0f2a1ea373d28f630021c8567f0afb035568 (patch) | |
tree | 718506ed87f23eb955170a4f9c5f58b3fe35fab3 /platform.cpp | |
parent | 698ec52d5c056f3584c46e67b199adcfba9f8d2e (diff) | |
download | abaddon-portaudio-f7ac0f2a1ea373d28f630021c8567f0afb035568.tar.gz abaddon-portaudio-f7ac0f2a1ea373d28f630021c8567f0afb035568.zip |
allow config to go in ~/.config/abaddon
Diffstat (limited to 'platform.cpp')
-rw-r--r-- | platform.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/platform.cpp b/platform.cpp index 48d2104..9448cc6 100644 --- a/platform.cpp +++ b/platform.cpp @@ -3,6 +3,8 @@ #include <fstream> #include <filesystem> +using namespace std::literals::string_literals; + bool IsFolder(std::string_view path) { std::error_code ec; const auto status = std::filesystem::status(path, ec); @@ -10,6 +12,13 @@ bool IsFolder(std::string_view path) { return status.type() == std::filesystem::file_type::directory; } +bool IsFile(std::string_view path) { + std::error_code ec; + const auto status = std::filesystem::status(path, ec); + if (ec) return false; + return status.type() == std::filesystem::file_type::regular; +} + #if defined(_WIN32) && defined(_MSC_VER) #include <Windows.h> #include <Shlwapi.h> @@ -73,6 +82,10 @@ std::string Platform::FindResourceFolder() { return "."; } +std::string Platform::FindConfigFile() { + return "./abaddon.ini"; +} + #elif defined(__linux__) std::string Platform::FindResourceFolder() { static std::string path; @@ -88,8 +101,23 @@ std::string Platform::FindResourceFolder() { found = true; return path; } + +std::string Platform::FindConfigFile() { + const auto home_path = std::string(std::getenv("HOME")) + "/.config/abaddon/abaddon.ini"; + for (const auto path : { "./abaddon.ini"s, home_path }) { + if (IsFile(path)) return path; + } + puts("can't find configuration file!"); + return "./abaddon.ini"; +} #else std::string Platform::FindResourceFolder() { puts("unknown OS, trying to load resources from cwd"); + return "."; +} + +std::string Platform::FindConfigFile() { + puts("unknown OS, trying to load config from cwd"); + return "./abaddon.ini"; } #endif |