From b29bdecfdf6de408aa46e48deff17f27f7383e57 Mon Sep 17 00:00:00 2001 From: Bush2021 <79072750+Bush2021@users.noreply.github.com> Date: Sun, 5 May 2024 20:13:44 -0400 Subject: [PATCH] chore: translate and standardize comments into English --- README.md | 8 ++++---- src/chrome++.cpp | 24 ++++++++++++------------ src/hijack.h | 13 +++++++------ src/hotkey.h | 6 ++---- src/iaccessible.h | 22 +++++++++++----------- src/pakfile.h | 15 ++++++++------- src/pakpatch.h | 2 +- src/patch.h | 43 +++++++++++++++++++------------------------ src/portable.h | 14 +++++++------- src/tabbookmark.h | 28 +++++++++++++++++----------- src/utils.h | 39 +++++++++++++++++++-------------------- 11 files changed, 107 insertions(+), 107 deletions(-) diff --git a/README.md b/README.md index 4f8b83c..2f6bcc7 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,12 @@ # Features * Double-click to close tab. -* Right-click to close tab. (Hold Shift to show the original menu.) -* Preserve the last tab (prevents the browser from closing when the last tab is closed; clicking the close button will not work.) +* Right-click to close tab (Hold Shift to show the original menu). +* Preserve the last tab (prevents the browser from closing when the last tab is closed; clicking the close button will not work). * Use the mouse wheel to switch tabs when hovering over the tab bar. * Use the mouse wheel to switch tabs when holding the right mouse button. -* Create new tab to opens the contents entered in address bar. (Can be configured to open in foreground or background.) -* Create new tab to opens bookmarks. (Can be configured to open in foreground or background.) +* Create new tab to opens the contents entered in address bar (Can be configured to open in foreground or background). +* Create new tab to opens bookmarks (Can be configured to open in foreground or background). * Disable the above two features when the current tab is a new tab. * Customize hotkeys to quickly hide the browser window (boss key). * Customize hotkeys to translate web page. diff --git a/src/chrome++.cpp b/src/chrome++.cpp index 35b91fa..1224f96 100644 --- a/src/chrome++.cpp +++ b/src/chrome++.cpp @@ -24,19 +24,19 @@ typedef int (*Startup)(); Startup ExeMain = NULL; void ChromePlus() { - // 快捷方式 + // Shortcut. SetAppId(); - // 便携化补丁 + // Portable hajack patch. MakeGreen(); - // 标签页,书签,地址栏增强 + // Enhancement of the address bar, tab, and bookmark. TabBookmark(); - // 给pak文件打补丁 + // Patch the pak file. PakPatch(); - // 处理热键 + // Process the hotkey. GetHotkey(); } @@ -49,28 +49,28 @@ void ChromePlusCommand(LPWSTR param) { } int Loader() { - // 硬补丁 + // Hard patch. MakePatch(); - // 只关注主界面 + // Only main interface. LPWSTR param = GetCommandLineW(); // DebugLog(L"param %s", param); if (!wcsstr(param, L"-type=")) { ChromePlusCommand(param); } - // 返回到主程序 + // Return to the main function. return ExeMain(); } void InstallLoader() { - // 获取程序入口点 + // Get the address of the original entry point of the main module. MODULEINFO mi; GetModuleInformation(GetCurrentProcess(), GetModuleHandle(NULL), &mi, sizeof(MODULEINFO)); PBYTE entry = (PBYTE)mi.EntryPoint; - // 入口点跳转到Loader + // Jump from the original entry to the loader. MH_STATUS status = MH_CreateHook(entry, Loader, (LPVOID*)&ExeMain); if (status == MH_OK) { MH_EnableHook(entry); @@ -88,10 +88,10 @@ EXTERNC BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID pv) { DisableThreadLibraryCalls(hModule); hInstance = hModule; - // 保持系统dll原有功能 + // Maintain the original function of system DLLs. LoadSysDll(hModule); - // 初始化HOOK库成功以后安装加载器 + // Install the loader after successfully initializing MinHook. MH_STATUS status = MH_Initialize(); if (status == MH_OK) { InstallLoader(); diff --git a/src/hijack.h b/src/hijack.h index 33c28f9..802f5bc 100644 --- a/src/hijack.h +++ b/src/hijack.h @@ -23,12 +23,13 @@ namespace hijack { __nop(); \ return __COUNTER__; \ } -// 用 __COUNTER__ 来生成一点不一样的代码,避免被 VS 自动合并相同函数 +// Use __COUNTER__ to generate slightly different code to avoid +// being automatically merged with the same functions by VS. #define EXPORT(api) int __cdecl api() NOP_FUNC -#pragma region 声明导出函数 -// 声明导出函数 +#pragma region Declare the exported functions +// Declare the exported functions. #pragma comment( \ linker, \ "/export:GetFileVersionInfoA=?GetFileVersionInfoA@hijack@@YAHXZ,@1") @@ -91,7 +92,7 @@ EXPORT(VerQueryValueW) } // namespace hijack #pragma endregion -#pragma region 还原导出函数 +#pragma region Restore the export function bool WriteMemory(PBYTE BaseAddress, PBYTE Buffer, DWORD nSize) { DWORD ProtectFlag = 0; if (VirtualProtectEx(GetCurrentProcess(), BaseAddress, nSize, @@ -105,7 +106,7 @@ bool WriteMemory(PBYTE BaseAddress, PBYTE Buffer, DWORD nSize) { return false; } -// 还原导出函数 +// Restore the export function. void InstallJMP(PBYTE BaseAddress, uintptr_t Function) { if (*BaseAddress == 0xE9) { BaseAddress++; @@ -133,7 +134,7 @@ void InstallJMP(PBYTE BaseAddress, uintptr_t Function) { } #pragma endregion -#pragma region 加载系统dll +#pragma region Load system dll void LoadVersion(HINSTANCE hModule) { PBYTE pImageBase = (PBYTE)hModule; PIMAGE_DOS_HEADER pimDH = (PIMAGE_DOS_HEADER)pImageBase; diff --git a/src/hotkey.h b/src/hotkey.h index 4bbfaec..a56d468 100644 --- a/src/hotkey.h +++ b/src/hotkey.h @@ -36,13 +36,13 @@ UINT ParseHotkeys(const wchar_t* keys) { } } else { TCHAR wch = key[0]; - if (key.length() == 1) // 解析单个字符A-Z、0-9等 + if (key.length() == 1) // Parse single characters A-Z, 0-9, etc. { if (isalnum(wch)) vk = toupper(wch); else vk = LOWORD(VkKeyScan(wch)); - } else if (wch == 'F' || wch == 'f') // 解析F1-F24功能键 + } else if (wch == 'F' || wch == 'f') // Parse the F1-F24 function keys. { if (isdigit(key[1])) { int FX = _wtoi(&key[1]); @@ -64,7 +64,6 @@ static bool is_hide = false; static std::vector hwnd_list; BOOL CALLBACK SearchChromeWindow(HWND hWnd, LPARAM lParam) { - // 隐藏 if (IsWindowVisible(hWnd)) { wchar_t buff[256]; GetClassNameW(hWnd, buff, 255); @@ -110,7 +109,6 @@ void Hotkey(const std::wstring& keys, HotkeyAction action) { UINT flag = ParseHotkeys(keys.c_str()); std::thread th([flag, action]() { - // 注册热键 RegisterHotKey(NULL, 0, LOWORD(flag), HIWORD(flag)); MSG msg; diff --git a/src/iaccessible.h b/src/iaccessible.h index b790d85..f6e313b 100644 --- a/src/iaccessible.h +++ b/src/iaccessible.h @@ -118,7 +118,7 @@ void TraversalAccessible(NodePtr node, Function f, bool raw_traversal = false) { } if (is_task_completed) { - arrChildren[j].pdispVal->Release(); // 立刻释放,避免内存泄漏 + arrChildren[j].pdispVal->Release(); // Release immediately to avoid memory leaks. continue; } @@ -179,7 +179,7 @@ NodePtr FindPageTabList(NodePtr node) { role == ROLE_SYSTEM_PAGETABLIST) { page_tab_list = child; } else if (role == ROLE_SYSTEM_PANE || role == ROLE_SYSTEM_TOOLBAR) { - // 必须保留这两个判断,否则会闪退 (#56) + // These two judgments must be retained, otherwise it will crash (#56) page_tab_list = FindPageTabList(child); } return page_tab_list; @@ -241,7 +241,7 @@ NodePtr GetMenuBarPane(HWND hwnd) { return menu_bar_pane; } -// 获取当前标签页数量 +// Gets the current number of tabs. __int64 GetTabCount(NodePtr top) { NodePtr page_tab_list = FindElementWithRole(top, ROLE_SYSTEM_PAGETABLIST); if (!page_tab_list) { @@ -295,7 +295,7 @@ NodePtr FindChildElement(NodePtr parent, long role, int skipcount = 0) { return element; } -// 鼠标是否在某个标签上 +// Whether the mouse is on a tab bool IsOnOneTab(NodePtr top, POINT pt) { NodePtr page_tab_list = FindElementWithRole(top, ROLE_SYSTEM_PAGETABLIST); if (!page_tab_list) { @@ -338,7 +338,7 @@ bool IsOnlyOneTab(NodePtr top) { return tab_count <= 1; } -// 鼠标是否在标签栏上 +// Whether the mouse is on the tab bar bool IsOnTheTabBar(NodePtr top, POINT pt) { bool flag = false; NodePtr page_tab_list = FindElementWithRole(top, ROLE_SYSTEM_PAGETABLIST); @@ -352,7 +352,7 @@ bool IsOnTheTabBar(NodePtr top, POINT pt) { return flag; } -// 从当前标签页的名称判断是否是新标签页 +// Determine whether it is a new tab page from the name of the current tab page. bool IsNameNewTab(NodePtr top) { bool flag = false; @@ -365,7 +365,7 @@ bool IsNameNewTab(NodePtr top) { TraversalAccessible(page_tab_list, [&new_tab_name](NodePtr child) { if (GetAccessibleRole(child) == ROLE_SYSTEM_PUSHBUTTON) { GetAccessibleName(child, [&new_tab_name](BSTR bstr) { - new_tab_name.reset(_wcsdup(bstr)); // 保存从新建标签页按钮获取的名称 + new_tab_name.reset(_wcsdup(bstr)); // Save the name obtained from the new tab button. }); } return false; @@ -405,7 +405,7 @@ bool IsNameNewTab(NodePtr top) { return flag; } -// 从标签页的文档 value 判断是否是新标签页 +// Determine whether it is a new tab page from the document value of the tab page. bool IsDocNewTab() { bool flag = false; HWND hwnd = FindWindowEx(GetForegroundWindow(), nullptr, @@ -438,7 +438,7 @@ bool IsOnNewTab(NodePtr top) { return IsNameNewTab(top) || IsDocNewTab(); } -// 鼠标是否在书签上 +// Whether the mouse is on a bookmark in the bookmark bar. bool IsOnBookmark(NodePtr top, POINT pt) { if (!top) { return false; @@ -471,7 +471,7 @@ bool IsOnBookmark(NodePtr top, POINT pt) { return flag; } -// 鼠标是否在菜单栏的书签文件(夹)上 +// Whether the mouse is on a bookmark in the menu bar (folder). bool IsOnMenuBookmark(NodePtr top, POINT pt) { NodePtr menu_bar = FindElementWithRole(top, ROLE_SYSTEM_MENUBAR); if (!menu_bar) { @@ -512,7 +512,7 @@ bool IsOnMenuBookmark(NodePtr top, POINT pt) { return flag; } -// 地址栏是否已经获得焦点 +// Whether the omnibox is focused. bool IsOmniboxFocus(NodePtr top) { NodePtr tool_bar = FindElementWithRole(top, ROLE_SYSTEM_TOOLBAR); if (!tool_bar) { diff --git a/src/pakfile.h b/src/pakfile.h index b071645..2f2d5c1 100644 --- a/src/pakfile.h +++ b/src/pakfile.h @@ -64,7 +64,8 @@ bool CheckHeader(uint8_t* buffer, PAK_ENTRY*& pak_entry, end_entry = pak_entry + pak_header->resource_count; } - // 为了保存最后一条的"下一条",这条特殊的条目的id一定为0 + // In order to save the "next item" of the last item, + // the id of this special item must be 0 if (!end_entry || end_entry->resource_id != 0) return false; @@ -76,7 +77,7 @@ void PakFind(uint8_t* buffer, uint8_t* pos, Function f) { PAK_ENTRY* pak_entry = NULL; PAK_ENTRY* end_entry = NULL; - // 检查文件头 + // Check the file header. if (!CheckHeader(buffer, pak_entry, end_entry)) return; @@ -98,7 +99,7 @@ void TraversalGZIPFile(uint8_t* buffer, Function f) { PAK_ENTRY* pak_entry = NULL; PAK_ENTRY* end_entry = NULL; - // 检查文件头 + // Check the file header. if (!CheckHeader(buffer, pak_entry, end_entry)) return; @@ -107,7 +108,7 @@ void TraversalGZIPFile(uint8_t* buffer, Function f) { uint32_t old_size = next_entry->file_offset - pak_entry->file_offset; if (old_size < 10 * 1024) { - // 小于10k文件跳过 + // Files smaller than 10 kb are skipped. pak_entry = next_entry; continue; } @@ -115,7 +116,7 @@ void TraversalGZIPFile(uint8_t* buffer, Function f) { BYTE gzip[] = {0x1F, 0x8B, 0x08}; size_t gzip_len = sizeof(gzip); if (memcmp(buffer + pak_entry->file_offset, gzip, gzip_len) != 0) { - // 不是gzip文件跳过 + // Files that are not gzip format are skipped. pak_entry = next_entry; continue; } @@ -133,7 +134,7 @@ void TraversalGZIPFile(uint8_t* buffer, Function f) { uint32_t new_len = old_size; bool changed = f(unpack_buffer, unpack_len, new_len); if (changed) { - // 如果有改变 + // If the file is changed. size_t compress_size = 0; uint8_t* compress_buffer = (uint8_t*)gzip_compress(unpack_buffer, new_len, &compress_size); @@ -142,7 +143,7 @@ void TraversalGZIPFile(uint8_t* buffer, Function f) { fwrite(compress_buffer, compress_size, 1, fp); fclose(fp);*/ - // gzip头 + // gzip header memcpy(buffer + pak_entry->file_offset, compress_buffer, 10); // extra diff --git a/src/pakpatch.h b/src/pakpatch.h index 2a27580..a00650b 100644 --- a/src/pakpatch.h +++ b/src/pakpatch.h @@ -55,7 +55,7 @@ HANDLE WINAPI MyMapViewOfFile(_In_ HANDLE hFileMappingObject, R"(hidden="true")"); } - const char prouct_title[] = u8R"({aboutBrowserVersion}
Chrome++ )" RELEASE_VER_STR u8R"( modified version
)"; + const char prouct_title[] = u8R"({aboutBrowserVersion}
Chrome++ )""alpha-dcde2e9" u8R"( modified version
)"; ReplaceStringInPlace(html, R"({aboutBrowserVersion})", prouct_title); diff --git a/src/patch.h b/src/patch.h index 284eb36..9e9f553 100644 --- a/src/patch.h +++ b/src/patch.h @@ -22,30 +22,25 @@ typedef NTSTATUS(WINAPI* pLdrLoadDll)(IN PWCHAR PathToFile OPTIONAL, pLdrLoadDll RawLdrLoadDll = nullptr; // https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/dialogs/outdated_upgrade_bubble.cc?q=outdated_upgrade_bubble&ss=chromium%2Fchromium%2Fsrc -// 该功能失效,需要修改 -// void Outdated(HMODULE module) -//{ -// // "OutdatedUpgradeBubble.Show" -//#ifdef _WIN64 -// BYTE search[] = {0x48, 0x89, 0x8C, 0x24, 0xF0, 0x00, 0x00, 0x00, 0x80, 0x3D}; -// uint8_t *match = SearchModuleRaw(module, search, sizeof(search)); -//#else -// BYTE search[] = {0x31, 0xE8, 0x89, 0x45, 0xF0, 0x88, 0x5D, 0xEF, 0x80, 0x3D}; -// uint8_t *match = SearchModuleRaw(module, search, sizeof(search)); -//#endif -// if (match) -// { -// if (*(match + 0xF) == 0x74) -// { -// BYTE patch[] = {0x90, 0x90}; -// WriteMemory(match + 0xF, patch, sizeof(patch)); -// } -// } -// else -// { -// DebugLog(L"patch Outdated failed %p", module); -// } -//} +// This function is invalid and needs to be modified. +// void Outdated(HMODULE module) { +// // "OutdatedUpgradeBubble.Show" +// #ifdef _WIN64 +// BYTE search[] = {0x48, 0x89, 0x8C, 0x24, 0xF0, 0x00, 0x00, 0x00, 0x80, 0x3D}; +// uint8_t* match = SearchModuleRaw(module, search, sizeof(search)); +// #else +// BYTE search[] = {0x31, 0xE8, 0x89, 0x45, 0xF0, 0x88, 0x5D, 0xEF, 0x80, 0x3D}; +// uint8_t* match = SearchModuleRaw(module, search, sizeof(search)); +// #endif +// if (match) { +// if (*(match + 0xF) == 0x74) { +// BYTE patch[] = {0x90, 0x90}; +// WriteMemory(match + 0xF, patch, sizeof(patch)); +// } +// } else { +// DebugLog(L"patch Outdated failed %p", module); +// } +// } void DevWarning(HMODULE module) { // "enable-automation" diff --git a/src/portable.h b/src/portable.h index 4b121d3..44efb8d 100644 --- a/src/portable.h +++ b/src/portable.h @@ -29,7 +29,7 @@ std::wstring JoinArgsString(std::vector lines, return text; } -// 构造新命令行 +// Construct new command line with portable mode. std::wstring GetCommand(LPWSTR param) { std::vector args; @@ -46,11 +46,11 @@ std::wstring GetCommand(LPWSTR param) { insert_pos = i; } for (int i = 0; i < argc; i++) { - // 保留原来参数 + // Preserve former arguments. if (i) args.push_back(argv[i]); - // 追加参数 + // Append new arguments. if (i == insert_pos) { args.push_back(L"--portable"); @@ -64,10 +64,10 @@ std::wstring GetCommand(LPWSTR param) { args.push_back(L"--disk-cache-dir=" + diskcache); } - // 获取命令行,然后追加参数 - // 截取拆分每个--开头的参数,然后多次 args.push_back - // 重复上述过程,直到字串中不再存在 -- 号 - // 这样就可以保证每个参数生效 + // Get the command line and append parameters + // Intercept and split the parameters starting with each --, + // and then args.push_back multiple times + // Repeat the above process until the -- sign no longer exists in the string { auto cr_command_line = GetCrCommandLine(); std::wstring temp = cr_command_line; diff --git a/src/tabbookmark.h b/src/tabbookmark.h index a3268d2..29d58a4 100644 --- a/src/tabbookmark.h +++ b/src/tabbookmark.h @@ -10,6 +10,9 @@ bool IsPressed(int key) { return key && (::GetKeyState(key) & KEY_PRESSED) != 0; } +// Compared with `IsOnlyOneTab`, this function additionally implements tick +// fault tolerance to prevent users from directly closing the window when +// they click too fast. bool IsNeedKeep(HWND hwnd, int32_t* ptr = nullptr) { if (!IsKeepLastTab()) { return false; @@ -28,7 +31,7 @@ bool IsNeedKeep(HWND hwnd, int32_t* ptr = nullptr) { if (tick > 0 && tick <= 250 && tab_count <= 2) { is_only_one_tab = true; } - if (tab_count == 0) { // 处理全屏等状态 + if (tab_count == 0) { // Processing full screen and other states. is_only_one_tab = false; } keep_tab = is_only_one_tab; @@ -60,7 +63,7 @@ class IniConfig { IniConfig config; -// 滚轮切换标签页 +// Use the mouse wheel to switch tabs bool HandleMouseWheel(WPARAM wParam, LPARAM lParam, PMOUSEHOOKSTRUCT pmouse) { if (wParam != WM_MOUSEWHEEL || (!config.is_wheel_tab && !config.is_wheel_tab_when_press_right_button)) { @@ -73,7 +76,7 @@ bool HandleMouseWheel(WPARAM wParam, LPARAM lParam, PMOUSEHOOKSTRUCT pmouse) { PMOUSEHOOKSTRUCTEX pwheel = (PMOUSEHOOKSTRUCTEX)lParam; int zDelta = GET_WHEEL_DELTA_WPARAM(pwheel->mouseData); - // 是否启用鼠标停留在标签栏时滚轮切换标签 + // If the mouse wheel is used to switch tabs when the mouse is on the tab bar. if (config.is_wheel_tab && IsOnTheTabBar(top_container_view, pmouse->pt)) { hwnd = GetTopWnd(hwnd); if (zDelta > 0) { @@ -84,7 +87,7 @@ bool HandleMouseWheel(WPARAM wParam, LPARAM lParam, PMOUSEHOOKSTRUCT pmouse) { return true; } - // 是否启用在任何位置按住右键时滚轮切换标签 + // If it is used to switch tabs when the right button is held. if (config.is_wheel_tab_when_press_right_button && IsPressed(VK_RBUTTON)) { hwnd = GetTopWnd(hwnd); if (zDelta > 0) { @@ -98,7 +101,7 @@ bool HandleMouseWheel(WPARAM wParam, LPARAM lParam, PMOUSEHOOKSTRUCT pmouse) { return false; } -// 双击关闭标签页 +// Double-click to close tab. int HandleDoubleClick(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) { if (wParam != WM_LBUTTONDBLCLK || !config.is_double_click_close) { return 0; @@ -106,6 +109,9 @@ int HandleDoubleClick(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) { HWND hwnd = WindowFromPoint(pmouse->pt); NodePtr top_container_view = GetTopContainerView(hwnd); + + // If the top_container_view is not found at the first time, try to close the + // find-in-page bar and find the top_container_view again. if (!top_container_view) { ExecuteCommand(IDC_CLOSE_FIND_OR_STOP, hwnd); top_container_view = GetTopContainerView(hwnd); @@ -129,7 +135,7 @@ int HandleDoubleClick(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) { return 0; } -// 右键关闭标签页 +// Right-click to close tab (Hold Shift to show the original menu). int HandleRightClick(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) { if (wParam != WM_RBUTTONUP || IsPressed(VK_SHIFT) || !config.is_right_click_close) { @@ -161,7 +167,7 @@ int HandleRightClick(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) { return 0; } -// 保留最后标签页 - 中键 +// Preserve the last tab when the middle button is clicked on the tab. int HandleMiddleClick(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) { if (wParam != WM_MBUTTONUP) { return 0; @@ -189,7 +195,7 @@ int HandleMiddleClick(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) { return 0; } -// 新标签页打开书签 +// Open bookmarks in a new tab from the bookmark bar. bool HandleBookmark(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) { if (wParam != WM_LBUTTONUP || IsPressed(VK_CONTROL) || IsPressed(VK_SHIFT) || config.is_bookmark_new_tab == "disabled") { @@ -214,7 +220,7 @@ bool HandleBookmark(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) { return false; } -// 新标签页打开书签文件夹中的书签 +// Open bookmarks in a new tab from a bookmark menu (folder). bool HandleBookmarkMenu(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) { if (wParam != WM_LBUTTONUP || IsPressed(VK_CONTROL) || IsPressed(VK_SHIFT) || config.is_bookmark_new_tab == "disabled") { @@ -327,7 +333,7 @@ int HandleKeepTab(WPARAM wParam) { } if (IsFullScreen(hwnd)) { - // 必须退出全屏才能找到标签 + // Have to exit full screen to find the tab. ExecuteCommand(IDC_FULLSCREEN, hwnd); } @@ -384,4 +390,4 @@ void TabBookmark() { GetCurrentThreadId()); } -#endif // TABBOOKMARK_H_ \ No newline at end of file +#endif // TABBOOKMARK_H_ diff --git a/src/utils.h b/src/utils.h index e10d417..a2bfffe 100644 --- a/src/utils.h +++ b/src/utils.h @@ -35,7 +35,7 @@ #define IDC_CLOSE_FIND_OR_STOP 37003 #define IDC_WINDOW_CLOSE_OTHER_TABS 35023 -// 字符串操作函数 +// String manipulation function. std::wstring Format(const wchar_t* format, va_list args) { std::vector buffer; @@ -70,7 +70,7 @@ std::string wstring_to_string(const std::wstring& wstr) { return str; } -// 指定分隔符、包裹符号分割字符串 +// Specify the delimiter and wrapper to split the string. std::vector StringSplit(const std::wstring& str, const wchar_t delim, const std::wstring& enclosure) { @@ -106,7 +106,7 @@ std::vector StringSplit(const std::wstring& str, return result; } -// 替换 ini 文件中的字符串 +// Replace string in INI file. void ReplaceStringIni(std::wstring& subject, const std::wstring& search, const std::wstring& replace) { size_t pos = 0; @@ -116,7 +116,7 @@ void ReplaceStringIni(std::wstring& subject, const std::wstring& search, } } -// 压缩HTML +// Compression html. std::string& ltrim(std::string& s) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) { return !std::isspace(ch); })); @@ -156,7 +156,6 @@ void compression_html(std::string& html) { } } -// 替换字符串 bool ReplaceStringInPlace(std::string& subject, const std::string& search, const std::string& replace) { bool find = false; @@ -170,8 +169,8 @@ bool ReplaceStringInPlace(std::string& subject, const std::string& search, } -// 内存和模块搜索函数 -// 搜索内存 +// Memory and module search functions. +// Search memory. uint8_t* memmem(uint8_t* src, int n, const uint8_t* sub, int m) { return (uint8_t*)FastSearch(src, n, sub, m); } @@ -230,8 +229,8 @@ uint8_t* SearchModuleRaw2(HMODULE module, const uint8_t* sub, int m) { //} -// 路径和文件操作函数 -// 获得程序所在文件夹 +// Path and file manipulation functions. +// Get the directory where the application is located. std::wstring GetAppDir() { wchar_t path[MAX_PATH]; ::GetModuleFileName(nullptr, path, MAX_PATH); @@ -249,14 +248,14 @@ bool isEndWith(const wchar_t* s, const wchar_t* sub) { return !_memicmp(s + len1 - len2, sub, len2 * sizeof(wchar_t)); } -// 获得指定路径的绝对路径 +// Get the absolute path. std::wstring GetAbsolutePath(const std::wstring& path) { wchar_t buffer[MAX_PATH]; ::GetFullPathNameW(path.c_str(), MAX_PATH, buffer, nullptr); return buffer; } -// 展开环境路径比如 %windir% +// Expand environment variables in the path. std::wstring ExpandEnvironmentPath(const std::wstring& path) { std::vector buffer(MAX_PATH); size_t ExpandedLength = ::ExpandEnvironmentStrings(path.c_str(), &buffer[0], @@ -270,7 +269,7 @@ std::wstring ExpandEnvironmentPath(const std::wstring& path) { } -// 日志函数 +// Debug log function. void DebugLog(const wchar_t* format, ...) { // va_list args; // @@ -293,7 +292,7 @@ void DebugLog(const wchar_t* format, ...) { } -// 窗口和用户界面操作函数 +// Window and message processing functions. HWND GetTopWnd(HWND hwnd) { while (::GetParent(hwnd) && ::IsWindowVisible(::GetParent(hwnd))) { hwnd = ::GetParent(hwnd); @@ -319,8 +318,8 @@ bool IsFullScreen(HWND hwnd) { } -// 键盘和鼠标输入函数 -// 发送组合按键操作 +// Keyboard and mouse input functions. +// Send the combined key operation. class SendKeys { public: template @@ -332,7 +331,7 @@ class SendKeys { input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY; input.ki.wVk = key; - // 修正鼠标消息 + // Correct the mouse message switch (key) { case VK_MBUTTON: input.type = INPUT_MOUSE; @@ -349,7 +348,7 @@ class SendKeys { for (auto& input : inputs_) { input.ki.dwFlags |= KEYEVENTF_KEYUP; - // 修正鼠标消息 + // Correct the mouse message switch (input.ki.wVk) { case VK_MBUTTON: input.mi.dwFlags = MOUSEEVENTF_MIDDLEUP; @@ -364,9 +363,9 @@ class SendKeys { std::vector inputs_; }; -// 发送鼠标消息 +// Send a single key operation. void SendOneMouse(int mouse) { - // 交换左右键 + // Swap the left and right mouse buttons (if defined). if (::GetSystemMetrics(SM_SWAPBUTTON) == TRUE) { if (mouse == MOUSEEVENTF_RIGHTDOWN) mouse = MOUSEEVENTF_LEFTDOWN; @@ -384,4 +383,4 @@ void SendOneMouse(int mouse) { ::SendInput(1, input, sizeof(INPUT)); } -#endif // UTILS_H_ \ No newline at end of file +#endif // UTILS_H_