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.
This commit is contained in:
Thomas Goyne 2012-01-08 01:35:56 +00:00
parent ae62cb75b4
commit d2d28401bd
5 changed files with 15 additions and 42 deletions

View file

@ -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

View file

@ -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

View file

@ -9,7 +9,6 @@
},
"Call Tips" : false,
"First Start" : true,
"Local Config" : false,
"Locale" : -1,
"Maximized" : false,
"Save Charset" : "UTF-8",

View file

@ -79,9 +79,9 @@
#include <libaegisub/scoped_ptr.h>
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<std::istream> 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();
}

View file

@ -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());
}