调整类重载,修复部分BUG,增加请求头检查
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
// CoreDeploy.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
|
||||
//
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
|
||||
#include "../UNSWebServerCore/ServerLogger.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
static const fs::path src = "F:\\UNSWebServerCore\\UNSWebServerCore\\";
|
||||
|
||||
/**
|
||||
* @brief 查找指定目录下所有包含 UNSWSC_DLL_EXPORT 宏的 .h 头文件
|
||||
*
|
||||
* @param source_dir 目标源代码文件夹路径
|
||||
* @return std::vector<std::string> 匹配到的文件名列表(纯文件名,不含路径)
|
||||
*/
|
||||
std::vector<std::string> FileExportHeaders(const std::string& source_dir)
|
||||
{
|
||||
std::vector<std::string> matching_files;
|
||||
const std::string target_macro = "UNSWSC_DLL_EXPORT";
|
||||
|
||||
fs::path dir_path(source_dir);
|
||||
|
||||
// 校验路径有效性
|
||||
std::error_code ec;
|
||||
if (!fs::exists(dir_path, ec) || !fs::is_directory(dir_path, ec))
|
||||
return matching_files;
|
||||
|
||||
// 递归遍历目录(跳过因权限不足无法访问的文件夹)
|
||||
auto options = fs::directory_options::skip_permission_denied;
|
||||
for (const auto& entry : fs::recursive_directory_iterator(dir_path, options, ec))
|
||||
{
|
||||
// 1. 过滤:必须是普通文件且扩展名为 .h
|
||||
if (entry.is_regular_file(ec) && entry.path().extension() == ".h")
|
||||
{
|
||||
std::ifstream file(entry.path(), std::ios::in);
|
||||
if (!file.is_open())
|
||||
continue;
|
||||
|
||||
// 2. 逐行读取并搜索关键字
|
||||
std::string line;
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
if (line.find(target_macro) != std::string::npos)
|
||||
{
|
||||
// 找到匹配项,提取纯文件名并加入列表
|
||||
matching_files.push_back(entry.path().filename().string());
|
||||
break; // 找到后跳出当前文件的读取,避免重复添加
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return matching_files;
|
||||
}
|
||||
|
||||
std::map<std::string, std::map<bool, std::vector<std::string>>> lib_files =
|
||||
{
|
||||
{
|
||||
"Debug",
|
||||
{
|
||||
{ true, { "UNSWebServerCored.lib" } },
|
||||
{ false, { "UNSWebServerCored.dll", "UNSWebServerCored.pdb" } }
|
||||
}
|
||||
},
|
||||
{
|
||||
"Release",
|
||||
{
|
||||
{ true, { "UNSWebServerCore.lib" } },
|
||||
{ false, { "UNSWebServerCore.dll", "UNSWebServerCore.pdb" } }
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
bool CopyHeaderFile(const fs::path& dest, const std::vector<std::string>& files)
|
||||
{
|
||||
SCLOGF_INFO("Header Copy Begin: {} -> {}", src, dest);
|
||||
for (const auto& file : files)
|
||||
{
|
||||
std::error_code ec;
|
||||
fs::copy_file((src / file), (dest / file), fs::copy_options::overwrite_existing, ec);
|
||||
if (ec)
|
||||
{
|
||||
SCLOGF_ERROR("Header [{}] Copy Failed: {} ({})", file, ec.value(), ec.message());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
SCLOGF_INFO("Header Copy Success, All File Copied To {}", dest);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CopyLibraryFile(const fs::path& dest, const std::string& arch_text)
|
||||
{
|
||||
SCLOGF_INFO("Library Copy Begin: {} -> {}", src, dest);
|
||||
for (const auto& [build, f_info] : lib_files)
|
||||
{
|
||||
fs::path dst_build_path = ((dest / "..") / arch_text) / build;
|
||||
for (const auto& [lib, files] : f_info)
|
||||
{
|
||||
fs::path dst_path = (lib ? dest : dst_build_path);
|
||||
for (const auto& file : files)
|
||||
{
|
||||
std::error_code ec;
|
||||
fs::path file_path = (((src / "..") / arch_text) / build) / file;
|
||||
fs::copy_file(file_path, (dst_path / file), fs::copy_options::overwrite_existing, ec);
|
||||
if (ec)
|
||||
{
|
||||
SCLOGF_ERROR("Library [{}] Copy Failed: {} ({})", file, ec.value(), ec.message());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SCLOGF_INFO("Library Copy Success, All File Copied To {}", dest);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeployCore(const fs::path& header_path, const fs::path& library_path = "")
|
||||
{
|
||||
if (header_path.empty())
|
||||
{
|
||||
SCLOGF_FATAL("ARG ERROR: Header IS Empty");
|
||||
return false;
|
||||
}
|
||||
auto header_files = FileExportHeaders(src.string());
|
||||
if (!CopyHeaderFile(header_path, header_files))
|
||||
{
|
||||
SCLOGF_FATAL("Header Copy Failed.");
|
||||
return false;
|
||||
}
|
||||
if (!CopyLibraryFile((library_path.empty() ? header_path : library_path), "x64"))
|
||||
{
|
||||
SCLOGF_FATAL("Library Copy Failed.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
SCLOG_CONSOLE_INIT(uns::llAll);
|
||||
|
||||
DeployCore("F:\\SVProjects\\SVUpdate\\OTAServer\\unswsc", "F:\\SVProjects\\SVUpdate\\OTAServer");
|
||||
|
||||
SCLOG_CLOSE();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>18.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{71d27301-6fd9-456f-956c-a52ce5e12675}</ProjectGuid>
|
||||
<RootNamespace>CoreDeploy</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<Manifest>
|
||||
<EnableSegmentHeap>true</EnableSegmentHeap>
|
||||
</Manifest>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<Manifest>
|
||||
<EnableSegmentHeap>true</EnableSegmentHeap>
|
||||
</Manifest>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<Manifest>
|
||||
<EnableSegmentHeap>true</EnableSegmentHeap>
|
||||
</Manifest>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;_WINDOWS;UNSWEBSERVERCORE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<Manifest>
|
||||
<EnableSegmentHeap>true</EnableSegmentHeap>
|
||||
</Manifest>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\UNSWebServerCore\LogArg.cpp" />
|
||||
<ClCompile Include="..\UNSWebServerCore\ServerLogger.cpp" />
|
||||
<ClCompile Include="CoreDeploy.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\UNSWebServerCore\Export.h" />
|
||||
<ClInclude Include="..\UNSWebServerCore\LogArg.h" />
|
||||
<ClInclude Include="..\UNSWebServerCore\ServerLogger.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="CoreDeploy.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\UNSWebServerCore\LogArg.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\UNSWebServerCore\ServerLogger.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\UNSWebServerCore\Export.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\UNSWebServerCore\LogArg.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\UNSWebServerCore\ServerLogger.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user