port some small fry to the new config system.

This commit is contained in:
Arisotura 2024-05-24 11:41:51 +02:00
parent f9449999ec
commit b5cc5a2cf7
5 changed files with 27 additions and 29 deletions

View File

@ -85,18 +85,6 @@ bool DirectLAN;
bool SavestateRelocSRAM; bool SavestateRelocSRAM;
int AudioInterp;
int AudioBitDepth;
int AudioVolume;
bool DSiVolumeSync;
int MicInputType;
std::string MicDevice;
std::string MicWavPath;
std::string LastROMFolder;
std::string RecentROMList[10];
std::string SaveFilePath; std::string SaveFilePath;
std::string SavestatePath; std::string SavestatePath;
std::string CheatFilePath; std::string CheatFilePath;
@ -411,6 +399,12 @@ size_t Array::Size()
return Data.size(); return Data.size();
} }
void Array::Clear()
{
toml::array newarray;
Data = newarray;
}
Array Array::GetArray(const int id) Array Array::GetArray(const int id)
{ {
while (Data.size() < id+1) while (Data.size() < id+1)

View File

@ -78,6 +78,8 @@ public:
size_t Size(); size_t Size();
void Clear();
Array GetArray(const int id); Array GetArray(const int id);
int GetInt(const int id); int GetInt(const int id);
@ -197,10 +199,6 @@ extern bool DirectLAN;
extern bool SavestateRelocSRAM; extern bool SavestateRelocSRAM;
extern std::string LastROMFolder;
extern std::string RecentROMList[10];
extern std::string SaveFilePath; extern std::string SaveFilePath;
extern std::string SavestatePath; extern std::string SavestatePath;
extern std::string CheatFilePath; extern std::string CheatFilePath;

View File

@ -139,7 +139,7 @@ void ROMInfoDialog::on_saveIconButton_clicked()
{ {
QString filename = QFileDialog::getSaveFileName(this, QString filename = QFileDialog::getSaveFileName(this,
"Save Icon", "Save Icon",
QString::fromStdString(Config::LastROMFolder), emuInstance->getGlobalConfig().GetQString("LastROMFolder"),
"PNG Images (*.png)"); "PNG Images (*.png)");
if (filename.isEmpty()) if (filename.isEmpty())
return; return;
@ -151,7 +151,7 @@ void ROMInfoDialog::on_saveAnimatedIconButton_clicked()
{ {
QString filename = QFileDialog::getSaveFileName(this, QString filename = QFileDialog::getSaveFileName(this,
"Save Animated Icon", "Save Animated Icon",
QString::fromStdString(Config::LastROMFolder), emuInstance->getGlobalConfig().GetQString("LastROMFolder"),
"GIF Images (*.gif)"); "GIF Images (*.gif)");
if (filename.isEmpty()) if (filename.isEmpty())
return; return;

View File

@ -251,9 +251,11 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
actOpenROMArchive->setShortcut(QKeySequence(Qt::Key_O | Qt::CTRL | Qt::SHIFT));*/ actOpenROMArchive->setShortcut(QKeySequence(Qt::Key_O | Qt::CTRL | Qt::SHIFT));*/
recentMenu = menu->addMenu("Open recent"); recentMenu = menu->addMenu("Open recent");
for (int i = 0; i < 10; ++i) Config::Array recentROMs = globalCfg.GetArray("RecentROM");
int numrecent = std::min(kMaxRecentROMs, (int)recentROMs.Size());
for (int i = 0; i < numrecent; ++i)
{ {
std::string item = Config::RecentROMList[i]; std::string item = recentROMs.GetString(i);
if (!item.empty()) if (!item.empty())
recentFileList.push_back(QString::fromStdString(item)); recentFileList.push_back(QString::fromStdString(item));
} }
@ -1154,13 +1156,13 @@ QStringList MainWindow::pickROM(bool gba)
const QString filename = QFileDialog::getOpenFileName( const QString filename = QFileDialog::getOpenFileName(
this, "Open " + console + " ROM", this, "Open " + console + " ROM",
QString::fromStdString(Config::LastROMFolder), globalCfg.GetQString("LastROMFolder"),
"All supported files (*" + allROMs + ")" + extraFilters "All supported files (*" + allROMs + ")" + extraFilters
); );
if (filename.isEmpty()) return {}; if (filename.isEmpty()) return {};
Config::LastROMFolder = QFileInfo(filename).dir().path().toStdString(); globalCfg.SetQString("LastROMFolder", QFileInfo(filename).dir().path());
return splitArchivePath(filename, false); return splitArchivePath(filename, false);
} }
@ -1223,8 +1225,7 @@ void MainWindow::onOpenFile()
void MainWindow::onClearRecentFiles() void MainWindow::onClearRecentFiles()
{ {
recentFileList.clear(); recentFileList.clear();
for (int i = 0; i < 10; i++) globalCfg.GetArray("RecentROM").Clear();
Config::RecentROMList[i] = "";
updateRecentFilesMenu(); updateRecentFilesMenu();
} }
@ -1232,9 +1233,12 @@ void MainWindow::updateRecentFilesMenu()
{ {
recentMenu->clear(); recentMenu->clear();
Config::Array recentroms = globalCfg.GetArray("RecentROM");
recentroms.Clear();
for (int i = 0; i < recentFileList.size(); ++i) for (int i = 0; i < recentFileList.size(); ++i)
{ {
if (i >= 10) break; if (i >= kMaxRecentROMs) break;
QString item_full = recentFileList.at(i); QString item_full = recentFileList.at(i);
QString item_display = item_full; QString item_display = item_full;
@ -1262,7 +1266,7 @@ void MainWindow::updateRecentFilesMenu()
actRecentFile_i->setData(item_full); actRecentFile_i->setData(item_full);
connect(actRecentFile_i, &QAction::triggered, this, &MainWindow::onClickRecentFile); connect(actRecentFile_i, &QAction::triggered, this, &MainWindow::onClickRecentFile);
Config::RecentROMList[i] = recentFileList.at(i).toStdString(); recentroms.SetQString(i, recentFileList.at(i));
} }
while (recentFileList.size() > 10) while (recentFileList.size() > 10)
@ -1435,7 +1439,7 @@ void MainWindow::onSaveState()
// TODO: specific 'last directory' for savestate files? // TODO: specific 'last directory' for savestate files?
QString qfilename = QFileDialog::getSaveFileName(this, QString qfilename = QFileDialog::getSaveFileName(this,
"Save state", "Save state",
QString::fromStdString(Config::LastROMFolder), globalCfg.GetQString("LastROMFolder"),
"melonDS savestates (*.mln);;Any file (*.*)"); "melonDS savestates (*.mln);;Any file (*.*)");
if (qfilename.isEmpty()) if (qfilename.isEmpty())
{ {
@ -1477,7 +1481,7 @@ void MainWindow::onLoadState()
// TODO: specific 'last directory' for savestate files? // TODO: specific 'last directory' for savestate files?
QString qfilename = QFileDialog::getOpenFileName(this, QString qfilename = QFileDialog::getOpenFileName(this,
"Load state", "Load state",
QString::fromStdString(Config::LastROMFolder), globalCfg.GetQString("LastROMFolder"),
"melonDS savestates (*.ml*);;Any file (*.*)"); "melonDS savestates (*.ml*);;Any file (*.*)");
if (qfilename.isEmpty()) if (qfilename.isEmpty())
{ {
@ -1526,7 +1530,7 @@ void MainWindow::onImportSavefile()
emuThread->emuPause(); emuThread->emuPause();
QString path = QFileDialog::getOpenFileName(this, QString path = QFileDialog::getOpenFileName(this,
"Select savefile", "Select savefile",
QString::fromStdString(Config::LastROMFolder), globalCfg.GetQString("LastROMFolder"),
"Savefiles (*.sav *.bin *.dsv);;Any file (*.*)"); "Savefiles (*.sav *.bin *.dsv);;Any file (*.*)");
if (path.isEmpty()) if (path.isEmpty())

View File

@ -40,6 +40,8 @@
class EmuInstance; class EmuInstance;
class EmuThread; class EmuThread;
const int kMaxRecentROMs = 10;
/* /*
class WindowBase : public QMainWindow class WindowBase : public QMainWindow
{ {