mirror of
https://github.com/Rosalie241/RMG.git
synced 2026-07-11 01:24:01 +02:00
RMG-Core: introduce & use ConvertStringEncoding
This commit is contained in:
@@ -9,6 +9,9 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(SDL2 REQUIRED sdl2)
|
||||
pkg_check_modules(MINIZIP REQUIRED minizip)
|
||||
if (WIN32)
|
||||
pkg_check_modules(ICONV REQUIRED iconv)
|
||||
endif(WIN32)
|
||||
|
||||
configure_file(Config.hpp.in Config.hpp)
|
||||
|
||||
@@ -18,6 +21,7 @@ set(RMG_CORE_SOURCES
|
||||
m64p/ConfigApi.cpp
|
||||
m64p/PluginApi.cpp
|
||||
CachedRomHeaderAndSettings.cpp
|
||||
ConvertStringEncoding.cpp
|
||||
Settings/Settings.cpp
|
||||
SpeedLimiter.cpp
|
||||
RomSettings.cpp
|
||||
@@ -69,7 +73,7 @@ if(UNIX)
|
||||
endif(UNIX)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(RMG-Core wsock32 ws2_32)
|
||||
target_link_libraries(RMG-Core wsock32 ws2_32 ${ICONV_LIBRARIES})
|
||||
endif(WIN32)
|
||||
|
||||
target_link_libraries(RMG-Core
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
#define CORE_INTERNAL
|
||||
#include "Core.hpp"
|
||||
#include "ConvertStringEncoding.hpp"
|
||||
|
||||
//
|
||||
// Local Variables
|
||||
@@ -28,7 +29,19 @@ void CoreDebugCallback(void* context, int level, const char* message)
|
||||
return;
|
||||
}
|
||||
|
||||
l_DebugCallbackFunc((CoreDebugMessageType)level, std::string(message));
|
||||
std::string messageString(message);
|
||||
|
||||
// convert string encoding accordingly
|
||||
if (messageString.starts_with("IS64:"))
|
||||
{
|
||||
messageString = CoreConvertStringEncoding(message, CoreStringEncoding::EUC_JP);
|
||||
}
|
||||
else
|
||||
{
|
||||
messageString = CoreConvertStringEncoding(message, CoreStringEncoding::Shift_JIS);
|
||||
}
|
||||
|
||||
l_DebugCallbackFunc((CoreDebugMessageType)level, messageString);
|
||||
}
|
||||
|
||||
void CoreStateCallback(void* context, m64p_core_param param, int value)
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Rosalie's Mupen GUI - https://github.com/Rosalie241/RMG
|
||||
* Copyright (C) 2020 Rosalie Wanders <rosalie@mailbox.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 3.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#define CORE_INTERNAL
|
||||
#include "ConvertStringEncoding.hpp"
|
||||
|
||||
#include "Error.hpp"
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
#include <iconv.h>
|
||||
|
||||
//
|
||||
// Exported Functions
|
||||
//
|
||||
|
||||
std::string CoreConvertStringEncoding(std::string str, CoreStringEncoding encoding)
|
||||
{
|
||||
std::string error;
|
||||
std::string encodingString;
|
||||
|
||||
iconv_t cd;
|
||||
|
||||
char inputBuf[256] = {0};
|
||||
char outputBuf[256] = {0};
|
||||
|
||||
char* inputBufPtr = (char*)str.c_str();
|
||||
char* outputBufPtr = outputBuf;
|
||||
|
||||
size_t inputBufSize = str.size();
|
||||
size_t outputBufSize = sizeof(outputBuf);
|
||||
|
||||
if (encoding == CoreStringEncoding::EUC_JP)
|
||||
{
|
||||
encodingString = "EUC-JP";
|
||||
}
|
||||
else
|
||||
{
|
||||
encodingString = "Shift_JIS";
|
||||
}
|
||||
|
||||
cd = iconv_open("UTF-8//TRANSLIT//IGNORE", encodingString.c_str());
|
||||
if (cd == (iconv_t)-1)
|
||||
{
|
||||
error = "CoreConvertStringEncoding Failed: ";
|
||||
error += "iconv_open Failed: ";
|
||||
error += errno;
|
||||
CoreSetError(error);
|
||||
return str;
|
||||
}
|
||||
|
||||
size_t ret = iconv(cd, &inputBufPtr, &inputBufSize, &outputBufPtr, &outputBufSize);
|
||||
if (ret == -1)
|
||||
{
|
||||
error = "CoreConvertStringEncoding Failed: ";
|
||||
error += "iconv Failed: ";
|
||||
error += errno;
|
||||
CoreSetError(error);
|
||||
|
||||
// reset iconv
|
||||
iconv(cd, nullptr, nullptr, nullptr, nullptr);
|
||||
iconv_close(cd);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
// reset iconv
|
||||
iconv(cd, nullptr, nullptr, nullptr, nullptr);
|
||||
iconv_close(cd);
|
||||
|
||||
return std::string(outputBuf);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Rosalie's Mupen GUI - https://github.com/Rosalie241/RMG
|
||||
* Copyright (C) 2020 Rosalie Wanders <rosalie@mailbox.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 3.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef CORE_CONVERTSTRINGENCODING_HPP
|
||||
#define CORE_CONVERTSTRINGENCODING_HPP
|
||||
#ifdef CORE_INTERNAL
|
||||
|
||||
#include <string>
|
||||
|
||||
enum class CoreStringEncoding : int
|
||||
{
|
||||
EUC_JP = 0,
|
||||
Shift_JIS = 1
|
||||
};
|
||||
|
||||
// attempts to convert the string (which uses encoding) to UTF-8,
|
||||
// on failure, returns original string
|
||||
std::string CoreConvertStringEncoding(std::string str, CoreStringEncoding encoding);
|
||||
|
||||
#endif // CORE_INTERNAL
|
||||
#endif // CORE_CONVERTSTRINGENCODING_HPP
|
||||
@@ -13,7 +13,9 @@
|
||||
#include <arpa/inet.h>
|
||||
#endif // _WIN32
|
||||
|
||||
#define CORE_INTERNAL
|
||||
#include "RomHeader.hpp"
|
||||
#include "ConvertStringEncoding.hpp"
|
||||
#include "Emulation.hpp"
|
||||
#include "m64p/Api.hpp"
|
||||
#include "Error.hpp"
|
||||
@@ -46,6 +48,7 @@ bool CoreGetCurrentRomHeader(CoreRomHeader& header)
|
||||
header.CRC1 = ntohl(m64p_header.CRC1);
|
||||
header.CRC2 = ntohl(m64p_header.CRC2);
|
||||
header.CountryCode = m64p_header.Country_code;
|
||||
header.Name = std::string((char*)m64p_header.Name);
|
||||
header.Name = CoreConvertStringEncoding((char*)m64p_header.Name, CoreStringEncoding::Shift_JIS);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -7,13 +7,16 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#define CORE_INTERNAL
|
||||
#include "RomSettings.hpp"
|
||||
#include "Emulation.hpp"
|
||||
#include "RomHeader.hpp"
|
||||
#include "m64p/Api.hpp"
|
||||
#include "Error.hpp"
|
||||
#include "Rom.hpp"
|
||||
|
||||
#include "Settings/Settings.hpp"
|
||||
#include "ConvertStringEncoding.hpp"
|
||||
|
||||
//
|
||||
// Local Variables
|
||||
@@ -46,7 +49,7 @@ bool CoreGetCurrentRomSettings(CoreRomSettings& settings)
|
||||
return false;
|
||||
}
|
||||
|
||||
settings.GoodName = std::string(m64p_settings.goodname);
|
||||
settings.GoodName = CoreConvertStringEncoding(m64p_settings.goodname, CoreStringEncoding::Shift_JIS);
|
||||
settings.MD5 = std::string(m64p_settings.MD5);
|
||||
settings.SaveType = m64p_settings.savetype;
|
||||
settings.DisableExtraMem = m64p_settings.disableextramem;
|
||||
|
||||
Reference in New Issue
Block a user