Skip to content

Commit

Permalink
修正英文系统上编译时间字符串的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lrisora committed Jul 4, 2024
1 parent 5ff8d22 commit 255b2d6
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 22 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ jobs:
- name: 设置 msbuild
uses: microsoft/setup-msbuild@v2
- name: 编译
run: msbuild -t:Build '-p:Configuration=Release;platform=x64' -m:4
run: |
cd ./MusicPlayer2/
bash ./print_compile_time.sh
cd ..
msbuild -t:Build '-p:Configuration=Release;platform=x64' -m:4
- name: 复制文件到 Release 文件夹
run: cp -R ./MusicPlayer2/language/ ./x64/Release/
- name: 上传文件
Expand Down Expand Up @@ -69,7 +73,11 @@ jobs:
- name: 设置 msbuild
uses: microsoft/setup-msbuild@v2
- name: 编译
run: msbuild -t:Build '-p:Configuration=Release;platform=x86' -m:4
run: |
cd ./MusicPlayer2/
bash ./print_compile_time.sh
cd ..
msbuild -t:Build '-p:Configuration=Release;platform=x86' -m:4
- name: 复制文件到 Release 文件夹
run: cp -R ./MusicPlayer2/language/ ./Release/
- name: 上传文件
Expand Down
6 changes: 5 additions & 1 deletion MusicPlayer2/AboutDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ bool CAboutDlg::InitializeControls()
temp += L" (Debug)";
#endif

wstring time_str, hash_str;
CCommon::GetLastCompileTime(time_str, hash_str);
temp += L" (" + hash_str + L")";

SetDlgItemTextW(IDC_STATIC_VERSION, temp.c_str());
temp = L"Copyright (C) 2017-" COPY_RIGHT_YEAR L" By ZhongYang\r\n";
temp += theApp.m_str_table.LoadTextFormat(L"TXT_ABOUTBOX_LAST_BUILD_DATE", { CCommon::GetLastCompileTime() });
temp += theApp.m_str_table.LoadTextFormat(L"TXT_ABOUTBOX_LAST_BUILD_DATE", { time_str });
SetDlgItemTextW(IDC_STATIC_COPYRIGHT, temp.c_str());
temp = theApp.m_str_table.LoadText(L"TXT_ABOUTBOX_THIRD_PARTY_LIB");
SetDlgItemTextW(IDC_STATIC_THIRD_PARTY_LIB, temp.c_str());
Expand Down
14 changes: 4 additions & 10 deletions MusicPlayer2/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1820,18 +1820,12 @@ POINT CCommon::CalculateWindowMoveOffset(CRect& check_rect, vector<CRect>& scree
return mov;
}

wstring CCommon::GetLastCompileTime()
void CCommon::GetLastCompileTime(wstring& time_str, wstring& hash_str)
{
wstring compile_time = GetTextResource(IDR_COMPILE_TIME, CodeType::ANSI);
size_t pos = compile_time.find(L"\r\n");
while (pos != wstring::npos)
{
compile_time.replace(pos, 2, L"");
pos = compile_time.find(L"\r\n");
}
if (!compile_time.empty())
compile_time.pop_back();
return compile_time;
size_t pos = compile_time.find(L'\n');
time_str = compile_time.substr(0, pos);
hash_str = compile_time.substr(pos + 1, 8); // 截取hash前8位
}

unsigned __int64 CCommon::GetCurTimeElapse()
Expand Down
2 changes: 1 addition & 1 deletion MusicPlayer2/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ class CCommon
static POINT CalculateWindowMoveOffset(CRect& check_rect, vector<CRect>& screen_rects);

//从资源文件读取上次编译时间
static wstring GetLastCompileTime();
static void GetLastCompileTime(wstring& time_str, wstring& hash_str);

static unsigned __int64 GetCurTimeElapse();

Expand Down
8 changes: 4 additions & 4 deletions MusicPlayer2/MusicPlayer2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<PreBuildEvent>
<Command>print_compile_time.bat</Command>
<Command>print_compile_time.sh</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand Down Expand Up @@ -146,7 +146,7 @@
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<PreBuildEvent>
<Command>print_compile_time.bat</Command>
<Command>print_compile_time.sh</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand Down Expand Up @@ -180,7 +180,7 @@
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<PreBuildEvent>
<Command>print_compile_time.bat</Command>
<Command>print_compile_time.sh</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand Down Expand Up @@ -214,7 +214,7 @@
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<PreBuildEvent>
<Command>print_compile_time.bat</Command>
<Command>print_compile_time.sh</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
4 changes: 0 additions & 4 deletions MusicPlayer2/print_compile_time.bat

This file was deleted.

6 changes: 6 additions & 0 deletions MusicPlayer2/print_compile_time.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# 获取当前时间并覆写文件
echo $(date +'%F %T') > compile_time.txt
# 获取当前提交hash
echo $(git rev-parse HEAD) >> compile_time.txt

0 comments on commit 255b2d6

Please sign in to comment.