Skip to content

Commit

Permalink
fix(custom_settings): accept "*.schema" as config id
Browse files Browse the repository at this point in the history
  • Loading branch information
lotem committed Nov 2, 2019
1 parent fd37cf6 commit 604da0b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/rime/lever/custom_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ namespace fs = boost::filesystem;

namespace rime {

static string remove_suffix(const string& input, const string& suffix) {
return boost::ends_with(input, suffix) ?
input.substr(0, input.length() - suffix.length()) : input;
}

static string custom_config_file(const string& config_id) {
return remove_suffix(config_id, ".schema") + ".custom.yaml";
}

CustomSettings::CustomSettings(Deployer* deployer,
const string& config_id,
const string& generator_id)
Expand All @@ -34,7 +43,7 @@ bool CustomSettings::Load() {
return false;
}
}
fs::path custom_config_path(user_data_path / (config_id_ + ".custom.yaml"));
fs::path custom_config_path(user_data_path / custom_config_file(config_id_));
custom_config_.LoadFromFile(custom_config_path.string());
modified_ = false;
return true;
Expand All @@ -46,7 +55,7 @@ bool CustomSettings::Save() {
Signature signature(generator_id_, "customization");
signature.Sign(&custom_config_, deployer_);
fs::path custom_config_path(deployer_->user_data_dir);
custom_config_path /= config_id_ + ".custom.yaml";
custom_config_path /= custom_config_file(config_id_);
custom_config_.SaveToFile(custom_config_path.string());
modified_ = false;
return true;
Expand Down Expand Up @@ -80,7 +89,7 @@ bool CustomSettings::Customize(const string& key,

bool CustomSettings::IsFirstRun() {
fs::path custom_config_path(deployer_->user_data_dir);
custom_config_path /= config_id_ + ".custom.yaml";
custom_config_path /= custom_config_file(config_id_);
Config config;
if (!config.LoadFromFile(custom_config_path.string()))
return true;
Expand Down

0 comments on commit 604da0b

Please sign in to comment.