fix config tox profile path relative to config and load plugins from
Some checks failed
ContinuousDelivery / windows (push) Waiting to run
ContinuousDelivery / windows-asan (push) Waiting to run
ContinuousDelivery / release (push) Blocked by required conditions
ContinuousIntegration / linux (push) Waiting to run
ContinuousIntegration / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Waiting to run
ContinuousIntegration / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Waiting to run
ContinuousIntegration / macos (push) Waiting to run
ContinuousIntegration / windows (push) Waiting to run
ContinuousDelivery / linux-ubuntu (push) Failing after 5m19s
ContinuousDelivery / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Failing after 6m35s
ContinuousDelivery / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Has been cancelled

config and skip setup screen option
This commit is contained in:
Green Sky 2024-08-10 11:46:29 +02:00
parent b133c5f79f
commit f9c9eefb40
No known key found for this signature in database

View File

@ -15,15 +15,21 @@
#include <fstream>
StartScreen::StartScreen(const std::vector<std::string_view>& args, SDL_Renderer* renderer, Theme& theme) : _renderer(renderer), _theme(theme) {
bool config_loaded {false};
std::string config_path;
for (size_t ai = 1; ai < args.size(); ai++) {
if (args.at(ai) == "--config" || args.at(ai) == "-c") {
if (config_loaded) {
std::cerr << "TOMATO error: config specified more than once!\n";
break;
}
if (args.size() == ai+1) {
std::cerr << "TOMATO error: argument '" << args.at(ai) << "' missing parameter!\n";
break;
}
ai++;
const auto& config_path = args.at(ai);
config_path = args.at(ai);
auto config_file = std::ifstream(static_cast<std::string>(config_path));
if (!config_file.is_open()) {
std::cerr << "TOMATO error: failed to open config file '" << config_path << "'\n";
@ -35,6 +41,7 @@ StartScreen::StartScreen(const std::vector<std::string_view>& args, SDL_Renderer
std::cerr << "TOMATO error in config json, exiting...\n";
break;
}
config_loaded = true;
} else if (args.at(ai) == "--plugin" || args.at(ai) == "-p") {
if (args.size() == ai+1) {
std::cerr << "TOMATO error: argument '" << args.at(ai) << "' missing parameter!\n";
@ -50,10 +57,14 @@ StartScreen::StartScreen(const std::vector<std::string_view>& args, SDL_Renderer
}
}
{ // seed tox save path
if (_conf.has_string("tox", "save_file_path")) {
_tox_profile_path = _conf.get_string("tox", "save_file_path").value();
// seed tox save path
if (_conf.has_string("tox", "save_file_path")) {
const auto config_path_base = std::filesystem::path{config_path}.parent_path();
std::filesystem::path real_tox_profile_path = static_cast<std::string>(_conf.get_string("tox", "save_file_path").value());
if (real_tox_profile_path.is_relative()) {
real_tox_profile_path = config_path_base / real_tox_profile_path;
}
_tox_profile_path = real_tox_profile_path.u8string();
}
float display_scale = SDL_GetWindowDisplayScale(SDL_GetRenderWindow(renderer));
@ -137,6 +148,23 @@ StartScreen::StartScreen(const std::vector<std::string_view>& args, SDL_Renderer
font_atlas->Build();
}
if (config_loaded) { // pull plugins from config
const auto config_path_base = std::filesystem::path{config_path}.parent_path();
for (const auto& [plugin_path, autoload] : _conf.entries_bool("PluginManager", "autoload")) {
if (!autoload) {
continue;
}
std::filesystem::path real_plugin_path = plugin_path;
if (real_plugin_path.is_relative()) {
real_plugin_path = config_path_base / real_plugin_path;
}
queued_plugin_paths.push_back(real_plugin_path.u8string());
}
}
}
Screen* StartScreen::render(float, bool&) {
@ -281,7 +309,14 @@ Screen* StartScreen::render(float, bool&) {
_fss.render();
return nullptr;
// TODO: dont check every frame
// do in tick instead?
if (_conf.get_bool("tomato", "skip_setup_and_load").value_or(false)) {
auto new_screen = std::make_unique<MainScreen>(std::move(_conf), _renderer, _theme, _tox_profile_path, _password, _user_name, queued_plugin_paths);
return new_screen.release();
} else {
return nullptr;
}
}
Screen* StartScreen::tick(float, bool&) {