From 0fb8f735e500e9055c89cf0330549e0f429dd2a8 Mon Sep 17 00:00:00 2001 From: Silent Date: Sat, 27 Mar 2021 16:57:37 +0100 Subject: [PATCH] GameList: Remove invalid characters when creating a desktop shortcut Fixes shortcut creation for games that have e.g. : in names. --- Source/Core/DolphinQt/GameList/GameList.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Source/Core/DolphinQt/GameList/GameList.cpp b/Source/Core/DolphinQt/GameList/GameList.cpp index f5f0c8d959..48600cc1a2 100644 --- a/Source/Core/DolphinQt/GameList/GameList.cpp +++ b/Source/Core/DolphinQt/GameList/GameList.cpp @@ -685,7 +685,18 @@ bool GameList::AddShortcutToDesktop() if (FAILED(SHGetKnownFolderPath(FOLDERID_Desktop, KF_FLAG_NO_ALIAS, nullptr, &desktop))) return false; - const auto& game_name = game->GetLongName(); + std::string game_name = game->GetLongName(); + // Sanitize the string by removing all characters that cannot be used in NTFS file names + game_name.erase(std::remove_if(game_name.begin(), game_name.end(), + [](char ch) { + static constexpr char illegal_characters[] = { + '<', '>', ':', '\"', '/', '\\', '|', '?', '*'}; + return std::find(std::begin(illegal_characters), + std::end(illegal_characters), + ch) != std::end(illegal_characters); + }), + game_name.end()); + std::wstring desktop_path = std::wstring(desktop.get()) + UTF8ToTStr("\\" + game_name + ".lnk"); auto persist_file = shell_link.try_query(); if (!persist_file)