More fixes

This commit is contained in:
boludoz 2023-10-07 15:20:48 -03:00
commit 46efdeb984
3 changed files with 21 additions and 14 deletions

View file

@ -13,7 +13,8 @@ namespace Common::FS {
std::u8string ToU8String(std::wstring_view w_string) { std::u8string ToU8String(std::wstring_view w_string) {
try { try {
auto utf8_string = boost::locale::conv::utf_to_utf<char>(w_string.data(), w_string.data() + w_string.size()); auto utf8_string = boost::locale::conv::utf_to_utf<char>(w_string.data(),
w_string.data() + w_string.size());
return std::u8string(utf8_string.begin(), utf8_string.end()); return std::u8string(utf8_string.begin(), utf8_string.end());
} catch (const boost::locale::conv::conversion_error) { } catch (const boost::locale::conv::conversion_error) {
return std::u8string{reinterpret_cast<const char8_t*>(w_string.data())}; return std::u8string{reinterpret_cast<const char8_t*>(w_string.data())};
@ -36,7 +37,8 @@ std::u8string_view BufferToU8StringView(std::span<const u8> buffer) {
std::wstring ToWString(std::u8string_view utf8_string) { std::wstring ToWString(std::u8string_view utf8_string) {
try { try {
return boost::locale::conv::utf_to_utf<wchar_t>(utf8_string.data(), utf8_string.data() + utf8_string.size()); return boost::locale::conv::utf_to_utf<wchar_t>(utf8_string.data(),
utf8_string.data() + utf8_string.size());
} catch (const boost::locale::conv::conversion_error) { } catch (const boost::locale::conv::conversion_error) {
return std::wstring(utf8_string.begin(), utf8_string.end()); return std::wstring(utf8_string.begin(), utf8_string.end());
} catch (const boost::locale::conv::invalid_charset_error) { } catch (const boost::locale::conv::invalid_charset_error) {

View file

@ -2825,11 +2825,12 @@ void GMainWindow::OnGameListNavigateToGamedbEntry(u64 program_id,
bool GMainWindow::SaveShortcutLink(const std::filesystem::path& shortcut_path_, const auto& comment, bool GMainWindow::SaveShortcutLink(const std::filesystem::path& shortcut_path_, const auto& comment,
const std::filesystem::path& icon_path_, const std::filesystem::path& icon_path_,
const std::filesystem::path& command_, const auto& arguments, const std::filesystem::path& command_, const auto& arguments,
const auto& categories, const auto& keywords) { const auto& categories, const auto& keywords, const auto& name_) {
const auto shortcut_path = shortcut_path_.string(); const auto shortcut_path = shortcut_path_.string();
const auto icon_path = icon_path_.string(); const auto icon_path = icon_path_.string();
const auto command = command_.string(); const auto command = command_.string();
const auto name = name_.string();
// This desktop file template was writing referencing // This desktop file template was writing referencing
// https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.0.html // https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.0.html
@ -2837,7 +2838,7 @@ bool GMainWindow::SaveShortcutLink(const std::filesystem::path& shortcut_path_,
shortcut_contents.append("[Desktop Entry]\n"); shortcut_contents.append("[Desktop Entry]\n");
shortcut_contents.append("Type=Application\n"); shortcut_contents.append("Type=Application\n");
shortcut_contents.append("Version=1.0\n"); shortcut_contents.append("Version=1.0\n");
shortcut_contents.append(fmt::format("Name={:s}\n", title)); shortcut_contents.append(fmt::format("Name={:s}\n", name));
shortcut_contents.append(fmt::format("Comment={:s}\n", comment)); shortcut_contents.append(fmt::format("Comment={:s}\n", comment));
shortcut_contents.append(fmt::format("Icon={:s}\n", icon_path)); shortcut_contents.append(fmt::format("Icon={:s}\n", icon_path));
shortcut_contents.append(fmt::format("TryExec={:s}\n", command)); shortcut_contents.append(fmt::format("TryExec={:s}\n", command));
@ -2860,7 +2861,7 @@ bool GMainWindow::SaveShortcutLink(const std::filesystem::path& shortcut_path_,
bool GMainWindow::SaveShortcutLink(const std::filesystem::path& shortcut_path, const auto& comment, bool GMainWindow::SaveShortcutLink(const std::filesystem::path& shortcut_path, const auto& comment,
const std::filesystem::path& icon_path, const std::filesystem::path& icon_path,
const std::filesystem::path& command, const auto& arguments, const std::filesystem::path& command, const auto& arguments,
const auto& categories, const auto& keywords) { const auto& categories, const auto& keywords, const auto& name) {
// Initialize COM // Initialize COM
CoInitialize(NULL); CoInitialize(NULL);
@ -2920,12 +2921,10 @@ bool GMainWindow::SaveShortcutLink(const std::filesystem::path& shortcut_path, c
return shortcut_success; return shortcut_success;
} }
#else #else
bool GMainWindow::SaveShortcutLink(const std::filesystem::path& shortcut_path_, bool GMainWindow::SaveShortcutLink(const std::filesystem::path& shortcut_path_, const auto& comment,
const std::string& comment,
const std::filesystem::path& icon_path_, const std::filesystem::path& icon_path_,
const std::filesystem::path& command_, const std::filesystem::path& command_, const auto& arguments,
const std::string& arguments, const std::string& categories, const auto& categories, const auto& keywords, const auto& name) {
const std::string& keywords) {
return false; return false;
} }
@ -3054,12 +3053,15 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const QString& game_p
QImage icon_jpeg = QImage icon_jpeg =
QImage::fromData(icon_image_file.data(), static_cast<int>(icon_image_file.size())); QImage::fromData(icon_image_file.data(), static_cast<int>(icon_image_file.size()));
#if defined(__linux__) || defined(__FreeBSD__) #if defined(__linux__) || defined(__FreeBSD__)
// Convert and write the icon as a PNG // Convert and write the icon as a PNG
if (!icon_jpeg.save(QString::fromStdString(icon_path.string()))) { if (!icon_jpeg.save(QString::fromStdString(icon_path.string()))) {
LOG_ERROR(Frontend, "Could not write icon as PNG to file"); LOG_ERROR(Frontend, "Could not write icon as PNG to file");
} else { } else {
LOG_INFO(Frontend, "Wrote an icon to {}", icon_path.string()); LOG_INFO(Frontend, "Wrote an icon to {}", icon_path.string());
} }
const auto name = title;
#elif defined(_WIN32) #elif defined(_WIN32)
// ICO is only for Windows // ICO is only for Windows
@ -3092,6 +3094,9 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const QString& game_p
const std::string comment = const std::string comment =
tr("Start %1 with the yuzu Emulator").arg(QString::fromStdString(title)).toStdString(); tr("Start %1 with the yuzu Emulator").arg(QString::fromStdString(title)).toStdString();
const std::string keywords = u8"Switch;Nintendo;";
const std::string categories = u8"Game;Emulator;Qt;";
#elif defined(_WIN32) #elif defined(_WIN32)
QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No; QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No;
int result = QMessageBox::information( int result = QMessageBox::information(
@ -3121,20 +3126,20 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const QString& game_p
} }
const std::filesystem::path sanitized_title = title_u8 + u8".lnk"; const std::filesystem::path sanitized_title = title_u8 + u8".lnk";
const std::filesystem::path shortcut_path = target_directory / (sanitized_title); const std::filesystem::path shortcut_path = target_directory / (sanitized_title);
const std::u8string keywords = u8"Switch;Nintendo;"; const std::u8string keywords = u8"Switch;Nintendo;";
const std::u8string categories = u8"Game;Emulator;Qt;"; const std::u8string categories = u8"Game;Emulator;Qt;";
const auto name = title_u8;
#else #else
const std::string comment{}; const std::string comment{};
const std::string arguments{}; const std::string arguments{};
const std::string categories{}; const std::string categories{};
const std::string keywords{}; const std::string keywords{};
const auto name = title;
#endif #endif
if (GMainWindow::SaveShortcutLink(shortcut_path, comment, icon_path, yuzu_command, arguments, if (GMainWindow::SaveShortcutLink(shortcut_path, comment, icon_path, yuzu_command, arguments,
categories, keywords)) { categories, keywords, name)) {
LOG_INFO(Frontend, "Wrote a shortcut to {}", shortcut_path.string()); LOG_INFO(Frontend, "Wrote a shortcut to {}", shortcut_path.string());
QMessageBox::information( QMessageBox::information(

View file

@ -426,7 +426,7 @@ private:
bool SaveShortcutLink(const std::filesystem::path& shortcut_path, const auto& comment, bool SaveShortcutLink(const std::filesystem::path& shortcut_path, const auto& comment,
const std::filesystem::path& icon_path, const std::filesystem::path& icon_path,
const std::filesystem::path& command, const auto& arguments, const std::filesystem::path& command, const auto& arguments,
const auto& categories, const auto& keywords); const auto& categories, const auto& keywords, const auto& name);
std::unique_ptr<Ui::MainWindow> ui; std::unique_ptr<Ui::MainWindow> ui;