WX: Use std::future for checking disc integrity
Simpler, and puts the call to CheckIntegrity right where it should be, instead of being hidden somewhere in a thread class. This also makes it more obvious what we're getting from the async task. Oh, and coincidentally, this fixes a random crash that could occur during the check. I'm not sure why.
This commit is contained in:
parent
4d0dd93098
commit
9d70b894bf
|
@ -5,7 +5,9 @@
|
||||||
#include "DolphinWX/ISOProperties/FilesystemPanel.h"
|
#include "DolphinWX/ISOProperties/FilesystemPanel.h"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <chrono>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <future>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -41,25 +43,6 @@ public:
|
||||||
std::unique_ptr<DiscIO::FileSystem> filesystem;
|
std::unique_ptr<DiscIO::FileSystem> filesystem;
|
||||||
};
|
};
|
||||||
|
|
||||||
class IntegrityCheckThread final : public wxThread
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit IntegrityCheckThread(const DiscIO::Volume* volume, DiscIO::Partition partition)
|
|
||||||
: wxThread{wxTHREAD_JOINABLE}, m_volume{volume}, m_partition{partition}
|
|
||||||
{
|
|
||||||
Create();
|
|
||||||
}
|
|
||||||
|
|
||||||
ExitCode Entry() override
|
|
||||||
{
|
|
||||||
return reinterpret_cast<ExitCode>(m_volume->CheckIntegrity(m_partition));
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
const DiscIO::Volume* const m_volume;
|
|
||||||
const DiscIO::Partition m_partition;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum : int
|
enum : int
|
||||||
{
|
{
|
||||||
ICON_DISC,
|
ICON_DISC,
|
||||||
|
@ -326,18 +309,15 @@ void FilesystemPanel::OnCheckPartitionIntegrity(wxCommandEvent& WXUNUSED(event))
|
||||||
const auto selection = m_tree_ctrl->GetSelection();
|
const auto selection = m_tree_ctrl->GetSelection();
|
||||||
WiiPartition* partition =
|
WiiPartition* partition =
|
||||||
static_cast<WiiPartition*>(m_tree_ctrl->GetItemData(m_tree_ctrl->GetSelection()));
|
static_cast<WiiPartition*>(m_tree_ctrl->GetItemData(m_tree_ctrl->GetSelection()));
|
||||||
IntegrityCheckThread thread(m_opened_iso.get(), partition->filesystem->GetPartition());
|
std::future<bool> is_valid = std::async(std::launch::async, [&] {
|
||||||
thread.Run();
|
return m_opened_iso->CheckIntegrity(partition->filesystem->GetPartition());
|
||||||
|
});
|
||||||
|
|
||||||
while (thread.IsAlive())
|
while (is_valid.wait_for(std::chrono::milliseconds(50)) != std::future_status::ready)
|
||||||
{
|
|
||||||
dialog.Pulse();
|
dialog.Pulse();
|
||||||
wxThread::Sleep(50);
|
dialog.Hide();
|
||||||
}
|
|
||||||
|
|
||||||
dialog.Destroy();
|
if (is_valid.get())
|
||||||
|
|
||||||
if (thread.Wait())
|
|
||||||
{
|
{
|
||||||
wxMessageBox(_("Integrity check completed. No errors have been found."),
|
wxMessageBox(_("Integrity check completed. No errors have been found."),
|
||||||
_("Integrity check completed"), wxOK | wxICON_INFORMATION, this);
|
_("Integrity check completed"), wxOK | wxICON_INFORMATION, this);
|
||||||
|
|
Loading…
Reference in New Issue