diff --git a/plugins/plugins_module.cc b/plugins/plugins_module.cc index af78c2bf89..7be14aa19d 100644 --- a/plugins/plugins_module.cc +++ b/plugins/plugins_module.cc @@ -32,14 +32,14 @@ class PluginManager { map plugin_libs_; }; -void PluginManager::LoadPlugins(fs::path plugins_dir) { +void PluginManager::LoadPlugins(path plugins_dir) { ModuleManager& mm = ModuleManager::instance(); if (!fs::is_directory(plugins_dir)) { return; } LOG(INFO) << "loading plugins from " << plugins_dir; for (fs::directory_iterator iter(plugins_dir), end; iter != end; ++iter) { - fs::path plugin_file = iter->path(); + path plugin_file = iter->path(); if (plugin_file.extension() == boost::dll::shared_library::suffix()) { fs::file_status plugin_file_status = fs::status(plugin_file); if (fs::is_regular_file(plugin_file_status)) { @@ -69,7 +69,7 @@ void PluginManager::LoadPlugins(fs::path plugins_dir) { } } -string PluginManager::plugin_name_of(fs::path plugin_file) { +string PluginManager::plugin_name_of(path plugin_file) { string name = plugin_file.stem().string(); // remove prefix "(lib)rime-" if (boost::starts_with(name, "librime-")) { diff --git a/src/rime/common.h b/src/rime/common.h index 0c7d637068..719c382dfc 100644 --- a/src/rime/common.h +++ b/src/rime/common.h @@ -9,6 +9,7 @@ #include +#include #include #include #include @@ -80,6 +81,12 @@ inline an New(Args&&... args) { using boost::signals2::connection; using boost::signals2::signal; +#ifdef _WIN32 +using path = std::filesystem::u8path; +#else +using std::filesystem::path; +#endif + } // namespace rime #endif // RIME_COMMON_H_ diff --git a/src/rime/config/save_output_plugin.cc b/src/rime/config/save_output_plugin.cc index 10d0b44541..727d8a9d5d 100644 --- a/src/rime/config/save_output_plugin.cc +++ b/src/rime/config/save_output_plugin.cc @@ -2,7 +2,6 @@ // Copyright RIME Developers // Distributed under the BSD License // -#include #include #include #include diff --git a/src/rime/deployer.cc b/src/rime/deployer.cc index 0386c1e0cc..8e8f03045c 100644 --- a/src/rime/deployer.cc +++ b/src/rime/deployer.cc @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include namespace rime { @@ -147,7 +147,7 @@ void Deployer::JoinMaintenanceThread() { } string Deployer::user_data_sync_dir() const { - return (std::filesystem::path(sync_dir) / user_id).string(); + return (path(sync_dir) / user_id).string(); } } // namespace rime diff --git a/src/rime/dict/dict_compiler.cc b/src/rime/dict/dict_compiler.cc index e6c374bad3..0899d561b1 100644 --- a/src/rime/dict/dict_compiler.cc +++ b/src/rime/dict/dict_compiler.cc @@ -22,8 +22,6 @@ #include #include -namespace fs = std::filesystem; - namespace rime { DictCompiler::DictCompiler(Dictionary* dictionary) @@ -39,7 +37,7 @@ DictCompiler::DictCompiler(Dictionary* dictionary) DictCompiler::~DictCompiler() {} static bool load_dict_settings_from_file(DictSettings* settings, - const fs::path& dict_file) { + const path& dict_file) { std::ifstream fin(dict_file.string().c_str()); bool success = settings->LoadDictHeader(fin); fin.close(); @@ -53,7 +51,7 @@ static bool get_dict_files_from_settings(vector* dict_files, for (auto it = tables->begin(); it != tables->end(); ++it) { string dict_name = As(*it)->str(); auto dict_file = source_resolver->ResolvePath(dict_name + ".dict.yaml"); - if (!fs::exists(dict_file)) { + if (!std::filesystem::exists(dict_file)) { LOG(ERROR) << "source file '" << dict_file << "' does not exist."; return false; } @@ -162,7 +160,7 @@ bool DictCompiler::Compile(const string& schema_file) { EntryCollector collector(std::move(syllabary)); DictSettings settings; auto dict_file = source_resolver_->ResolvePath(pack_name + ".dict.yaml"); - if (!fs::exists(dict_file)) { + if (!std::filesystem::exists(dict_file)) { LOG(ERROR) << "source file '" << dict_file << "' does not exist."; continue; } @@ -188,8 +186,8 @@ bool DictCompiler::Compile(const string& schema_file) { return true; } -static fs::path relocate_target(const fs::path& source_path, - ResourceResolver* target_resolver) { +static path relocate_target(const path& source_path, + ResourceResolver* target_resolver) { auto resource_id = source_path.filename().string(); return target_resolver->ResolvePath(resource_id); } @@ -208,7 +206,7 @@ bool DictCompiler::BuildTable(int table_index, collector.Configure(settings); collector.Collect(dict_files); if (options_ & kDump) { - fs::path dump_path(table->file_name()); + path dump_path(table->file_name()); dump_path.replace_extension(".txt"); collector.Dump(dump_path.string()); } @@ -313,7 +311,7 @@ bool DictCompiler::BuildPrism(const string& schema_file, bool enable_correction = false; // Avoid if initializer to comfort compilers if (config.GetBool("translator/enable_correction", &enable_correction) && enable_correction) { - fs::path corrector_path(prism_->file_name()); + path corrector_path(prism_->file_name()); corrector_path.replace_extension(""); corrector_path.replace_extension(".correction.bin"); auto target_path = relocate_target(corrector_path, @@ -331,9 +329,9 @@ bool DictCompiler::BuildPrism(const string& schema_file, #endif } if ((options_ & kDump) && !script.empty()) { - fs::path path(prism_->file_name()); - path.replace_extension(".txt"); - script.Dump(path.string()); + path dump_path(prism_->file_name()); + dump_path.replace_extension(".txt"); + script.Dump(dump_path.string()); } // build .prism.bin { diff --git a/src/rime/dict/level_db.cc b/src/rime/dict/level_db.cc index c3a753fa77..271eef3720 100644 --- a/src/rime/dict/level_db.cc +++ b/src/rime/dict/level_db.cc @@ -5,7 +5,6 @@ // 2014-12-04 Chen Gong // -#include #include #include #include diff --git a/src/rime/dict/preset_vocabulary.cc b/src/rime/dict/preset_vocabulary.cc index 4596621a1e..bf81f5ee75 100644 --- a/src/rime/dict/preset_vocabulary.cc +++ b/src/rime/dict/preset_vocabulary.cc @@ -4,7 +4,6 @@ // // 2011-11-27 GONG Chen // -#include #include #include #include diff --git a/src/rime/dict/reverse_lookup_dictionary.cc b/src/rime/dict/reverse_lookup_dictionary.cc index d87ab92e34..b21628c6cf 100644 --- a/src/rime/dict/reverse_lookup_dictionary.cc +++ b/src/rime/dict/reverse_lookup_dictionary.cc @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include diff --git a/src/rime/dict/user_db_recovery_task.cc b/src/rime/dict/user_db_recovery_task.cc index ab3c8ea29f..2278a94708 100644 --- a/src/rime/dict/user_db_recovery_task.cc +++ b/src/rime/dict/user_db_recovery_task.cc @@ -12,8 +12,6 @@ #include #include -namespace fs = std::filesystem; - namespace rime { UserDbRecoveryTask::UserDbRecoveryTask(an db) : db_(db) { @@ -65,15 +63,15 @@ void UserDbRecoveryTask::RestoreUserDataFromSnapshot(Deployer* deployer) { string dict_name(db_->name()); boost::erase_last(dict_name, component->extension()); // locate snapshot file - std::filesystem::path dir(deployer->user_data_sync_dir()); + path dir(deployer->user_data_sync_dir()); // try *.userdb.txt - fs::path snapshot_path = dir / (dict_name + UserDb::snapshot_extension()); - if (!fs::exists(snapshot_path)) { + path snapshot_path = dir / (dict_name + UserDb::snapshot_extension()); + if (!std::filesystem::exists(snapshot_path)) { // try *.userdb.*.snapshot string legacy_snapshot_file = dict_name + component->extension() + ".snapshot"; snapshot_path = dir / legacy_snapshot_file; - if (!fs::exists(snapshot_path)) { + if (!std::filesystem::exists(snapshot_path)) { return; // not found } } diff --git a/src/rime/gear/simplifier.cc b/src/rime/gear/simplifier.cc index a90f0c818f..7f3331441b 100644 --- a/src/rime/gear/simplifier.cc +++ b/src/rime/gear/simplifier.cc @@ -5,7 +5,6 @@ // 2011-12-12 GONG Chen // #include -#include #include #include #include @@ -25,11 +24,6 @@ #include #include -#ifdef _MSC_VER -#include -namespace fs = std::filesystem; -#endif - static const char* quote_left = "\xe3\x80\x94"; //"\xef\xbc\x88"; static const char* quote_right = "\xe3\x80\x95"; //"\xef\xbc\x89"; @@ -42,13 +36,9 @@ class Opencc { opencc::Config config; try { // windows config_path in CP_ACP, convert it to UTF-8 -#ifdef _MSC_VER - fs::path path{config_path}; - converter_ = - config.NewFromFile(opencc::UTF8Util::U16ToU8(path.wstring())); -#else + path path{config_path}; converter_ = config.NewFromFile(config_path); -#endif /* _MSC_VER */ + const list conversions = converter_->GetConversionChain()->GetConversions(); dict_ = conversions.front()->GetDict(); @@ -178,7 +168,6 @@ Simplifier::Simplifier(const Ticket& ticket) } void Simplifier::Initialize() { - using namespace std::filesystem; initialized_ = true; // no retry path opencc_config_path = opencc_config_; if (opencc_config_path.extension().string() == ".ini") { diff --git a/src/rime/lever/custom_settings.cc b/src/rime/lever/custom_settings.cc index b332a6c10a..c07dd2bf34 100644 --- a/src/rime/lever/custom_settings.cc +++ b/src/rime/lever/custom_settings.cc @@ -5,14 +5,11 @@ // 2012-02-26 GONG Chen // #include -#include #include #include #include #include -namespace fs = std::filesystem; - namespace rime { static string remove_suffix(const string& input, const string& suffix) { @@ -31,17 +28,15 @@ CustomSettings::CustomSettings(Deployer* deployer, : deployer_(deployer), config_id_(config_id), generator_id_(generator_id) {} bool CustomSettings::Load() { - fs::path config_path = - fs::path(deployer_->staging_dir) / (config_id_ + ".yaml"); + path config_path = path(deployer_->staging_dir) / (config_id_ + ".yaml"); if (!config_.LoadFromFile(config_path.string())) { - config_path = - fs::path(deployer_->prebuilt_data_dir) / (config_id_ + ".yaml"); + config_path = path(deployer_->prebuilt_data_dir) / (config_id_ + ".yaml"); if (!config_.LoadFromFile(config_path.string())) { LOG(WARNING) << "cannot find '" << config_id_ << ".yaml'."; } } - fs::path custom_config_path = - fs::path(deployer_->user_data_dir) / custom_config_file(config_id_); + path custom_config_path = + path(deployer_->user_data_dir) / custom_config_file(config_id_); if (!custom_config_.LoadFromFile(custom_config_path.string())) { return false; } @@ -54,7 +49,7 @@ bool CustomSettings::Save() { return false; Signature signature(generator_id_, "customization"); signature.Sign(&custom_config_, deployer_); - fs::path custom_config_path(deployer_->user_data_dir); + path custom_config_path(deployer_->user_data_dir); custom_config_path /= custom_config_file(config_id_); custom_config_.SaveToFile(custom_config_path.string()); modified_ = false; @@ -87,7 +82,7 @@ bool CustomSettings::Customize(const string& key, const an& item) { } bool CustomSettings::IsFirstRun() { - fs::path custom_config_path(deployer_->user_data_dir); + path custom_config_path(deployer_->user_data_dir); custom_config_path /= custom_config_file(config_id_); Config config; if (!config.LoadFromFile(custom_config_path.string())) diff --git a/src/rime/lever/customizer.cc b/src/rime/lever/customizer.cc index 32bd8a298f..f08fed61d5 100644 --- a/src/rime/lever/customizer.cc +++ b/src/rime/lever/customizer.cc @@ -4,6 +4,7 @@ // // 2011-12-12 GONG Chen // +#include #include #include #include @@ -60,7 +61,7 @@ bool Customizer::UpdateConfigFile() { } } - fs::path custom_path(dest_path_); + path custom_path(dest_path_); if (custom_path.extension() != ".yaml") { custom_path.clear(); } else { diff --git a/src/rime/lever/customizer.h b/src/rime/lever/customizer.h index 70fa3626af..5a6b76cb4f 100644 --- a/src/rime/lever/customizer.h +++ b/src/rime/lever/customizer.h @@ -5,14 +5,14 @@ #ifndef RIME_CUSTOMIZER_H_ #define RIME_CUSTOMIZER_H_ -#include +#include namespace rime { class Customizer { public: - Customizer(const std::filesystem::path& source_path, - const std::filesystem::path& dest_path, + Customizer(const path& source_path, + const path& dest_path, const string& version_key) : source_path_(source_path), dest_path_(dest_path), @@ -22,8 +22,8 @@ class Customizer { bool UpdateConfigFile(); protected: - std::filesystem::path source_path_; - std::filesystem::path dest_path_; + path source_path_; + path dest_path_; string version_key_; }; diff --git a/src/rime/lever/deployment_tasks.cc b/src/rime/lever/deployment_tasks.cc index 8b0e128061..9cad6df5c4 100644 --- a/src/rime/lever/deployment_tasks.cc +++ b/src/rime/lever/deployment_tasks.cc @@ -47,12 +47,12 @@ bool DetectModifications::Run(Deployer* deployer) { time_t last_modified = 0; try { for (auto dir : data_dirs_) { - fs::path p = fs::canonical(dir); + path p = fs::canonical(dir); last_modified = (std::max)(last_modified, filesystem::to_time_t(fs::last_write_time(p))); if (fs::is_directory(p)) { for (fs::directory_iterator iter(p), end; iter != end; ++iter) { - fs::path entry(iter->path()); + path entry(iter->path()); if (fs::is_regular_file(fs::canonical(entry)) && entry.extension().string() == ".yaml" && entry.filename().string() != "user.yaml") { @@ -83,8 +83,8 @@ bool DetectModifications::Run(Deployer* deployer) { bool InstallationUpdate::Run(Deployer* deployer) { LOG(INFO) << "updating rime installation info."; - const fs::path shared_data_path(deployer->shared_data_dir); - const fs::path user_data_path(deployer->user_data_dir); + const path shared_data_path(deployer->shared_data_dir); + const path user_data_path(deployer->user_data_dir); if (!fs::exists(user_data_path)) { LOG(INFO) << "creating user data dir: " << user_data_path.string(); std::error_code ec; @@ -92,7 +92,7 @@ bool InstallationUpdate::Run(Deployer* deployer) { LOG(ERROR) << "Error creating user data dir: " << user_data_path.string(); } } - fs::path installation_info(user_data_path / "installation.yaml"); + path installation_info(user_data_path / "installation.yaml"); Config config; string installation_id; string last_distro_code_name; @@ -109,7 +109,7 @@ bool InstallationUpdate::Run(Deployer* deployer) { if (config.GetString("sync_dir", &sync_dir)) { deployer->sync_dir = sync_dir; } else { - deployer->sync_dir = (fs::path(user_data_path) / "sync").string(); + deployer->sync_dir = (path(user_data_path) / "sync").string(); } LOG(INFO) << "sync dir: " << deployer->sync_dir; if (config.GetString("distribution_code_name", &last_distro_code_name)) { @@ -260,7 +260,7 @@ SchemaUpdate::SchemaUpdate(TaskInitializer arg) : verbose_(false) { } } -static bool MaybeCreateDirectory(fs::path dir) { +static bool MaybeCreateDirectory(path dir) { std::error_code ec; if (fs::create_directories(dir, ec)) { return true; @@ -282,10 +282,10 @@ static bool RemoveVersionSuffix(string* version, const string& suffix) { return false; } -static bool TrashDeprecatedUserCopy(const fs::path& shared_copy, - const fs::path& user_copy, +static bool TrashDeprecatedUserCopy(const path& shared_copy, + const path& user_copy, const string& version_key, - const fs::path& trash) { + const path& trash) { if (!fs::exists(shared_copy) || !fs::exists(user_copy) || fs::equivalent(shared_copy, user_copy)) { return false; @@ -311,7 +311,7 @@ static bool TrashDeprecatedUserCopy(const fs::path& shared_copy, if (!MaybeCreateDirectory(trash)) { return false; } - fs::path backup = trash / user_copy.filename(); + path backup = trash / user_copy.filename(); std::error_code ec; fs::rename(user_copy, backup, ec); if (ec) { @@ -324,7 +324,7 @@ static bool TrashDeprecatedUserCopy(const fs::path& shared_copy, } bool SchemaUpdate::Run(Deployer* deployer) { - fs::path source_path(schema_file_); + path source_path(schema_file_); if (!fs::exists(source_path)) { LOG(ERROR) << "Error updating schema: nonexistent file '" << schema_file_ << "'."; @@ -359,7 +359,7 @@ bool SchemaUpdate::Run(Deployer* deployer) { } LOG(INFO) << "preparing dictionary '" << dict_name << "'."; - const fs::path user_data_path(deployer->user_data_dir); + const path user_data_path(deployer->user_data_dir); if (!MaybeCreateDirectory(deployer->staging_dir)) { return false; } @@ -409,7 +409,7 @@ static bool ConfigNeedsUpdate(Config* config) { LOG(WARNING) << "invalid timestamp for " << entry.first; return true; } - fs::path source_file = resolver->ResolvePath(entry.first); + path source_file = resolver->ResolvePath(entry.first); if (!fs::exists(source_file)) { if (recorded_time) { LOG(INFO) << "source file no longer exists: " << source_file.string(); @@ -428,12 +428,12 @@ static bool ConfigNeedsUpdate(Config* config) { } bool ConfigFileUpdate::Run(Deployer* deployer) { - const fs::path shared_data_path(deployer->shared_data_dir); - const fs::path user_data_path(deployer->user_data_dir); + const path shared_data_path(deployer->shared_data_dir); + const path user_data_path(deployer->user_data_dir); // trash deprecated user copy created by an older version of Rime - fs::path source_config_path(shared_data_path / file_name_); - fs::path dest_config_path(user_data_path / file_name_); - fs::path trash = user_data_path / "trash"; + path source_config_path(shared_data_path / file_name_); + path dest_config_path(user_data_path / file_name_); + path trash = user_data_path / "trash"; if (TrashDeprecatedUserCopy(source_config_path, dest_config_path, version_key_, trash)) { LOG(INFO) << "deprecated user copy of '" << file_name_ << "' is moved to " @@ -451,14 +451,14 @@ bool ConfigFileUpdate::Run(Deployer* deployer) { } bool PrebuildAllSchemas::Run(Deployer* deployer) { - const fs::path shared_data_path(deployer->shared_data_dir); - const fs::path user_data_path(deployer->user_data_dir); + const path shared_data_path(deployer->shared_data_dir); + const path user_data_path(deployer->user_data_dir); if (!fs::exists(shared_data_path) || !fs::is_directory(shared_data_path)) return false; bool success = true; for (fs::directory_iterator iter(shared_data_path), end; iter != end; ++iter) { - fs::path entry(iter->path()); + path entry(iter->path()); if (boost::ends_with(entry.string(), ".schema.yaml")) { the t(new SchemaUpdate(entry.string())); if (!t->Run(deployer)) @@ -469,8 +469,8 @@ bool PrebuildAllSchemas::Run(Deployer* deployer) { } bool SymlinkingPrebuiltDictionaries::Run(Deployer* deployer) { - const fs::path shared_data_path(deployer->shared_data_dir); - const fs::path user_data_path(deployer->user_data_dir); + const path shared_data_path(deployer->shared_data_dir); + const path user_data_path(deployer->user_data_dir); if (!fs::exists(shared_data_path) || !fs::is_directory(shared_data_path) || !fs::exists(user_data_path) || !fs::is_directory(user_data_path) || fs::equivalent(shared_data_path, user_data_path)) @@ -478,7 +478,7 @@ bool SymlinkingPrebuiltDictionaries::Run(Deployer* deployer) { bool success = false; // remove symlinks to shared data files created by previous version for (fs::directory_iterator test(user_data_path), end; test != end; ++test) { - fs::path entry(test->path()); + path entry(test->path()); if (fs::is_symlink(entry)) { try { // a symlink becomes dangling if the target file is no longer provided @@ -538,16 +538,16 @@ static bool IsCustomizedCopy(const string& file_name) { bool BackupConfigFiles::Run(Deployer* deployer) { LOG(INFO) << "backing up config files."; - const fs::path user_data_path(deployer->user_data_dir); + const path user_data_path(deployer->user_data_dir); if (!fs::exists(user_data_path)) return false; - fs::path backup_dir(deployer->user_data_sync_dir()); + path backup_dir(deployer->user_data_sync_dir()); if (!MaybeCreateDirectory(backup_dir)) { return false; } int success = 0, failure = 0, latest = 0, skipped = 0; for (fs::directory_iterator iter(user_data_path), end; iter != end; ++iter) { - fs::path entry(iter->path()); + path entry(iter->path()); if (!fs::is_regular_file(entry)) continue; auto file_extension = entry.extension().string(); @@ -555,7 +555,7 @@ bool BackupConfigFiles::Run(Deployer* deployer) { bool is_text_file = file_extension == ".txt"; if (!is_yaml_file && !is_text_file) continue; - fs::path backup = backup_dir / entry.filename(); + path backup = backup_dir / entry.filename(); if (fs::exists(backup) && Checksum(backup.string()) == Checksum(entry.string())) { ++latest; // already up-to-date @@ -582,13 +582,13 @@ bool BackupConfigFiles::Run(Deployer* deployer) { bool CleanupTrash::Run(Deployer* deployer) { LOG(INFO) << "clean up trash."; - const fs::path user_data_path(deployer->user_data_dir); + const path user_data_path(deployer->user_data_dir); if (!fs::exists(user_data_path)) return false; - fs::path trash = user_data_path / "trash"; + path trash = user_data_path / "trash"; int success = 0, failure = 0; for (fs::directory_iterator iter(user_data_path), end; iter != end; ++iter) { - fs::path entry(iter->path()); + path entry(iter->path()); if (!fs::is_regular_file(entry)) continue; auto filename = entry.filename().string(); @@ -599,7 +599,7 @@ bool CleanupTrash::Run(Deployer* deployer) { if (!success && !MaybeCreateDirectory(trash)) { return false; } - fs::path backup = trash / entry.filename(); + path backup = trash / entry.filename(); std::error_code ec; fs::rename(entry, backup, ec); if (ec) { @@ -642,7 +642,7 @@ bool CleanOldLogFiles::Run(Deployer* deployer) { int removed = 0; for (const auto& dir : dirs) { - vector files; + vector files; DLOG(INFO) << "temp directory: " << dir; // preparing files for (const auto& entry : fs::directory_iterator(dir)) { diff --git a/src/rime/lever/switcher_settings.cc b/src/rime/lever/switcher_settings.cc index 39bbd96794..7cc4650667 100644 --- a/src/rime/lever/switcher_settings.cc +++ b/src/rime/lever/switcher_settings.cc @@ -47,7 +47,7 @@ bool SwitcherSettings::SetHotkeys(const string& hotkeys) { return false; } -void SwitcherSettings::GetAvailableSchemasFromDirectory(const fs::path& dir) { +void SwitcherSettings::GetAvailableSchemasFromDirectory(const path& dir) { if (!fs::exists(dir) || !fs::is_directory(dir)) { LOG(INFO) << "directory '" << dir.string() << "' does not exist."; return; diff --git a/src/rime/lever/switcher_settings.h b/src/rime/lever/switcher_settings.h index 8a61866b76..84ea902ba7 100644 --- a/src/rime/lever/switcher_settings.h +++ b/src/rime/lever/switcher_settings.h @@ -7,8 +7,8 @@ #ifndef RIME_SWITCHER_SETTINGS_H_ #define RIME_SWITCHER_SETTINGS_H_ -#include #include "custom_settings.h" +#include namespace rime { @@ -37,7 +37,7 @@ class SwitcherSettings : public CustomSettings { const string& hotkeys() const { return hotkeys_; } private: - void GetAvailableSchemasFromDirectory(const std::filesystem::path& dir); + void GetAvailableSchemasFromDirectory(const path& dir); void GetSelectedSchemasFromConfig(); void GetHotkeysFromConfig(); diff --git a/src/rime/lever/user_dict_manager.cc b/src/rime/lever/user_dict_manager.cc index 891aa4274d..c107eed644 100644 --- a/src/rime/lever/user_dict_manager.cc +++ b/src/rime/lever/user_dict_manager.cc @@ -59,9 +59,9 @@ bool UserDictManager::Backup(const string& dict_name) { return false; } } - std::filesystem::path dir(deployer_->user_data_sync_dir()); - if (!std::filesystem::exists(dir)) { - if (!std::filesystem::create_directories(dir)) { + path dir(deployer_->user_data_sync_dir()); + if (!fs::exists(dir)) { + if (!fs::create_directories(dir)) { LOG(ERROR) << "error creating directory '" << dir.string() << "'."; return false; } @@ -161,7 +161,7 @@ bool UserDictManager::UpgradeUserDict(const string& dict_name) { if (!legacy_db->OpenReadOnly() || !UserDbHelper(legacy_db).IsUserDb()) return false; LOG(INFO) << "upgrading user dict '" << dict_name << "'."; - fs::path trash = fs::path(deployer_->user_data_dir) / "trash"; + path trash = path(deployer_->user_data_dir) / "trash"; if (!fs::exists(trash)) { std::error_code ec; if (!fs::create_directories(trash, ec)) { @@ -170,7 +170,7 @@ bool UserDictManager::UpgradeUserDict(const string& dict_name) { } } string snapshot_file = dict_name + UserDb::snapshot_extension(); - fs::path snapshot_path = trash / snapshot_file; + path snapshot_path = trash / snapshot_file; return legacy_db->Backup(snapshot_path.string()) && legacy_db->Close() && legacy_db->Remove() && Restore(snapshot_path.string()); } @@ -178,7 +178,7 @@ bool UserDictManager::UpgradeUserDict(const string& dict_name) { bool UserDictManager::Synchronize(const string& dict_name) { LOG(INFO) << "synchronize user dict '" << dict_name << "'."; bool success = true; - fs::path sync_dir(deployer_->sync_dir); + path sync_dir(deployer_->sync_dir); if (!fs::exists(sync_dir)) { std::error_code ec; if (!fs::create_directories(sync_dir, ec)) { @@ -191,7 +191,7 @@ bool UserDictManager::Synchronize(const string& dict_name) { for (fs::directory_iterator it(sync_dir), end; it != end; ++it) { if (!fs::is_directory(it->path())) continue; - fs::path file_path = it->path() / snapshot_file; + path file_path = it->path() / snapshot_file; if (fs::exists(file_path)) { LOG(INFO) << "merging snapshot file: " << file_path.string(); if (!Restore(file_path.string())) { diff --git a/src/rime/lever/user_dict_manager.h b/src/rime/lever/user_dict_manager.h index 25e4647451..8028bf8c19 100644 --- a/src/rime/lever/user_dict_manager.h +++ b/src/rime/lever/user_dict_manager.h @@ -7,7 +7,7 @@ #ifndef RIME_USER_DICT_MANAGER_H_ #define RIME_USER_DICT_MANAGER_H_ -#include +#include #include namespace rime { @@ -38,7 +38,7 @@ class RIME_API UserDictManager { protected: Deployer* deployer_; - std::filesystem::path path_; + path path_; UserDb::Component* user_db_component_; }; diff --git a/src/rime/resource.cc b/src/rime/resource.cc index b44d8d8df9..f96d7c89f2 100644 --- a/src/rime/resource.cc +++ b/src/rime/resource.cc @@ -10,7 +10,7 @@ namespace rime { string ResourceResolver::ToResourceId(const string& file_path) const { - string path_string = std::filesystem::path(file_path).generic_string(); + string path_string = path(file_path).generic_string(); bool has_prefix = boost::starts_with(path_string, type_.prefix); bool has_suffix = boost::ends_with(path_string, type_.suffix); size_t start = (has_prefix ? type_.prefix.length() : 0); @@ -19,7 +19,7 @@ string ResourceResolver::ToResourceId(const string& file_path) const { } string ResourceResolver::ToFilePath(const string& resource_id) const { - std::filesystem::path file_path(resource_id); + path file_path(resource_id); bool missing_prefix = !file_path.has_parent_path() && !boost::starts_with(resource_id, type_.prefix); bool missing_suffix = !boost::ends_with(resource_id, type_.suffix); @@ -27,19 +27,16 @@ string ResourceResolver::ToFilePath(const string& resource_id) const { (missing_suffix ? type_.suffix : ""); } -std::filesystem::path ResourceResolver::ResolvePath(const string& resource_id) { +path ResourceResolver::ResolvePath(const string& resource_id) { return std::filesystem::absolute( - root_path_ / - std::filesystem::path(type_.prefix + resource_id + type_.suffix)); + root_path_ / path(type_.prefix + resource_id + type_.suffix)); } -std::filesystem::path FallbackResourceResolver::ResolvePath( - const string& resource_id) { +path FallbackResourceResolver::ResolvePath(const string& resource_id) { auto default_path = ResourceResolver::ResolvePath(resource_id); if (!std::filesystem::exists(default_path)) { auto fallback_path = std::filesystem::absolute( - fallback_root_path_ / - std::filesystem::path(type_.prefix + resource_id + type_.suffix)); + fallback_root_path_ / path(type_.prefix + resource_id + type_.suffix)); if (std::filesystem::exists(fallback_path)) { return fallback_path; } diff --git a/src/rime/resource.h b/src/rime/resource.h index 56ba738287..564abd67ca 100644 --- a/src/rime/resource.h +++ b/src/rime/resource.h @@ -6,7 +6,6 @@ #ifndef RIME_RESOURCE_H_ #define RIME_RESOURCE_H_ -#include #include #include @@ -24,17 +23,15 @@ class RIME_API ResourceResolver { public: explicit ResourceResolver(const ResourceType type) : type_(type) {} virtual ~ResourceResolver() {} - virtual std::filesystem::path ResolvePath(const string& resource_id); + virtual path ResolvePath(const string& resource_id); string ToResourceId(const string& file_path) const; string ToFilePath(const string& resource_id) const; - void set_root_path(std::filesystem::path root_path) { - root_path_ = root_path; - } - std::filesystem::path root_path() const { return root_path_; } + void set_root_path(path root_path) { root_path_ = root_path; } + path root_path() const { return root_path_; } protected: const ResourceType type_; - std::filesystem::path root_path_; + path root_path_; }; // try fallback path if target file doesn't exist in root path @@ -42,13 +39,13 @@ class RIME_API FallbackResourceResolver : public ResourceResolver { public: explicit FallbackResourceResolver(const ResourceType& type) : ResourceResolver(type) {} - std::filesystem::path ResolvePath(const string& resource_id) override; - void set_fallback_root_path(std::filesystem::path fallback_root_path) { + path ResolvePath(const string& resource_id) override; + void set_fallback_root_path(path fallback_root_path) { fallback_root_path_ = fallback_root_path; } private: - std::filesystem::path fallback_root_path_; + path fallback_root_path_; }; } // namespace rime diff --git a/src/rime/setup.cc b/src/rime/setup.cc index c387a35f93..7bb387be66 100644 --- a/src/rime/setup.cc +++ b/src/rime/setup.cc @@ -14,15 +14,12 @@ #include #endif // RIME_ENABLE_LOGGING -#include #include #include #include #include #include -namespace fs = std::filesystem; - namespace rime { #define Q(x) #x @@ -65,12 +62,11 @@ RIME_API void SetupDeployer(RimeTraits* traits) { deployer.prebuilt_data_dir = traits->prebuilt_data_dir; else deployer.prebuilt_data_dir = - (fs::path(deployer.shared_data_dir) / "build").string(); + (path(deployer.shared_data_dir) / "build").string(); if (PROVIDED(traits, staging_dir)) deployer.staging_dir = traits->staging_dir; else - deployer.staging_dir = - (fs::path(deployer.user_data_dir) / "build").string(); + deployer.staging_dir = (path(deployer.user_data_dir) / "build").string(); } RIME_API void SetupLogging(const char* app_name, diff --git a/test/resource_resolver_test.cc b/test/resource_resolver_test.cc index 18290d1baa..1b2ad92b8d 100644 --- a/test/resource_resolver_test.cc +++ b/test/resource_resolver_test.cc @@ -16,7 +16,7 @@ TEST(RimeResourceResolverTest, ResolvePath) { ResourceResolver rr(kMineralsType); rr.set_root_path("/starcraft"); auto actual = rr.ResolvePath("enough"); - fs::path expected = + path expected = fs::absolute(fs::current_path()).root_name().string() + "/starcraft/not_enough.minerals"; EXPECT_TRUE(actual.is_absolute()); @@ -28,7 +28,7 @@ TEST(RimeResourceResolverTest, FallbackRootPath) { rr.set_fallback_root_path("fallback"); fs::create_directory("fallback"); { - fs::path nonexistent_default = "not_present.minerals"; + path nonexistent_default = "not_present.minerals"; fs::remove(nonexistent_default); auto fallback = fs::absolute("fallback/not_present.minerals"); std::ofstream(fallback.string()).close(); diff --git a/tools/rime_deployer.cc b/tools/rime_deployer.cc index cf4c022da1..d03e52bf78 100644 --- a/tools/rime_deployer.cc +++ b/tools/rime_deployer.cc @@ -5,7 +5,6 @@ // 2012-07-07 GONG Chen // #include -#include #include #include #include @@ -13,8 +12,6 @@ #include #include "codepage.h" -namespace fs = std::filesystem; - using namespace rime; int add_schema(int count, char* schemas[]) { @@ -75,10 +72,10 @@ static void setup_deployer(Deployer* deployer, int argc, char* argv[]) { deployer->staging_dir = argv[2]; } else { deployer->staging_dir = - (fs::path(deployer->user_data_dir) / "build").string(); + (path(deployer->user_data_dir) / "build").string(); } deployer->prebuilt_data_dir = - (fs::path(deployer->shared_data_dir) / "build").string(); + (path(deployer->shared_data_dir) / "build").string(); } int main(int argc, char* argv[]) {