75 lines
2.5 KiB
C++
75 lines
2.5 KiB
C++
#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"});
|
|
}
|
|
}
|
|
}
|