Skip to content

Commit

Permalink
chore: remove Boost.Filesystem dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Prcuvu committed Aug 30, 2018
1 parent dae945c commit 4a4a0cb
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 63 deletions.
13 changes: 7 additions & 6 deletions WeaselDeployer/DictManagementDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,32 @@ 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));
WCHAR wdir[MAX_PATH] = {0};
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;
}
Expand Down
6 changes: 2 additions & 4 deletions WeaselDeployer/UIStyleSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ bool UIStyleSettings::GetPresetColorSchemes(std::vector<ColorSchemeInfo>* 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() {
Expand Down
8 changes: 5 additions & 3 deletions WeaselIME/WeaselIME.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 0 additions & 8 deletions WeaselIME/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@

#include "immdev.h"

#pragma warning(disable : 4819)

#include <boost/filesystem.hpp>

#pragma warning(default : 4819)

#include <map>
#include <memory>
#include <mutex>
#include <string>

using boost::filesystem::wpath;
2 changes: 0 additions & 2 deletions WeaselIPC/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#pragma warning(disable : 4996)

#include <boost/interprocess/streams/bufferstream.hpp>
#include <boost/interprocess/windows_shared_memory.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include <boost/archive/text_wiarchive.hpp>

#pragma warning(default: 4819)
Expand Down
70 changes: 35 additions & 35 deletions WeaselSetup/imesetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -110,30 +107,30 @@ 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;
}
}
return retval;
}

// 注册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)
{
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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, &register_ime);
retval += install_ime_file(ime_src_path, L".dll", hant, silent, &register_text_service);
Expand All @@ -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));
Expand Down Expand Up @@ -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));
}
4 changes: 0 additions & 4 deletions WeaselTSF/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
#include <msctf.h>
#include <assert.h>

// #include <boost/filesystem.hpp>

#include <map>
#include <memory>
#include <string>

// using boost::filesystem::wpath;
2 changes: 1 addition & 1 deletion include/PipeChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}


Expand Down

0 comments on commit 4a4a0cb

Please sign in to comment.