Portable way of opening URLs and directories (#156)

Replaced every instance of ShellExecute with wxLaunchDefaultBrowser
This commit is contained in:
bitscher 2022-09-03 13:32:31 -07:00 committed by GitHub
parent f3c70e69b4
commit 1a1de370e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 67 deletions

View File

@ -1,9 +1,5 @@
#include "gui/ChecksumTool.h" #include "gui/ChecksumTool.h"
#ifdef _WIN32
#include <shellapi.h>
#endif
#include "Cafe/TitleList/GameInfo.h" #include "Cafe/TitleList/GameInfo.h"
#include "gui/helpers/wxCustomEvents.h" #include "gui/helpers/wxCustomEvents.h"
#include "util/helpers/helpers.h" #include "util/helpers/helpers.h"
@ -521,11 +517,8 @@ void ChecksumTool::VerifyJsonEntry(const rapidjson::Document& doc)
} }
file.flush(); file.flush();
file.close(); file.close();
#ifdef _WIN32
ShellExecuteA(GetHWND(), "open", path.c_str(), nullptr, nullptr, SW_SHOWNORMAL); wxLaunchDefaultBrowser(fmt::format("file:{}", path));
#else
assert_dbg();
#endif
} }
else else
wxMessageBox(_("Can't open file to write!"), _("Error"), wxOK | wxCENTRE | wxICON_ERROR, this); wxMessageBox(_("Can't open file to write!"), _("Error"), wxOK | wxCENTRE | wxICON_ERROR, this);

View File

@ -37,10 +37,6 @@
#include "Cafe/GraphicPack/GraphicPack.h" #include "Cafe/GraphicPack/GraphicPack.h"
#include "Cafe/TitleList/GameInfo.h" #include "Cafe/TitleList/GameInfo.h"
#ifdef _WIN32
#include <shellapi.h>
#endif
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include "util/helpers/SystemException.h" #include "util/helpers/SystemException.h"
#include "gui/DownloadGraphicPacksWindow.h" #include "gui/DownloadGraphicPacksWindow.h"
@ -1951,11 +1947,7 @@ public:
"/*****************************************************************************/\r\n" "/*****************************************************************************/\r\n"
); );
delete fs; delete fs;
#ifdef _WIN32 wxLaunchDefaultBrowser(fmt::format("file:{}", _utf8Wrapper(tempPath)));
ShellExecute(0, 0, tempPath.generic_wstring().c_str(), 0, 0, SW_SHOW);
#else
assert_dbg();
#endif
}); });
lineSizer->Add(noticeLink, 0); lineSizer->Add(noticeLink, 0);
lineSizer->Add(new wxStaticText(parent, -1, ")"), 0); lineSizer->Add(new wxStaticText(parent, -1, ")"), 0);

View File

@ -1,9 +1,5 @@
#include "gui/TitleManager.h" #include "gui/TitleManager.h"
#ifdef _WIN32
#include <shellapi.h>
#endif
#include "gui/helpers/wxCustomEvents.h" #include "gui/helpers/wxCustomEvents.h"
#include "gui/helpers/wxCustomData.h" #include "gui/helpers/wxCustomData.h"
#include "Cafe/TitleList/GameInfo.h" #include "Cafe/TitleList/GameInfo.h"
@ -483,11 +479,7 @@ void TitleManager::OnSaveOpenDirectory(wxCommandEvent& event)
if (!fs::exists(target) || !fs::is_directory(target)) if (!fs::exists(target) || !fs::is_directory(target))
return; return;
#ifdef _WIN32 wxLaunchDefaultBrowser(fmt::format("file:{}", _utf8Wrapper(target)));
ShellExecuteW(GetHWND(), L"open", target.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
#else
assert_dbg();
#endif
} }
void TitleManager::OnSaveDelete(wxCommandEvent& event) void TitleManager::OnSaveDelete(wxCommandEvent& event)

View File

@ -4,9 +4,6 @@
#include "util/helpers/helpers.h" #include "util/helpers/helpers.h"
#include "gui/GameProfileWindow.h" #include "gui/GameProfileWindow.h"
#ifdef _WIN32
#include <shellapi.h>
#endif
#include <numeric> #include <numeric>
#include <wx/wupdlock.h> #include <wx/wupdlock.h>
@ -473,6 +470,7 @@ void wxGameList::OnContextMenu(wxContextMenuEvent& event)
menu.Append(kContextMenuStart, _("&Start")); menu.Append(kContextMenuStart, _("&Start"));
bool isFavorite = false; bool isFavorite = false;
std::error_code ec;
menu.AppendSeparator(); menu.AppendSeparator();
menu.AppendCheckItem(kContextMenuFavorite, _("&Favorite"))->Check(isFavorite); menu.AppendCheckItem(kContextMenuFavorite, _("&Favorite"))->Check(isFavorite);
@ -481,7 +479,7 @@ void wxGameList::OnContextMenu(wxContextMenuEvent& event)
menu.AppendSeparator(); menu.AppendSeparator();
menu.Append(kWikiPage, _("&Wiki page")); menu.Append(kWikiPage, _("&Wiki page"));
menu.Append(kContextMenuGameFolder, _("&Game directory")); menu.Append(kContextMenuGameFolder, _("&Game directory"));
menu.Append(kContextMenuSaveFolder, _("&Save directory"))->Enable(true); menu.Append(kContextMenuSaveFolder, _("&Save directory"))->Enable(fs::is_directory(gameInfo.GetSaveFolder(), ec));
menu.Append(kContextMenuUpdateFolder, _("&Update directory"))->Enable(gameInfo.HasUpdate()); menu.Append(kContextMenuUpdateFolder, _("&Update directory"))->Enable(gameInfo.HasUpdate());
menu.Append(kContextMenuDLCFolder, _("&DLC directory"))->Enable(gameInfo.HasAOC()); menu.Append(kContextMenuDLCFolder, _("&DLC directory"))->Enable(gameInfo.HasAOC());
@ -552,13 +550,9 @@ void wxGameList::OnContextMenuSelected(wxCommandEvent& event)
} }
case kContextMenuGameFolder: case kContextMenuGameFolder:
{ {
#ifdef _WIN32
fs::path path(gameInfo.GetBase().GetPath()); fs::path path(gameInfo.GetBase().GetPath());
_stripPathFilename(path); _stripPathFilename(path);
ShellExecuteW(GetHWND(), L"open", path.c_str(), nullptr, nullptr, SW_SHOWNORMAL); wxLaunchDefaultBrowser(fmt::format("file:{}", _utf8Wrapper(path)));
#else
assert_dbg();
#endif
break; break;
} }
case kWikiPage: case kWikiPage:
@ -572,44 +566,28 @@ void wxGameList::OnContextMenuSelected(wxCommandEvent& event)
wxASSERT(!tokens.empty()); wxASSERT(!tokens.empty());
const std::string company_code = gameInfo.GetBase().GetMetaInfo()->GetCompanyCode(); const std::string company_code = gameInfo.GetBase().GetMetaInfo()->GetCompanyCode();
wxASSERT(company_code.size() >= 2); wxASSERT(company_code.size() >= 2);
#ifdef _WIN32 wxLaunchDefaultBrowser(fmt::format("https://wiki.cemu.info/wiki/{}{}", *tokens.rbegin(), company_code.substr(company_code.size() - 2).c_str()));
ShellExecuteA(GetHWND(), "open", fmt::format("https://wiki.cemu.info/wiki/{}{}", *tokens.rbegin(), company_code.substr(company_code.size() - 2)).c_str(), nullptr, nullptr, SW_SHOWNORMAL);
#else
assert_dbg();
#endif
} }
break; break;
} }
case kContextMenuSaveFolder: case kContextMenuSaveFolder:
{ {
#ifdef _WIN32 wxLaunchDefaultBrowser(fmt::format("file:{}", _utf8Wrapper(gameInfo.GetSaveFolder())));
ShellExecuteW(GetHWND(), L"open", gameInfo.GetSaveFolder().c_str(), nullptr, nullptr, SW_SHOWNORMAL);
#else
assert_dbg();
#endif
break; break;
} }
case kContextMenuUpdateFolder: case kContextMenuUpdateFolder:
{ {
#ifdef _WIN32
fs::path path(gameInfo.GetUpdate().GetPath()); fs::path path(gameInfo.GetUpdate().GetPath());
_stripPathFilename(path); _stripPathFilename(path);
ShellExecuteW(GetHWND(), L"open", path.c_str(), nullptr, nullptr, SW_SHOWNORMAL); wxLaunchDefaultBrowser(fmt::format("file:{}", _utf8Wrapper(path)));
#else
assert_dbg();
#endif
break; break;
} }
case kContextMenuDLCFolder: case kContextMenuDLCFolder:
{ {
#ifdef _WIN32
fs::path path(gameInfo.GetAOC().front().GetPath()); fs::path path(gameInfo.GetAOC().front().GetPath());
_stripPathFilename(path); _stripPathFilename(path);
ShellExecuteW(GetHWND(), L"open", path.c_str(), nullptr, nullptr, SW_SHOWNORMAL); wxLaunchDefaultBrowser(fmt::format("file:{}", _utf8Wrapper(path)));
#else
assert_dbg();
#endif
break; break;
} }
case kContextMenuEditGraphicPacks: case kContextMenuEditGraphicPacks:

View File

@ -20,9 +20,6 @@
#include "../wxHelper.h" #include "../wxHelper.h"
#include <functional> #include <functional>
#ifdef _WIN32
#include <shellapi.h>
#endif
#include "config/ActiveSettings.h" #include "config/ActiveSettings.h"
#include "gui/ChecksumTool.h" #include "gui/ChecksumTool.h"
@ -855,11 +852,7 @@ void wxTitleManagerList::OnContextMenuSelected(wxCommandEvent& event)
case kContextMenuOpenDirectory: case kContextMenuOpenDirectory:
{ {
const auto path = fs::is_directory(entry->path) ? entry->path : entry->path.parent_path(); const auto path = fs::is_directory(entry->path) ? entry->path : entry->path.parent_path();
#ifdef _WIN32 wxLaunchDefaultBrowser(fmt::format("file:{}", _utf8Wrapper(path)));
ShellExecuteW(GetHWND(), L"open", path.generic_wstring().c_str(), nullptr, nullptr, SW_SHOWNORMAL);
#else
assert_dbg();
#endif
} }
break; break;
case kContextMenuDelete: case kContextMenuDelete: