Skip to content

Commit

Permalink
chore: apply clang format
Browse files Browse the repository at this point in the history
This patch won't change any code logic, just format code base.
  • Loading branch information
Bambooin authored and fxliang committed Feb 28, 2024
1 parent 30ae76b commit 21d2bf9
Show file tree
Hide file tree
Showing 108 changed files with 14,973 additions and 14,931 deletions.
2,618 changes: 1,390 additions & 1,228 deletions RimeWithWeasel/RimeWithWeasel.cpp

Large diffs are not rendered by default.

77 changes: 36 additions & 41 deletions RimeWithWeasel/WeaselUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,48 @@
namespace fs = boost::filesystem;

fs::path WeaselUserDataPath() {
WCHAR _path[MAX_PATH] = {0};
const WCHAR KEY[] = L"Software\\Rime\\Weasel";
HKEY hKey;
LSTATUS ret = RegOpenKey(HKEY_CURRENT_USER, KEY, &hKey);
if (ret == ERROR_SUCCESS)
{
DWORD len = sizeof(_path);
DWORD type = 0;
DWORD data = 0;
ret = RegQueryValueEx(hKey, L"RimeUserDir", NULL, &type, (LPBYTE)_path, &len);
RegCloseKey(hKey);
if (ret == ERROR_SUCCESS && type == REG_SZ && _path[0])
{
return fs::path(_path);
}
}
// default location
ExpandEnvironmentStringsW(L"%AppData%\\Rime", _path, _countof(_path));
return fs::path(_path);
WCHAR _path[MAX_PATH] = {0};
const WCHAR KEY[] = L"Software\\Rime\\Weasel";
HKEY hKey;
LSTATUS ret = RegOpenKey(HKEY_CURRENT_USER, KEY, &hKey);
if (ret == ERROR_SUCCESS) {
DWORD len = sizeof(_path);
DWORD type = 0;
DWORD data = 0;
ret =
RegQueryValueEx(hKey, L"RimeUserDir", NULL, &type, (LPBYTE)_path, &len);
RegCloseKey(hKey);
if (ret == ERROR_SUCCESS && type == REG_SZ && _path[0]) {
return fs::path(_path);
}
}
// default location
ExpandEnvironmentStringsW(L"%AppData%\\Rime", _path, _countof(_path));
return fs::path(_path);
}

fs::path WeaselSharedDataPath() {
wchar_t _path[MAX_PATH] = {0};
GetModuleFileNameW(NULL, _path, _countof(_path));
return fs::path(_path).remove_filename().append("data");
wchar_t _path[MAX_PATH] = {0};
GetModuleFileNameW(NULL, _path, _countof(_path));
return fs::path(_path).remove_filename().append("data");
}

std::string GetCustomResource(const char *name, const char *type)
{
const HINSTANCE module = 0; // main executable
HRSRC hRes = FindResourceA(module, name, type);
if ( hRes )
{
HGLOBAL hData = LoadResource(module, hRes);
if ( hData )
{
const char *data = (const char*)::LockResource(hData);
size_t size = ::SizeofResource(module, hRes);
std::string GetCustomResource(const char* name, const char* type) {
const HINSTANCE module = 0; // main executable
HRSRC hRes = FindResourceA(module, name, type);
if (hRes) {
HGLOBAL hData = LoadResource(module, hRes);
if (hData) {
const char* data = (const char*)::LockResource(hData);
size_t size = ::SizeofResource(module, hRes);

if ( data && size )
{
if ( data[size-1] == '\0' ) // null-terminated string
size--;
return std::string(data, size);
}
}
if (data && size) {
if (data[size - 1] == '\0') // null-terminated string
size--;
return std::string(data, size);
}
}
}

return std::string();
return std::string();
}
Loading

0 comments on commit 21d2bf9

Please sign in to comment.