Skip to content

Commit

Permalink
Merge pull request Bush2021#13 from YorkWaugh/main
Browse files Browse the repository at this point in the history
Simplify additional parameter logic.
  • Loading branch information
Bush2021 authored Oct 17, 2023
2 parents b26093c + 74c833c commit 34bb9db
Showing 1 changed file with 7 additions and 37 deletions.
44 changes: 7 additions & 37 deletions src/portable.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,61 +82,31 @@ std::wstring GetCommand(LPWSTR param)
args.push_back(L"--disable-features=RendererCodeIntegrity");

// 获取命令行,然后追加参数
// 如果存在 = 号,参数会被识别成值
// 修改方法是截取拆分,然后多次 args.push_back
// 首先检测是否存在 =,不存在按照原有方法处理
// 若存在,以匹配到的第一个 = 为中心,向前匹配 -- 为开头,向后匹配空格为结尾,把这整一段提取出来,单独 push_back
// 然后再把提取出来的部分从原有的字符串中删除,再 push_back 剩下的部分
// 重复上述过程,直到字符串中不再存在 = 号
// 这样就可以保证参数不会被识别成值了
// 似乎必须特殊处理等号,暂时不知道怎么一起处理
if (GetCrCommandLine().length() > 0)
// 截取拆分每个--开头的参数,然后多次 args.push_back
// 重复上述过程,直到字串中不再存在 -- 号
// 这样就可以保证每个参数生效
{
auto cr_command_line = GetCrCommandLine();
std::wstring temp = cr_command_line;
temp = temp + L" ";
while (true)
{
auto pos = temp.find(L"=");
auto pos = temp.find(L"--");
if (pos == std::wstring::npos)
{
break;
}
else
{
auto pos1 = temp.rfind(L"--", pos);
auto pos2 = temp.find(L" ", pos);
if (pos1 == std::wstring::npos || pos2 == std::wstring::npos)
{
break;
}
else
{
args.push_back(temp.substr(pos1, pos2 - pos1));
temp = temp.substr(0, pos1) + temp.substr(pos2);
}
}
}
// 单独处理剩余参数
while (true)
{
auto pos1 = temp.find(L"--");
if (pos1 == std::wstring::npos)
{
break;
}
else
{
auto pos2 = temp.find(L"--", pos1 + 2);
auto pos2 = temp.find(L" --", pos);
if (pos2 == std::wstring::npos)
{
args.push_back(temp);
break;
}
else
{
args.push_back(temp.substr(pos1, pos2 - pos1));
temp = temp.substr(pos2);
args.push_back(temp.substr(pos, pos2 - pos));
temp = temp.substr(0, pos) + temp.substr(pos2 + 1);
}
}
}
Expand Down

0 comments on commit 34bb9db

Please sign in to comment.