Fix crash on VFS Tool (#16146)

This commit is contained in:
Antonino Di Guardo 2024-09-29 02:11:27 +02:00 committed by GitHub
parent 37d2317b68
commit 3f66297593
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 8 deletions

View File

@ -43,7 +43,7 @@ bool vfs::mount(std::string_view vpath, std::string_view path, bool is_dir)
return false;
}
// Workaround
// Initialize vfs_manager if not yet initialized (e.g. g_fxo->reset() was previously invoked)
g_fxo->need<vfs_manager>();
auto& table = g_fxo->get<vfs_manager>();
@ -196,6 +196,13 @@ bool vfs::unmount(std::string_view vpath)
std::string vfs::get(std::string_view vpath, std::vector<std::string>* out_dir, std::string* out_path)
{
// Just to make the code more robust.
// It should never happen because we take care to initialize Emu (and so also vfs_manager) with Emu.Init() before this function is invoked
if (!g_fxo->is_init<vfs_manager>())
{
fmt::throw_exception("vfs_manager not initialized");
}
auto& table = g_fxo->get<vfs_manager>();
reader_lock lock(table.mutex);
@ -372,6 +379,13 @@ using char2 = char8_t;
std::string vfs::retrieve(std::string_view path, const vfs_directory* node, std::vector<std::string_view>* mount_path)
{
// Just to make the code more robust.
// It should never happen because we take care to initialize Emu (and so also vfs_manager) with Emu.Init() before this function is invoked
if (!g_fxo->is_init<vfs_manager>())
{
fmt::throw_exception("vfs_manager not initialized");
}
auto& table = g_fxo->get<vfs_manager>();
if (!node)

View File

@ -1986,7 +1986,7 @@ void main_window::OnEmuStop()
ui->removeHDD1CachesAct->setEnabled(true);
ui->removeAllCachesAct->setEnabled(true);
ui->removeSavestatesAct->setEnabled(true);
ui->cleanupGameListAct->setEnabled(true);
ui->cleanUpGameListAct->setEnabled(true);
ui->actionManage_Users->setEnabled(true);
ui->confCamerasAct->setEnabled(true);
@ -2039,7 +2039,7 @@ void main_window::OnEmuReady() const
ui->removeHDD1CachesAct->setEnabled(false);
ui->removeAllCachesAct->setEnabled(false);
ui->removeSavestatesAct->setEnabled(false);
ui->cleanupGameListAct->setEnabled(false);
ui->cleanUpGameListAct->setEnabled(false);
}
void main_window::EnableMenus(bool enabled) const
@ -2694,7 +2694,7 @@ void main_window::CreateConnects()
connect(ui->removeHDD1CachesAct, &QAction::triggered, this, &main_window::RemoveHDD1Caches);
connect(ui->removeAllCachesAct, &QAction::triggered, this, &main_window::RemoveAllCaches);
connect(ui->removeSavestatesAct, &QAction::triggered, this, &main_window::RemoveSavestates);
connect(ui->cleanupGameListAct, &QAction::triggered, this, &main_window::CleanupGameList);
connect(ui->cleanUpGameListAct, &QAction::triggered, this, &main_window::CleanUpGameList);
connect(ui->removeFirmwareCacheAct, &QAction::triggered, this, &main_window::RemoveFirmwareCache);
connect(ui->createFirmwareCacheAct, &QAction::triggered, this, &main_window::CreateFirmwareCache);
@ -3604,7 +3604,7 @@ void main_window::RemoveSavestates()
}
}
void main_window::CleanupGameList()
void main_window::CleanUpGameList()
{
if (QMessageBox::question(this, tr("Confirm Removal"), tr("Remove invalid game paths from game list?\n"
"Undetectable games (zombies) as well as corrupted games will be removed from the game list file (games.yml)")) != QMessageBox::Yes)

View File

@ -132,7 +132,7 @@ private Q_SLOTS:
void RemoveHDD1Caches();
void RemoveAllCaches();
void RemoveSavestates();
void CleanupGameList();
void CleanUpGameList();
void RemoveFirmwareCache();
void CreateFirmwareCache();

View File

@ -193,7 +193,7 @@
<addaction name="removeAllCachesAct"/>
<addaction name="removeSavestatesAct"/>
<addaction name="separator"/>
<addaction name="cleanupGameListAct"/>
<addaction name="cleanUpGameListAct"/>
</widget>
<widget class="QMenu" name="menuFirmware">
<property name="title">
@ -1166,7 +1166,7 @@
<string>Remove Savestates</string>
</property>
</action>
<action name="cleanupGameListAct">
<action name="cleanUpGameListAct">
<property name="text">
<string>Clean up Game List</string>
</property>

View File

@ -2,6 +2,7 @@
#include "vfs_tool_dialog.h"
#include "ui_vfs_tool_dialog.h"
#include "Emu/VFS.h"
#include "Emu/System.h"
vfs_tool_dialog::vfs_tool_dialog(QWidget *parent)
: QDialog(parent)
@ -22,6 +23,12 @@ vfs_tool_dialog::~vfs_tool_dialog()
void vfs_tool_dialog::handle_vfs_path(const QString& path)
{
// Initialize Emu if not yet initialized (e.g. Emu.Kill() was previously invoked) before using some of the following vfs:: functions (e.g. vfs::get())
if (Emu.IsStopped())
{
Emu.Init();
}
const std::string spath = path.toStdString();
const std::string vfs_get_path = vfs::get(spath);
const std::string vfs_retrieve_path = vfs::retrieve(spath);