From 698ec52d5c056f3584c46e67b199adcfba9f8d2e Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Wed, 30 Jun 2021 18:15:03 -0400 Subject: try loading resources from share, fallback to cwd --- platform.hpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'platform.hpp') diff --git a/platform.hpp b/platform.hpp index 70da6ce..cc0f01a 100644 --- a/platform.hpp +++ b/platform.hpp @@ -1,5 +1,7 @@ #pragma once +#include namespace Platform { bool SetupFonts(); +std::string FindResourceFolder(); } -- cgit v1.2.3 From f7ac0f2a1ea373d28f630021c8567f0afb035568 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Wed, 30 Jun 2021 19:21:29 -0400 Subject: allow config to go in ~/.config/abaddon --- abaddon.cpp | 2 +- platform.cpp | 28 ++++++++++++++++++++++++++++ platform.hpp | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) (limited to 'platform.hpp') diff --git a/abaddon.cpp b/abaddon.cpp index 6add0bb..8b08c8a 100644 --- a/abaddon.cpp +++ b/abaddon.cpp @@ -21,7 +21,7 @@ #endif Abaddon::Abaddon() - : m_settings("abaddon.ini") + : m_settings(Platform::FindConfigFile()) , m_emojis(GetResPath() + "/emojis.bin") , m_discord(m_settings.GetUseMemoryDB()) { // stupid but easy LoadFromSettings(); diff --git a/platform.cpp b/platform.cpp index 48d2104..9448cc6 100644 --- a/platform.cpp +++ b/platform.cpp @@ -3,6 +3,8 @@ #include #include +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 #include @@ -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 diff --git a/platform.hpp b/platform.hpp index cc0f01a..cde1cb4 100644 --- a/platform.hpp +++ b/platform.hpp @@ -4,4 +4,5 @@ namespace Platform { bool SetupFonts(); std::string FindResourceFolder(); +std::string FindConfigFile(); } -- cgit v1.2.3