forked from rime/librime
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(path): convert to native encoding on Windows
Follow @fxliang 's PR, use `u8path` on Windows to convert UTF-8 string to Windows native path. Closes rime#804 Fixes rime/weasel#576 Fixes rime/weasel#1080 BREAKING CHANGE: `installation.yaml` should be UTF-8 encoded. Previouly on Windows, the file can be written in local encoding to enable paths with non-ASCII characters. It should be updated to UTF-8 after this change.
- Loading branch information
Showing
23 changed files
with
124 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
// 2014-12-04 Chen Gong <[email protected]> | ||
// | ||
|
||
#include <filesystem> | ||
#include <leveldb/db.h> | ||
#include <leveldb/write_batch.h> | ||
#include <rime/common.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
// | ||
// 2011-11-27 GONG Chen <[email protected]> | ||
// | ||
#include <filesystem> | ||
#include <utf8.h> | ||
#include <rime/resource.h> | ||
#include <rime/service.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
// 2011-12-12 GONG Chen <[email protected]> | ||
// | ||
#include <boost/algorithm/string.hpp> | ||
#include <filesystem> | ||
#include <stdint.h> | ||
#include <utf8.h> | ||
#include <utility> | ||
|
@@ -25,11 +24,6 @@ | |
#include <opencc/Dict.hpp> | ||
#include <opencc/DictEntry.hpp> | ||
|
||
#ifdef _MSC_VER | ||
#include <opencc/UTF8Util.hpp> | ||
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<opencc::ConversionPtr> 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") { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,11 @@ | |
// 2012-02-26 GONG Chen <[email protected]> | ||
// | ||
#include <boost/algorithm/string.hpp> | ||
#include <filesystem> | ||
#include <rime/config.h> | ||
#include <rime/deployer.h> | ||
#include <rime/signature.h> | ||
#include <rime/lever/custom_settings.h> | ||
|
||
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<ConfigItem>& 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())) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
// | ||
// 2011-12-12 GONG Chen <[email protected]> | ||
// | ||
#include <filesystem> | ||
#include <stdint.h> | ||
#include <rime/common.h> | ||
#include <rime/config.h> | ||
|
@@ -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 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.