From 77aa52c7794fab1f987c127b1540843d4501de70 Mon Sep 17 00:00:00 2001 From: Yimura Date: Sat, 24 Jul 2021 15:27:41 +0200 Subject: [PATCH] feat(Globals): Made settings save location const --- BigBaseV2.lnk | Bin 2226 -> 2091 bytes BigBaseV2/src/core/globals.hpp | 28 +++++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/BigBaseV2.lnk b/BigBaseV2.lnk index f7d339d739733e4dbea0b4852b11722d2e65d09b..0a51d5fb059a3f0b3f4d826b5609ca6f19adf112 100644 GIT binary patch delta 737 zcmdlaxLRO>NPRaG2ZI0u1B3nAob5AeuQOiUuvTj(kp3_7loLdQC4uscK#U9u7_AuO zUEHOZBa7^pyL286o%%1^;GG&!of^aYeIOGZUH`=EmRx6K-OB7x1T;y1dU+Vg1`&oP zh7txD24}ZmH?evKL$IkYf)30QVsI=da7ipl1d5bMMaE6Lf7zoqUEFxjJB?jO&;GhU zKRwK`)BWi2>;v2C9T+$nSb!G22--38OOVkdJ)j;xut}m|5U04H zCr@`L$KX1kUtFLL1DX3JNPRlU1ZzJ~=!u}2z-Xk$=){o8kPdWCB117lD$r3zKs6FT z91g@XKn&6cqIH271j2w=5Qv$9Se|>fh=34~!QgBa6Iz^FR2-9-mr|5Ec@~q5pb~=~ z5XKYaglivLt0Ym+~6NIK64)# zd!`)}V%hbA-8A*(Yr!?&ctS*v>Ln18pB%=f%cwZHg-u;Hks*&Eg`o)OwHUNG&}3kk ze1h#h+s_4{R5y7oyE!{F#Z7+At|bqYW^iV(0%{8dhfEQWi~)uc)HtALtS9GlsLQ0y Y{&4Ff*Gi`?+n?wy)?sV|dk9JZ0GbuRp8x;= delta 864 zcmZ22ut{)&NJuji2ZI0u1H-XRFFmJOTxC@ERf;MrM9^SKpgbcGBLik85eE5y2mTin zURh-dEV{wLplx6B*(zpoBa?7_1%n}2{TshD4?%{|;?$yIh7<-)1{Q|*``-BZ zr-8)vfGXsfLCTt#z>0x{6_`<1b)6xUp_n0+p$JGaFgO6o3?MHD2#pzx81#T zxUZ*VcXAA_0|vVb++n4@AUTi;TVH|#S`5vEo5J%apJx~Kl>myT0U+LM1W%G85Y0fTpe6p&sD zG!kSYH;{k3b(`JK)NeiutRBBlEt+o&l1l)}0Zm^J0i;2o2pnm;DXGQTCHVym3<^Ka zr2pQx*JFxFqI=d|1F=a9-p^=W@=~yAMnUT#ixyKX^1LVtHb*mwFi$?us>`S}`7f(F zH&Xmg)@75N?7?<}E!x`)m;olMv756)Gr{B(b}eQt28PLkY{Dp7*0Nhqe#NdTqk69W V>WzYazXn$qM+fiy<`CCINC1Vs%ijP1 diff --git a/BigBaseV2/src/core/globals.hpp b/BigBaseV2/src/core/globals.hpp index d3cd08d4..7dbdd728 100644 --- a/BigBaseV2/src/core/globals.hpp +++ b/BigBaseV2/src/core/globals.hpp @@ -119,12 +119,9 @@ struct globals { void attempt_save() { nlohmann::json& j = this->to_json(); - if (j != this->options) - { - this->save(); - this->options = j; - } + if (deep_compare(this->options, j)) + this->save(); } bool load() @@ -132,7 +129,7 @@ struct globals { this->default_options = this->to_json(); std::string settings_file = std::getenv("appdata"); - settings_file += "\\BigBaseV2\\settings.json"; + settings_file += this->settings_location; std::ifstream file(settings_file); @@ -143,7 +140,18 @@ struct globals { file.open(settings_file); } - file >> this->options; + try + { + file >> this->options; + } + catch (const std::exception&) + { + LOG(WARNING) << "Detected corrupt settings, writing default config..."; + + this->write_default_config(); + + return this->load(); + } bool should_save = this->deep_compare(this->options, this->default_options); @@ -159,6 +167,8 @@ struct globals { } private: + const char* settings_location = "\\BigBaseV2\\settings.json"; + bool deep_compare(nlohmann::json& current_settings, const nlohmann::json& default_settings) { bool should_save = false; @@ -191,7 +201,7 @@ private: bool save() { std::string settings_file = std::getenv("appdata"); - settings_file += "\\BigBaseV2\\settings.json"; + settings_file += this->settings_location; std::ofstream file(settings_file, std::ios::out | std::ios::trunc); file << this->to_json().dump(4); @@ -203,7 +213,7 @@ private: bool write_default_config() { std::string settings_file = std::getenv("appdata"); - settings_file += "\\BigBaseV2\\settings.json"; + settings_file += this->settings_location; std::ofstream file(settings_file, std::ios::out); file << this->to_json().dump(4);