Skip to content

Commit

Permalink
调整设置入口
Browse files Browse the repository at this point in the history
  • Loading branch information
shuax committed Jun 14, 2016
1 parent d591d00 commit d2a20fa
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 15 deletions.
8 changes: 4 additions & 4 deletions GreenChrome.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,31 @@
<IntDir>$(ProjectDir)$(Configuration)\$(Platform)\</IntDir>
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
<TargetName>wtsapi32</TargetName>
<TargetName>winmm</TargetName>
<IncludePath>src\WTL;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)\Release\x64\</OutDir>
<IntDir>$(ProjectDir)$(Configuration)\$(Platform)\</IntDir>
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
<TargetName>wtsapi32</TargetName>
<TargetName>winmm</TargetName>
<IncludePath>src\WTL;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)\Debug\x86\</OutDir>
<IntDir>$(ProjectDir)$(Configuration)\$(Platform)\</IntDir>
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
<TargetName>wtsapi32</TargetName>
<TargetName>winmm</TargetName>
<IncludePath>src\WTL;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)\Release\x86\</OutDir>
<IntDir>$(ProjectDir)$(Configuration)\$(Platform)\</IntDir>
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
<TargetName>wtsapi32</TargetName>
<TargetName>winmm</TargetName>
<IncludePath>src\WTL;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
Expand Down
6 changes: 3 additions & 3 deletions src/CustomCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ void CustomCommand(const wchar_t *iniPath, const wchar_t *exeFolder, const wchar
{
WaitForSingleObject(pi.hProcess, INFINITE);

// 释放句柄
CloseHandle(FirstRun);

// 结束时杀掉启动时运行的程序
KillAtEnd(iniPath, program_handles);

// 结束时运行
LaunchAtEnd(iniPath, exeFolder);

// 释放句柄
CloseHandle(FirstRun);
}

CloseHandle(pi.hProcess);
Expand Down
58 changes: 51 additions & 7 deletions src/PatchResourcesPak.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void RemovePakUpdateError(uint8_t *buffer)
}
}

void BuildAboutDescription(uint8_t *buffer)
void ModifyHelpPage(uint8_t *buffer)
{
BYTE search_start[] = R"(
<body class="uber-frame">
Expand All @@ -119,7 +119,7 @@ void BuildAboutDescription(uint8_t *buffer)
)";

uint8_t* pos = memmem(buffer, resources_pak_size, search_start, sizeof(search_start) - 1);
if(pos)
if (pos)
{
TraversalPakFile(buffer, [=](uint8_t *begin, uint8_t* end, uint32_t size) {
if (pos >= begin && pos <= end)
Expand All @@ -128,7 +128,7 @@ void BuildAboutDescription(uint8_t *buffer)
std::string html((char*)begin, size);
compression_html(html);

const char prouct_title[] = u8R"(<br><div>您正在使用 GreenChrome )" RELEASE_VER_STR u8R"( <button><a href="http://settings.shuax.com/gc/" target="_blank" style="text-decoration:none;color:#444;">点击设置</a></button></div></div><div id="product-container">)";
const char prouct_title[] = u8R"(<br><div>GreenChrome )" RELEASE_VER_STR u8R"(</div><div id="product-container">)";
ReplaceStringInPlace(html, R"(</div><div id="product-container">)", prouct_title);

if (html.length() <= size)
Expand All @@ -141,7 +141,49 @@ void BuildAboutDescription(uint8_t *buffer)
}
else
{
DebugLog(L"BuildAboutDescription size failed");
DebugLog(L"ModifyHelpPage size failed");
}

return true;
}
return false;
});
}
else
{
DebugLog(L"ModifyHelpPage failed");
}
}


void ModifySettingsPage(uint8_t *buffer)
{
BYTE search_start[] = R"(<h3 i18n-content="sectionTitleSync"></h3>)";

uint8_t* pos = memmem(buffer, resources_pak_size, search_start, sizeof(search_start) - 1);
if (pos)
{
TraversalPakFile(buffer, [=](uint8_t *begin, uint8_t* end, uint32_t size) {
if (pos >= begin && pos <= end)
{
// 压缩HTML以备写入补丁信息
std::string html((char*)begin, size);
compression_html(html);

const char prouct_title[] = u8R"(<section><h3>GreenChrome</h3><div class="settings-row">如果喜欢它,可以 <a class="alert-link" href="https://www.shuax.com/donate.html" target="_blank">鼓励作者</a> 继续完善。</div><button><a href="http://settings.shuax.com/gc/" target="_blank" style="text-decoration:none;color:#444;">点击设置</a></button></section><section id="sync-section">)";
ReplaceStringInPlace(html, R"(<section id="sync-section">)", prouct_title);

if (html.length() <= size)
{
// 写入修改
memcpy(begin, html.c_str(), html.length());

// 填充空格
memset(begin + html.length(), ' ', size - html.length());
}
else
{
DebugLog(L"ModifySettingsPage size failed");
}

return true;
Expand All @@ -151,7 +193,7 @@ void BuildAboutDescription(uint8_t *buffer)
}
else
{
DebugLog(L"BuildAboutDescription failed");
DebugLog(L"ModifySettingsPage failed");
}
}

Expand Down Expand Up @@ -199,8 +241,10 @@ HANDLE WINAPI MyMapViewOfFile(
RemovePakUpdateError((BYTE*)buffer);
}

// 构造关于描述
BuildAboutDescription((BYTE*)buffer);
// 修改关于页面
ModifyHelpPage((BYTE*)buffer);
// 修改设置页面
ModifySettingsPage((BYTE*)buffer);
}

return buffer;
Expand Down
2 changes: 1 addition & 1 deletion src/SettingWeb.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "cJSON\cJSON.h"

const char extra_header[] = "Content-Type: text/xml; charset=utf-8\r\nAccess-Control-Allow-Origin: http://settings.shuax.com";
const char extra_header[] = "Content-Type: text/html; charset=utf-8\r\nAccess-Control-Allow-Origin: http://settings.shuax.com";

void ReadList(cJSON *root, const wchar_t *iniPath, const wchar_t *name)
{
Expand Down

0 comments on commit d2a20fa

Please sign in to comment.