From 293741a939a4e5c88d328438d4c76157fc8c82d7 Mon Sep 17 00:00:00 2001 From: bela333 Date: Mon, 28 Oct 2019 08:22:33 +0100 Subject: [PATCH] Fixed Unicode characters in config file --- DiscordDiva/config.cpp | 25 ++++++++++++++----------- DiscordDiva/config.h | 1 + DiscordDiva/discord.cpp | 1 + 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/DiscordDiva/config.cpp b/DiscordDiva/config.cpp index 8f60bdf..17822cd 100644 --- a/DiscordDiva/config.cpp +++ b/DiscordDiva/config.cpp @@ -16,19 +16,22 @@ void GetOverrideName(int songID, char* defaultName, char* buffer, rsize_t buffer wchar_t configID[7]; //pv_000\0 swprintf_s(configID, L"pv_%03d", songID); - //Converting arguments to wchar_t* - //defaultName - size_t defaultName_len = strlen(defaultName)+1; - wchar_t* wDefaultName = new wchar_t[defaultName_len]; - mbstowcs_s((size_t*)NULL, wDefaultName, defaultName_len, defaultName, _TRUNCATE); + int lenDefaultName = MultiByteToWideChar(CP_UTF8, 0, defaultName, -1, 0, 0); + wchar_t* wDefaultName = new wchar_t[lenDefaultName]; + MultiByteToWideChar(CP_UTF8, 0, defaultName, -1, wDefaultName, lenDefaultName); - wchar_t* wBuffer = new wchar_t[bufferSize]; + //Populate wBuffer with either the default name or the override + wchar_t* wBuffer = new wchar_t[bufferSize*2]; + GetPrivateProfileStringW(L"override", configID, wDefaultName, wBuffer, bufferSize*2, CONFIG_FILE); - GetPrivateProfileStringW(L"override", configID, wDefaultName, wBuffer, bufferSize, CONFIG_FILE); + int lenName = WideCharToMultiByte(CP_UTF8, 0, wBuffer, -1, 0, 0, 0, 0); + char* name = new char[lenName]; + WideCharToMultiByte(CP_UTF8, 0, wBuffer, -1, buffer, bufferSize, 0, 0); - //Convert buffer from wchar_t* - wcstombs_s((size_t)NULL, buffer, bufferSize, wBuffer, _TRUNCATE); - delete wDefaultName; - delete wBuffer; + //Freeing resources + delete[] wBuffer; + delete[] wDefaultName; + delete[] name; + } \ No newline at end of file diff --git a/DiscordDiva/config.h b/DiscordDiva/config.h index 7af1e29..38828db 100644 --- a/DiscordDiva/config.h +++ b/DiscordDiva/config.h @@ -1,4 +1,5 @@ #pragma once #include +#include void GetOverrideName(int songID, char* defaultName, char* buffer, rsize_t bufferSize); \ No newline at end of file diff --git a/DiscordDiva/discord.cpp b/DiscordDiva/discord.cpp index 3cadfe7..3319ef8 100644 --- a/DiscordDiva/discord.cpp +++ b/DiscordDiva/discord.cpp @@ -87,6 +87,7 @@ void ChangeActivity(int isPlaying, char* songName, int isPV, Difficulty difficul coreMutex.lock(); if (activities == nullptr || core == nullptr) { + coreMutex.unlock(); return; } activities->update_activity(activities, &activity, NULL, UpdateActivityCallback);