Update to spice2x-25-04-25 (pre-apply)
> broken commit
This commit is contained in:
+39
-24
@@ -12,10 +12,21 @@ namespace cfg {
|
||||
|
||||
// globals
|
||||
std::unique_ptr<cfg::ScreenResize> SCREENRESIZE;
|
||||
std::optional<std::string> SCREEN_RESIZE_CFG_PATH_OVERRIDE;
|
||||
|
||||
ScreenResize::ScreenResize() {
|
||||
this->config_path = std::string(getenv("APPDATA")) + "\\spicetools_screen_resize.json";
|
||||
if (fileutils::file_exists(this->config_path)) {
|
||||
bool file_exists = false;
|
||||
if (SCREEN_RESIZE_CFG_PATH_OVERRIDE.has_value()) {
|
||||
this->config_path = SCREEN_RESIZE_CFG_PATH_OVERRIDE.value();
|
||||
if (fileutils::file_exists(this->config_path)) {
|
||||
log_info("ScreenResize", "loading config from: {}", this->config_path.string());
|
||||
file_exists = true;
|
||||
}
|
||||
} else {
|
||||
this->config_path =
|
||||
fileutils::get_config_file_path("ScreenResize", "spicetools_screen_resize.json", &file_exists);
|
||||
}
|
||||
if (file_exists) {
|
||||
this->config_load();
|
||||
}
|
||||
}
|
||||
@@ -24,10 +35,9 @@ namespace cfg {
|
||||
}
|
||||
|
||||
void ScreenResize::config_load() {
|
||||
log_info("ScreenResize", "loading config");
|
||||
|
||||
std::string config = fileutils::text_read(this->config_path);
|
||||
if (config.empty()) {
|
||||
log_info("ScreenResize", "config is empty");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -66,14 +76,18 @@ namespace cfg {
|
||||
eamuse_get_game(),
|
||||
use_game_setting,
|
||||
root);
|
||||
load_int_value(doc, root + "offset_x", this->offset_x);
|
||||
load_int_value(doc, root + "offset_y", this->offset_y);
|
||||
load_float_value(doc, root + "scale_x", this->scale_x);
|
||||
load_float_value(doc, root + "scale_y", this->scale_y);
|
||||
|
||||
load_bool_value(doc, root + "enable_screen_resize", this->enable_screen_resize);
|
||||
load_bool_value(doc, root + "enable_linear_filter", this->enable_linear_filter);
|
||||
load_bool_value(doc, root + "keep_aspect_ratio", this->keep_aspect_ratio);
|
||||
load_bool_value(doc, root + "centered", this->centered);
|
||||
for (size_t i = 0; i < std::size(this->scene_settings); i++) {
|
||||
auto& scene = this->scene_settings[i];
|
||||
const std::string prefix = fmt::format("scenes/{}/", i);
|
||||
load_int_value(doc, root + prefix + "offset_x", scene.offset_x);
|
||||
load_int_value(doc, root + prefix + "offset_y", scene.offset_y);
|
||||
load_float_value(doc, root + prefix + "scale_x", scene.scale_x);
|
||||
load_float_value(doc, root + prefix + "scale_y", scene.scale_y);
|
||||
load_bool_value(doc, root + prefix + "keep_aspect_ratio", scene.keep_aspect_ratio);
|
||||
}
|
||||
|
||||
// windowed settings are always under game settings
|
||||
root = "/sp2x_games/" + eamuse_get_game() + "/";
|
||||
@@ -95,7 +109,7 @@ namespace cfg {
|
||||
bool ScreenResize::load_bool_value(rapidjson::Document& doc, std::string path, bool& value) {
|
||||
const auto v = rapidjson::Pointer(path).Get(doc);
|
||||
if (!v) {
|
||||
log_warning("ScreenResize", "{} not found", path);
|
||||
log_misc("ScreenResize", "{} not found", path);
|
||||
return false;
|
||||
}
|
||||
if (!v->IsBool()) {
|
||||
@@ -109,7 +123,7 @@ namespace cfg {
|
||||
bool ScreenResize::load_int_value(rapidjson::Document& doc, std::string path, int& value) {
|
||||
const auto v = rapidjson::Pointer(path).Get(doc);
|
||||
if (!v) {
|
||||
log_warning("ScreenResize", "{} not found", path);
|
||||
log_misc("ScreenResize", "{} not found", path);
|
||||
return false;
|
||||
}
|
||||
if (!v->IsInt()) {
|
||||
@@ -123,7 +137,7 @@ namespace cfg {
|
||||
bool ScreenResize::load_uint32_value(rapidjson::Document& doc, std::string path, uint32_t& value) {
|
||||
const auto v = rapidjson::Pointer(path).Get(doc);
|
||||
if (!v) {
|
||||
log_warning("ScreenResize", "{} not found", path);
|
||||
log_misc("ScreenResize", "{} not found", path);
|
||||
return false;
|
||||
}
|
||||
if (!v->IsUint()) {
|
||||
@@ -137,7 +151,7 @@ namespace cfg {
|
||||
bool ScreenResize::load_float_value(rapidjson::Document& doc, std::string path, float& value) {
|
||||
const auto v = rapidjson::Pointer(path).Get(doc);
|
||||
if (!v) {
|
||||
log_warning("ScreenResize", "{} not found", path);
|
||||
log_misc("ScreenResize", "{} not found", path);
|
||||
return false;
|
||||
}
|
||||
if (v->IsInt()) {
|
||||
@@ -156,8 +170,6 @@ namespace cfg {
|
||||
}
|
||||
|
||||
void ScreenResize::config_save() {
|
||||
log_info("ScreenResize", "saving config");
|
||||
|
||||
rapidjson::Document doc;
|
||||
std::string config = fileutils::text_read(this->config_path);
|
||||
if (!config.empty()) {
|
||||
@@ -179,14 +191,17 @@ namespace cfg {
|
||||
root);
|
||||
|
||||
// full screen image settings
|
||||
rapidjson::Pointer(root + "offset_x").Set(doc, this->offset_x);
|
||||
rapidjson::Pointer(root + "offset_y").Set(doc, this->offset_y);
|
||||
rapidjson::Pointer(root + "scale_x").Set(doc, this->scale_x);
|
||||
rapidjson::Pointer(root + "scale_y").Set(doc, this->scale_y);
|
||||
rapidjson::Pointer(root + "enable_screen_resize").Set(doc, this->enable_screen_resize);
|
||||
rapidjson::Pointer(root + "enable_linear_filter").Set(doc, this->enable_linear_filter);
|
||||
rapidjson::Pointer(root + "keep_aspect_ratio").Set(doc, this->keep_aspect_ratio);
|
||||
rapidjson::Pointer(root + "centered").Set(doc, this->centered);
|
||||
for (size_t i = 0; i < std::size(this->scene_settings); i++) {
|
||||
auto& scene = this->scene_settings[i];
|
||||
const std::string prefix = fmt::format("scenes/{}/", i);
|
||||
rapidjson::Pointer(root + prefix + "offset_x").Set(doc, scene.offset_x);
|
||||
rapidjson::Pointer(root + prefix + "offset_y").Set(doc, scene.offset_y);
|
||||
rapidjson::Pointer(root + prefix + "scale_x").Set(doc, scene.scale_x);
|
||||
rapidjson::Pointer(root + prefix + "scale_y").Set(doc, scene.scale_y);
|
||||
rapidjson::Pointer(root + prefix + "keep_aspect_ratio").Set(doc, scene.keep_aspect_ratio);
|
||||
}
|
||||
|
||||
// windowed mode settings
|
||||
rapidjson::Pointer(root + "w_always_on_top").Set(doc, this->window_always_on_top);
|
||||
@@ -204,10 +219,10 @@ namespace cfg {
|
||||
doc.Accept(writer);
|
||||
|
||||
// save to file
|
||||
if (fileutils::text_write(this->config_path, buffer.GetString())) {
|
||||
if (fileutils::write_config_file("ScreenResize", this->config_path, buffer.GetString())) {
|
||||
// this->config_dirty = false;
|
||||
} else {
|
||||
log_warning("ScreenResize", "unable to save config file to {}", this->config_path);
|
||||
log_warning("ScreenResize", "unable to save config file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user