mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-03 21:41:19 +12:00
Fix encoding error in input profile filenames
- Controller profile filenames now encode unicode characters correctly - Removed dependency on boost::filesystem. There is still an indirect dependency on it from another boost module it seems - Refactored some code to use FileStream instead of ifstream/ofstream
This commit is contained in:
parent
8b3f36ad50
commit
f65dbe8437
4 changed files with 44 additions and 29 deletions
|
@ -92,12 +92,12 @@ bool InputManager::load(size_t player_index, std::string_view filename)
|
|||
|
||||
try
|
||||
{
|
||||
std::ifstream file(file_path);
|
||||
if (!file.is_open())
|
||||
auto xmlData = FileStream::LoadIntoMemory(file_path);
|
||||
if (!xmlData || xmlData->empty())
|
||||
return false;
|
||||
|
||||
|
||||
pugi::xml_document doc;
|
||||
if (!doc.load(file))
|
||||
if (!doc.load_buffer(xmlData->data(), xmlData->size()))
|
||||
return false;
|
||||
|
||||
const pugi::xml_node root = doc.document_element();
|
||||
|
@ -216,12 +216,15 @@ bool InputManager::migrate_config(const fs::path& file_path)
|
|||
{
|
||||
try
|
||||
{
|
||||
std::ifstream file(file_path);
|
||||
if (!file.is_open())
|
||||
auto xmlData = FileStream::LoadIntoMemory(file_path);
|
||||
if (!xmlData || xmlData->empty())
|
||||
return false;
|
||||
|
||||
std::string iniDataStr((const char*)xmlData->data(), xmlData->size());
|
||||
|
||||
std::stringstream iniData(iniDataStr);
|
||||
boost::property_tree::ptree m_data;
|
||||
read_ini(file, m_data);
|
||||
read_ini(iniData, m_data);
|
||||
|
||||
const auto emulate_string = m_data.get<std::string>("General.emulate");
|
||||
const auto api_string = m_data.get<std::string>("General.api");
|
||||
|
@ -455,7 +458,7 @@ bool InputManager::save(size_t player_index, std::string_view filename)
|
|||
if (is_default_file)
|
||||
file_path /= fmt::format("controller{}", player_index);
|
||||
else
|
||||
file_path /= filename;
|
||||
file_path /= _utf8ToPath(filename);
|
||||
|
||||
file_path.replace_extension(".xml"); // force .xml extension
|
||||
|
||||
|
@ -540,15 +543,15 @@ bool InputManager::save(size_t player_index, std::string_view filename)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::ofstream file(file_path, std::ios::out | std::ios::trunc);
|
||||
if (file.is_open())
|
||||
{
|
||||
doc.save(file);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
FileStream* fs = FileStream::createFile2(file_path);
|
||||
if (!fs)
|
||||
return false;
|
||||
std::stringstream xmlData;
|
||||
doc.save(xmlData);
|
||||
std::string xmlStr = xmlData.str();
|
||||
fs->writeData(xmlStr.data(), xmlStr.size());
|
||||
delete fs;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InputManager::is_gameprofile_set(size_t player_index) const
|
||||
|
@ -792,7 +795,7 @@ std::vector<std::string> InputManager::get_profiles()
|
|||
const auto& p = entry.path();
|
||||
if (p.has_extension() && (p.extension() == ".xml" || p.extension() == ".txt"))
|
||||
{
|
||||
auto stem = p.filename().stem().string();
|
||||
auto stem = _pathToUtf8(p.filename().stem());
|
||||
if (is_valid_profilename(stem))
|
||||
{
|
||||
tmp.emplace(stem);
|
||||
|
@ -808,7 +811,7 @@ std::vector<std::string> InputManager::get_profiles()
|
|||
|
||||
bool InputManager::is_valid_profilename(const std::string& name)
|
||||
{
|
||||
if (!boost::filesystem::windows_name(name))
|
||||
if (!IsValidFilename(name))
|
||||
return false;
|
||||
|
||||
// dont allow default profile names
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue