Skip to content

Commit

Permalink
feat: support customize startup parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Bush2021 authored Oct 12, 2023
1 parent bd6ab84 commit 8687356
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
Binary file modified src/chrome++.ini
Binary file not shown.
39 changes: 31 additions & 8 deletions src/portable.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ bool IsIniExist()
return false;
}

// 如果 ini 存在,从中读取 CommandLine;如果 ini 不存在,或者存在,但是 CommandLine 为空,则返回空字符串
std::wstring GetCrCommandLine()
{
if (IsIniExist())
{
std::wstring IniPath = GetAppDir() + L"\\chrome++.ini";
TCHAR CommandLineBuffer[MAX_PATH];
::GetPrivateProfileStringW(L"General", L"CommandLine", L"", CommandLineBuffer, MAX_PATH, IniPath.c_str());
return std::wstring(CommandLineBuffer);
}
else
{
return std::wstring(L"");
}
}

// 如果 ini 存在,读取 UserData 并配置,否则使用默认值
std::wstring GetUserDataDir()
{
Expand All @@ -82,7 +98,7 @@ std::wstring GetUserDataDir()
{
::PathCanonicalize(UserDataBuffer, path.data());
}

std::wstring ExpandedPath = ExpandEnvironmentPath(UserDataBuffer);

// 替换 %app%
Expand Down Expand Up @@ -127,7 +143,7 @@ std::wstring GetDiskCacheDir()
{
::PathCanonicalize(CacheDirBuffer, path.data());
}

std::wstring ExpandedPath = ExpandEnvironmentPath(CacheDirBuffer);

// 替换 %app%
Expand Down Expand Up @@ -179,25 +195,32 @@ std::wstring GetCommand(LPWSTR param)
{
args.push_back(L"--portable");

args.push_back(L"--no-first-run");

args.push_back(L"--disable-features=RendererCodeIntegrity,FlashDeprecationWarning");

// if (IsNeedPortable())
// 获取命令行,然后追加参数
{
auto diskcache = GetDiskCacheDir();
auto cr_command_line = GetCrCommandLine();

wchar_t temp[MAX_PATH];
wsprintf(temp, L"--disk-cache-dir=%s", diskcache.c_str());
wsprintf(temp, L"%s", cr_command_line.c_str());
args.push_back(temp);
}

{
auto userdata = GetUserDataDir();

wchar_t temp[MAX_PATH];
wsprintf(temp, L"--user-data-dir=%s", userdata.c_str());
args.push_back(temp);
}
// if (IsNeedPortable())
{
auto diskcache = GetDiskCacheDir();

wchar_t temp[MAX_PATH];
wsprintf(temp, L"--disk-cache-dir=%s", diskcache.c_str());
args.push_back(temp);
}
}
}
LocalFree(argv);
Expand All @@ -224,4 +247,4 @@ void Portable(LPWSTR param)
{
ExitProcess(0);
}
}
}

0 comments on commit 8687356

Please sign in to comment.