From 656efa5e205d656f525f8c673f8f6f98912c7a74 Mon Sep 17 00:00:00 2001 From: Filjo Abraham Date: Tue, 7 Jul 2020 21:38:52 -0500 Subject: [PATCH] CDVD: drive selection submenu and OS-specific fixes --- pcsx2/CDVD/CDVDdiscReader.cpp | 6 +- pcsx2/CDVD/CDVDdiscReader.h | 1 - pcsx2/CDVD/CDVDdiscThread.cpp | 2 +- pcsx2/CDVD/{Unix => Linux}/DriveUtility.cpp | 17 ++- pcsx2/CDVD/{Unix => Linux}/IOCtlSrc.cpp | 21 +++- pcsx2/CDVD/Windows/DriveUtility.cpp | 31 +++-- pcsx2/CDVD/Windows/IOCtlSrc.cpp | 3 +- pcsx2/CMakeLists.txt | 16 +-- pcsx2/System/SysCoreThread.cpp | 8 +- pcsx2/gui/App.h | 6 +- pcsx2/gui/AppConfig.cpp | 25 +++- pcsx2/gui/AppConfig.h | 3 +- pcsx2/gui/AppMain.cpp | 7 +- pcsx2/gui/AppRes.cpp | 10 ++ pcsx2/gui/DriveList.cpp | 110 ++++++++++++++++++ pcsx2/gui/DriveList.h | 60 ++++++++++ pcsx2/gui/MainFrame.h | 1 + pcsx2/gui/MainMenuClicks.cpp | 31 ++--- pcsx2/windows/VCprojects/pcsx2.vcxproj | 22 ++-- .../windows/VCprojects/pcsx2.vcxproj.filters | 16 ++- 20 files changed, 310 insertions(+), 86 deletions(-) rename pcsx2/CDVD/{Unix => Linux}/DriveUtility.cpp (93%) rename pcsx2/CDVD/{Unix => Linux}/IOCtlSrc.cpp (95%) create mode 100644 pcsx2/gui/DriveList.cpp create mode 100644 pcsx2/gui/DriveList.h diff --git a/pcsx2/CDVD/CDVDdiscReader.cpp b/pcsx2/CDVD/CDVDdiscReader.cpp index fdbc20609a..8402ed3efb 100644 --- a/pcsx2/CDVD/CDVDdiscReader.cpp +++ b/pcsx2/CDVD/CDVDdiscReader.cpp @@ -1,5 +1,5 @@ /* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2014 David Quintana [gigaherz] + * Copyright (C) 2002-2020 PCSX2 Dev Team * * PCSX2 is free software: you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Found- @@ -171,9 +171,9 @@ void StopKeepAliveThread() s32 CALLBACK DISCopen(const char* pTitle) { #if defined(_WIN32) - std::wstring drive = g_Conf->Folders.RunDisc.ToString().ToStdWstring(); + std::wstring drive = g_Conf->Folders.RunDisc.GetPath().ToStdWstring(); #else - std::string drive = g_Conf->Folders.RunDisc.ToString().ToStdString(); + std::string drive = g_Conf->Folders.RunDisc.GetPath().ToStdString(); #endif GetValidDrive(drive); diff --git a/pcsx2/CDVD/CDVDdiscReader.h b/pcsx2/CDVD/CDVDdiscReader.h index 7f01f8f9af..f80bda91cc 100644 --- a/pcsx2/CDVD/CDVDdiscReader.h +++ b/pcsx2/CDVD/CDVDdiscReader.h @@ -108,5 +108,4 @@ s32 cdvdDirectReadSector(u32 sector, s32 mode, u8* buffer); s32 cdvdGetMediaType(); s32 cdvdRefreshData(); void cdvdParseTOC(); - #endif /* __CDVD_DISC_READER_H__ */ \ No newline at end of file diff --git a/pcsx2/CDVD/CDVDdiscThread.cpp b/pcsx2/CDVD/CDVDdiscThread.cpp index 96b8de9d65..5ccda1b09f 100644 --- a/pcsx2/CDVD/CDVDdiscThread.cpp +++ b/pcsx2/CDVD/CDVDdiscThread.cpp @@ -1,5 +1,5 @@ /* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2014 David Quintana [gigaherz] + * Copyright (C) 2002-2020 PCSX2 Dev Team * * PCSX2 is free software: you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Found- diff --git a/pcsx2/CDVD/Unix/DriveUtility.cpp b/pcsx2/CDVD/Linux/DriveUtility.cpp similarity index 93% rename from pcsx2/CDVD/Unix/DriveUtility.cpp rename to pcsx2/CDVD/Linux/DriveUtility.cpp index 8b2f4a792a..748e7955e0 100644 --- a/pcsx2/CDVD/Unix/DriveUtility.cpp +++ b/pcsx2/CDVD/Linux/DriveUtility.cpp @@ -1,5 +1,5 @@ /* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2020 PCSX2 Dev Team + * Copyright (C) 2002-2020 PCSX2 Dev Team * * PCSX2 is free software: you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Found- @@ -16,14 +16,18 @@ #include "PrecompiledHeader.h" #include "../CDVDdiscReader.h" +#ifdef __linux__ #include -#include #include +#endif + +#include #include #include std::vector GetOpticalDriveList() { +#ifdef __linux__ udev* udev_context = udev_new(); if (!udev_context) return {}; @@ -51,11 +55,15 @@ std::vector GetOpticalDriveList() udev_unref(udev_context); return drives; +#else + return {}; +#endif } void GetValidDrive(std::string& drive) { if (!drive.empty()) { +#ifdef __linux__ int fd = open(drive.c_str(), O_RDONLY | O_NONBLOCK); if (fd != -1) { if (ioctl(fd, CDROM_GET_CAPABILITY, 0) == -1) @@ -65,6 +73,9 @@ void GetValidDrive(std::string& drive) else { drive.clear(); } +#else + drive.clear(); +#endif } if (drive.empty()) { auto drives = GetOpticalDriveList(); @@ -73,4 +84,4 @@ void GetValidDrive(std::string& drive) } if (!drive.empty()) printf(" * CDVD: Opening drive '%s'...\n", drive.c_str()); -} \ No newline at end of file +} diff --git a/pcsx2/CDVD/Unix/IOCtlSrc.cpp b/pcsx2/CDVD/Linux/IOCtlSrc.cpp similarity index 95% rename from pcsx2/CDVD/Unix/IOCtlSrc.cpp rename to pcsx2/CDVD/Linux/IOCtlSrc.cpp index de7c5bac54..a46db025de 100644 --- a/pcsx2/CDVD/Unix/IOCtlSrc.cpp +++ b/pcsx2/CDVD/Linux/IOCtlSrc.cpp @@ -1,5 +1,5 @@ /* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2016 PCSX2 Dev Team + * Copyright (C) 2002-2020 PCSX2 Dev Team * * PCSX2 is free software: you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Found- @@ -16,7 +16,10 @@ #include "PrecompiledHeader.h" #include "../CDVDdiscReader.h" +#ifdef __linux__ #include +#endif + #include #include #include @@ -103,6 +106,7 @@ bool IOCtlSrc::ReadSectors2048(u32 sector, u32 count, u8* buffer) const bool IOCtlSrc::ReadSectors2352(u32 sector, u32 count, u8* buffer) const { +#ifdef __linux__ union { cdrom_msf msf; @@ -122,10 +126,14 @@ bool IOCtlSrc::ReadSectors2352(u32 sector, u32 count, u8* buffer) const } return true; +#else + return false; +#endif } bool IOCtlSrc::ReadDVDInfo() { +#ifdef __linux__ dvd_struct dvdrs; dvdrs.type = DVD_STRUCT_PHYSICAL; dvdrs.physical.layer_num = 0; @@ -165,10 +173,14 @@ bool IOCtlSrc::ReadDVDInfo() } return true; +#else + return false; +#endif } bool IOCtlSrc::ReadCDInfo() { +#ifdef __linux__ cdrom_tochdr header; if (ioctl(m_device, CDROMREADTOCHDR, &header) == -1) @@ -194,10 +206,14 @@ bool IOCtlSrc::ReadCDInfo() m_media_type = -1; return true; +#else + return false; +#endif } bool IOCtlSrc::DiscReady() { +#ifdef __linux__ if (m_device == -1) return false; @@ -213,4 +229,7 @@ bool IOCtlSrc::DiscReady() } return !!m_sectors; +#else + return false; +#endif } diff --git a/pcsx2/CDVD/Windows/DriveUtility.cpp b/pcsx2/CDVD/Windows/DriveUtility.cpp index 3ff853450a..ff47b6195e 100644 --- a/pcsx2/CDVD/Windows/DriveUtility.cpp +++ b/pcsx2/CDVD/Windows/DriveUtility.cpp @@ -1,20 +1,17 @@ -//Copyright (C) 2020 PCSX2 Dev Team -//Copyright (c) David Quintana -// -//This library is free software; you can redistribute it and/or -//modify it under the terms of the GNU Lesser General Public -//License as published by the Free Software Foundation; either -//version 3.0 of the License, or (at your option) any later version. -// -//This library is distributed in the hope that it will be useful, -//but WITHOUT ANY WARRANTY; without even the implied warranty of -//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -//Lesser General Public License for more details. -// -//You should have received a copy of the GNU Lesser General Public -//License along with this library; if not, write to the Free Software -//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -// +/* PCSX2 - PS2 Emulator for PCs + * Copyright (C) 2002-2020 PCSX2 Dev Team + * + * PCSX2 is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with PCSX2. + * If not, see . + */ #include "PrecompiledHeader.h" #include "../CDVDdiscReader.h" diff --git a/pcsx2/CDVD/Windows/IOCtlSrc.cpp b/pcsx2/CDVD/Windows/IOCtlSrc.cpp index 702101b205..fc46edcf7e 100644 --- a/pcsx2/CDVD/Windows/IOCtlSrc.cpp +++ b/pcsx2/CDVD/Windows/IOCtlSrc.cpp @@ -1,6 +1,5 @@ /* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2016 PCSX2 Dev Team - * Copyright (C) 2002-2014 David Quintana [gigaherz] + * Copyright (C) 2002-2020 PCSX2 Dev Team * * PCSX2 is free software: you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Found- diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt index 1c43cc9e91..aa14aa1226 100644 --- a/pcsx2/CMakeLists.txt +++ b/pcsx2/CMakeLists.txt @@ -286,6 +286,7 @@ set(pcsx2GuiSources gui/Debugger/DebuggerLists.cpp gui/Debugger/DisassemblyDialog.cpp gui/Debugger/DebugEvents.cpp + gui/DriveList.cpp gui/ExecutorThread.cpp gui/FrameForGS.cpp gui/GlobalCommands.cpp @@ -343,6 +344,7 @@ set(pcsx2GuiHeaders gui/Dialogs/ConfigurationDialog.h gui/Dialogs/LogOptionsDialog.h gui/Dialogs/ModalPopups.h + gui/DriveList.h gui/GSFrame.h gui/i18n.h gui/IsoDropTarget.h @@ -403,8 +405,8 @@ set(pcsx2IPUHeaders # Linux sources set(pcsx2LinuxSources - CDVD/Unix/DriveUtility.cpp - CDVD/Unix/IOCtlSrc.cpp + CDVD/Linux/DriveUtility.cpp + CDVD/Linux/IOCtlSrc.cpp gui/CpuUsageProviderLnx.cpp Linux/LnxConsolePipe.cpp Linux/LnxKeyCodes.cpp @@ -412,8 +414,8 @@ set(pcsx2LinuxSources ) set(pcsx2OSXSources - CDVD/Unix/DriveUtility.cpp - CDVD/Unix/IOCtlSrc.cpp + CDVD/Linux/DriveUtility.cpp + CDVD/Linux/IOCtlSrc.cpp gui/CpuUsageProviderLnx.cpp Linux/LnxConsolePipe.cpp # Linux/LnxKeyCodes.cpp @@ -421,6 +423,8 @@ set(pcsx2OSXSources ) set(pcsx2FreeBSDSources + CDVD/Linux/DriveUtility.cpp + CDVD/Linux/IOCtlSrc.cpp gui/CpuUsageProviderLnx.cpp Linux/LnxConsolePipe.cpp Linux/LnxKeyCodes.cpp @@ -658,10 +662,6 @@ if(APPLE) set(Platform ${pcsx2OSXSources} ${pcsx2LinuxHeaders}) - - set(Platform_Libs - ${LIBUDEV_LIBRARIES} - ) endif() if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") diff --git a/pcsx2/System/SysCoreThread.cpp b/pcsx2/System/SysCoreThread.cpp index 64185ae27c..b26d182688 100644 --- a/pcsx2/System/SysCoreThread.cpp +++ b/pcsx2/System/SysCoreThread.cpp @@ -285,13 +285,7 @@ void SysCoreThread::OnSuspendInThread() void SysCoreThread::OnResumeInThread( bool isSuspended ) { GetCorePlugins().Open(); - - // When applying settings thread isn't suspended - // so any components that are still loaded don't need to be opened again - if (isSuspended) - { - DoCDVDopen(); - } + DoCDVDopen(); } diff --git a/pcsx2/gui/App.h b/pcsx2/gui/App.h index 89cedc46cc..5b0031b5bc 100644 --- a/pcsx2/gui/App.h +++ b/pcsx2/gui/App.h @@ -26,6 +26,7 @@ #include "AppCommon.h" #include "AppCoreThread.h" #include "RecentIsoList.h" +#include "DriveList.h" #ifndef DISABLE_RECORDING # include "Recording/VirtualPad.h" @@ -98,7 +99,6 @@ enum MenuIdentifiers // Run SubSection MenuId_Cdvd_Source, - MenuId_DriveSelector, MenuId_Src_Iso, MenuId_Src_Disc, MenuId_Src_NoDisc, @@ -106,6 +106,8 @@ enum MenuIdentifiers MenuId_RecentIsos_reservedStart, MenuId_IsoBrowse = MenuId_RecentIsos_reservedStart + 100, // Open dialog, runs selected iso. MenuId_IsoClear, + MenuId_DriveSelector, + MenuId_DriveListRefresh, MenuId_Ask_On_Booting, MenuId_Boot_CDVD, MenuId_Boot_CDVD2, @@ -527,6 +529,7 @@ protected: std::unique_ptr m_StderrRedirHandle; std::unique_ptr m_RecentIsoList; + std::unique_ptr m_DriveList; std::unique_ptr m_Resources; public: @@ -618,6 +621,7 @@ public: wxMenu& GetRecentIsoMenu(); RecentIsoManager& GetRecentIsoManager(); + wxMenu& GetDriveListMenu(); pxAppResources& GetResourceCache(); const wxIconBundle& GetIconBundle(); diff --git a/pcsx2/gui/AppConfig.cpp b/pcsx2/gui/AppConfig.cpp index be6bfcf594..e6648fd450 100644 --- a/pcsx2/gui/AppConfig.cpp +++ b/pcsx2/gui/AppConfig.cpp @@ -641,7 +641,6 @@ void AppConfig::LoadSaveRootItems( IniInterface& ini ) ini.Entry( L"CurrentIso", res, res, ini.IsLoading() || IsPortable() ); CurrentIso = res.GetFullPath(); - IniEntry( CurrentDisc ); IniEntry( CurrentBlockdump ); IniEntry( CurrentELF ); IniEntry( CurrentIRX ); @@ -728,7 +727,7 @@ AppConfig::FolderOptions::FolderOptions() , RunIso ( PathDefs::GetDocuments() ) // raw default is always the Documents folder. , RunELF ( PathDefs::GetDocuments() ) // raw default is always the Documents folder. - , RunDisc ( PathDefs::GetDocuments() ) + , RunDisc ( PathDefs::GetDocuments().GetFilename() ) { bitset = 0xffffffff; } @@ -1261,10 +1260,17 @@ static void LoadUiSettings() g_Conf->CurrentIso.clear(); } - if( !wxDirExists( g_Conf->CurrentDisc ) ) +#if defined(_WIN32) + if( !g_Conf->Folders.RunDisc.DirExists() ) { - g_Conf->CurrentDisc.clear(); + g_Conf->Folders.RunDisc.Clear(); } +#else + if (!g_Conf->Folders.RunDisc.Exists()) + { + g_Conf->Folders.RunDisc.Clear(); + } +#endif sApp.DispatchUiSettingsEvent( loader ); } @@ -1301,10 +1307,17 @@ static void SaveUiSettings() g_Conf->CurrentIso.clear(); } - if( !wxDirExists( g_Conf->CurrentDisc ) ) +#if defined(_WIN32) + if (!g_Conf->Folders.RunDisc.DirExists()) { - g_Conf->CurrentDisc.clear(); + g_Conf->Folders.RunDisc.Clear(); } +#else + if (!g_Conf->Folders.RunDisc.Exists()) + { + g_Conf->Folders.RunDisc.Clear(); + } +#endif sApp.GetRecentIsoManager().Add( g_Conf->CurrentIso ); diff --git a/pcsx2/gui/AppConfig.h b/pcsx2/gui/AppConfig.h index 32024f7fd8..d70df3d984 100644 --- a/pcsx2/gui/AppConfig.h +++ b/pcsx2/gui/AppConfig.h @@ -166,7 +166,7 @@ public: wxDirName RunIso; // last used location for Iso loading. wxDirName RunELF; // last used location for ELF loading. - wxDirName RunDisc; // last used location for Disc loading. + wxFileName RunDisc; // last used location for Disc loading. FolderOptions(); void LoadSave( IniInterface& conf ); @@ -325,7 +325,6 @@ public: bool AskOnBoot; wxString CurrentIso; - wxString CurrentDisc; wxString CurrentBlockdump; wxString CurrentELF; wxString CurrentIRX; diff --git a/pcsx2/gui/AppMain.cpp b/pcsx2/gui/AppMain.cpp index fe7f3e1709..5ee5a85ba6 100644 --- a/pcsx2/gui/AppMain.cpp +++ b/pcsx2/gui/AppMain.cpp @@ -1185,7 +1185,12 @@ void SysUpdateIsoSrcFile( const wxString& newIsoFile ) void SysUpdateDiscSrcDrive( const wxString& newDiscDrive ) { - g_Conf->CurrentDisc = newDiscDrive; +#if defined(_WIN32) + g_Conf->Folders.RunDisc = wxFileName::DirName(newDiscDrive); +#else + g_Conf->Folders.RunDisc = wxFileName(newDiscDrive); +#endif + AppSaveSettings(); sMainFrame.UpdateCdvdSrcSelection(); } diff --git a/pcsx2/gui/AppRes.cpp b/pcsx2/gui/AppRes.cpp index 437285b453..835ec61c22 100644 --- a/pcsx2/gui/AppRes.cpp +++ b/pcsx2/gui/AppRes.cpp @@ -68,6 +68,16 @@ RecentIsoManager& Pcsx2App::GetRecentIsoManager() return *m_RecentIsoList->Manager; } +wxMenu& Pcsx2App::GetDriveListMenu() +{ + if( !m_DriveList ) + { + m_DriveList = std::unique_ptr(new DriveList()); + } + + return *m_DriveList->Menu; +} + pxAppResources& Pcsx2App::GetResourceCache() { ScopedLock lock( m_mtx_Resources ); diff --git a/pcsx2/gui/DriveList.cpp b/pcsx2/gui/DriveList.cpp new file mode 100644 index 0000000000..6c78007c03 --- /dev/null +++ b/pcsx2/gui/DriveList.cpp @@ -0,0 +1,110 @@ +/* PCSX2 - PS2 Emulator for PCs + * Copyright (C) 2002-2020 PCSX2 Dev Team + * + * PCSX2 is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with PCSX2. + * If not, see . + */ + +#include "PrecompiledHeader.h" +#include "DriveList.h" +#include "MainFrame.h" +#include "../CDVD/CDVDdiscReader.h" + +DriveList::DriveList() +{ + Menu = new wxMenu(); + Manager = std::unique_ptr(new DriveListManager(Menu)); +} + +DriveListManager::DriveListManager(wxMenu* menu) + : m_Menu( menu ) +{ + m_Menu->Append(MenuId_DriveListRefresh, _("&Refresh")); + m_Menu->AppendSeparator(); + RefreshList(); + + // Bind on app level so that the event can be accessed outside DriveListManager + wxGetApp().Bind(wxEVT_MENU, &DriveListManager::OnRefreshClicked, this, MenuId_DriveListRefresh); +} + +void DriveListManager::ClearList() +{ + for (uint i = 0; i < m_Items.size(); i++) + { + m_Menu->Unbind(wxEVT_MENU, &DriveListManager::OnChangedSelection, this, m_Items.at(i)->itemPtr->GetId()); + m_Menu->Destroy(m_Items.at(i)->itemPtr); + } + + m_Items.clear(); +} + +void DriveListManager::RefreshList() +{ + ClearList(); + auto drives = GetOpticalDriveList(); + bool itemChecked = false; + + for (auto i : drives) + { + std::unique_ptr dli = std::unique_ptr(new DriveListItem()); + dli->driveLetter = wxString(i); + dli->itemPtr = m_Menu->AppendRadioItem(wxID_ANY, i); + + // Check the last used drive item + if (g_Conf->Folders.RunDisc == dli->driveLetter) + { + dli->itemPtr->Check(true); + itemChecked = true; + } + + m_Menu->Bind(wxEVT_MENU, &DriveListManager::OnChangedSelection, this, dli->itemPtr->GetId()); + m_Items.push_back(std::move(dli)); + } + + // Last used drive not found so use first found drive + if (itemChecked == false && m_Items.size() > 0) + { + m_Items.at(0)->itemPtr->Check(true); + + SysUpdateDiscSrcDrive(m_Items.at(0)->driveLetter); + } +} + +void DriveListManager::OnChangedSelection( wxCommandEvent& evt ) +{ + uint index = m_Items.size(); + + for (uint i = 0; i < m_Items.size(); i++) + { + if( (m_Items.at(i)->itemPtr != NULL) && (m_Items.at(i)->itemPtr->GetId() == evt.GetId()) ) + { + index = i; + break; + } + } + + if (index >= m_Items.size()) + { + evt.Skip(); + return; + } + + m_Items.at(index)->itemPtr->Check(true); + + ScopedCoreThreadPopup paused_core; + SwapOrReset_Disc(m_Menu->GetWindow(), paused_core, m_Items.at(index)->driveLetter); +} + +void DriveListManager::OnRefreshClicked( wxCommandEvent& evt ) +{ + RefreshList(); +} + diff --git a/pcsx2/gui/DriveList.h b/pcsx2/gui/DriveList.h new file mode 100644 index 0000000000..eab42e15ae --- /dev/null +++ b/pcsx2/gui/DriveList.h @@ -0,0 +1,60 @@ +/* PCSX2 - PS2 Emulator for PCs + * Copyright (C) 2002-2020 PCSX2 Dev Team + * + * PCSX2 is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with PCSX2. + * If not, see . + */ + +#pragma once + +#include "AppCoreThread.h" + +class DriveListManager : public wxEvtHandler +{ +protected: + struct DriveListItem + { + wxString driveLetter; + wxMenuItem* itemPtr; + + DriveListItem() { itemPtr = NULL; } + + DriveListItem( const wxString& src ) + : driveLetter( src ) + { + itemPtr = NULL; + } + }; + + std::vector> m_Items; + wxMenu* m_Menu; + +public: + DriveListManager(wxMenu* menu); + virtual ~DriveListManager() = default; + + void RefreshList(); + +protected: + void ClearList(); + void OnChangedSelection( wxCommandEvent& evt ); + void OnRefreshClicked( wxCommandEvent& evt ); +}; + +struct DriveList +{ + wxMenu* Menu; + std::unique_ptr Manager; + + DriveList(); +}; + +extern wxWindowID SwapOrReset_Disc(wxWindow* owner, IScopedCoreThread& core, const wxString driveLetter); diff --git a/pcsx2/gui/MainFrame.h b/pcsx2/gui/MainFrame.h index 530ff2bfb6..8c5d96d761 100644 --- a/pcsx2/gui/MainFrame.h +++ b/pcsx2/gui/MainFrame.h @@ -124,6 +124,7 @@ protected: wxMenu& m_GameSettingsSubmenu; wxMenuItem* m_menuItem_RecentIsoMenu; + wxMenuItem* m_menuItem_DriveListMenu; wxMenuItem& m_MenuItem_Console; #if defined(__unix__) wxMenuItem& m_MenuItem_Console_Stdio; diff --git a/pcsx2/gui/MainMenuClicks.cpp b/pcsx2/gui/MainMenuClicks.cpp index cc8829bce6..8868ad45ef 100644 --- a/pcsx2/gui/MainMenuClicks.cpp +++ b/pcsx2/gui/MainMenuClicks.cpp @@ -185,7 +185,7 @@ wxWindowID SwapOrReset_Disc( wxWindow* owner, IScopedCoreThread& core, const wxS { wxWindowID result = wxID_CANCEL; - if ((g_Conf->CdvdSource == CDVD_SourceType::Disc) && (driveLetter == g_Conf->CurrentDisc)) + if ((g_Conf->CdvdSource == CDVD_SourceType::Disc) && (driveLetter == g_Conf->Folders.RunDisc.GetPath())) { core.AllowResume(); return result; @@ -356,12 +356,12 @@ bool MainEmuFrame::_DoSelectELFBrowser() bool MainEmuFrame::_DoSelectDiscBrowser(wxString& driveLetter) { - DriveSelectorDialog driveDialog(this, g_Conf->Folders.RunDisc.ToString()); + DriveSelectorDialog driveDialog(this, g_Conf->Folders.RunDisc.GetPath()); if (driveDialog.ShowModal() != wxID_CANCEL) { driveLetter = driveDialog.GetSelectedDrive(); - g_Conf->Folders.RunDisc = wxDirName(driveLetter); + SysUpdateDiscSrcDrive(driveLetter); return true; } @@ -406,33 +406,37 @@ void MainEmuFrame::_DoBootCdvd() } else if( g_Conf->CdvdSource == CDVD_SourceType::Disc ) { - bool selector = g_Conf->CurrentDisc.IsEmpty(); + #if defined(_WIN32) + const bool driveExists = g_Conf->Folders.RunDisc.DirExists(); + #else + const bool driveExists = g_Conf->Folders.RunDisc.Exists(); + #endif - if( !selector && !wxDirExists(g_Conf->CurrentDisc) ) + if( !driveExists ) { // The previous mounted disc isn't mounted anymore wxDialogWithHelpers dialog( this, _("Drive not mounted!") ); dialog += dialog.Heading( - _("An error occured while trying to read drive: ") + g_Conf->CurrentDisc + L"\n\n" + + _("An error occured while trying to read drive: ") + g_Conf->Folders.RunDisc.GetPath() + L"\n\n" + _("Error: The configured drive does not exist. Click OK to select a new drive for CDVD.") ); + // Send event to refresh drive list submenu + wxCommandEvent event(wxEVT_MENU, MenuId_DriveListRefresh); + wxGetApp().ProcessEvent(event); + pxIssueConfirmation( dialog, MsgButtons().OK() ); - selector = true; - } - - if( selector || g_Conf->AskOnBoot ) - { wxString driveLetter; - if( !_DoSelectDiscBrowser( driveLetter ) ) + if (!_DoSelectDiscBrowser(driveLetter)) { paused_core.AllowResume(); return; } - SysUpdateDiscSrcDrive( driveLetter ); + // Refresh again after selection + wxGetApp().ProcessEvent(event); } } @@ -493,7 +497,6 @@ void MainEmuFrame::Menu_DiscBrowse_Click(wxCommandEvent& event) } SwapOrReset_Disc(this, core, driveLetter); - AppSaveSettings(); } wxString GetMsg_IsoImageChanged() diff --git a/pcsx2/windows/VCprojects/pcsx2.vcxproj b/pcsx2/windows/VCprojects/pcsx2.vcxproj index 25a5b49d1b..c0f9f2270d 100644 --- a/pcsx2/windows/VCprojects/pcsx2.vcxproj +++ b/pcsx2/windows/VCprojects/pcsx2.vcxproj @@ -148,25 +148,17 @@ - - false - false - false - + - - true - true - true + + true - - true - true - true + + true @@ -194,6 +186,7 @@ + @@ -434,6 +427,7 @@ + @@ -631,4 +625,4 @@ - \ No newline at end of file + diff --git a/pcsx2/windows/VCprojects/pcsx2.vcxproj.filters b/pcsx2/windows/VCprojects/pcsx2.vcxproj.filters index dad2c8cb98..4f82fcde2d 100644 --- a/pcsx2/windows/VCprojects/pcsx2.vcxproj.filters +++ b/pcsx2/windows/VCprojects/pcsx2.vcxproj.filters @@ -151,7 +151,7 @@ {be861049-a142-4650-85a5-a2fdd4eef011} - + {a5904fb6-e846-4cbf-940c-ca1c604140a0} @@ -882,11 +882,14 @@ System\Ps2\Iop\CDVD\Windows - - System\Ps2\Iop\CDVD\Unix + + System\Ps2\Iop\CDVD\Linux - - System\Ps2\Iop\CDVD\Unix + + System\Ps2\Iop\CDVD\Linux + + + AppHost @@ -1339,6 +1342,9 @@ System\Ps2\Iop\CDVD + + AppHost\Include +