wstring -> string issue finally solved

This commit is contained in:
cdozdil
2024-07-21 12:36:57 +03:00
parent 2394597c42
commit 91c695f4d6
11 changed files with 27 additions and 69 deletions
+2 -7
View File
@@ -32,11 +32,8 @@ Config::Config(std::wstring fileName)
bool Config::Reload(std::filesystem::path iniPath)
{
auto pathWStr = iniPath.wstring();
std::string pathStr(pathWStr.length(), 0);
std::transform(pathWStr.begin(), pathWStr.end(), pathStr.begin(), [](wchar_t c) { return (char)c; });
spdlog::info("Trying to load ini from: {0}", pathStr);
spdlog::info("Trying to load ini from: {0}", wstring_to_string(pathWStr));
if (ini.LoadFile(iniPath.c_str()) == SI_OK)
{
// Upscalers
@@ -601,10 +598,8 @@ bool Config::SaveIni()
}
auto pathWStr = absoluteFileName.wstring();
std::string pathStr(pathWStr.length(), 0);
std::transform(pathWStr.begin(), pathWStr.end(), pathStr.begin(), [](wchar_t c) { return (char)c; });
spdlog::info("Trying to save ini to: {0}", pathStr);
spdlog::info("Trying to save ini to: {0}", wstring_to_string(pathWStr));
return ini.SaveFile(absoluteFileName.wstring().c_str()) >= 0;
}
+2 -8
View File
@@ -60,10 +60,7 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D11_Init_Ext(unsigned long long InApp
spdlog::info("NVSDK_NGX_D3D11_Init_Ext SDK: {0:x}", (int)InSDKVersion);
std::wstring string(InApplicationDataPath);
std::string str(string.length(), 0);
std::transform(string.begin(), string.end(), str.begin(), [](wchar_t c) { return (char)c; });
spdlog::debug("NVSDK_NGX_D3D11_Init_Ext InApplicationDataPath {0}", str);
spdlog::debug("NVSDK_NGX_D3D11_Init_Ext InApplicationDataPath {0}", wstring_to_string(string));
Config::Instance()->NVNGX_FeatureInfo_Paths.clear();
@@ -74,11 +71,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D11_Init_Ext(unsigned long long InApp
const wchar_t* path = InFeatureInfo->PathListInfo.Path[i];
std::wstring iniPathW(path);
std::string iniPath(iniPathW.length(), 0);
std::transform(iniPathW.begin(), iniPathW.end(), iniPath.begin(), [](wchar_t c) { return (char)c; });
Config::Instance()->NVNGX_FeatureInfo_Paths.push_back(iniPathW);
spdlog::debug("NVSDK_NGX_D3D11_Init_Ext PathListInfo[{0}]: {1}", i, iniPath);
spdlog::debug("NVSDK_NGX_D3D11_Init_Ext PathListInfo[{0}]: {1}", i, wstring_to_string(iniPathW));
}
}
+3 -9
View File
@@ -226,10 +226,7 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Init_Ext(unsigned long long InApp
spdlog::info("NVSDK_NGX_D3D12_Init_Ext SDK: {0:x}", (unsigned int)InSDKVersion);
appDataPath = InApplicationDataPath;
std::string str(appDataPath.length(), 0);
std::transform(appDataPath.begin(), appDataPath.end(), str.begin(), [](wchar_t c) { return (char)c; });
spdlog::info("NVSDK_NGX_D3D12_Init_Ext InApplicationDataPath {0}", str);
spdlog::info("NVSDK_NGX_D3D12_Init_Ext InApplicationDataPath {0}", wstring_to_string(appDataPath));
Config::Instance()->NVNGX_FeatureInfo_Paths.clear();
@@ -243,13 +240,10 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Init_Ext(unsigned long long InApp
std::wstring iniPathW(path);
std::string iniPath(iniPathW.length(), 0);
std::transform(iniPathW.begin(), iniPathW.end(), iniPath.begin(), [](wchar_t c) { return (char)c; });
spdlog::debug("NVSDK_NGX_D3D12_Init_Ext PathListInfo[{1}] checking nvngx.ini file in: {0}", iniPath, i);
spdlog::debug("NVSDK_NGX_D3D12_Init_Ext PathListInfo[{1}] checking nvngx.ini file in: {0}", wstring_to_string(iniPathW), i);
if (Config::Instance()->LoadFromPath(path))
spdlog::info("NVSDK_NGX_D3D12_Init_Ext PathListInfo[{1}] nvngx.ini file reloaded from: {0}", iniPath, i);
spdlog::info("NVSDK_NGX_D3D12_Init_Ext PathListInfo[{1}] nvngx.ini file reloaded from: {0}", wstring_to_string(iniPathW), i);
}
}
+3 -9
View File
@@ -98,22 +98,16 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_VULKAN_Init_Ext2(unsigned long long InA
}
spdlog::info("NVSDK_NGX_VULKAN_Init_Ext2 InApplicationId: {0}", InApplicationId);
spdlog::info("NVSDK_NGX_VULKAN_Init_Ext2 InSDKVersion: {0:x}", (unsigned int)InSDKVersion);
spdlog::info("NVSDK_NGX_VULKAN_Init_Ext2 InSDKVersion: {0:x}", (UINT)InSDKVersion);
std::wstring string(InApplicationDataPath);
std::string str(string.length(), 0);
std::transform(string.begin(), string.end(), str.begin(), [](wchar_t c) { return (char)c; });
spdlog::debug("NVSDK_NGX_VULKAN_Init_Ext2 InApplicationDataPath {0}", str);
spdlog::debug("NVSDK_NGX_VULKAN_Init_Ext2 InApplicationDataPath {0}", wstring_to_string(string));
if (Config::Instance()->NVNGX_FeatureInfo_Paths.size() > 0)
{
for (size_t i = 0; i < Config::Instance()->NVNGX_FeatureInfo_Paths.size(); ++i)
{
std::string str(Config::Instance()->NVNGX_FeatureInfo_Paths[i].length(), 0);
std::transform(Config::Instance()->NVNGX_FeatureInfo_Paths[i].begin(), Config::Instance()->NVNGX_FeatureInfo_Paths[i].end(), str.begin(), [](wchar_t c) { return (char)c; });
spdlog::debug("NVSDK_NGX_VULKAN_Init_Ext2 PathListInfo[{0}]: {1}", i, str);
spdlog::debug("NVSDK_NGX_VULKAN_Init_Ext2 PathListInfo[{0}]: {1}", i, wstring_to_string(Config::Instance()->NVNGX_FeatureInfo_Paths[i]));
}
}
+1 -5
View File
@@ -542,11 +542,7 @@ public:
for (size_t i = 0; i < Config::Instance()->NVNGX_FeatureInfo_Paths.size(); ++i)
{
paths[i] = Config::Instance()->NVNGX_FeatureInfo_Paths[i].c_str();
std::string str(Config::Instance()->NVNGX_FeatureInfo_Paths[i].length(), 0);
std::transform(Config::Instance()->NVNGX_FeatureInfo_Paths[i].begin(), Config::Instance()->NVNGX_FeatureInfo_Paths[i].end(), str.begin(), [](wchar_t c) { return (char)c; });
spdlog::debug("NVNGXProxy::GetFeatureCommonInfo paths[{0}]: {1}", i, str);
spdlog::debug("NVNGXProxy::GetFeatureCommonInfo paths[{0}]: {1}", i, wstring_to_string(Config::Instance()->NVNGX_FeatureInfo_Paths[i]));
}
fcInfo->PathListInfo.Path = paths;
+2 -2
View File
@@ -81,8 +81,8 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>$(SolutionDir)external\vulkan\include;$(SolutionDir)external\nvngx_dlss_sdk;$(SolutionDir)external\xess\inc\xess;$(SolutionDir)external\FidelityFX-SDK\ffx-api\include\ffx_api;$(SolutionDir)external\simpleini;$(SolutionDir)external\unordered_dense\include;$(SolutionDir)external\spdlog\include;$(IncludePath)</IncludePath>
<LibraryPath>$(ProjectDir)fsr2\lib;$(ProjectDir)fsr2_212\lib;$(ProjectDir)vulkan;$(ProjectDir)d3dx;$(ProjectDir)detours;$(SolutionDir)external\xess\lib;$(LibraryPath)</LibraryPath>
<TargetName>winmm</TargetName>
<OutDir>D:\Folders\Games\Deep Rock Galactic\FSD\Binaries\Win64\</OutDir>
<TargetName>dxgi</TargetName>
<OutDir>D:\Folders\Games\SteamLibrary\steamapps\common\EVERSPACE™ 2 - Demo\ES2\Binaries\Win64\</OutDir>
<IntDir>.\x64\Debug</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+1 -3
View File
@@ -30,15 +30,13 @@ inline static std::string ResultToString(FfxErrorCode result)
inline static void FfxLogCallback(FfxFsr2MsgType type, const wchar_t* message)
{
std::wstring string(message);
std::string str(string.length(), 0);
std::transform(string.begin(), string.end(), str.begin(), [](wchar_t c) { return (char)c; });
//if (type == FFX_FSR2_MESSAGE_TYPE_ERROR)
// spdlog::error("FSR2Feature::LogCallback FSR Runtime: {0}", str);
//else if (type == FFX_FSR2_MESSAGE_TYPE_WARNING)
// spdlog::warn("FSR2Feature::LogCallback FSR Runtime: {0}", str);
//else
spdlog::debug("FSR2Feature::LogCallback FSR Runtime: {0}", str);
spdlog::debug("FSR2Feature::LogCallback FSR Runtime: {0}", wstring_to_string(string));
}
class FSR2Feature : public virtual IFeature
+1 -3
View File
@@ -23,15 +23,13 @@ inline static std::string ResultToString(ffxReturnCode_t result)
inline static void FfxLogCallback(uint32_t type, const wchar_t* message)
{
std::wstring string(message);
std::string str(string.length(), 0);
std::transform(string.begin(), string.end(), str.begin(), [](wchar_t c) { return (char)c; });
//if (type == FFX_API_MESSAGE_TYPE_ERROR)
// spdlog::error("FSR31Feature::LogCallback FSR Runtime: {0}", str);
//else if (type == FFX_API_MESSAGE_TYPE_WARNING)
// spdlog::warn("FSR31Feature::LogCallback FSR Runtime: {0}", str);
//else
spdlog::debug("FSR31Feature::LogCallback FSR Runtime: {0}", str);
spdlog::debug("FSR31Feature::LogCallback FSR Runtime: {0}", wstring_to_string(string));
}
class FSR31Feature : public virtual IFeature
+2 -4
View File
@@ -228,8 +228,7 @@ static HMODULE hkLoadLibraryW(LPCWSTR lpLibFileName)
for (size_t i = 0; i < lcaseLibName.size(); i++)
lcaseLibName[i] = std::tolower(lcaseLibName[i]);
std::string lcaseLibNameA(lcaseLibName.length(), 0);
std::transform(lcaseLibName.begin(), lcaseLibName.end(), lcaseLibNameA.begin(), [](wchar_t c) { return (char)c; });
auto lcaseLibNameA = wstring_to_string(lcaseLibName);
#ifdef DEBUG
spdlog::trace("hkLoadLibraryW call: {0}", lcaseLibNameA);
@@ -452,8 +451,7 @@ static HMODULE hkLoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFla
for (size_t i = 0; i < lcaseLibName.size(); i++)
lcaseLibName[i] = std::tolower(lcaseLibName[i]);
std::string lcaseLibNameA(lcaseLibName.length(), 0);
std::transform(lcaseLibName.begin(), lcaseLibName.end(), lcaseLibNameA.begin(), [](wchar_t c) { return (char)c; });
auto lcaseLibNameA = wstring_to_string(lcaseLibName);
#ifdef DEBUG
spdlog::trace("hkLoadLibraryExW call: {0}", lcaseLibNameA);
+6 -7
View File
@@ -1424,7 +1424,7 @@ static bool CheckDx12(ID3D12Device* InDevice)
if (result != S_OK)
{
spdlog::error("ImGuiOverlayDx12::CheckDx12 D3D12CreateDevice: {0:X}", (unsigned long)result);
spdlog::error("ImGuiOverlayDx12::CheckDx12 D3D12CreateDevice: {0:X}", (UINT)result);
return false;
}
}
@@ -1435,7 +1435,7 @@ static bool CheckDx12(ID3D12Device* InDevice)
result = device->CreateCommandQueue(&desc, IID_PPV_ARGS(&cq));
if (result != S_OK)
{
spdlog::error("ImGuiOverlayDx12::CheckDx12 CreateCommandQueue: {0:X}", (unsigned long)result);
spdlog::error("ImGuiOverlayDx12::CheckDx12 CreateCommandQueue: {0:X}", (UINT)result);
return false;
}
@@ -1484,7 +1484,7 @@ static bool CheckFSR3()
if (offxCreateFrameinterpolationSwapchainForHwndDX12_Mod != nullptr)
{
spdlog::info("ImGuiOverlayDx12::CheckMods Uniscaler's ffxCreateFrameinterpolationSwapchainForHwndDX12 found");
spdlog::info("ImGuiOverlayDx12::CheckFSR3 Uniscaler's ffxCreateFrameinterpolationSwapchainForHwndDX12 found");
_bindedFSR3_Uniscaler = true;
_bindedFSR3_Mod = true;
}
@@ -1496,7 +1496,7 @@ static bool CheckFSR3()
if (offxCreateFrameinterpolationSwapchainForHwndDX12_Mod != nullptr)
{
spdlog::info("ImGuiOverlayDx12::CheckMods Nukem's ffxCreateFrameinterpolationSwapchainForHwndDX12 found");
spdlog::info("ImGuiOverlayDx12::CheckFSR3 Nukem's ffxCreateFrameinterpolationSwapchainForHwndDX12 found");
_bindedFSR3_Mod = true;
}
}
@@ -1523,7 +1523,7 @@ static bool CheckFSR3()
// Hook FSR3 ffxGetDX12SwapchainPtr methods
if (offxCreateFrameinterpolationSwapchainForHwndDX12_FSR3)
{
spdlog::info("ImGuiOverlayDx12::CheckMods FSR3's ffxCreateFrameinterpolationSwapchainForHwndDX12 found");
spdlog::info("ImGuiOverlayDx12::CheckFSR3 FSR3's ffxCreateFrameinterpolationSwapchainForHwndDX12 found");
_bindedFSR3_Native = true;
DetourTransactionBegin();
@@ -1542,7 +1542,7 @@ static bool CheckFSR3()
if (oFfxCreateContext_FSR3)
{
spdlog::info("ImGuiOverlayDx12::CheckMods FSR3's ffxCreateContext found");
spdlog::info("ImGuiOverlayDx12::CheckFSR3 FSR3's ffxCreateContext found");
_bindedFSR3_Native = true;
DetourTransactionBegin();
@@ -1573,7 +1573,6 @@ static bool BindAll(HWND InHWnd, ID3D12Device* InDevice)
do
{
if (!CheckDx12(InDevice))
break;
+4 -12
View File
@@ -28,19 +28,11 @@
inline HMODULE dllModule;
inline DWORD processId;
inline static std::string wstring_to_string(const std::wstring& wstr)
inline static std::string wstring_to_string(const std::wstring& wide_str)
{
size_t len = std::wcstombs(nullptr, wstr.c_str(), 0);
if (len == static_cast<size_t>(-1))
{
throw std::runtime_error("Conversion error");
}
std::vector<char> str(len + 1);
std::wcstombs(str.data(), wstr.c_str(), len + 1);
return std::string(str.data());
std::string str(wide_str.length(), 0);
std::transform(wide_str.begin(), wide_str.end(), str.begin(), [](wchar_t c) { return (char)c; });
return str;
}
inline static std::wstring string_to_wstring(const std::string& str)