Skip to content

Commit

Permalink
Merge pull request #361 from Exzap/tweaks
Browse files Browse the repository at this point in the history
Fix encoding error in input profiles + update metainfo
  • Loading branch information
Exzap committed Oct 12, 2022
2 parents 8b3f36a + 0412dec commit f42bebd
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 33 deletions.
5 changes: 1 addition & 4 deletions dist/linux/info.cemu.Cemu.metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,11 @@
<url type="bugtracker">https://github.com/cemu-project/Cemu/issues</url>
<url type="faq">https://cemu.info/faq.html</url>
<url type="help">https://wiki.cemu.info</url>
<url type="vcs-browser">https://github.com/cemu-project/Cemu</url>
<!-- <url type="vcs-browser">https://github.com/cemu-project/Cemu</url> -->
<categories>
<category>Game</category>
<category>Emulator</category>
</categories>
<requires>
<memory>4096</memory>
</requires>
<recommends>
<memory>8192</memory>
</recommends>
Expand Down
11 changes: 2 additions & 9 deletions src/Cafe/GameProfile/GameProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,8 @@ bool GameProfile::Load(uint64_t title_id)
void GameProfile::Save(uint64_t title_id)
{
auto gameProfileDir = ActiveSettings::GetConfigPath("gameProfiles");
if (std::error_code ex_ec; !fs::exists(gameProfileDir, ex_ec) && !ex_ec) {
std::error_code cr_ec;
fs::create_directories(gameProfileDir, cr_ec);
}
if (std::error_code ex_ec; !fs::exists(gameProfileDir, ex_ec))
fs::create_directories(gameProfileDir, ex_ec);
auto gameProfilePath = gameProfileDir / fmt::format("{:016x}.ini", title_id);
FileStream* fs = FileStream::createFile2(gameProfilePath);
if (!fs)
Expand Down Expand Up @@ -309,16 +307,11 @@ void GameProfile::Save(uint64_t title_id)
fs->writeLine("");

fs->writeLine("[Graphics]");
//WRITE_OPTIONAL_ENTRY(gpuBufferCacheAccuracy);
WRITE_ENTRY(accurateShaderMul);
WRITE_OPTIONAL_ENTRY(precompiledShaders);
WRITE_OPTIONAL_ENTRY(graphics_api);
fs->writeLine("");

/*stream_writeLine(stream_gameProfile, "[Audio]");
WRITE_ENTRY(disableAudio);
stream_writeLine(stream_gameProfile, "");*/

fs->writeLine("[Controller]");
for (int i = 0; i < 8; ++i)
{
Expand Down
1 change: 0 additions & 1 deletion src/Common/precompiled.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
#include <boost/nowide/convert.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/asio.hpp>
#include <boost/filesystem.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>

Expand Down
41 changes: 22 additions & 19 deletions src/input/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
20 changes: 20 additions & 0 deletions src/util/helpers/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,26 @@ inline uint64 MakeU64(uint32 high, uint32 low)
return ((uint64)high << 32) | ((uint64)low);
}

static bool IsValidFilename(std::string_view sv)
{
for (auto& it : sv)
{
uint8 c = (uint8)it;
if (c < 0x20)
return false;
if (c == '.' || c == '#' || c == '/' || c == '\\' ||
c == '<' || c == '>' || c == '|' || c == ':' ||
c == '\"')
return false;
}
if (!sv.empty())
{
if (sv.back() == ' ' || sv.back() == '.')
return false;
}
return true;
}

// MAJOR; MINOR
std::pair<DWORD, DWORD> GetWindowsVersion();
bool IsWindows81OrGreater();
Expand Down

0 comments on commit f42bebd

Please sign in to comment.