mirror of https://github.com/PCSX2/pcsx2.git
UI: Async bios enumeration
Update pcsx2/gui/Panels/BiosSelectorPanel.cpp gonna squash this 1sec Co-authored-by: Silent <CookiePLMonster@users.noreply.github.com>
This commit is contained in:
parent
2101e17004
commit
24e5d909d0
|
@ -26,6 +26,9 @@
|
|||
|
||||
using namespace pxSizerFlags;
|
||||
|
||||
wxDECLARE_EVENT(pxEvt_BiosEnumerationFinished, wxCommandEvent);
|
||||
wxDEFINE_EVENT(pxEvt_BiosEnumerationFinished, wxCommandEvent);
|
||||
|
||||
// =====================================================================================================
|
||||
// BaseSelectorPanel
|
||||
// =====================================================================================================
|
||||
|
@ -115,6 +118,8 @@ Panels::BiosSelectorPanel::BiosSelectorPanel( wxWindow* parent )
|
|||
*this += 8;
|
||||
*this += m_FolderPicker | StdExpand();
|
||||
|
||||
Bind(pxEvt_BiosEnumerationFinished, &BiosSelectorPanel::OnEnumComplete, this);
|
||||
|
||||
Bind(wxEVT_BUTTON, &BiosSelectorPanel::OnRefreshSelections, this, refreshButton->GetId());
|
||||
}
|
||||
|
||||
|
@ -162,28 +167,49 @@ bool Panels::BiosSelectorPanel::ValidateEnumerationStatus()
|
|||
return validated;
|
||||
}
|
||||
|
||||
void Panels::BiosSelectorPanel::DoRefresh()
|
||||
void Panels::BiosSelectorPanel::EnumThread::ExecuteTaskInThread()
|
||||
{
|
||||
if (!m_BiosList) return;
|
||||
|
||||
m_ComboBox->Clear();
|
||||
|
||||
const wxFileName right(g_Conf->FullpathToBios());
|
||||
bool biosSet = false;
|
||||
|
||||
for(size_t i=0; i<m_BiosList->GetCount(); ++i)
|
||||
for (size_t i = 0; i < m_parent.m_BiosList->GetCount(); ++i)
|
||||
{
|
||||
wxString description;
|
||||
if (!IsBIOS((*m_BiosList)[i], description)) continue;
|
||||
int sel = m_ComboBox->Append( description, (void*)i );
|
||||
|
||||
if (wxFileName((*m_BiosList)[i] ) == right)
|
||||
{
|
||||
m_ComboBox->SetSelection(sel);
|
||||
biosSet = true;
|
||||
}
|
||||
if (!IsBIOS((*m_parent.m_BiosList)[i], description)) continue;
|
||||
Result.emplace_back(std::move(description), i);
|
||||
}
|
||||
|
||||
if ((!biosSet) && !(m_ComboBox->IsEmpty()))
|
||||
m_ComboBox->SetSelection(0);
|
||||
wxCommandEvent done(pxEvt_BiosEnumerationFinished);
|
||||
done.SetClientData(this);
|
||||
m_parent.GetEventHandler()->AddPendingEvent(done);
|
||||
}
|
||||
|
||||
void Panels::BiosSelectorPanel::DoRefresh()
|
||||
{
|
||||
m_ComboBox->Clear();
|
||||
if (!m_BiosList->size()) return;
|
||||
|
||||
m_ComboBox->Append(wxString("Enumerating BIOSes..."));
|
||||
m_ComboBox->Update();
|
||||
|
||||
m_EnumeratorThread.reset(new EnumThread(*this));
|
||||
|
||||
m_EnumeratorThread->Start();
|
||||
}
|
||||
|
||||
void Panels::BiosSelectorPanel::OnEnumComplete(wxCommandEvent &evt)
|
||||
{
|
||||
auto enumThread = static_cast<EnumThread*>(evt.GetClientData());
|
||||
// Sanity check, in case m_BiosList was updated by ValidateEnumerationStatus() while the EnumThread was running
|
||||
if (m_EnumeratorThread.get() != enumThread || m_BiosList->size() < enumThread->Result.size()) return;
|
||||
|
||||
const wxFileName& currentBios = g_Conf->FullpathToBios();
|
||||
m_ComboBox->Clear(); // Clear the "Enumerating BIOSes..."
|
||||
|
||||
for (const std::pair<wxString, u32>& result : enumThread->Result)
|
||||
{
|
||||
const int sel = m_ComboBox->Append(result.first, reinterpret_cast<void*>(result.second));
|
||||
if (currentBios == wxFileName((*m_BiosList)[result.second]))
|
||||
m_ComboBox->SetSelection(sel);
|
||||
}
|
||||
};
|
||||
|
||||
Panels::BiosSelectorPanel::EnumThread::EnumThread(BiosSelectorPanel &parent) : m_parent(parent)
|
||||
{};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* PCSX2 - PS2 Emulator for PCs
|
||||
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
||||
* Copyright (C) 2002-2021 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-
|
||||
|
@ -460,10 +460,32 @@ namespace Panels
|
|||
BiosSelectorPanel( wxWindow* parent );
|
||||
virtual ~BiosSelectorPanel() = default;
|
||||
|
||||
class EnumThread : public Threading::pxThread
|
||||
{
|
||||
public:
|
||||
std::vector<std::pair<wxString, u32>> Result;
|
||||
|
||||
virtual ~EnumThread()
|
||||
{
|
||||
try {
|
||||
pxThread::Cancel();
|
||||
}
|
||||
DESTRUCTOR_CATCHALL
|
||||
}
|
||||
EnumThread(BiosSelectorPanel& parent);
|
||||
|
||||
protected:
|
||||
void ExecuteTaskInThread();
|
||||
BiosSelectorPanel& m_parent;
|
||||
};
|
||||
|
||||
protected:
|
||||
virtual void Apply();
|
||||
virtual void AppStatusEvent_OnSettingsApplied();
|
||||
virtual void DoRefresh();
|
||||
virtual void OnEnumComplete(wxCommandEvent& evt);
|
||||
virtual bool ValidateEnumerationStatus();
|
||||
|
||||
std::unique_ptr<EnumThread> m_EnumeratorThread;
|
||||
};
|
||||
} // namespace Panels
|
||||
|
|
Loading…
Reference in New Issue