Roms List improvements

This commit is contained in:
2026-06-14 22:30:10 +02:00
parent 95d202f378
commit 10d3daf86a
7 changed files with 160 additions and 92 deletions
+74
View File
@@ -0,0 +1,74 @@
#include <RomsList.hpp>
#include <QHeaderView>
#include <QThread>
#include <GeneralSettings.hpp>
#include <Options.hpp>
#include <Mem.hpp>
RomsListTable::RomsListTable(GeneralSettings *general) {
verticalHeader()->hide();
horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
setSizePolicy({QSizePolicy::Maximum, QSizePolicy::Maximum});
setSelectionMode(QAbstractItemView::SingleSelection);
setSelectionBehavior(QAbstractItemView::SelectRows);
setEditTriggers(QAbstractItemView::NoEditTriggers);
setSortingEnabled(true);
setColumnCount(4);
setHorizontalHeaderItem(0, new QTableWidgetItem("Name"));
setHorizontalHeaderItem(1, new QTableWidgetItem("Regions"));
setHorizontalHeaderItem(2, new QTableWidgetItem("Last played"));
setHorizontalHeaderItem(3, new QTableWidgetItem("Time played"));
connect(general, &GeneralSettings::romFolderSelected, this, [&] {
std::thread popThread([&] {
populate(Options::GetRomsPath());
emit populateFinished();
});
popThread.detach();
});
connect(general, &GeneralSettings::romFolderCleared, this, [&] {
for (int i = 0; i < rowCount(); i++)
removeRow(i);
romsList = {};
emit cleared();
});
std::thread popThread([&] {
populate(Options::GetRomsPath());
emit populateFinished();
});
popThread.detach();
}
void RomsListTable::populate(const std::string &romsPath) {
if (!romsPath.empty()) {
for (const auto &file : fs::recursive_directory_iterator{romsPath}) {
if (!file.is_regular_file())
continue;
auto filename = file.path().string();
bool isPlain = std::ranges::any_of(std::array{".n64", ".z64", ".v64"},
[&](const std::string &ext) { return file.path().extension() == ext; });
bool isArchive =
std::ranges::any_of(std::array{".zip", ".7z", ".rar", ".tar"},
[&](const std::string &ext) { return file.path().extension() == ext; });
if (!isArchive && !isPlain)
continue;
auto rom = n64::Mem::LoadROM(isArchive, filename);
auto regions = n64::GameDB::match(rom);
if (rom.gameNameDB.empty())
rom.gameNameDB = fs::path(filename).stem().string();
romsList.push_back(
{rom.header.countryCode, rom.header.version, filename, rom.gameNameDB, regions, "Never", "0h 00m 00s"});
}
}
}