Skip to content

Commit 899cd57

Browse files
authored
Merge pull request #199 from OpenBrickProtocolFoundation/more_flatpak_fixes
More flatpak fixes
2 parents 74154d5 + f7c0a22 commit 899cd57

File tree

6 files changed

+69
-26
lines changed

6 files changed

+69
-26
lines changed

io.github.openbrickprotocolfoundation.oopetris.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
app-id: io.github.openbrickprotocolfoundation.oopetris
22
runtime: org.freedesktop.Platform
3-
runtime-version: "24.08"
3+
runtime-version: '24.08'
44
sdk: org.freedesktop.Sdk
55
command: oopetris
66
modules:
@@ -24,13 +24,14 @@ modules:
2424
- -Dbuild_installer=true
2525
- --libdir=lib
2626
- -Dtests=true
27+
- --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
2728
builddir: true
2829
build-options:
2930
build-args:
3031
- --share=network
3132
sources:
3233
- type: dir
33-
path: "."
34+
path: '.'
3435
skip:
3536
- .github/
3637
- .vscode/

src/executables/game/main.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ namespace {
3434
void initialize_spdlog() {
3535

3636
const auto logs_path = utils::get_root_folder() / "logs";
37-
if (not std::filesystem::exists(logs_path)) {
38-
std::filesystem::create_directory(logs_path);
37+
38+
auto created_log_dir = utils::create_directory(logs_path, true);
39+
if (created_log_dir.has_value()) {
40+
std::cerr << "warning: couldn't create logs directory '" << logs_path.string()
41+
<< "': disabled file logger\n";
3942
}
4043

4144
std::vector<spdlog::sink_ptr> sinks;
@@ -46,9 +49,13 @@ namespace {
4649
#else
4750
sinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_mt>());
4851
#endif
49-
sinks.push_back(std::make_shared<spdlog::sinks::rotating_file_sink_mt>(
50-
fmt::format("{}/oopetris.log", logs_path.string()), 1024 * 1024 * 10, 5, true
51-
));
52+
53+
if (not created_log_dir.has_value()) {
54+
sinks.push_back(std::make_shared<spdlog::sinks::rotating_file_sink_mt>(
55+
fmt::format("{}/oopetris.log", logs_path.string()), 1024 * 1024 * 10, 5, true
56+
));
57+
}
58+
5259
auto combined_logger = std::make_shared<spdlog::logger>("combined_logger", begin(sinks), end(sinks));
5360
spdlog::set_default_logger(combined_logger);
5461

src/helper/graphic_utils.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,32 @@ utils::ExitException::ExitException(int status_code) noexcept : m_status_code{ s
147147
return "An exit exception occurred";
148148
}
149149

150+
std::optional<std::string> utils::create_directory(const std::filesystem::path& folder, bool recursive) {
151+
152+
if (std::filesystem::exists(folder)) {
153+
return std::nullopt;
154+
}
155+
156+
try {
157+
if (recursive) {
158+
auto result = std::filesystem::create_directories(folder);
159+
if (not result) {
160+
return "an unknown error occurred";
161+
}
162+
return std::nullopt;
163+
}
164+
165+
166+
auto result = std::filesystem::create_directory(folder);
167+
if (not result) {
168+
return "an unknown error occurred";
169+
}
170+
return std::nullopt;
171+
} catch (const std::exception& error) {
172+
return error.what();
173+
}
174+
}
175+
150176
void utils::exit(int status_code) {
151177
#if defined(__ANDROID__)
152178
// calling exit() in android doesn't do the correct job, it completely avoids resource cleanup by the underlying SDLActivity.java

src/helper/graphic_utils.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "helper/constants.hpp"
88

99
#include <SDL.h>
10+
#include <filesystem>
1011
#include <spdlog/spdlog.h>
1112

1213
namespace utils {
@@ -34,6 +35,9 @@ namespace utils {
3435
};
3536

3637

38+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::optional<std::string>
39+
create_directory(const std::filesystem::path& folder, bool recursive);
40+
3741
// this needs some special handling, so the macro is defined here
3842
#if defined(_MSC_VER)
3943
#if defined(OOPETRIS_LIBRARY_GRAPHICS_TYPE) && OOPETRIS_LIBRARY_GRAPHICS_TYPE == 0

src/input/input_creator.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "input_creator.hpp"
1414

1515
#include <fmt/format.h>
16+
#include <spdlog/spdlog.h>
1617
#include <stdexcept>
1718

1819
namespace {
@@ -123,32 +124,34 @@ input::get_game_parameters_for_replay(
123124

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

126-
if (not std::filesystem::exists(recording_directory_path)) {
127-
std::filesystem::create_directory(recording_directory_path);
128-
}
129127

130-
const auto date_time_str = date.to_string();
128+
auto dir_result = utils::create_directory(recording_directory_path, true);
129+
if (not dir_result.has_value()) {
131130

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

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

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

140-
auto recording_writer_create_result =
141-
recorder::RecordingWriter::get_writer(file_path, std::move(tetrion_headers), std::move(information));
142-
if (not recording_writer_create_result.has_value()) {
143-
throw std::runtime_error(recording_writer_create_result.error());
144-
}
145140

146-
const auto recording_writer =
147-
std::make_shared<recorder::RecordingWriter>(std::move(recording_writer_create_result.value()));
141+
auto recording_writer_create_result =
142+
recorder::RecordingWriter::get_writer(file_path, std::move(tetrion_headers), std::move(information));
143+
if (not recording_writer_create_result.has_value()) {
144+
throw std::runtime_error(recording_writer_create_result.error());
145+
}
148146

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

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

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

153156
return result;
154157
}

src/manager/settings_manager.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ SettingsManager::SettingsManager(ServiceProvider* service_provider) : m_service_
1414
if (result.has_value()) {
1515
m_settings = result.value();
1616
} else {
17-
spdlog::error("unable to load settings from \"{}\": {}", detail::settings_filename, result.error());
17+
spdlog::warn("unable to load settings from \"{}\": {}", detail::settings_filename, result.error());
1818
spdlog::warn("applying default settings");
1919

2020
m_settings = {
21-
detail::Settings{ {}, std::nullopt, 1.0, false }
21+
detail::Settings{ .controls = {}, .selected = std::nullopt, .volume = 1.0, .discord = false }
2222
};
23+
24+
//TODO(Totto): save the file, if it doesn't exist, if it has an error, just leave it there
2325
}
2426
}
2527

0 commit comments

Comments
 (0)