Skip to content

Commit

Permalink
Merge pull request #12 from YorkWaugh/main
Browse files Browse the repository at this point in the history
Handle each startup parameter separately.
  • Loading branch information
Bush2021 committed Oct 16, 2023
2 parents 62ee6b4 + cc65121 commit f5de24b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 23 deletions.
Binary file modified src/chrome++.ini
Binary file not shown.
5 changes: 2 additions & 3 deletions src/config.h
Expand Up @@ -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
Expand All @@ -25,7 +25,6 @@ std::wstring GetCrCommandLine()
}
}


// 如果 ini 存在,读取 UserData 并配置,否则使用默认值
std::wstring GetUserDataDir()
{
Expand Down
67 changes: 47 additions & 20 deletions src/portable.h
Expand Up @@ -84,32 +84,59 @@ 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<std::wstring> lines;
std::wstring line;
for (auto c : command)
auto cr_command_line = GetCrCommandLine();
std::wstring temp = cr_command_line;
temp = temp + L" ";
while (true)

This comment has been minimized.

Copy link
@avatartw

avatartw Oct 16, 2023

后面那段while已经把每个参数单独args.push_back
不须要另外处理 = 了

This comment has been minimized.

Copy link
@YorkWaugh

YorkWaugh Oct 16, 2023

Contributor

我本来也是这么认为的,但是测试下来存在“=”的启动参数必须放在前面,不然似乎会导致后面的参数失效。我不清楚为什么会这样。

This comment has been minimized.

Copy link
@avatartw

avatartw Oct 16, 2023

我用自己fork修改的 vivaldi++测试没问题
用vivaldi++,是因为chrome++不知道为什么会memory leak

测试参数
--disable-direct-composition-video-overlays --blink-settings=dnsPrefetchingEnabled=false --disable-crash-reporter --disable-breakpad --no-report-upload --disable-logging --realtime-reporting-url=0.0.0.0 --reporting-connector-url=0.0.0.0 --no-default-browser-check

This comment has been minimized.

Copy link
@Bush2021

Bush2021 Oct 16, 2023

Author Owner
            if (GetCrCommandLine().length() > 0)
            {
                auto cr_command_line = GetCrCommandLine();
                std::wstring temp = cr_command_line;
                temp = temp + L" ";
                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);
                        }
                    }
                }
            }

有点小问题,不过其实基本好了,这个版本没加。

This comment has been minimized.

Copy link
@Bush2021

Bush2021 Oct 16, 2023

Author Owner

我用自己fork修改的 vivaldi++测试没问题 用vivaldi++,是因为chrome++不知道为什么会memory leak

测试参数 --disable-direct-composition-video-overlays --blink-settings=dnsPrefetchingEnabled=false --disable-crash-reporter --disable-breakpad --no-report-upload --disable-logging --realtime-reporting-url=0.0.0.0 --reporting-connector-url=0.0.0.0 --no-default-browser-check

确实有人说过内存泄漏的问题,但是我没有复现,理论上代码也是一样的,不知道问题是什么。

{
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;
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);
}
}
line += c;
}
if (line.length() > 0)
lines.push_back(line);
for (auto &line : lines)

while (true)
{
args.push_back(line);
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);
}
}
}
}

Expand Down

0 comments on commit f5de24b

Please sign in to comment.