summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-06-30 18:15:03 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2021-06-30 18:15:03 -0400
commit698ec52d5c056f3584c46e67b199adcfba9f8d2e (patch)
tree3b48df8eed852c2f4ecbdbcaaff9bf29d16f7b50
parent220aa6d13a9cb12687139305c6f68eb9cf6f73a1 (diff)
downloadabaddon-portaudio-698ec52d5c056f3584c46e67b199adcfba9f8d2e.tar.gz
abaddon-portaudio-698ec52d5c056f3584c46e67b199adcfba9f8d2e.zip
try loading resources from share, fallback to cwd
-rw-r--r--abaddon.cpp24
-rw-r--r--abaddon.hpp5
-rw-r--r--components/chatinputindicator.cpp5
-rw-r--r--components/memberlist.cpp3
-rw-r--r--components/ratelimitindicator.cpp5
-rw-r--r--imgmanager.cpp3
-rw-r--r--platform.cpp34
-rw-r--r--platform.hpp2
-rw-r--r--settings.cpp2
-rw-r--r--windows/guildsettings/memberspane.cpp3
-rw-r--r--windows/profile/userinfopane.cpp5
-rw-r--r--windows/profilewindow.cpp4
12 files changed, 80 insertions, 15 deletions
diff --git a/abaddon.cpp b/abaddon.cpp
index 4e900dc..6add0bb 100644
--- a/abaddon.cpp
+++ b/abaddon.cpp
@@ -22,7 +22,7 @@
Abaddon::Abaddon()
: m_settings("abaddon.ini")
- , m_emojis("res/emojis.bin")
+ , m_emojis(GetResPath() + "/emojis.bin")
, m_discord(m_settings.GetUseMemoryDB()) { // stupid but easy
LoadFromSettings();
@@ -426,6 +426,24 @@ void Abaddon::on_user_menu_remove_recipient() {
m_discord.RemoveGroupDMRecipient(m_main_window->GetChatActiveChannel(), m_shown_user_menu_id);
}
+std::string Abaddon::GetCSSPath() {
+ const static auto path = Platform::FindResourceFolder() + "/css";
+ return path;
+}
+
+std::string Abaddon::GetResPath() {
+ const static auto path = Platform::FindResourceFolder() + "/res";
+ return path;
+}
+
+std::string Abaddon::GetCSSPath(const std::string &path) {
+ return GetCSSPath() + path;
+}
+
+std::string Abaddon::GetResPath(const std::string &path) {
+ return GetResPath() + path;
+}
+
void Abaddon::ActionConnect() {
if (!m_discord.IsStarted())
StartDiscord();
@@ -643,11 +661,11 @@ void Abaddon::ActionReloadSettings() {
void Abaddon::ActionReloadCSS() {
try {
Gtk::StyleContext::remove_provider_for_screen(Gdk::Screen::get_default(), m_css_provider);
- m_css_provider->load_from_path(m_settings.GetMainCSS());
+ m_css_provider->load_from_path(GetCSSPath("/" + m_settings.GetMainCSS()));
Gtk::StyleContext::add_provider_for_screen(Gdk::Screen::get_default(), m_css_provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
Gtk::StyleContext::remove_provider_for_screen(Gdk::Screen::get_default(), m_css_low_provider);
- m_css_low_provider->load_from_path("./css/application-low-priority.css");
+ m_css_low_provider->load_from_path(GetCSSPath("/application-low-priority.css"));
Gtk::StyleContext::add_provider_for_screen(Gdk::Screen::get_default(), m_css_low_provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION - 1);
} catch (Glib::Error &e) {
Gtk::MessageDialog dlg(*m_main_window, "css failed to load (" + e.what() + ")", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
diff --git a/abaddon.hpp b/abaddon.hpp
index 1d14c33..d3b9c1c 100644
--- a/abaddon.hpp
+++ b/abaddon.hpp
@@ -86,6 +86,11 @@ public:
void ManageHeapWindow(Gtk::Window *window);
+ static std::string GetCSSPath();
+ static std::string GetResPath();
+ static std::string GetCSSPath(const std::string &path);
+ static std::string GetResPath(const std::string &path);
+
protected:
void ShowGuildVerificationGateDialog(Snowflake guild_id);
diff --git a/components/chatinputindicator.cpp b/components/chatinputindicator.cpp
index 3b43b7e..8b05c71 100644
--- a/components/chatinputindicator.cpp
+++ b/components/chatinputindicator.cpp
@@ -21,8 +21,9 @@ ChatInputIndicator::ChatInputIndicator()
m_label.show();
// try loading gif
- if (!std::filesystem::exists("./res/typing_indicator.gif")) return;
- auto gif_data = ReadWholeFile("./res/typing_indicator.gif");
+ const static auto path = Abaddon::GetResPath("/typing_indicator.gif");
+ if (!std::filesystem::exists(path)) return;
+ auto gif_data = ReadWholeFile(path);
auto loader = Gdk::PixbufLoader::create();
loader->signal_size_prepared().connect([&](int inw, int inh) {
int w, h;
diff --git a/components/memberlist.cpp b/components/memberlist.cpp
index ed02505..e91ce88 100644
--- a/components/memberlist.cpp
+++ b/components/memberlist.cpp
@@ -17,7 +17,8 @@ MemberListUserRow::MemberListUserRow(const std::optional<GuildData> &guild, cons
static bool crown = Abaddon::Get().GetSettings().GetShowOwnerCrown();
if (crown && guild.has_value() && guild->OwnerID == data.ID) {
try {
- auto pixbuf = Gdk::Pixbuf::create_from_file("./res/crown.png", 12, 12);
+ const static auto crown_path = Abaddon::GetResPath("/crown.png");
+ auto pixbuf = Gdk::Pixbuf::create_from_file(crown_path, 12, 12);
m_crown = Gtk::manage(new Gtk::Image(pixbuf));
m_crown->set_valign(Gtk::ALIGN_CENTER);
m_crown->set_margin_end(8);
diff --git a/components/ratelimitindicator.cpp b/components/ratelimitindicator.cpp
index d962f98..6115900 100644
--- a/components/ratelimitindicator.cpp
+++ b/components/ratelimitindicator.cpp
@@ -15,9 +15,10 @@ RateLimitIndicator::RateLimitIndicator()
add(m_img);
m_label.show();
- if (std::filesystem::exists("./res/clock.png")) {
+ const static auto clock_path = Abaddon::GetResPath("/clock.png");
+ if (std::filesystem::exists(clock_path)) {
try {
- const auto pixbuf = Gdk::Pixbuf::create_from_file("./res/clock.png");
+ const auto pixbuf = Gdk::Pixbuf::create_from_file(clock_path);
int w, h;
GetImageDimensions(pixbuf->get_width(), pixbuf->get_height(), w, h, 20, 10);
m_img.property_pixbuf() = pixbuf->scale_simple(w, h, Gdk::INTERP_BILINEAR);
diff --git a/imgmanager.cpp b/imgmanager.cpp
index 261b8d6..b97083c 100644
--- a/imgmanager.cpp
+++ b/imgmanager.cpp
@@ -1,5 +1,6 @@
#include "imgmanager.hpp"
#include "util.hpp"
+#include "abaddon.hpp"
ImageManager::ImageManager() {
m_cb_dispatcher.connect(sigc::mem_fun(*this, &ImageManager::RunCallbacks));
@@ -112,7 +113,7 @@ Glib::RefPtr<Gdk::Pixbuf> ImageManager::GetPlaceholder(int size) {
return m_pixs.at(name);
try {
- auto buf = Gdk::Pixbuf::create_from_file("res/decamarks.png", size, size);
+ auto buf = Gdk::Pixbuf::create_from_file(Abaddon::Get().GetResPath() + "/decamarks.png", size, size);
m_pixs[name] = buf;
return buf;
} catch (std::exception &e) {
diff --git a/platform.cpp b/platform.cpp
index 5d913a3..48d2104 100644
--- a/platform.cpp
+++ b/platform.cpp
@@ -1,6 +1,14 @@
#include "platform.hpp"
#include <string>
#include <fstream>
+#include <filesystem>
+
+bool IsFolder(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::directory;
+}
#if defined(_WIN32) && defined(_MSC_VER)
#include <Windows.h>
@@ -59,3 +67,29 @@ bool Platform::SetupFonts() {
return true;
}
#endif
+
+#if defined(_WIN32)
+std::string Platform::FindResourceFolder() {
+ return ".";
+}
+
+#elif defined(__linux__)
+std::string Platform::FindResourceFolder() {
+ static std::string path;
+ static bool found = false;
+ if (found) return path;
+
+ if (IsFolder("/usr/share/abaddon/res") && IsFolder("/usr/share/abaddon/css")) {
+ path = "/usr/share/abaddon";
+ } else {
+ puts("resources are not in /usr/share/abaddon, will try to load from cwd");
+ path = ".";
+ }
+ found = true;
+ return path;
+}
+#else
+std::string Platform::FindResourceFolder() {
+ puts("unknown OS, trying to load resources from cwd");
+}
+#endif
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 <string>
namespace Platform {
bool SetupFonts();
+std::string FindResourceFolder();
}
diff --git a/settings.cpp b/settings.cpp
index 6083d96..b9c18b7 100644
--- a/settings.cpp
+++ b/settings.cpp
@@ -75,7 +75,7 @@ bool SettingsManager::GetPrefetch() const {
}
std::string SettingsManager::GetMainCSS() const {
- return GetSettingString("gui", "css", "./css/main.css");
+ return GetSettingString("gui", "css", "main.css");
}
bool SettingsManager::GetShowAnimations() const {
diff --git a/windows/guildsettings/memberspane.cpp b/windows/guildsettings/memberspane.cpp
index 12655ca..8e5c29c 100644
--- a/windows/guildsettings/memberspane.cpp
+++ b/windows/guildsettings/memberspane.cpp
@@ -116,7 +116,8 @@ GuildSettingsMembersListItem::GuildSettingsMembersListItem(const GuildData &guil
static bool crown = Abaddon::Get().GetSettings().GetShowOwnerCrown();
if (crown && guild.OwnerID == member.User->ID) {
try {
- auto pixbuf = Gdk::Pixbuf::create_from_file("./res/crown.png", 12, 12);
+ const static auto crown_path = Abaddon::GetResPath("/crown.png");
+ auto pixbuf = Gdk::Pixbuf::create_from_file(crown_path, 12, 12);
m_crown = Gtk::manage(new Gtk::Image(pixbuf));
m_crown->set_valign(Gtk::ALIGN_CENTER);
m_crown->set_margin_start(10);
diff --git a/windows/profile/userinfopane.cpp b/windows/profile/userinfopane.cpp
index f510f4a..33e04ef 100644
--- a/windows/profile/userinfopane.cpp
+++ b/windows/profile/userinfopane.cpp
@@ -7,7 +7,7 @@ ConnectionItem::ConnectionItem(const ConnectionData &conn)
, m_box(Gtk::ORIENTATION_HORIZONTAL) {
Glib::RefPtr<Gdk::Pixbuf> pixbuf;
try {
- pixbuf = Gdk::Pixbuf::create_from_file("./res/" + conn.Type + ".png", 32, 32);
+ pixbuf = Gdk::Pixbuf::create_from_file(Abaddon::GetResPath("/" + conn.Type + ".png"), 32, 32);
} catch (const Glib::Exception &e) {}
std::string url;
if (conn.Type == "github")
@@ -53,7 +53,8 @@ ConnectionItem::ConnectionItem(const ConnectionData &conn)
m_overlay.add(m_box);
if (conn.IsVerified) {
try {
- static auto pb = Gdk::Pixbuf::create_from_file("./res/checkmark.png", 24, 24);
+ const static auto checkmarks_path = Abaddon::GetResPath("/checkmark.png");
+ static auto pb = Gdk::Pixbuf::create_from_file(checkmarks_path, 24, 24);
m_check = Gtk::manage(new Gtk::Image(pb));
m_check->get_style_context()->add_class("profile-connection-check");
m_check->set_margin_end(25);
diff --git a/windows/profilewindow.cpp b/windows/profilewindow.cpp
index 90e98f1..f4bc3c9 100644
--- a/windows/profilewindow.cpp
+++ b/windows/profilewindow.cpp
@@ -111,9 +111,9 @@ void ProfileWindow::OnFetchProfile(const UserProfileData &data) {
Glib::RefPtr<Gdk::Pixbuf> pixbuf;
try {
if (name == "verifiedbot")
- pixbuf = Gdk::Pixbuf::create_from_file("./res/checkmark.png", 24, 24);
+ pixbuf = Gdk::Pixbuf::create_from_file(Abaddon::GetResPath("/checkmark.png"), 24, 24);
else
- pixbuf = Gdk::Pixbuf::create_from_file("./res/" + name + ".png", 24, 24);
+ pixbuf = Gdk::Pixbuf::create_from_file(Abaddon::GetResPath("/" + name + ".png"), 24, 24);
} catch (const Glib::Exception &e) {
pixbuf = Abaddon::Get().GetImageManager().GetPlaceholder(24);
}