Skip to content

Commit f42bebd

Browse files
authored
Merge pull request #361 from Exzap/tweaks
Fix encoding error in input profiles + update metainfo
2 parents 8b3f36a + 0412dec commit f42bebd

File tree

5 files changed

+45
-33
lines changed

5 files changed

+45
-33
lines changed

dist/linux/info.cemu.Cemu.metainfo.xml

+1-4
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,11 @@
6060
<url type="bugtracker">https://github.com/cemu-project/Cemu/issues</url>
6161
<url type="faq">https://cemu.info/faq.html</url>
6262
<url type="help">https://wiki.cemu.info</url>
63-
<url type="vcs-browser">https://github.com/cemu-project/Cemu</url>
63+
<!-- <url type="vcs-browser">https://github.com/cemu-project/Cemu</url> -->
6464
<categories>
6565
<category>Game</category>
6666
<category>Emulator</category>
6767
</categories>
68-
<requires>
69-
<memory>4096</memory>
70-
</requires>
7168
<recommends>
7269
<memory>8192</memory>
7370
</recommends>

src/Cafe/GameProfile/GameProfile.cpp

+2-9
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,8 @@ bool GameProfile::Load(uint64_t title_id)
277277
void GameProfile::Save(uint64_t title_id)
278278
{
279279
auto gameProfileDir = ActiveSettings::GetConfigPath("gameProfiles");
280-
if (std::error_code ex_ec; !fs::exists(gameProfileDir, ex_ec) && !ex_ec) {
281-
std::error_code cr_ec;
282-
fs::create_directories(gameProfileDir, cr_ec);
283-
}
280+
if (std::error_code ex_ec; !fs::exists(gameProfileDir, ex_ec))
281+
fs::create_directories(gameProfileDir, ex_ec);
284282
auto gameProfilePath = gameProfileDir / fmt::format("{:016x}.ini", title_id);
285283
FileStream* fs = FileStream::createFile2(gameProfilePath);
286284
if (!fs)
@@ -309,16 +307,11 @@ void GameProfile::Save(uint64_t title_id)
309307
fs->writeLine("");
310308

311309
fs->writeLine("[Graphics]");
312-
//WRITE_OPTIONAL_ENTRY(gpuBufferCacheAccuracy);
313310
WRITE_ENTRY(accurateShaderMul);
314311
WRITE_OPTIONAL_ENTRY(precompiledShaders);
315312
WRITE_OPTIONAL_ENTRY(graphics_api);
316313
fs->writeLine("");
317314

318-
/*stream_writeLine(stream_gameProfile, "[Audio]");
319-
WRITE_ENTRY(disableAudio);
320-
stream_writeLine(stream_gameProfile, "");*/
321-
322315
fs->writeLine("[Controller]");
323316
for (int i = 0; i < 8; ++i)
324317
{

src/Common/precompiled.h

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
#include <boost/nowide/convert.hpp>
7070
#include <boost/algorithm/string.hpp>
7171
#include <boost/asio.hpp>
72-
#include <boost/filesystem.hpp>
7372
#include <glm/glm.hpp>
7473
#include <glm/gtc/quaternion.hpp>
7574

src/input/InputManager.cpp

+22-19
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ bool InputManager::load(size_t player_index, std::string_view filename)
9292

9393
try
9494
{
95-
std::ifstream file(file_path);
96-
if (!file.is_open())
95+
auto xmlData = FileStream::LoadIntoMemory(file_path);
96+
if (!xmlData || xmlData->empty())
9797
return false;
98-
98+
9999
pugi::xml_document doc;
100-
if (!doc.load(file))
100+
if (!doc.load_buffer(xmlData->data(), xmlData->size()))
101101
return false;
102102

103103
const pugi::xml_node root = doc.document_element();
@@ -216,12 +216,15 @@ bool InputManager::migrate_config(const fs::path& file_path)
216216
{
217217
try
218218
{
219-
std::ifstream file(file_path);
220-
if (!file.is_open())
219+
auto xmlData = FileStream::LoadIntoMemory(file_path);
220+
if (!xmlData || xmlData->empty())
221221
return false;
222222

223+
std::string iniDataStr((const char*)xmlData->data(), xmlData->size());
224+
225+
std::stringstream iniData(iniDataStr);
223226
boost::property_tree::ptree m_data;
224-
read_ini(file, m_data);
227+
read_ini(iniData, m_data);
225228

226229
const auto emulate_string = m_data.get<std::string>("General.emulate");
227230
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)
455458
if (is_default_file)
456459
file_path /= fmt::format("controller{}", player_index);
457460
else
458-
file_path /= filename;
461+
file_path /= _utf8ToPath(filename);
459462

460463
file_path.replace_extension(".xml"); // force .xml extension
461464

@@ -540,15 +543,15 @@ bool InputManager::save(size_t player_index, std::string_view filename)
540543
}
541544
}
542545
}
543-
544-
545-
std::ofstream file(file_path, std::ios::out | std::ios::trunc);
546-
if (file.is_open())
547-
{
548-
doc.save(file);
549-
return true;
550-
}
551-
return false;
546+
FileStream* fs = FileStream::createFile2(file_path);
547+
if (!fs)
548+
return false;
549+
std::stringstream xmlData;
550+
doc.save(xmlData);
551+
std::string xmlStr = xmlData.str();
552+
fs->writeData(xmlStr.data(), xmlStr.size());
553+
delete fs;
554+
return true;
552555
}
553556

554557
bool InputManager::is_gameprofile_set(size_t player_index) const
@@ -792,7 +795,7 @@ std::vector<std::string> InputManager::get_profiles()
792795
const auto& p = entry.path();
793796
if (p.has_extension() && (p.extension() == ".xml" || p.extension() == ".txt"))
794797
{
795-
auto stem = p.filename().stem().string();
798+
auto stem = _pathToUtf8(p.filename().stem());
796799
if (is_valid_profilename(stem))
797800
{
798801
tmp.emplace(stem);
@@ -808,7 +811,7 @@ std::vector<std::string> InputManager::get_profiles()
808811

809812
bool InputManager::is_valid_profilename(const std::string& name)
810813
{
811-
if (!boost::filesystem::windows_name(name))
814+
if (!IsValidFilename(name))
812815
return false;
813816

814817
// dont allow default profile names

src/util/helpers/helpers.h

+20
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,26 @@ inline uint64 MakeU64(uint32 high, uint32 low)
231231
return ((uint64)high << 32) | ((uint64)low);
232232
}
233233

234+
static bool IsValidFilename(std::string_view sv)
235+
{
236+
for (auto& it : sv)
237+
{
238+
uint8 c = (uint8)it;
239+
if (c < 0x20)
240+
return false;
241+
if (c == '.' || c == '#' || c == '/' || c == '\\' ||
242+
c == '<' || c == '>' || c == '|' || c == ':' ||
243+
c == '\"')
244+
return false;
245+
}
246+
if (!sv.empty())
247+
{
248+
if (sv.back() == ' ' || sv.back() == '.')
249+
return false;
250+
}
251+
return true;
252+
}
253+
234254
// MAJOR; MINOR
235255
std::pair<DWORD, DWORD> GetWindowsVersion();
236256
bool IsWindows81OrGreater();

0 commit comments

Comments
 (0)