diff --git a/Common/System/Request.cpp b/Common/System/Request.cpp index f1e0d43edfed..e6be092b0dbd 100644 --- a/Common/System/Request.cpp +++ b/Common/System/Request.cpp @@ -138,3 +138,7 @@ void System_CreateGameShortcut(const Path &path, const std::string &title) { void System_ShowFileInFolder(const Path &path) { g_requestManager.MakeSystemRequest(SystemRequestType::SHOW_FILE_IN_FOLDER, NO_REQUESTER_TOKEN, nullptr, nullptr, path.ToString(), "", 0); } + +void System_BrowseForFolder(RequesterToken token, const std::string &title, const Path &initialPath, RequestCallback callback, RequestFailedCallback failedCallback) { + g_requestManager.MakeSystemRequest(SystemRequestType::BROWSE_FOR_FOLDER, token, callback, failedCallback, title, initialPath.ToCString(), 0); +} diff --git a/Common/System/Request.h b/Common/System/Request.h index 3cd4f2a3be2f..da54f46838a3 100644 --- a/Common/System/Request.h +++ b/Common/System/Request.h @@ -107,9 +107,7 @@ inline void System_BrowseForFile(RequesterToken token, const std::string &title, g_requestManager.MakeSystemRequest(SystemRequestType::BROWSE_FOR_FILE, token, callback, failedCallback, title, "", (int)type); } -inline void System_BrowseForFolder(RequesterToken token, const std::string &title, RequestCallback callback, RequestFailedCallback failedCallback = nullptr) { - g_requestManager.MakeSystemRequest(SystemRequestType::BROWSE_FOR_FOLDER, token, callback, failedCallback, title, "", 0); -} +void System_BrowseForFolder(RequesterToken token, const std::string &title, const Path &initialPath, RequestCallback callback, RequestFailedCallback failedCallback = nullptr); // The returned string is username + '\n' + password. inline void System_AskUsernamePassword(RequesterToken token, const std::string &title, RequestCallback callback, RequestFailedCallback failedCallback = nullptr) { diff --git a/Common/UI/PopupScreens.cpp b/Common/UI/PopupScreens.cpp index 1a294ac05c82..57e9e13774f8 100644 --- a/Common/UI/PopupScreens.cpp +++ b/Common/UI/PopupScreens.cpp @@ -713,7 +713,7 @@ std::string FileChooserChoice::ValueText() const { FolderChooserChoice::FolderChooserChoice(RequesterToken token, std::string *value, const std::string &text, LayoutParams *layoutParams) : AbstractChoiceWithValueDisplay(text, layoutParams), value_(value), token_(token) { OnClick.Add([=](UI::EventParams &) { - System_BrowseForFolder(token_, text_, [=](const std::string &returnValue, int) { + System_BrowseForFolder(token_, text_, Path(*value), [=](const std::string &returnValue, int) { if (*value_ != returnValue) { *value = returnValue; UI::EventParams e{}; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index eb7555e83758..720097c25e6e 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1343,7 +1343,8 @@ UI::EventReturn GameSettingsScreen::OnSavePathOther(UI::EventParams &e) { const Path &PPSSPPpath = File::GetExeDirectory(); if (otherinstalled_) { auto di = GetI18NCategory(I18NCat::DIALOG); - std::string folder = W32Util::BrowseForFolder(MainWindow::GetHWND(), di->T("Choose PPSSPP save folder")); + std::string initialPath = g_Config.memStickDirectory.ToCString(); + std::string folder = W32Util::BrowseForFolder(MainWindow::GetHWND(), di->T("Choose PPSSPP save folder"), initialPath); if (folder.size()) { g_Config.memStickDirectory = Path(folder); FILE *f = File::OpenCFile(PPSSPPpath / "installed.txt", "wb"); diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 1c26b4f8a846..3d8ef0932291 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -604,7 +604,7 @@ UI::EventReturn GameBrowser::LastClick(UI::EventParams &e) { UI::EventReturn GameBrowser::BrowseClick(UI::EventParams &e) { auto mm = GetI18NCategory(I18NCat::MAINMENU); - System_BrowseForFolder(token_, mm->T("Choose folder"), [this](const std::string &filename, int) { + System_BrowseForFolder(token_, mm->T("Choose folder"), path_.GetPath(), [this](const std::string &filename, int) { this->SetPath(Path(filename)); }); return UI::EVENT_DONE; diff --git a/UI/MemStickScreen.cpp b/UI/MemStickScreen.cpp index c59f968bcb0c..5f4e412d8e19 100644 --- a/UI/MemStickScreen.cpp +++ b/UI/MemStickScreen.cpp @@ -418,7 +418,7 @@ UI::EventReturn MemStickScreen::UseStorageRoot(UI::EventParams ¶ms) { UI::EventReturn MemStickScreen::Browse(UI::EventParams ¶ms) { auto mm = GetI18NCategory(I18NCat::MAINMENU); - System_BrowseForFolder(GetRequesterToken(), mm->T("Choose folder"), [=](const std::string &value, int) { + System_BrowseForFolder(GetRequesterToken(), mm->T("Choose folder"), g_Config.memStickDirectory, [=](const std::string &value, int) { Path pendingMemStickFolder = Path(value); INFO_LOG(SYSTEM, "Got folder: '%s'", pendingMemStickFolder.c_str()); // Browse finished. Let's pop up the confirmation dialog. diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index 65538da423b5..c07eef4c6730 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -333,7 +333,7 @@ namespace MainWindow { W32Util::MakeTopMost(GetHWND(), false); if (browseDirectory) { - System_BrowseForFolder(token, mm->T("Load"), [](const std::string &value, int) { + System_BrowseForFolder(token, mm->T("Load"), Path(), [](const std::string &value, int) { BrowseAndBootDone(value); }); } else { diff --git a/Windows/W32Util/ShellUtil.cpp b/Windows/W32Util/ShellUtil.cpp index e6d0078625ce..4f03d3a1c804 100644 --- a/Windows/W32Util/ShellUtil.cpp +++ b/Windows/W32Util/ShellUtil.cpp @@ -14,18 +14,32 @@ namespace W32Util { - std::string BrowseForFolder(HWND parent, const char *title) - { + std::string BrowseForFolder(HWND parent, std::string_view title, std::string_view initialPath) { std::wstring titleString = ConvertUTF8ToWString(title); - return BrowseForFolder(parent, titleString.c_str()); + return BrowseForFolder(parent, titleString.c_str(), initialPath); } - std::string BrowseForFolder(HWND parent, const wchar_t *title) - { + static int CALLBACK BrowseFolderCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) { + if (uMsg == BFFM_INITIALIZED) { + LPCTSTR path = reinterpret_cast(lpData); + ::SendMessage(hwnd, BFFM_SETSELECTION, true, (LPARAM)path); + } + return 0; + } + + std::string BrowseForFolder(HWND parent, const wchar_t *title, std::string_view initialPath) { BROWSEINFO info{}; info.hwndOwner = parent; info.lpszTitle = title; - info.ulFlags = BIF_EDITBOX | BIF_RETURNONLYFSDIRS | BIF_USENEWUI; + info.ulFlags = BIF_EDITBOX | BIF_RETURNONLYFSDIRS | BIF_USENEWUI | BIF_NEWDIALOGSTYLE; + + std::wstring initialPathW; + + if (!initialPath.empty()) { + initialPathW = ConvertUTF8ToWString(initialPath); + info.lParam = reinterpret_cast(initialPathW.c_str()); + info.lpfn = BrowseFolderCallback; + } //info.pszDisplayName auto idList = SHBrowseForFolder(&info); diff --git a/Windows/W32Util/ShellUtil.h b/Windows/W32Util/ShellUtil.h index 78f304929a7a..033f90ab8170 100644 --- a/Windows/W32Util/ShellUtil.h +++ b/Windows/W32Util/ShellUtil.h @@ -1,20 +1,25 @@ #pragma once #include +#include #include #include -namespace W32Util -{ - std::string BrowseForFolder(HWND parent, const char *title); - std::string BrowseForFolder(HWND parent, const wchar_t *title); - bool BrowseForFileName (bool _bLoad, HWND _hParent, const wchar_t*_pTitle, - const wchar_t *_pInitialFolder,const wchar_t *_pFilter,const wchar_t*_pExtension, - std::string& _strFileName); - std::vector BrowseForFileNameMultiSelect(bool _bLoad, HWND _hParent, const wchar_t*_pTitle, - const wchar_t*_pInitialFolder,const wchar_t*_pFilter,const wchar_t*_pExtension); +namespace W32Util { - std::string UserDocumentsPath(); +// Can't make initialPath a string_view, need the null so might as well require it. +std::string BrowseForFolder(HWND parent, std::string_view title, std::string_view initialPath); +std::string BrowseForFolder(HWND parent, const wchar_t *title, std::string_view initialPath); - bool CreateDesktopShortcut(const std::string &argumentPath, std::string gameTitle); -} +bool BrowseForFileName(bool _bLoad, HWND _hParent, + const wchar_t *_pTitle, const wchar_t *_pInitialFolder, const wchar_t *_pFilter, const wchar_t *_pExtension, + std::string& _strFileName); + +std::vector BrowseForFileNameMultiSelect(bool _bLoad, HWND _hParent, const wchar_t *_pTitle, + const wchar_t *_pInitialFolder, const wchar_t *_pFilter, const wchar_t *_pExtension); + +std::string UserDocumentsPath(); + +bool CreateDesktopShortcut(const std::string &argumentPath, std::string gameTitle); + +} // namespace diff --git a/Windows/main.cpp b/Windows/main.cpp index 22cc681f9014..72e9021ae552 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -598,7 +598,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string case SystemRequestType::BROWSE_FOR_FOLDER: { std::thread([=] { - std::string folder = W32Util::BrowseForFolder(MainWindow::GetHWND(), param1.c_str()); + std::string folder = W32Util::BrowseForFolder(MainWindow::GetHWND(), param1, param2); if (folder.size()) { g_requestManager.PostSystemSuccess(requestId, folder.c_str()); } else {