From 28340d7dc7cb1b501de511b2a1c66b90542a0260 Mon Sep 17 00:00:00 2001 From: York Waugh <67750590+YorkWaugh@users.noreply.github.com> Date: Mon, 16 Oct 2023 20:34:17 +0800 Subject: [PATCH 1/2] Revert "Read the startup parameters for the entire section "CommandLine"" This reverts commit 62ee6b4d6064534cdcf67f480ec0a216e113e585. --- src/chrome++.ini | Bin 3452 -> 3406 bytes src/config.h | 5 ++--- src/portable.h | 49 ++++++++++++++++++++++++++--------------------- src/version.h | 2 +- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/chrome++.ini b/src/chrome++.ini index 95f07de8bf7aa1360a62f10cbe3b8bca619b5817..b006de2dc1eca425ada65e4bc2665267b1048bee 100644 GIT binary patch delta 124 zcmew(bxvx-J67#th608}hGd3R1|0?kh7^W;AejdwOMrAaLlID}fPt5Ri@};fVX{1% zIHT=kdp6n0No*>Uo7lA`Z)5Wjt*Wxg;Q7z%*Vvhq?9+i;tpb}EqwVIS?AuuZPkn^+#&MJ66LShD?S$hExUxh9rg}Af3pN4P=)v2jc0CXkoPz{|kJU=0+B zo?Oo^&KV2iPc~$eWd+MkHe^?YvI^PCg_DwfI?86)WXudCO{X>^*apVf&C}VpvjPAd CmLUfK diff --git a/src/config.h b/src/config.h index d2cfcde..5cd456b 100644 --- a/src/config.h +++ b/src/config.h @@ -9,14 +9,14 @@ bool IsIniExist() return false; } -// 如果 ini 存在,修改为从 ini 中读取整个名为 CommandLine 的 section 的内容,否则返回空字符串 +// 如果 ini 存在,从中读取 CommandLine;如果 ini 不存在,或者存在,但是 CommandLine 为空,则返回空字符串 std::wstring GetCrCommandLine() { if (IsIniExist()) { std::wstring IniPath = GetAppDir() + L"\\chrome++.ini"; TCHAR CommandLineBuffer[MAX_PATH]; - ::GetPrivateProfileSectionW(L"CommandLine", CommandLineBuffer, MAX_PATH, IniPath.c_str()); + ::GetPrivateProfileStringW(L"General", L"CommandLine", L"", CommandLineBuffer, MAX_PATH, IniPath.c_str()); return std::wstring(CommandLineBuffer); } else @@ -25,7 +25,6 @@ std::wstring GetCrCommandLine() } } - // 如果 ini 存在,读取 UserData 并配置,否则使用默认值 std::wstring GetUserDataDir() { diff --git a/src/portable.h b/src/portable.h index a4dd4d4..322ab17 100644 --- a/src/portable.h +++ b/src/portable.h @@ -84,32 +84,37 @@ std::wstring GetCommand(LPWSTR param) // 获取命令行,然后追加参数 // 如果存在 = 号,参数会被识别成值 // 修改方法是截取拆分,然后多次 args.push_back - // 首先检测获取到的多行数据长度是否大于 0 - // 若大于0,以每行为单位,把一整行提取出来,单独 push_back - // 重复上述过程,直到字符串长度为 0 - // 这样就可以保证参数正常追加 - std::wstring command = GetCrCommandLine(); - if (command.length() > 0) + // 首先检测是否存在 =,不存在按照原有方法处理 + // 若存在,以匹配到的第一个 = 为中心,向前匹配 -- 为开头,向后匹配空格为结尾,把这整一段提取出来,单独 push_back + // 然后再把提取出来的部分从原有的字符串中删除,再 push_back 剩下的部分 + // 重复上述过程,直到字符串中不再存在 = 号 + // 这样就可以保证参数不会被识别成值了 { - std::vector lines; - std::wstring line; - for (auto c : command) + auto cr_command_line = GetCrCommandLine(); + std::wstring temp = cr_command_line; + while (true) { - if (c == L'\r') - continue; - if (c == L'\n') + auto pos = temp.find(L"="); + if (pos == std::wstring::npos) { - lines.push_back(line); - line.clear(); - continue; + args.push_back(temp); + break; + } + else + { + auto pos1 = temp.rfind(L"--", pos); + auto pos2 = temp.find(L" ", pos); + if (pos1 == std::wstring::npos || pos2 == std::wstring::npos) + { + args.push_back(temp); + break; + } + else + { + args.push_back(temp.substr(pos1, pos2 - pos1)); + temp = temp.substr(0, pos1) + temp.substr(pos2); + } } - line += c; - } - if (line.length() > 0) - lines.push_back(line); - for (auto &line : lines) - { - args.push_back(line); } } diff --git a/src/version.h b/src/version.h index 63388d6..707c86b 100644 --- a/src/version.h +++ b/src/version.h @@ -1,6 +1,6 @@ #define RELEASE_VER_MAIN 1 #define RELEASE_VER_SUB 5 -#define RELEASE_VER_FIX 9 +#define RELEASE_VER_FIX 8 #define TOSTRING2(arg) #arg #define TOSTRING(arg) TOSTRING2(arg) From cc6512167e102fcd1fa84fbef86ebf708748dc25 Mon Sep 17 00:00:00 2001 From: York Waugh <67750590+YorkWaugh@users.noreply.github.com> Date: Mon, 16 Oct 2023 20:39:00 +0800 Subject: [PATCH 2/2] Restore the original ini file format Restore the original ini file format, fix bugs --- src/portable.h | 26 ++++++++++++++++++++++++-- src/version.h | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/portable.h b/src/portable.h index 322ab17..a9dceb6 100644 --- a/src/portable.h +++ b/src/portable.h @@ -92,12 +92,12 @@ std::wstring GetCommand(LPWSTR param) { auto cr_command_line = GetCrCommandLine(); std::wstring temp = cr_command_line; + temp = temp + L" "; while (true) { auto pos = temp.find(L"="); if (pos == std::wstring::npos) { - args.push_back(temp); break; } else @@ -106,7 +106,6 @@ std::wstring GetCommand(LPWSTR param) auto pos2 = temp.find(L" ", pos); if (pos1 == std::wstring::npos || pos2 == std::wstring::npos) { - args.push_back(temp); break; } else @@ -116,6 +115,29 @@ std::wstring GetCommand(LPWSTR param) } } } + + while (true) + { + auto pos1 = temp.find(L"--"); + if (pos1 == std::wstring::npos) + { + break; + } + else + { + auto pos2 = temp.find(L"--", pos1 + 2); + if (pos2 == std::wstring::npos) + { + args.push_back(temp); + break; + } + else + { + args.push_back(temp.substr(pos1, pos2 - pos1)); + temp = temp.substr(pos2); + } + } + } } { diff --git a/src/version.h b/src/version.h index 707c86b..63388d6 100644 --- a/src/version.h +++ b/src/version.h @@ -1,6 +1,6 @@ #define RELEASE_VER_MAIN 1 #define RELEASE_VER_SUB 5 -#define RELEASE_VER_FIX 8 +#define RELEASE_VER_FIX 9 #define TOSTRING2(arg) #arg #define TOSTRING(arg) TOSTRING2(arg)