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"
#ifdef _WIN32
#include <shellapi.h>
#endif
#include "Cafe/TitleList/GameInfo.h"
#include "gui/helpers/wxCustomEvents.h"
#include "util/helpers/helpers.h"
@ -521,11 +517,8 @@ void ChecksumTool::VerifyJsonEntry(const rapidjson::Document& doc)
}
file.flush();
file.close();
#ifdef _WIN32
ShellExecuteA(GetHWND(), "open", path.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
#else
assert_dbg();
#endif
wxLaunchDefaultBrowser(fmt::format("file:{}", path));
}
else
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/TitleList/GameInfo.h"
#ifdef _WIN32
#include <shellapi.h>
#endif
#include <boost/algorithm/string.hpp>
#include "util/helpers/SystemException.h"
#include "gui/DownloadGraphicPacksWindow.h"
@ -1951,11 +1947,7 @@ public:
"/*****************************************************************************/\r\n"
);
delete fs;
#ifdef _WIN32
ShellExecute(0, 0, tempPath.generic_wstring().c_str(), 0, 0, SW_SHOW);
#else
assert_dbg();
#endif
wxLaunchDefaultBrowser(fmt::format("file:{}", _utf8Wrapper(tempPath)));
});
lineSizer->Add(noticeLink, 0);
lineSizer->Add(new wxStaticText(parent, -1, ")"), 0);

View File

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

View File

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

View File

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