Remove the old AsyncFileDialog thingy

This commit is contained in:
Henrik Rydgård 2023-03-24 21:32:20 +01:00
parent a73ac49d59
commit 56c26eef4d
7 changed files with 32 additions and 121 deletions

View File

@ -1060,10 +1060,6 @@ namespace MainWindow
UpdateWindowTitle();
break;
case WM_USER_BROWSE_BOOT_DONE:
BrowseAndBootDone();
break;
case WM_USER_RESTART_EMUTHREAD:
NativeSetRestarting();
InputDevice::StopPolling();

View File

@ -16,7 +16,6 @@ namespace MainWindow
WM_USER_SAVESTATE_FINISH = WM_USER + 100,
WM_USER_UPDATE_UI = WM_USER + 101,
WM_USER_WINDOW_TITLE_CHANGED = WM_USER + 103,
WM_USER_BROWSE_BOOT_DONE = WM_USER + 104,
WM_USER_TOGGLE_FULLSCREEN = WM_USER + 105,
WM_USER_RESTART_EMUTHREAD = WM_USER + 106,
WM_USER_SWITCHUMD_UPDATED = WM_USER + 107

View File

@ -15,6 +15,7 @@
#include "Common/Data/Encoding/Utf8.h"
#include "Common/System/System.h"
#include "Common/System/NativeApp.h"
#include "Common/System/Request.h"
#include "Common/File/FileUtil.h"
#include "Common/Log.h"
#include "Common/LogManager.h"
@ -55,7 +56,6 @@ extern bool g_TakeScreenshot;
namespace MainWindow {
extern HINSTANCE hInst;
extern bool noFocusPause;
static W32Util::AsyncBrowseDialog *browseDialog;
static bool browsePauseAfter;
static std::unordered_map<int, std::string> initialMenuKeys;
@ -303,6 +303,8 @@ namespace MainWindow {
}
}
void BrowseAndBootDone(std::string filename);
void BrowseAndBoot(std::string defaultPath, bool browseDirectory) {
static std::wstring filter = L"All supported file types (*.iso *.cso *.pbp *.elf *.prx *.zip *.ppdmp)|*.pbp;*.elf;*.iso;*.cso;*.prx;*.zip;*.ppdmp|PSP ROMs (*.iso *.cso *.pbp *.elf *.prx)|*.pbp;*.elf;*.iso;*.cso;*.prx|Homebrew/Demos installers (*.zip)|*.zip|All files (*.*)|*.*||";
for (int i = 0; i < (int)filter.length(); i++) {
@ -316,34 +318,28 @@ namespace MainWindow {
if (!browsePauseAfter)
Core_EnableStepping(true, "ui.boot", 0);
}
auto mm = GetI18NCategory("MainMenu");
W32Util::MakeTopMost(GetHWND(), false);
if (browseDirectory) {
browseDialog = new W32Util::AsyncBrowseDialog(GetHWND(), WM_USER_BROWSE_BOOT_DONE, L"Choose directory");
System_BrowseForFolder(mm->T("Load"), [](const std::string &value, int) {
BrowseAndBootDone(value);
});
} else {
browseDialog = new W32Util::AsyncBrowseDialog(W32Util::AsyncBrowseDialog::OPEN, GetHWND(), WM_USER_BROWSE_BOOT_DONE, L"LoadFile", ConvertUTF8ToWString(defaultPath), filter, L"*.pbp;*.elf;*.iso;*.cso;");
System_BrowseForFile(mm->T("Load"), BrowseFileType::BOOTABLE, [](const std::string &value, int) {
BrowseAndBootDone(value);
});
}
}
void BrowseAndBootDone() {
std::string filename;
if (!browseDialog->GetResult(filename)) {
if (!browsePauseAfter) {
Core_EnableStepping(false);
}
} else {
if (GetUIState() == UISTATE_INGAME || GetUIState() == UISTATE_EXCEPTION || GetUIState() == UISTATE_PAUSEMENU) {
Core_EnableStepping(false);
}
filename = ReplaceAll(filename, "\\", "/");
NativeMessageReceived("boot", filename.c_str());
void BrowseAndBootDone(std::string filename) {
if (GetUIState() == UISTATE_INGAME || GetUIState() == UISTATE_EXCEPTION || GetUIState() == UISTATE_PAUSEMENU) {
Core_EnableStepping(false);
}
filename = ReplaceAll(filename, "\\", "/");
NativeMessageReceived("boot", filename.c_str());
W32Util::MakeTopMost(GetHWND(), g_Config.bTopMost);
delete browseDialog;
browseDialog = 0;
}
static void UmdSwitchAction() {
@ -442,7 +438,7 @@ namespace MainWindow {
// Parse the menu selections:
switch (wmId) {
case ID_FILE_LOAD:
BrowseAndBoot("");
BrowseAndBoot("", false);
break;
case ID_FILE_LOAD_DIR:

View File

@ -8,7 +8,6 @@ namespace MainWindow {
void MainWindowMenu_Process(HWND hWnd, WPARAM wParam);
void TranslateMenus(HWND hWnd, HMENU menu);
void BrowseAndBoot(std::string defaultPath, bool browseDirectory = false);
void BrowseAndBootDone();
void setTexScalingMultiplier(int level);
void SetIngameMenuItemStates(HMENU menu, const GlobalUIState state);
}

View File

@ -178,45 +178,6 @@ namespace W32Util
return result;
}
AsyncBrowseDialog::AsyncBrowseDialog(HWND parent, UINT completeMsg, std::wstring title)
: type_(DIR), parent_(parent), completeMsg_(completeMsg), title_(title), complete_(false), result_(false) {
thread_ = new std::thread(std::bind(&AsyncBrowseDialog::Execute, this));
thread_->detach();
}
AsyncBrowseDialog::AsyncBrowseDialog(Type type, HWND parent, UINT completeMsg, std::wstring title, std::wstring initialFolder, std::wstring filter, std::wstring extension)
: type_(type), parent_(parent), completeMsg_(completeMsg), title_(title), initialFolder_(initialFolder), filter_(filter), extension_(extension), complete_(false), result_(false) {
thread_ = new std::thread(std::bind(&AsyncBrowseDialog::Execute, this));
thread_->detach();
}
AsyncBrowseDialog::~AsyncBrowseDialog() {
delete thread_;
}
bool AsyncBrowseDialog::GetResult(std::string &filename) {
filename = filename_;
return result_;
}
void AsyncBrowseDialog::Execute() {
switch (type_) {
case DIR:
filename_ = BrowseForFolder(parent_, title_.c_str());
result_ = !filename_.empty();
complete_ = true;
break;
case OPEN:
case SAVE:
result_ = BrowseForFileName(type_ == OPEN, parent_, title_.c_str(), initialFolder_.size() ? initialFolder_.c_str() : 0, filter_.c_str(), extension_.c_str(), filename_);
complete_ = true;
break;
}
PostMessage(parent_, completeMsg_, 0, 0);
}
// http://msdn.microsoft.com/en-us/library/aa969393.aspx
HRESULT CreateLink(LPCWSTR lpszPathObj, LPCWSTR lpszArguments, LPCWSTR lpszPathLink, LPCWSTR lpszDesc) {

View File

@ -16,41 +16,5 @@ namespace W32Util
std::string UserDocumentsPath();
struct AsyncBrowseDialog {
public:
enum Type {
OPEN,
SAVE,
DIR,
};
// For a directory.
AsyncBrowseDialog(HWND parent, UINT completeMsg, std::wstring title);
// For a file (OPEN or SAVE.)
AsyncBrowseDialog(Type type, HWND parent, UINT completeMsg, std::wstring title, std::wstring initialFolder, std::wstring filter, std::wstring extension);
~AsyncBrowseDialog();
bool GetResult(std::string &filename);
Type GetType() {
return type_;
}
private:
void Execute();
std::thread *thread_;
Type type_;
HWND parent_;
UINT completeMsg_;
std::wstring title_;
std::wstring initialFolder_;
std::wstring filter_;
std::wstring extension_;
bool complete_;
bool result_;
std::string filename_;
};
bool CreateDesktopShortcut(const std::string &argumentPath, std::string gameTitle);
}

View File

@ -113,7 +113,6 @@ int g_activeWindow = 0;
// Used for all the system dialogs.
static std::thread g_dialogThread;
static bool g_dialogRunning = false;
WindowsInputManager g_inputManager;
@ -492,11 +491,9 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
return true;
}
case SystemRequestType::INPUT_TEXT_MODAL:
if (g_dialogRunning) {
if (g_dialogThread.joinable())
g_dialogThread.join();
}
g_dialogRunning = true;
g_dialogThread = std::thread([=] {
std::string out;
if (InputBox_GetString(MainWindow::GetHInstance(), MainWindow::GetHWND(), ConvertUTF8ToWString(param1).c_str(), param2, out)) {
@ -505,13 +502,12 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
g_requestManager.PostSystemFailure(requestId);
}
});
g_dialogThread.detach();
return true;
case SystemRequestType::BROWSE_FOR_IMAGE:
if (g_dialogRunning) {
if (g_dialogThread.joinable())
g_dialogThread.join();
}
g_dialogRunning = true;
g_dialogThread = std::thread([=] {
std::string out;
if (W32Util::BrowseForFileName(true, MainWindow::GetHWND(), ConvertUTF8ToWString(param1).c_str(), nullptr,
@ -521,6 +517,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
g_requestManager.PostSystemFailure(requestId);
}
});
g_dialogThread.detach();
return true;
case SystemRequestType::BROWSE_FOR_FILE:
{
@ -542,11 +539,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
default:
return false;
}
if (g_dialogRunning) {
g_dialogThread.join();
}
g_dialogRunning = true;
g_dialogThread = std::thread([=] {
std::string out;
if (W32Util::BrowseForFileName(true, MainWindow::GetHWND(), ConvertUTF8ToWString(param1).c_str(), nullptr, filter.c_str(), L"", out)) {
@ -555,16 +548,20 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
g_requestManager.PostSystemFailure(requestId);
}
});
g_dialogThread.detach();
return true;
}
case SystemRequestType::BROWSE_FOR_FOLDER:
{
std::string folder = W32Util::BrowseForFolder(MainWindow::GetHWND(), param1.c_str());
if (folder.size()) {
g_requestManager.PostSystemSuccess(requestId, folder.c_str());
} else {
g_requestManager.PostSystemFailure(requestId);
}
g_dialogThread = std::thread([=] {
std::string folder = W32Util::BrowseForFolder(MainWindow::GetHWND(), param1.c_str());
if (folder.size()) {
g_requestManager.PostSystemSuccess(requestId, folder.c_str());
} else {
g_requestManager.PostSystemFailure(requestId);
}
});
g_dialogThread.detach();
return true;
}
case SystemRequestType::TOGGLE_FULLSCREEN_STATE:
@ -726,9 +723,8 @@ static void WinMainInit() {
}
static void WinMainCleanup() {
if (g_dialogRunning) {
if (g_dialogThread.joinable()) {
g_dialogThread.join();
g_dialogRunning = false;
}
net::Shutdown();
CoUninitialize();