Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More flatpak fixes #199

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions io.github.openbrickprotocolfoundation.oopetris.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
app-id: io.github.openbrickprotocolfoundation.oopetris
runtime: org.freedesktop.Platform
runtime-version: "24.08"
runtime-version: '24.08'
sdk: org.freedesktop.Sdk
command: oopetris
modules:
Expand All @@ -24,13 +24,14 @@ modules:
- -Dbuild_installer=true
- --libdir=lib
- -Dtests=true
- --force-fallback-for=fmt # note, the freedesktop sdk has this installed, but it is not copiable into the runtime, so we need to build it ourself, to be able to install it correctly
builddir: true
build-options:
build-args:
- --share=network
sources:
- type: dir
path: "."
path: '.'
skip:
- .github/
- .vscode/
Expand Down
17 changes: 12 additions & 5 deletions src/executables/game/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ namespace {
void initialize_spdlog() {

const auto logs_path = utils::get_root_folder() / "logs";
if (not std::filesystem::exists(logs_path)) {
std::filesystem::create_directory(logs_path);

auto created_log_dir = utils::create_directory(logs_path, true);
if (created_log_dir.has_value()) {
std::cerr << "warning: couldn't create logs directory '" << logs_path.string()
<< "': disabled file logger\n";
}

std::vector<spdlog::sink_ptr> sinks;
Expand All @@ -46,9 +49,13 @@ namespace {
#else
sinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_mt>());
#endif
sinks.push_back(std::make_shared<spdlog::sinks::rotating_file_sink_mt>(
fmt::format("{}/oopetris.log", logs_path.string()), 1024 * 1024 * 10, 5, true
));

if (not created_log_dir.has_value()) {
sinks.push_back(std::make_shared<spdlog::sinks::rotating_file_sink_mt>(
fmt::format("{}/oopetris.log", logs_path.string()), 1024 * 1024 * 10, 5, true
));
}

auto combined_logger = std::make_shared<spdlog::logger>("combined_logger", begin(sinks), end(sinks));
spdlog::set_default_logger(combined_logger);

Expand Down
26 changes: 26 additions & 0 deletions src/helper/graphic_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,32 @@ utils::ExitException::ExitException(int status_code) noexcept : m_status_code{ s
return "An exit exception occurred";
}

std::optional<std::string> utils::create_directory(const std::filesystem::path& folder, bool recursive) {

if (std::filesystem::exists(folder)) {
return std::nullopt;
}

try {
if (recursive) {
auto result = std::filesystem::create_directories(folder);
if (not result) {
return "an unknown error occurred";
}
return std::nullopt;
}


auto result = std::filesystem::create_directory(folder);
if (not result) {
return "an unknown error occurred";
}
return std::nullopt;
} catch (const std::exception& error) {
return error.what();
}
}

void utils::exit(int status_code) {
#if defined(__ANDROID__)
// calling exit() in android doesn't do the correct job, it completely avoids resource cleanup by the underlying SDLActivity.java
Expand Down
4 changes: 4 additions & 0 deletions src/helper/graphic_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "helper/constants.hpp"

#include <SDL.h>
#include <filesystem>
#include <spdlog/spdlog.h>

namespace utils {
Expand Down Expand Up @@ -34,6 +35,9 @@ namespace utils {
};


OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::optional<std::string>
create_directory(const std::filesystem::path& folder, bool recursive);

// this needs some special handling, so the macro is defined here
#if defined(_MSC_VER)
#if defined(OOPETRIS_LIBRARY_GRAPHICS_TYPE) && OOPETRIS_LIBRARY_GRAPHICS_TYPE == 0
Expand Down
37 changes: 20 additions & 17 deletions src/input/input_creator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "input_creator.hpp"

#include <fmt/format.h>
#include <spdlog/spdlog.h>
#include <stdexcept>

namespace {
Expand Down Expand Up @@ -123,32 +124,34 @@ input::get_game_parameters_for_replay(

const auto recording_directory_path = utils::get_root_folder() / constants::recordings_directory;

if (not std::filesystem::exists(recording_directory_path)) {
std::filesystem::create_directory(recording_directory_path);
}

const auto date_time_str = date.to_string();
auto dir_result = utils::create_directory(recording_directory_path, true);
if (not dir_result.has_value()) {

if (not date_time_str.has_value()) {
throw std::runtime_error{ fmt::format("Erro in date to string conversion: {}", date_time_str.error()) };
}
const auto date_time_str = date.to_string();

const auto filename = fmt::format("{}.{}", date_time_str.value(), constants::recording::extension);
const auto file_path = recording_directory_path / filename;
if (not date_time_str.has_value()) {
throw std::runtime_error{ fmt::format("Erro in date to string conversion: {}", date_time_str.error()) };
}

const auto filename = fmt::format("{}.{}", date_time_str.value(), constants::recording::extension);
const auto file_path = recording_directory_path / filename;

auto recording_writer_create_result =
recorder::RecordingWriter::get_writer(file_path, std::move(tetrion_headers), std::move(information));
if (not recording_writer_create_result.has_value()) {
throw std::runtime_error(recording_writer_create_result.error());
}

const auto recording_writer =
std::make_shared<recorder::RecordingWriter>(std::move(recording_writer_create_result.value()));
auto recording_writer_create_result =
recorder::RecordingWriter::get_writer(file_path, std::move(tetrion_headers), std::move(information));
if (not recording_writer_create_result.has_value()) {
throw std::runtime_error(recording_writer_create_result.error());
}

const auto recording_writer =
std::make_shared<recorder::RecordingWriter>(std::move(recording_writer_create_result.value()));

std::get<1>(result).recording_writer = recording_writer;

std::get<1>(result).recording_writer = recording_writer;
} else {
spdlog::warn("Couldn't create recordings folder {}: skipping creation of a recording", dir_result.value());
}

return result;
}
6 changes: 4 additions & 2 deletions src/manager/settings_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ SettingsManager::SettingsManager(ServiceProvider* service_provider) : m_service_
if (result.has_value()) {
m_settings = result.value();
} else {
spdlog::error("unable to load settings from \"{}\": {}", detail::settings_filename, result.error());
spdlog::warn("unable to load settings from \"{}\": {}", detail::settings_filename, result.error());
spdlog::warn("applying default settings");

m_settings = {
detail::Settings{ {}, std::nullopt, 1.0, false }
detail::Settings{ .controls = {}, .selected = std::nullopt, .volume = 1.0, .discord = false }
};

//TODO(Totto): save the file, if it doesn't exist, if it has an error, just leave it there
}
}

Expand Down
Loading