修复构建 改为源码依赖

This commit is contained in:
2024-09-27 19:03:10 +08:00
parent fde177894a
commit ccf642ef92
9 changed files with 115 additions and 42 deletions

View File

@@ -129,7 +129,14 @@ file(GLOB_RECURSE EXPORTED_HEADERS ${CMAKE_SOURCE_DIR}/src/*.h)
foreach (HEADER ${EXPORTED_HEADERS})
get_filename_component(HEADER_DIR ${HEADER} DIRECTORY)
get_filename_component(HEADER_NAME ${HEADER} NAME)
string(REPLACE "${CMAKE_SOURCE_DIR}/src/" "" HEADER_RELATIVE_PATH ${HEADER_DIR})
# 检查 HEADER_DIR 是否包含 "/src/"
string(FIND ${HEADER_DIR} "/src/" SRC_DIR_INDEX)
# 判断是否找到
if (SRC_DIR_INDEX GREATER -1)
string(REPLACE "${CMAKE_SOURCE_DIR}/src/" "" HEADER_RELATIVE_PATH ${HEADER_DIR})
else()
string(REPLACE "${CMAKE_SOURCE_DIR}/src" "" HEADER_RELATIVE_PATH ${HEADER_DIR})
endif()
file(COPY ${HEADER} DESTINATION ${OUTPUT_DIR}/include/${HEADER_RELATIVE_PATH})
endforeach ()

View File

@@ -1,9 +1,12 @@
#include "Log.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_sinks.h"
void Log::Init(LogLevel level, std::string fileName)
{
spdlog::stdout_logger_mt("console");
spdlog::set_level(static_cast<spdlog::level::level_enum>(level)); // 设置日志级别为 debug
spdlog::set_pattern("[%H:%M:%S %z] [%n] [%^---%L---%$] [thread %t] %v");
}

View File

@@ -2,17 +2,24 @@
#include <locale>
#include <codecvt>
template<typename To, typename From>
To Convert(const From& input) {
std::wstring_convert<std::codecvt_utf8<typename From::value_type>, typename From::value_type> converter;
return converter.to_bytes(input);
}
namespace WinDevcie {
std::string Wstring2String(const std::wstring& input) {
return Convert<std::string>(input);
}
namespace Utils {
std::string Wchar2String(const WCHAR* input) {
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
return converter.to_bytes(input);
}
template<typename To, typename From>
To Convert(const From& input) {
std::wstring_convert<std::codecvt_utf8<typename From::value_type>, typename From::value_type> converter;
return converter.to_bytes(input);
}
std::string Wstring2String(const std::wstring& input) {
return Convert<std::string>(input);
}
std::string Wchar2String(const WCHAR* input) {
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
return converter.to_bytes(input);
}
}
}

View File

@@ -1,7 +1,7 @@
#include "ScreenManager.h"
#include "spdlog/spdlog.h"
#include "Utils/StringUtil.h"
#include "Utils/Log.h"
#include "../Utils/StringUtil.h"
#include "../Utils/Log.h"
#include <dxgi.h>
ScreenManager::ScreenManager()
@@ -56,7 +56,7 @@ void ScreenManager::_UpdateDisplayAdapterList()
DXGI_ADAPTER_DESC adapterDesc;
pAdapter->GetDesc(&adapterDesc);
spdlog::info("Adapter Index:{0}, Description:{1}, DeviceId:{2}, VendorId:{3}, SubSysId:{4}, Revision:{5}, AdapterLuid(H-L):{6}-{7} ",
adapterIndex, Wchar2String(adapterDesc.Description), adapterDesc.DeviceId, adapterDesc.VendorId, adapterDesc.SubSysId,
adapterIndex, WinDevcie::Utils::Wchar2String(adapterDesc.Description), adapterDesc.DeviceId, adapterDesc.VendorId, adapterDesc.SubSysId,
adapterDesc.Revision, adapterDesc.AdapterLuid.HighPart, adapterDesc.AdapterLuid.LowPart);
// print adapter output info
@@ -72,7 +72,7 @@ void ScreenManager::_UpdateDisplayAdapterList()
{
// 输出友好名称
spdlog::info("Adapter Output Index:{0}, DeviceName:{1}, szDevice:{2}, right:{3}, bottom:{4}",
j, Wchar2String(outputDesc.DeviceName), monitorInfo.szDevice, monitorInfo.rcMonitor.right, monitorInfo.rcMonitor.bottom);
j, WinDevcie::Utils::Wchar2String(outputDesc.DeviceName), monitorInfo.szDevice, monitorInfo.rcMonitor.right, monitorInfo.rcMonitor.bottom);
}
}
}
@@ -110,7 +110,7 @@ BOOL ScreenManager::_EnumMonitorProc(HMONITOR hMonitor)
if (DisplayConfigGetDeviceInfo(&targetDeviceName.header) == ERROR_SUCCESS)
{
spdlog::info("_UpdateMonitorInfoMap, monitorDevicePath:{0}, monitorFriendlyDeviceName:{1}",
Wchar2String(targetDeviceName.monitorDevicePath), Wchar2String(targetDeviceName.monitorFriendlyDeviceName));
WinDevcie::Utils::Wchar2String(targetDeviceName.monitorDevicePath), WinDevcie::Utils::Wchar2String(targetDeviceName.monitorFriendlyDeviceName));
// 获取指定 HMONITOR 的分辨率信息
DEVMODE dm;

View File

@@ -0,0 +1,15 @@
#include "WinDeviceManager.h"
#include "Utils/Log.h"
WinDevice::WinDeviceManager::WinDeviceManager() {
}
WinDevice::WinDeviceManager::~WinDeviceManager() {
}
void WinDevice::WinDeviceManager::Init() {
Log::Init(LogLevel::Debug, "WinDevice.log");
}

View File

@@ -0,0 +1,16 @@
#ifndef WINDEVICEMANAGER_H
#define WINDEVICEMANAGER_H
#endif // WINDEVICEMANAGER_H
namespace WinDevice {
class WinDeviceManager
{
public:
WinDeviceManager();
~WinDeviceManager();
static void Init();
};
}