From f0945502795c5a5e624f7c0206574cdd823aa2cb Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Wed, 3 May 2017 08:20:31 +0200 Subject: [PATCH] Use correct resource path and check for errors on splash screen creation --- src/anbox/config.cpp | 8 ++++++++ src/anbox/config.h | 3 +++ src/anbox/ui/splash_screen.cpp | 14 +++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/anbox/config.cpp b/src/anbox/config.cpp index 7c0961e..d6be507 100644 --- a/src/anbox/config.cpp +++ b/src/anbox/config.cpp @@ -41,6 +41,10 @@ void anbox::SystemConfiguration::set_data_path(const std::string &path) { data_path = path; } +void anbox::SystemConfiguration::set_resource_path(const std::string &path) { + resource_path = path; +} + fs::path anbox::SystemConfiguration::data_dir() const { return data_path; } @@ -76,6 +80,10 @@ std::string anbox::SystemConfiguration::application_item_dir() const { return dir.string(); } +std::string anbox::SystemConfiguration::resource_dir() const { + return resource_path.string(); +} + anbox::SystemConfiguration& anbox::SystemConfiguration::instance() { static SystemConfiguration config; return config; diff --git a/src/anbox/config.h b/src/anbox/config.h index 91f72c6..e3417d8 100644 --- a/src/anbox/config.h +++ b/src/anbox/config.h @@ -31,6 +31,7 @@ class SystemConfiguration { virtual ~SystemConfiguration() = default; void set_data_path(const std::string &path); + void set_resource_path(const std::string &path); boost::filesystem::path data_dir() const; std::string rootfs_dir() const; @@ -40,11 +41,13 @@ class SystemConfiguration { std::string container_socket_path() const; std::string input_device_dir() const; std::string application_item_dir() const; + std::string resource_dir() const; protected: SystemConfiguration() = default; boost::filesystem::path data_path = "/var/lib/anbox"; + boost::filesystem::path resource_path = "/usr/share/anbox"; }; } // namespace anbox diff --git a/src/anbox/ui/splash_screen.cpp b/src/anbox/ui/splash_screen.cpp index fc94dba..c8c7f86 100644 --- a/src/anbox/ui/splash_screen.cpp +++ b/src/anbox/ui/splash_screen.cpp @@ -16,6 +16,7 @@ */ #include "anbox/ui/splash_screen.h" +#include "anbox/config.h" #include "anbox/utils.h" #include @@ -37,11 +38,22 @@ SplashScreen::SplashScreen() { } auto surface = SDL_GetWindowSurface(window_); + if (!surface) + BOOST_THROW_EXCEPTION(std::runtime_error("Could not retrieve surface for our window")); + SDL_FillRect(surface, nullptr, SDL_MapRGB(surface->format, 0xee, 0xee, 0xee)); SDL_UpdateWindowSurface(window_); auto renderer = SDL_CreateRenderer(window_, -1, SDL_RENDERER_ACCELERATED); - auto img = IMG_LoadTexture(renderer, "/snap/anbox/current/snap/gui/icon.png"); + if (!renderer) + BOOST_THROW_EXCEPTION(std::runtime_error("Could not create renderer")); + + const auto icon_path = utils::string_format("%s/ui/icon.png", SystemConfiguration::instance().resource_dir()); + auto img = IMG_LoadTexture(renderer, icon_path.c_str()); + if (!img) { + const auto msg = utils::string_format("Failed to create texture from %s", icon_path); + BOOST_THROW_EXCEPTION(std::runtime_error(msg)); + } const auto tex_width = 128, tex_height = 128; SDL_Rect r{(width - tex_width) / 2, (height - tex_height) / 2, 128, 128};