私は国際的なプラグインに取り組んでおり、UTF-16 文字列で問題が発生しました。FB::FactoryBase::GetLoggingMethods を使用して %APPDATA% にログを保存しようとしています。現在、次のように定義されています。
void getLoggingMethods(FB::Log::LogMethodList& outMethods) {
try {
boost::filesystem::path appDataPath = FB::System::getLocalAppDataPath("AppName");
boost::filesystem::path logDirPath = appDataPath / "Logs";
if(!exists(logDirPath)) {
// create the directory
boost::filesystem::create_directories(logDirPath);
}
if (exists(logDirPath) && is_directory(logDirPath)) {
boost::filesystem::path logPath = logDirPath / "app_name.log";
outMethods.push_back(std::make_pair(FB::Log::LogMethod_File, logPath.string()));
}
} catch(...) { /* safely fail here */ }
}
この問題は、ユーザーのユーザー名に UTF-16 文字が含まれている場合に発生します。これは例外をスローします。
ただし、for 入力outMethods.push_back
が必要です。からにstd::string
変換すると、その UTF-16 文字が失われます (パスが無効になります)。std::wstring
std::string
何か案は?
編集:boost::filesystem::path にコンストラクターの LPCWSTR を指定することで、何とか動作させることができました。
boost::filesystem::path appDataPath =
FB::utf8_to_wstring(FB::System::getLocalAppDataPath("AppName")).c_str();
boost::filesystem::path logDirPath = appDataPath / "Logs";
if(!exists(logDirPath)) {
// create the directory
boost::filesystem::create_directories(logDirPath);
}
if (exists(logDirPath) && is_directory(logDirPath)) {
boost::filesystem::path logPath = logDirPath / "app_name.log";
outMethods.push_back(
std::make_pair(
FB::Log::LogMethod_File, FB::wstring_to_utf8(logPath.wstring())
)
);
}