diff --git a/src/rime/config/plugins.h b/src/rime/config/plugins.h index 36691fcfe..7d965a918 100644 --- a/src/rime/config/plugins.h +++ b/src/rime/config/plugins.h @@ -51,6 +51,21 @@ class BuildInfoPlugin : public ConfigCompilerPlugin { Review ReviewLinkOutput; }; +class ResourceResolver; +struct ResourceType; + +class SaveOutputPlugin : public ConfigCompilerPlugin { + public: + SaveOutputPlugin(const ResourceType& output_resource); + ~SaveOutputPlugin(); + + Review ReviewCompileOutput; + Review ReviewLinkOutput; + + private: + the resource_resolver_; +}; + } // namespace rime #endif // RIME_CONFIG_PLUGINS_H_ diff --git a/src/rime/config/save_output_plugin.cc b/src/rime/config/save_output_plugin.cc new file mode 100644 index 000000000..d559a4f17 --- /dev/null +++ b/src/rime/config/save_output_plugin.cc @@ -0,0 +1,33 @@ +// +// Copyright RIME Developers +// Distributed under the BSD License +// +#include +#include +#include +#include +#include +#include + +namespace rime { + +SaveOutputPlugin::SaveOutputPlugin(const ResourceType& output_resource) + : resource_resolver_(new ResourceResolver(output_resource)) { + resource_resolver_->set_root_path( + Service::instance().deployer().user_data_dir); +} + +SaveOutputPlugin::~SaveOutputPlugin() {} + +bool SaveOutputPlugin::ReviewCompileOutput( + ConfigCompiler* compiler, an resource) { + return true; +} + +bool SaveOutputPlugin::ReviewLinkOutput( + ConfigCompiler* compiler, an resource) { + auto file_path = resource_resolver_->ResolvePath(resource->resource_id); + return resource->data->SaveToFile(file_path.string()); +} + +} // namespace rime diff --git a/src/rime/core_module.cc b/src/rime/core_module.cc index 382753189..175d23ea7 100644 --- a/src/rime/core_module.cc +++ b/src/rime/core_module.cc @@ -20,20 +20,21 @@ static void rime_core_initialize() { LOG(INFO) << "registering core components."; Registry& r = Registry::instance(); + const ResourceType build_output{"config", "build/", ".yaml"}; auto config_builder = new ConfigComponent( - [](ConfigBuilder* builder) { + [&](ConfigBuilder* builder) { builder->InstallPlugin(new AutoPatchConfigPlugin); builder->InstallPlugin(new DefaultConfigPlugin); builder->InstallPlugin(new LegacyPresetConfigPlugin); builder->InstallPlugin(new LegacyDictionaryConfigPlugin); builder->InstallPlugin(new BuildInfoPlugin); + builder->InstallPlugin(new SaveOutputPlugin(build_output)); }); r.Register("config_builder", config_builder); - //auto config_loader = - // new ConfigComponent({"config", "build/", ".yaml"}); - r.Register("config", config_builder); - r.Register("schema", new SchemaComponent(config_builder)); + auto config_loader = new ConfigComponent(build_output); + r.Register("config", config_loader); + r.Register("schema", new SchemaComponent(config_loader)); auto user_config = new ConfigComponent( [](ConfigLoader* loader) {