From d2d28401bd1fca6111ac7a444c0f9e39204a3f0f Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sun, 8 Jan 2012 01:35:56 +0000 Subject: [PATCH] Change how local config mode works Rather than loading both the local and user config files and saving to the local directory if an option is set, simply try to load the local config file, and if it exists switch to local mode and never even touch the user file. Originally committed to SVN as r6244. --- aegisub/libaegisub/common/option.cpp | 5 --- .../libaegisub/include/libaegisub/option.h | 4 --- aegisub/src/libresrc/default_config.json | 1 - aegisub/src/main.cpp | 31 +++++++++---------- aegisub/tests/libaegisub_option.cpp | 16 ---------- 5 files changed, 15 insertions(+), 42 deletions(-) diff --git a/aegisub/libaegisub/common/option.cpp b/aegisub/libaegisub/common/option.cpp index 5371ffa02..4036fea6a 100644 --- a/aegisub/libaegisub/common/option.cpp +++ b/aegisub/libaegisub/common/option.cpp @@ -187,9 +187,4 @@ void Options::Flush() { json::Writer::Write(obj_out, io::Save(config_file).Get()); } -void Options::SetConfigPath(std::string const& new_path) { - config_file = new_path; - Flush(); -} - } // namespace agi diff --git a/aegisub/libaegisub/include/libaegisub/option.h b/aegisub/libaegisub/include/libaegisub/option.h index 091f86414..ea4c7ac81 100644 --- a/aegisub/libaegisub/include/libaegisub/option.h +++ b/aegisub/libaegisub/include/libaegisub/option.h @@ -106,10 +106,6 @@ public: /// Write the user configuration to disk, throws an exception if something goes wrong. void Flush(); - - /// Change where the configuration file should be saved to - /// @param new_path New location of the configuration file - void SetConfigPath(std::string const& new_path); }; } // namespace agi diff --git a/aegisub/src/libresrc/default_config.json b/aegisub/src/libresrc/default_config.json index 6aa57914f..d4902ebf1 100644 --- a/aegisub/src/libresrc/default_config.json +++ b/aegisub/src/libresrc/default_config.json @@ -9,7 +9,6 @@ }, "Call Tips" : false, "First Start" : true, - "Local Config" : false, "Locale" : -1, "Maximized" : false, "Save Charset" : "UTF-8", diff --git a/aegisub/src/main.cpp b/aegisub/src/main.cpp index 03777321f..558b40e55 100644 --- a/aegisub/src/main.cpp +++ b/aegisub/src/main.cpp @@ -79,9 +79,9 @@ #include namespace config { - agi::Options *opt; - agi::MRUManager *mru; - agi::Path *path; + agi::Options *opt = 0; + agi::MRUManager *mru = 0; + agi::Path *path = 0; } @@ -167,30 +167,29 @@ bool AegisubApp::OnInit() { // Set config file StartupLog("Load configuration"); - try { - config::opt = new agi::Options(STD_STR(StandardPaths::DecodePath("?user/config.json")), GET_DEFAULT_CONFIG(default_config)); - } catch (agi::Exception& e) { - LOG_E("config/init") << "Caught exception: " << e.GetName() << " -> " << e.GetMessage(); - } - #ifdef __WXMSW__ // Try loading configuration from the install dir if one exists there try { std::string conf_local(STD_STR(StandardPaths::DecodePath("?data/config.json"))); agi::scoped_ptr localConfig(agi::io::Open(conf_local)); - config::opt->ConfigNext(*localConfig); + config::opt = new agi::Options(conf_local, GET_DEFAULT_CONFIG(default_config)); - if (OPT_GET("App/Local Config")->GetBool()) { - // Local config, make ?user mean ?data so all user settings are placed in install dir - StandardPaths::SetPathValue("?user", StandardPaths::DecodePath("?data")); - StandardPaths::SetPathValue("?local", StandardPaths::DecodePath("?data")); - config::opt->SetConfigPath(conf_local); - } + // Local config, make ?user mean ?data so all user settings are placed in install dir + StandardPaths::SetPathValue("?user", StandardPaths::DecodePath("?data")); + StandardPaths::SetPathValue("?local", StandardPaths::DecodePath("?data")); } catch (agi::acs::AcsError const&) { // File doesn't exist or we can't read it // Might be worth displaying an error in the second case } #endif + + try { + if (!config::opt) + config::opt = new agi::Options(STD_STR(StandardPaths::DecodePath("?user/config.json")), GET_DEFAULT_CONFIG(default_config)); + } catch (agi::Exception& e) { + LOG_E("config/init") << "Caught exception: " << e.GetName() << " -> " << e.GetMessage(); + } + try { config::opt->ConfigUser(); } diff --git a/aegisub/tests/libaegisub_option.cpp b/aegisub/tests/libaegisub_option.cpp index e642881ed..6207e989b 100644 --- a/aegisub/tests/libaegisub_option.cpp +++ b/aegisub/tests/libaegisub_option.cpp @@ -261,19 +261,3 @@ TEST_F(lagi_option, empty_array_decays_to_first_used_type) { EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::OptionValueErrorInvalidListType); } } - -TEST_F(lagi_option, change_out_path) { - util::remove("data/options/tmp"); - util::remove("data/options/tmp2"); - - agi::Options opt("data/options/tmp", default_opt, agi::Options::FLUSH_SKIP); - ASSERT_NO_THROW(opt.SetConfigPath("data/options/tmp2")); - - std::ifstream flushed_opts("data/options/tmp2"); - ASSERT_TRUE(flushed_opts.good()); - - flushed_opts.seekg(0, std::ios::end); - EXPECT_GT(flushed_opts.tellg(), 0); - - EXPECT_FALSE(std::ifstream("data/options/tmp").good()); -}