feat: 将字体文件嵌入 dll

This commit is contained in:
Xu Liu 2021-10-19 21:13:03 +08:00
commit 23ecf609c6
9 changed files with 73 additions and 54 deletions

View file

@ -14,7 +14,7 @@ namespace Magpie {
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application {
public static readonly Version APP_VERSION = new Version("0.6.0.0");
public static readonly Version APP_VERSION = new Version("0.7.0.0");
public static readonly string APPLICATION_DIR = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
public static readonly string SCALE_MODELS_JSON_PATH =
Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "ScaleModels.json");

View file

@ -45,5 +45,5 @@ using System.Windows;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.6.0.0")]
[assembly: AssemblyFileVersion("0.6.0.0")]
[assembly: AssemblyVersion("0.7.0.0")]
[assembly: AssemblyFileVersion("0.7.0.0")]

View file

@ -81,19 +81,23 @@ void serialize(Archive& ar, EffectConstantDesc& o) {
ar& o.label;
ar& index;
if (index == 1) {
if (index == 0) {
o.maxValue = {};
} else if (index == 1) {
o.maxValue = 0.0f;
ar& std::get<1>(o.maxValue);
} else if (index == 2) {
} else {
o.maxValue = 0;
ar& std::get<2>(o.maxValue);
}
ar& index;
if (index == 1) {
if (index == 0) {
o.minValue = {};
} else if (index == 1) {
o.minValue = 0.0f;
ar& std::get<1>(o.minValue);
} else if (index == 2) {
} else {
o.minValue = 0;
ar& std::get<2>(o.minValue);
}
@ -175,7 +179,7 @@ bool EffectCache::Load(const wchar_t* fileName, std::string_view hash, EffectDes
}
if (std::memcmp(buf.data(), bufHash.data(), bufHash.size()) != 0) {
SPDLOG_LOGGER_INFO(logger, "哈希检查失败");
SPDLOG_LOGGER_ERROR(logger, "缓存文件校验失败");
return false;
}
@ -193,7 +197,7 @@ bool EffectCache::Load(const wchar_t* fileName, std::string_view hash, EffectDes
ia& desc;
} catch (...) {
SPDLOG_LOGGER_INFO(logger, "反序列化失败");
SPDLOG_LOGGER_ERROR(logger, "反序列化失败");
desc = {};
return false;
}
@ -240,7 +244,6 @@ void EffectCache::Save(const wchar_t* fileName, std::string_view hash, const Eff
}
} else {
// 删除所有该文件的缓存
std::wregex regex(fmt::format(L"^{}_[0-9,a-f]{{{}}}.cmfx$", ConvertFileName(fileName),
Utils::Hasher::GetInstance()->GetHashLength() * 2), std::wregex::optimize | std::wregex::nosubs);
@ -258,7 +261,7 @@ void EffectCache::Save(const wchar_t* fileName, std::string_view hash, const Eff
}
if (!DeleteFile((L".\\cache\\"s + findData.cFileName).c_str())) {
SPDLOG_LOGGER_ERROR(logger, MakeWin32ErrorMsg(fmt::format("删除缓存文件{}失败",
SPDLOG_LOGGER_ERROR(logger, MakeWin32ErrorMsg(fmt::format("删除缓存文件 {} 失败",
StrUtils::UTF16ToUTF8(findData.cFileName))));
}
}

View file

@ -1,8 +1,7 @@
#include "pch.h"
#include "FrameRateDrawer.h"
#include "App.h"
using namespace std::chrono;
#include "resource.h"
bool FrameRateDrawer::Initialize(ComPtr<ID3D11Texture2D> renderTarget, const RECT& destRect) {
@ -19,7 +18,20 @@ bool FrameRateDrawer::Initialize(ComPtr<ID3D11Texture2D> renderTarget, const REC
_vp.Height = FLOAT(destRect.bottom - destRect.top);
_spriteBatch.reset(new SpriteBatch(renderer.GetD3DDC().Get()));
_spriteFont.reset(new SpriteFont(renderer.GetD3DDevice().Get(), L"assets/OpenSans.spritefont"));
// 从资源文件获取字体
HMODULE hInst = App::GetInstance().GetHInstance();
HRSRC hRsrc = FindResource(hInst, MAKEINTRESOURCE(IDR_FRAME_RATE_FONT), RT_RCDATA);
if (!hRsrc) {
return false;
}
HGLOBAL hRes = LoadResource(hInst, hRsrc);
if (!hRes) {
return false;
}
_spriteFont.reset(new SpriteFont(renderer.GetD3DDevice().Get(),
(const uint8_t*)LockResource(hRes), SizeofResource(hInst, hRsrc)));
return true;
}

View file

@ -26,8 +26,8 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_DEFAULT
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,6,0,0
PRODUCTVERSION 0,6,0,0
FILEVERSION 0,7,0,0
PRODUCTVERSION 0,7,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -42,12 +42,12 @@ BEGIN
BEGIN
BLOCK "040004b0"
BEGIN
VALUE "FileVersion", "0.6.0.0"
VALUE "FileVersion", "0.7.0.0"
VALUE "InternalName", "Runtime.dll"
VALUE "LegalCopyright", "Copyright (C) 2021"
VALUE "OriginalFilename", "Runtime.dll"
VALUE "ProductName", "Magpie"
VALUE "ProductVersion", "0.6.0.0"
VALUE "ProductVersion", "0.7.0.0"
END
END
BLOCK "VarFileInfo"
@ -91,6 +91,14 @@ END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// RCDATA
//
IDR_FRAME_RATE_FONT RCDATA "assets\\OpenSans.spritefont"
#endif // 中文(简体,中国) resources
/////////////////////////////////////////////////////////////////////////////

View file

@ -199,16 +199,16 @@
<ClCompile Include="GraphicsCaptureFrameSource.cpp" />
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="assets\OpenSans.spritefont">
<None Include="assets\OpenSans.spritefont">
<FileType>Document</FileType>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)assets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)assets</DestinationFolders>
</CopyFileToFolders>
</None>
<None Include="cpp.hint" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Version.rc" />
<ResourceCompile Include="Runtime.rc" />
</ItemGroup>
<ItemGroup>
<FxCompile Include="shaders\CopyPS.hlsl">

View file

@ -124,6 +124,9 @@
<ItemGroup>
<None Include="cpp.hint" />
<None Include="packages.config" />
<None Include="assets\OpenSans.spritefont">
<Filter>资源文件</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Filter Include="着色器">
@ -146,7 +149,7 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Version.rc">
<ResourceCompile Include="Runtime.rc">
<Filter>资源文件</Filter>
</ResourceCompile>
</ItemGroup>
@ -165,9 +168,6 @@
</FxCompile>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="assets\OpenSans.spritefont">
<Filter>资源文件</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="shaders\Lanczos.hlsl">
<Filter>着色器</Filter>
</CopyFileToFolders>

View file

@ -1,12 +1,14 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by version.rc
// Microsoft Visual C++ 生成的包含文件。
// 供 Runtime.rc 使用
//
#define IDR_FRAME_RATE_FONT 101
// 新对象的下一组默认值
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101

View file

@ -1,5 +1,3 @@
from os import path
import glob
import re
import sys
@ -13,40 +11,36 @@ versionComma = version.replace('.', ',')
rootDir = '..\\..'
csProjects = ["Magpie"]
cppProjects = ["Runtime"]
# C# 项目
for csProject in csProjects:
with open(rootDir + '\\' + csProject + '\\Properties\\AssemblyInfo.cs', mode='r+', encoding='utf8') as f:
src = f.read()
# Magpie
with open(rootDir + '\\Magpie\\Properties\\AssemblyInfo.cs', mode='r+', encoding='utf8') as f:
src = f.read()
src = re.sub(r'AssemblyVersion\([^*]*?\)', 'AssemblyVersion(\"' + version + '\")', src)
src = re.sub(r'AssemblyFileVersion\([^*]*?\)', 'AssemblyFileVersion(\"' + version + '\")', src)
src = re.sub(r'AssemblyVersion\([^*]*?\)', 'AssemblyVersion(\"' + version + '\")', src)
src = re.sub(r'AssemblyFileVersion\([^*]*?\)', 'AssemblyFileVersion(\"' + version + '\")', src)
f.seek(0)
f.truncate()
f.write(src)
f.seek(0)
f.truncate()
f.write(src)
# Magpie 的全局变量
with open(rootDir + '\\Magpie\\App.xaml.cs', mode='r+', encoding='utf8') as f:
src = f.read()
src = re.sub(r'Version\(".*?"\)', 'Version("' + version + '")', src)
f.seek(0)
f.truncate()
f.write(src)
# C++ 项目
for cppProject in cppProjects:
with open(rootDir + '\\' + cppProject + '\\version.rc', mode='r+', encoding='utf8') as f:
src = f.read()
# Runtime
with open(rootDir + '\\Runtime\\Runtime.rc', mode='r+', encoding='utf8') as f:
src = f.read()
src = re.sub(r'FILEVERSION .*?\n', 'FILEVERSION ' + versionComma + '\n', src)
src = re.sub(r'PRODUCTVERSION .*?\n', 'PRODUCTVERSION ' + versionComma + '\n', src)
src = re.sub(r'"FileVersion",[ ]*?".*?"\n', '"FileVersion", "' + version + '"\n', src)
src = re.sub(r'"ProductVersion",[ ]*?".*?"\n', '"ProductVersion", "' + version + '"\n', src)
src = re.sub(r'FILEVERSION .*?\n', 'FILEVERSION ' + versionComma + '\n', src)
src = re.sub(r'PRODUCTVERSION .*?\n', 'PRODUCTVERSION ' + versionComma + '\n', src)
src = re.sub(r'"FileVersion",[ ]*?".*?"\n', '"FileVersion", "' + version + '"\n', src)
src = re.sub(r'"ProductVersion",[ ]*?".*?"\n', '"ProductVersion", "' + version + '"\n', src)
f.seek(0)
f.truncate()
f.write(src)
f.seek(0)
f.truncate()
f.write(src)