Split DiskUtils into BootableUtils

This commit is contained in:
Mahmood - Zer0xFF 2024-10-22 11:11:49 +01:00
parent 9eaf97ae4d
commit c3f138a424
17 changed files with 133 additions and 84 deletions

View file

@ -249,25 +249,3 @@ bool DiskUtils::TryGetDiskId(const fs::path& imagePath, std::string* diskIdPtr)
return false;
}
}
bool DiskUtils::IsBootableExecutablePath(const fs::path& filePath)
{
auto extension = filePath.extension().string();
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
return (extension == ".elf");
}
bool DiskUtils::IsBootableDiscImagePath(const fs::path& filePath)
{
const auto& supportedExtensions = DiskUtils::GetSupportedExtensions();
auto extension = filePath.extension().string();
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
auto extensionIterator = supportedExtensions.find(extension);
return extensionIterator != std::end(supportedExtensions);
}
bool DiskUtils::IsBootableArcadeDefPath(const fs::path& filePath)
{
auto extension = filePath.extension().string();
return (extension == ".arcadedef");
}

View file

@ -18,9 +18,4 @@ namespace DiskUtils
SystemConfigMap ParseSystemConfigFile(Framework::CStream*);
bool TryGetDiskId(const fs::path&, std::string*);
bool IsBootableExecutablePath(const fs::path&);
bool IsBootableDiscImagePath(const fs::path&);
bool IsBootableArcadeDefPath(const fs::path&);
}

View file

@ -1,6 +1,6 @@
#include "../ui_shared/BootablesProcesses.h"
#include "../ui_shared/BootablesDbClient.h"
#include "DiskUtils.h"
#include "ui_shared/BootableUtils.h"
#include "com_virtualapplications_play_Bootable.h"
#include "NativeShared.h"
@ -109,7 +109,7 @@ extern "C" JNIEXPORT void Java_com_virtualapplications_play_BootablesInterop_set
extern "C" JNIEXPORT jboolean Java_com_virtualapplications_play_BootablesInterop_IsBootableExecutablePath(JNIEnv* env, jclass clazz, jstring bootablePathString)
{
auto bootablePath = fs::path(GetStringFromJstring(env, bootablePathString));
return DiskUtils::IsBootableExecutablePath(bootablePath);
return BootableUtils::IsBootableExecutablePath(bootablePath);
}
extern "C" JNIEXPORT jboolean Java_com_virtualapplications_play_BootablesInterop_DoesBootableExist(JNIEnv* env, jclass clazz, jstring bootablePathString)

View file

@ -11,7 +11,7 @@
#ifdef HAS_GSH_VULKAN
#include "GSH_VulkaniOS.h"
#endif
#include "DiskUtils.h"
#include "../ui_shared/BootableUtils.h"
#include "PH_Generic.h"
#include "../../tools/PsfPlayer/Source/SH_OpenAL.h"
#include "../ui_shared/StatsManager.h"
@ -127,7 +127,7 @@ CPS2VM::NewFrameEvent::Connection g_newFrameConnection;
g_virtualMachine->Reset();
auto bootablePath = fs::path([self.bootablePath fileSystemRepresentation]);
if(DiskUtils::IsBootableExecutablePath(bootablePath))
if(BootableUtils::IsBootableExecutablePath(bootablePath))
{
g_virtualMachine->m_ee->m_os->BootFromFile(bootablePath);
}

View file

@ -10,6 +10,14 @@ project(Play_Libretro_Core)
add_definitions(-DPLAY_VERSION="${PROJECT_Version}")
if(NOT TARGET ui_shared)
add_subdirectory(
${CMAKE_CURRENT_SOURCE_DIR}/../ui_shared
${CMAKE_CURRENT_BINARY_DIR}/ui_shared
)
endif()
list(APPEND PROJECT_LIBS ui_shared)
if(NOT TARGET PlayCore)
add_subdirectory(
${CMAKE_CURRENT_SOURCE_DIR}/../

View file

@ -3,7 +3,7 @@
#include "Log.h"
#include "AppConfig.h"
#include "PS2VM.h"
#include "DiskUtils.h"
#include "ui_shared/BootableUtils.h"
#include "PS2VM_Preferences.h"
#include "GSH_OpenGL_Libretro.h"
@ -491,11 +491,11 @@ bool retro_load_game(const retro_game_info* info)
#endif
fs::path filePath = info->path;
if(DiskUtils::IsBootableExecutablePath(filePath))
if(BootableUtils::IsBootableExecutablePath(filePath))
{
m_bootCommand = LastOpenCommand(BootType::ELF, filePath);
}
else if(DiskUtils::IsBootableDiscImagePath(filePath))
else if(BootableUtils::IsBootableDiscImagePath(filePath))
{
m_bootCommand = LastOpenCommand(BootType::CD, filePath);
CAppConfig::GetInstance().SetPreferencePath(PREF_PS2_CDROM0_PATH, filePath);

View file

@ -69,7 +69,7 @@ void BootableModel::SetWidth(int width)
}
/* start of BootImageItemDelegate */
BootableCoverQVariant::BootableCoverQVariant(std::string key, std::string title, fs::path path, BootablesDb::BootableStateList states, BootablesDb::BOOTABLE_TYPE bootableType)
BootableCoverQVariant::BootableCoverQVariant(std::string key, std::string title, fs::path path, BootablesDb::BootableStateList states, BootableUtils::BOOTABLE_TYPE bootableType)
: m_key(key)
, m_title(title)
, m_path(path)

View file

@ -6,6 +6,7 @@
#include <QAbstractTableModel>
#include <QStyledItemDelegate>
#include "ui_shared/BootablesDbClient.h"
#include "ui_shared/BootableUtils.h"
class BootableModel : public QAbstractTableModel
{
@ -31,7 +32,7 @@ class BootableCoverQVariant
{
public:
explicit BootableCoverQVariant(std::string = "PH", std::string = "", fs::path = "", BootablesDb::BootableStateList = {}, BootablesDb::BOOTABLE_TYPE = BootablesDb::BOOTABLE_TYPE::UNKNOWN);
explicit BootableCoverQVariant(std::string = "PH", std::string = "", fs::path = "", BootablesDb::BootableStateList = {}, BootableUtils::BOOTABLE_TYPE = BootableUtils::UNKNOWN);
~BootableCoverQVariant() = default;
void paint(QPainter* painter, const QRect& rect, const QPalette& palette, int mode) const;
@ -50,7 +51,7 @@ private:
fs::path m_path;
std::string m_statusColor;
BootablesDb::BootableStateList m_states;
BootablesDb::BOOTABLE_TYPE m_bootableType;
BootableUtils::BOOTABLE_TYPE m_bootableType;
};
Q_DECLARE_METATYPE(BootableCoverQVariant)

View file

@ -35,11 +35,11 @@ QBootablesView::QBootablesView(QWidget* parent)
m_sortingMethod = CAppConfig::GetInstance().GetPreferenceInteger("ui.sortmethod.v2") & BootablesDb::CClient::SORT_METHOD_NONE;
ui->comboBox->setCurrentIndex(m_sortingMethod);
CAppConfig::GetInstance().RegisterPreferenceInteger("ui.filterbootabletype", BootablesDb::BOOTABLE_TYPE::PS2_DISC | BootablesDb::BOOTABLE_TYPE::PS2_ARCADE | BootablesDb::BOOTABLE_TYPE::PS2_ELF);
CAppConfig::GetInstance().RegisterPreferenceInteger("ui.filterbootabletype", BootableUtils::PS2_DISC | BootableUtils::PS2_ARCADE | BootableUtils::PS2_ELF);
auto filter = CAppConfig::GetInstance().GetPreferenceInteger("ui.filterbootabletype");
ui->checkBox_ps2->setChecked(filter & BootablesDb::BOOTABLE_TYPE::PS2_DISC);
ui->checkBox_ps2_arcade->setChecked(filter & BootablesDb::BOOTABLE_TYPE::PS2_ARCADE);
ui->checkBox_ps2_elf->setChecked(filter & BootablesDb::BOOTABLE_TYPE::PS2_ELF);
ui->checkBox_ps2->setChecked(filter & BootableUtils::PS2_DISC);
ui->checkBox_ps2_arcade->setChecked(filter & BootableUtils::PS2_ARCADE);
ui->checkBox_ps2_elf->setChecked(filter & BootableUtils::PS2_ELF);
m_proxyModel->setBootableTypeFilterState(filter, 1);
@ -48,17 +48,17 @@ QBootablesView::QBootablesView(QWidget* parent)
};
connect(ui->checkBox_ps2, &QCheckBox::stateChanged, [this, updateFilterPref](int state) {
m_proxyModel->setBootableTypeFilterState(BootablesDb::BOOTABLE_TYPE::PS2_DISC, state);
m_proxyModel->setBootableTypeFilterState(BootableUtils::PS2_DISC, state);
updateFilterPref(m_proxyModel);
});
connect(ui->checkBox_ps2_arcade, &QCheckBox::stateChanged, [this, updateFilterPref](int state) {
m_proxyModel->setBootableTypeFilterState(BootablesDb::BOOTABLE_TYPE::PS2_ARCADE, state);
m_proxyModel->setBootableTypeFilterState(BootableUtils::PS2_ARCADE, state);
updateFilterPref(m_proxyModel);
});
connect(ui->checkBox_ps2_elf, &QCheckBox::stateChanged, [this, updateFilterPref](int state) {
m_proxyModel->setBootableTypeFilterState(BootablesDb::BOOTABLE_TYPE::PS2_ELF, state);
m_proxyModel->setBootableTypeFilterState(BootableUtils::PS2_ELF, state);
updateFilterPref(m_proxyModel);
});

View file

@ -46,7 +46,7 @@
#include "ui_debugmenu.h"
#endif
#include "input/PH_GenericInput.h"
#include "DiskUtils.h"
#include "ui_shared/BootableUtils.h"
#include "PathUtils.h"
#include <zstd_zlibwrapper.h>
@ -1187,16 +1187,16 @@ void MainWindow::SetupBootableView()
QBootablesView::BootCallback bootGameCallback = [&, showEmu](fs::path filePath) {
try
{
if(DiskUtils::IsBootableDiscImagePath(filePath))
if(BootableUtils::IsBootableDiscImagePath(filePath))
{
LoadCDROM(filePath);
BootCDROM();
}
else if(DiskUtils::IsBootableExecutablePath(filePath))
else if(BootableUtils::IsBootableExecutablePath(filePath))
{
BootElf(filePath);
}
else if(DiskUtils::IsBootableArcadeDefPath(filePath))
else if(BootableUtils::IsBootableArcadeDefPath(filePath))
{
BootArcadeMachine(filePath);
}

View file

@ -267,7 +267,7 @@ void ArcadeUtils::RegisterArcadeMachines()
try
{
auto def = ReadArcadeMachineDefinition(arcadeDefsPath / arcadeDefFilename);
BootablesDb::CClient::GetInstance().RegisterBootable(arcadeDefFilename, "", "", BootablesDb::BOOTABLE_TYPE::PS2_ARCADE);
BootablesDb::CClient::GetInstance().RegisterBootable(arcadeDefFilename, "", "", BootableUtils::PS2_ARCADE);
BootablesDb::CClient::GetInstance().SetTitle(arcadeDefFilename, def.name.c_str());
}
catch(const std::exception& exception)

View file

@ -0,0 +1,60 @@
#include <algorithm>
#include <cstring>
#include "BootableUtils.h"
#include "DiskUtils.h"
bool BootableUtils::IsBootableExecutablePath(const fs::path& filePath)
{
auto extension = filePath.extension().string();
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
return (extension == ".elf");
}
bool BootableUtils::IsBootableDiscImagePath(const fs::path& filePath)
{
const auto& supportedExtensions = DiskUtils::GetSupportedExtensions();
auto extension = filePath.extension().string();
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
auto extensionIterator = supportedExtensions.find(extension);
return extensionIterator != std::end(supportedExtensions);
}
bool BootableUtils::IsBootableArcadeDefPath(const fs::path& filePath)
{
auto extension = filePath.extension().string();
return (extension == ".arcadedef");
}
BootableUtils::BOOTABLE_TYPE BootableUtils::GetBootableType(const fs::path& filePath)
{
auto extension = filePath.extension().string();
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
if(extension == ".elf")
return BootableUtils::BOOTABLE_TYPE::PS2_ELF;
if(extension == ".arcadedef")
return BootableUtils::BOOTABLE_TYPE::PS2_ARCADE;
if(BootableUtils::IsBootableDiscImagePath(filePath))
{
try
{
auto opticalMedia = DiskUtils::CreateOpticalMediaFromPath(filePath, COpticalMedia::CREATE_AUTO_DISABLE_DL_DETECT);
auto fileSystem = opticalMedia->GetFileSystem();
auto systemConfigFile = std::unique_ptr<Framework::CStream>(fileSystem->Open("SYSTEM.CNF;1"));
if(!systemConfigFile) return BootableUtils::BOOTABLE_TYPE::UNKNOWN;
auto systemConfig = DiskUtils::ParseSystemConfigFile(systemConfigFile.get());
auto bootItemIterator = systemConfig.find("BOOT2");
if(bootItemIterator != std::end(systemConfig))
{
return BootableUtils::BOOTABLE_TYPE::PS2_DISC;
}
}
catch(const std::exception&)
{
}
}
return BootableUtils::BOOTABLE_TYPE::UNKNOWN;
}

View file

@ -0,0 +1,23 @@
#pragma once
#include <string>
#include "filesystem_def.h"
namespace BootableUtils
{
enum BOOTABLE_TYPE
{
UNKNOWN = 0,
PS2_DISC = 1 << 0,
PS2_ARCADE = 1 << 1,
PS2_ELF = 1 << 2,
};
bool TryGetDiskId(const fs::path&, std::string*);
bool IsBootableExecutablePath(const fs::path&);
bool IsBootableDiscImagePath(const fs::path&);
bool IsBootableArcadeDefPath(const fs::path&);
BOOTABLE_TYPE GetBootableType(const fs::path&);
}

View file

@ -101,7 +101,7 @@ std::vector<Bootable> CClient::GetBootables(int32_t sortMethod)
return bootables;
}
void CClient::RegisterBootable(const fs::path& path, const char* title, const char* discId, BootablesDb::BOOTABLE_TYPE bootableType)
void CClient::RegisterBootable(const fs::path& path, const char* title, const char* discId, BootableUtils::BOOTABLE_TYPE bootableType)
{
Framework::CSqliteStatement statement(m_db, "INSERT OR IGNORE INTO bootables (path, title, discId, bootableType) VALUES (?,?,?,?)");
statement.BindText(1, Framework::PathUtils::GetNativeStringFromPath(path).c_str());
@ -209,7 +209,7 @@ Bootable CClient::ReadBootable(Framework::CSqliteStatement& statement)
bootable.overview = reinterpret_cast<const char*>(sqlite3_column_text(statement, 5));
bootable.lastBootedTime = sqlite3_column_int(statement, 4);
bootable.states = GetGameStates(bootable.discId);
bootable.bootableType = static_cast<BootablesDb::BOOTABLE_TYPE>(sqlite3_column_int(statement, 6));
bootable.bootableType = static_cast<BootableUtils::BOOTABLE_TYPE>(sqlite3_column_int(statement, 6));
return bootable;
}
@ -234,17 +234,17 @@ void CClient::UpgradeDb()
{
Framework::CSqliteStatement statement(db, "UPDATE bootables SET bootableType = ? WHERE path LIKE '%.arcade%';");
statement.BindInteger(1, BootablesDb::BOOTABLE_TYPE::PS2_ARCADE);
statement.BindInteger(1, BootableUtils::PS2_ARCADE);
statement.StepNoResult();
}
{
Framework::CSqliteStatement statement(db, "UPDATE bootables SET bootableType = ? WHERE path LIKE '%.elf%';");
statement.BindInteger(1, BootablesDb::BOOTABLE_TYPE::PS2_ELF);
statement.BindInteger(1, BootableUtils::PS2_ELF);
statement.StepNoResult();
}
{
Framework::CSqliteStatement statement(db, "UPDATE bootables SET bootableType = ? WHERE bootableType = 0;");
statement.BindInteger(1, BootablesDb::BOOTABLE_TYPE::PS2_DISC);
statement.BindInteger(1, BootableUtils::PS2_DISC);
statement.StepNoResult();
}

View file

@ -7,6 +7,7 @@
#include "Singleton.h"
#include "sqlite/SqliteDb.h"
#include "sqlite/SqliteStatement.h"
#include "BootableUtils.h"
namespace BootablesDb
{
@ -17,14 +18,6 @@ namespace BootablesDb
};
using BootableStateList = std::vector<BootableState>;
enum BOOTABLE_TYPE
{
UNKNOWN = 0,
PS2_DISC = 1 << 0,
PS2_ARCADE = 1 << 1,
PS2_ELF = 1 << 2,
};
struct Bootable
{
fs::path path;
@ -34,7 +27,7 @@ namespace BootablesDb
std::string overview;
time_t lastBootedTime = 0;
BootableStateList states;
BOOTABLE_TYPE bootableType = BOOTABLE_TYPE::UNKNOWN;
BootableUtils::BOOTABLE_TYPE bootableType = BootableUtils::UNKNOWN;
};
class CClient : public CSingleton<CClient>
@ -57,7 +50,7 @@ namespace BootablesDb
std::vector<Bootable> GetBootables(int32_t = SORT_METHOD_NONE);
BootableStateList GetStates();
void RegisterBootable(const fs::path&, const char*, const char*, BootablesDb::BOOTABLE_TYPE);
void RegisterBootable(const fs::path&, const char*, const char*, BootableUtils::BOOTABLE_TYPE);
void UnregisterBootable(const fs::path&);
void SetDiscId(const fs::path&, const char*);

View file

@ -3,6 +3,7 @@
#include "BootablesProcesses.h"
#include "BootablesDbClient.h"
#include "TheGamesDbClient.h"
#include "BootableUtils.h"
#include "DiskUtils.h"
#include "PathUtils.h"
#include "StringUtils.h"
@ -57,31 +58,19 @@ bool TryRegisterBootable(const fs::path& path)
{
try
{
std::string serial;
BootablesDb::BOOTABLE_TYPE bootableType = BootablesDb::BOOTABLE_TYPE::UNKNOWN;
if(
!BootablesDb::CClient::GetInstance().BootableExists(path) &&
!DiskUtils::IsBootableExecutablePath(path) &&
!(DiskUtils::IsBootableDiscImagePath(path) && DiskUtils::TryGetDiskId(path, &serial)) &&
!DiskUtils::IsBootableArcadeDefPath(path))
if(BootablesDb::CClient::GetInstance().BootableExists(path))
{
return false;
}
if(DiskUtils::IsBootableDiscImagePath(path))
{
bootableType = BootablesDb::BOOTABLE_TYPE::PS2_DISC;
}
else if(DiskUtils::IsBootableExecutablePath(path))
{
bootableType = BootablesDb::BOOTABLE_TYPE::PS2_ELF;
}
else if(DiskUtils::IsBootableArcadeDefPath(path))
{
bootableType = BootablesDb::BOOTABLE_TYPE::PS2_ARCADE;
}
BootableUtils::BOOTABLE_TYPE bootableType = BootableUtils::GetBootableType(path);
if(bootableType == BootableUtils::UNKNOWN)
return false;
assert(bootableType != BootablesDb::BOOTABLE_TYPE::UNKNOWN);
std::string serial;
if(bootableType == BootableUtils::PS2_DISC)
if(!DiskUtils::TryGetDiskId(path, &serial))
return false;
BootablesDb::CClient::GetInstance().RegisterBootable(path, path.filename().string().c_str(), serial.c_str(), bootableType);
return true;

View file

@ -60,6 +60,8 @@ set(SHARED_UI_SRC_FILES
BootablesDbClient.h
BootablesProcesses.cpp
BootablesProcesses.h
BootableUtils.cpp
BootableUtils.h
TheGamesDbClient.cpp
TheGamesDbClient.h
StatsManager.cpp