From 4a4a0cbd1565fbe947c941f945c82dce19fa9ea5 Mon Sep 17 00:00:00 2001 From: Prcuvu Date: Thu, 30 Aug 2018 17:28:23 +0800 Subject: [PATCH] chore: remove Boost.Filesystem dependency --- WeaselDeployer/DictManagementDialog.cpp | 13 ++--- WeaselDeployer/UIStyleSettings.cpp | 6 +-- WeaselIME/WeaselIME.cpp | 8 +-- WeaselIME/stdafx.h | 8 --- WeaselIPC/stdafx.h | 2 - WeaselSetup/imesetup.cpp | 70 ++++++++++++------------- WeaselTSF/stdafx.h | 4 -- include/PipeChannel.h | 2 +- 8 files changed, 50 insertions(+), 63 deletions(-) diff --git a/WeaselDeployer/DictManagementDialog.cpp b/WeaselDeployer/DictManagementDialog.cpp index 23e92f7c9..b220e8fa6 100644 --- a/WeaselDeployer/DictManagementDialog.cpp +++ b/WeaselDeployer/DictManagementDialog.cpp @@ -53,7 +53,7 @@ LRESULT DictManagementDialog::OnBackup(WORD, WORD code, HWND, BOOL&) { MessageBox(L"請在左列選擇要導出的詞典名稱。", L":-(", MB_OK | MB_ICONINFORMATION); return 0; } - boost::filesystem::wpath path; + std::wstring path; { char dir[MAX_PATH] = {0}; rime_get_api()->get_user_data_sync_dir(dir, _countof(dir)); @@ -61,23 +61,24 @@ LRESULT DictManagementDialog::OnBackup(WORD, WORD code, HWND, BOOL&) { MultiByteToWideChar(CP_ACP, 0, dir, -1, wdir, _countof(wdir)); path = wdir; } - if (_waccess(path.wstring().c_str(), 0) != 0 && - !boost::filesystem::create_directories(path)) { + if (_waccess_s(path.c_str(), 0) != 0 && + !CreateDirectoryW(path.c_str(), NULL) && + GetLastError() == ERROR_PATH_NOT_FOUND) { MessageBox(L"未能完成導出操作。會不會是同步文件夾無法訪問?", L":-(", MB_OK | MB_ICONERROR); return 0; } WCHAR dict_name[100] = {0}; user_dict_list_.GetText(sel, dict_name); - path /= std::wstring(dict_name) + L".userdb.txt"; + path += std::wstring(L"\\") + dict_name + L".userdb.txt"; if (!api_->backup_user_dict(wcstoutf8(dict_name))) { MessageBox(L"不知哪裏出錯了,未能完成導出操作。", L":-(", MB_OK | MB_ICONERROR); return 0; } - else if (_waccess(path.wstring().c_str(), 0) != 0) { + else if (_waccess(path.c_str(), 0) != 0) { MessageBox(L"咦,輸出的快照文件找不着了。", L":-(", MB_OK | MB_ICONERROR); return 0; } - std::wstring param = L"/select, \"" + path.wstring() + L"\""; + std::wstring param = L"/select, \"" + path + L"\""; ShellExecute(NULL, L"open", L"explorer.exe", param.c_str(), NULL, SW_SHOWNORMAL); return 0; } diff --git a/WeaselDeployer/UIStyleSettings.cpp b/WeaselDeployer/UIStyleSettings.cpp index 38156bdc8..043a447da 100644 --- a/WeaselDeployer/UIStyleSettings.cpp +++ b/WeaselDeployer/UIStyleSettings.cpp @@ -37,10 +37,8 @@ bool UIStyleSettings::GetPresetColorSchemes(std::vector* result } std::string UIStyleSettings::GetColorSchemePreview(const std::string& color_scheme_id) { - boost::filesystem::path preview_path(rime_get_api()->get_shared_data_dir()); - preview_path /= "preview"; - preview_path /= "color_scheme_" + color_scheme_id + ".png"; - return preview_path.string(); + return std::string(rime_get_api()->get_shared_data_dir()) + + "\\preview\\color_scheme_" + color_scheme_id + ".png"; } std::string UIStyleSettings::GetActiveColorScheme() { diff --git a/WeaselIME/WeaselIME.cpp b/WeaselIME/WeaselIME.cpp index 6c65ec383..e80c8eb94 100644 --- a/WeaselIME/WeaselIME.cpp +++ b/WeaselIME/WeaselIME.cpp @@ -99,9 +99,11 @@ WeaselIME::WeaselIME(HIMC hIMC) , m_preferCandidatePos(false) { WCHAR path[MAX_PATH]; - GetModuleFileName(NULL, path, _countof(path)); - std::wstring exe = wpath(path).filename().wstring(); - if (iequals(L"chrome.exe", exe)) + WCHAR fname[_MAX_FNAME]; + WCHAR ext[_MAX_EXT]; + GetModuleFileNameW(NULL, path, _countof(path)); + _wsplitpath_s(path, NULL, 0, NULL, 0, fname, _countof(fname), ext, _countof(ext)); + if (iequals(L"chrome", fname) && iequals(L"exe", ext)) m_preferCandidatePos = true; } diff --git a/WeaselIME/stdafx.h b/WeaselIME/stdafx.h index 710e29f3c..3d329251f 100644 --- a/WeaselIME/stdafx.h +++ b/WeaselIME/stdafx.h @@ -15,15 +15,7 @@ #include "immdev.h" -#pragma warning(disable : 4819) - -#include - -#pragma warning(default : 4819) - #include #include #include #include - -using boost::filesystem::wpath; diff --git a/WeaselIPC/stdafx.h b/WeaselIPC/stdafx.h index 937b37e0c..0e62e9e06 100644 --- a/WeaselIPC/stdafx.h +++ b/WeaselIPC/stdafx.h @@ -15,8 +15,6 @@ #pragma warning(disable : 4996) #include -#include -#include #include #pragma warning(default: 4819) diff --git a/WeaselSetup/imesetup.cpp b/WeaselSetup/imesetup.cpp index f21311c8c..43767cc45 100644 --- a/WeaselSetup/imesetup.cpp +++ b/WeaselSetup/imesetup.cpp @@ -17,9 +17,6 @@ const GUID c_guidProfile = HKL ImeHKL = 0; - -using boost::filesystem::wpath; - BOOL copy_file(const std::wstring& src, const std::wstring& dest) { BOOL ret = CopyFile(src.c_str(), dest.c_str(), FALSE); @@ -57,47 +54,47 @@ BOOL delete_file(const std::wstring& file) return ret; } -typedef int (*ime_register_func)(const wpath& ime_path, bool register_ime, bool is_wow64, bool hant, bool silent); +typedef int (*ime_register_func)(const std::wstring& ime_path, bool register_ime, bool is_wow64, bool hant, bool silent); -int install_ime_file(wpath& srcPath, const std::wstring& ext, bool hant, bool silent, ime_register_func func) +int install_ime_file(std::wstring& srcPath, const std::wstring& ext, bool hant, bool silent, ime_register_func func) { - wpath destPath; - wpath wow64Path; + std::wstring destPath; + std::wstring wow64Path; WCHAR path[MAX_PATH]; GetModuleFileName(GetModuleHandle(NULL), path, _countof(path)); - srcPath = path; bool is_x64 = (sizeof(HANDLE) == 8); std::wstring srcFileName = (hant ? L"weaselt" : L"weasel"); srcFileName += (is_x64 ? L"x64" + ext : ext); - srcPath = srcPath.remove_leaf() / srcFileName; + WCHAR drive[_MAX_DRIVE]; + WCHAR dir[_MAX_DIR]; + _wsplitpath_s(path, drive, _countof(drive), dir, _countof(dir), NULL, 0, NULL, 0); + srcPath = std::wstring(drive) + dir + L'\\' + srcFileName; GetSystemDirectory(path, _countof(path)); - destPath = path; - destPath /= L"weasel" + ext; + destPath = std::wstring(path) + L"\\weasel" + ext; if (GetSystemWow64Directory(path, _countof(path))) { - wow64Path = path; - wow64Path /= L"weasel" + ext; + wow64Path = std::wstring(path) + L"\\weasel" + ext; } int retval = 0; // 复制 .dll/.ime 到系统目录 - if (!copy_file(srcPath.wstring(), destPath.wstring())) + if (!copy_file(srcPath, destPath)) { - if (!silent) MessageBox(NULL, destPath.wstring().c_str(), L"安裝失敗", MB_ICONERROR | MB_OK); + if (!silent) MessageBox(NULL, destPath.c_str(), L"安裝失敗", MB_ICONERROR | MB_OK); return 1; } retval += func(destPath, true, false, hant, silent); if (!wow64Path.empty()) { - std::wstring x86 = srcPath.wstring(); + std::wstring x86 = srcPath; ireplace_last(x86, L"x64" + ext, ext); - if (!copy_file(x86, wow64Path.wstring())) + if (!copy_file(x86, wow64Path)) { - if (!silent) MessageBox(NULL, wow64Path.wstring().c_str(), L"安裝失敗", MB_ICONERROR | MB_OK); + if (!silent) MessageBox(NULL, wow64Path.c_str(), L"安裝失敗", MB_ICONERROR | MB_OK); return 1; } retval += func(wow64Path, true, true, hant, silent); @@ -110,22 +107,22 @@ int uninstall_ime_file(const std::wstring& ext, bool silent, ime_register_func f int retval = 0; WCHAR path[MAX_PATH]; GetSystemDirectory(path, _countof(path)); - wpath imePath = path; - imePath /= L"weasel" + ext; + std::wstring imePath(path); + imePath += L"\\weasel" + ext; retval += func(imePath, false, false, false, silent); - if (!delete_file(imePath.wstring())) + if (!delete_file(imePath)) { - if (!silent) MessageBox(NULL, imePath.wstring().c_str(), L"卸載失敗", MB_ICONERROR | MB_OK); + if (!silent) MessageBox(NULL, imePath.c_str(), L"卸載失敗", MB_ICONERROR | MB_OK); retval += 1; } if (GetSystemWow64Directory(path, _countof(path))) { - wpath wow64Path = path; - wow64Path /= L"weasel" + ext; + std::wstring wow64Path(path); + wow64Path += L"\\weasel" + ext; retval += func(wow64Path, false, true, false, silent); - if (!delete_file(wow64Path.wstring())) + if (!delete_file(wow64Path)) { - if (!silent) MessageBox(NULL, wow64Path.wstring().c_str(), L"卸載失敗", MB_ICONERROR | MB_OK); + if (!silent) MessageBox(NULL, wow64Path.c_str(), L"卸載失敗", MB_ICONERROR | MB_OK); retval += 1; } } @@ -133,7 +130,7 @@ int uninstall_ime_file(const std::wstring& ext, bool silent, ime_register_func f } // 注册IME输入法 -int register_ime(const wpath& ime_path, bool register_ime, bool is_wow64, bool hant, bool silent) +int register_ime(const std::wstring& ime_path, bool register_ime, bool is_wow64, bool hant, bool silent) { if (is_wow64) { @@ -145,7 +142,7 @@ int register_ime(const wpath& ime_path, bool register_ime, bool is_wow64, bool h if (register_ime) { - HKL hKL = ImmInstallIME(ime_path.wstring().c_str(), WEASEL_IME_NAME); + HKL hKL = ImmInstallIME(ime_path.c_str(), WEASEL_IME_NAME); if (!hKL) { // manually register ime @@ -348,13 +345,13 @@ void unregister_text_service() UnregisterServer(); } // 注册TSF输入法 -int register_text_service(const wpath& tsf_path, bool register_ime, bool is_wow64, bool hant, bool silent) +int register_text_service(const std::wstring& tsf_path, bool register_ime, bool is_wow64, bool hant, bool silent) { if (!register_ime) enable_profile(FALSE, hant); if (register_ime) { - if (!RegisterServer(tsf_path.wstring(), is_wow64) || !RegisterProfiles(tsf_path.wstring(), ImeHKL) || !RegisterCategories()) + if (!RegisterServer(tsf_path, is_wow64) || !RegisterProfiles(tsf_path, ImeHKL) || !RegisterCategories()) { unregister_text_service(); MessageBox(NULL, L"註冊輸入法錯誤", L"安装/卸載失败", MB_ICONERROR | MB_OK); @@ -373,7 +370,7 @@ int register_text_service(const wpath& tsf_path, bool register_ime, bool is_wow6 int install(bool hant, bool silent) { - wpath ime_src_path; + std::wstring ime_src_path; int retval = 0; retval += install_ime_file(ime_src_path, L".ime", hant, silent, ®ister_ime); retval += install_ime_file(ime_src_path, L".dll", hant, silent, ®ister_text_service); @@ -388,7 +385,10 @@ int install(bool hant, bool silent) return 1; } - std::wstring rootDir = ime_src_path.parent_path().wstring(); + WCHAR drive[_MAX_DRIVE]; + WCHAR dir[_MAX_DIR]; + _wsplitpath_s(ime_src_path.c_str(), drive, _countof(drive), dir, _countof(dir), NULL, 0, NULL, 0); + std::wstring rootDir = std::wstring(drive) + dir; ret = RegSetValueEx(hKey, L"WeaselRoot", 0, REG_SZ, (const BYTE*)rootDir.c_str(), (rootDir.length() + 1) * sizeof(WCHAR)); @@ -438,7 +438,7 @@ int uninstall(bool silent) bool has_installed() { WCHAR path[MAX_PATH]; GetSystemDirectory(path, _countof(path)); - wpath imePath = path; - imePath /= L"weasel.ime"; - return boost::filesystem::exists(imePath); + std::wstring sysPath(path); + DWORD attr = GetFileAttributesW((sysPath + L"\\weasel.ime").c_str()); + return (attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY)); } diff --git a/WeaselTSF/stdafx.h b/WeaselTSF/stdafx.h index ef383a4d9..4f325e742 100644 --- a/WeaselTSF/stdafx.h +++ b/WeaselTSF/stdafx.h @@ -15,10 +15,6 @@ #include #include -// #include - #include #include #include - -// using boost::filesystem::wpath; diff --git a/include/PipeChannel.h b/include/PipeChannel.h index ef7369e63..c14c2d61f 100644 --- a/include/PipeChannel.h +++ b/include/PipeChannel.h @@ -127,7 +127,7 @@ namespace weasel { } // Use whole buffer to receive data in client - return handler((LPWSTR)buffer.get(), buff_size * sizeof(char) / sizeof(wchar_t)); + return handler((LPWSTR)buffer.get(), (UINT)(buff_size * sizeof(char) / sizeof(wchar_t))); }