From a9b03f081a5c5407ae0c154c9dc52d59487a21e2 Mon Sep 17 00:00:00 2001 From: wh201906 Date: Sun, 4 Jun 2023 02:25:46 +0800 Subject: [PATCH] Remember different client paths(max num:32) Helpful for me --- src/ui/mainwindow.cpp | 69 ++++++++++++++++++++++++++++++++++++++----- src/ui/mainwindow.h | 6 +++- src/ui/mainwindow.ui | 12 +++++++- 3 files changed, 78 insertions(+), 9 deletions(-) diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index baab385..f07f3d9 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -160,7 +160,7 @@ void MainWindow::on_PM3_connectButton_clicked() QString port = ui->PM3_portBox->currentData().toString(); QString startArgs = ui->Set_Client_startArgsEdit->text(); - QString clientPath = ui->PM3_pathEdit->text(); + QString clientPath = ui->PM3_pathBox->currentText(); QFileInfo clientFile(clientPath); if(!clientFile.exists()) @@ -180,7 +180,7 @@ void MainWindow::on_PM3_connectButton_clicked() port = ""; // a symbol QStringList args = startArgs.replace("", port).split(' '); - saveClientPath(clientPath); + addClientPath(clientPath); QProcess envSetProcess; QString envScriptPath = ui->Set_Client_envScriptEdit->text(); @@ -1102,9 +1102,7 @@ void MainWindow::uiInit() } settings->endGroup(); - settings->beginGroup("Client_Path"); - ui->PM3_pathEdit->setText(settings->value("path", "proxmark3").toString()); - settings->endGroup(); + loadClientPathList(); ui->Set_Client_GUIWorkingDirLabel->setText(QDir::currentPath()); @@ -1343,10 +1341,67 @@ void MainWindow::on_GroupBox_clicked(bool checked) settings->endGroup(); } -void MainWindow::saveClientPath(const QString& path) +void MainWindow::addClientPath(const QString& path) +{ + m_clientPathList.removeAll(path); + m_clientPathList.prepend(path); + while(m_clientPathList.size() > 32) // the maximum count of path items + m_clientPathList.removeLast(); + // sync to the storage + saveClientPathList(); + // sync to the UI + loadClientPathList(); +} + +void MainWindow::loadClientPathList() { + m_clientPathList.clear(); settings->beginGroup("Client_Path"); - settings->setValue("path", path); + int len = settings->beginReadArray("pathList"); + settings->endArray(); + if(settings->contains("path") && len == 0) + { + qDebug() << "Using old client path storage"; + m_clientPathList += settings->value("path", "proxmark3").toString(); + } + else + { + int arrayLen = settings->beginReadArray("pathList"); + for(int i = 0; i < arrayLen; i++) + { + settings->setArrayIndex(i); + QString path = settings->value("path").toString(); + if(!path.isEmpty()) + m_clientPathList += path; + } + settings->endArray(); + } + settings->endGroup(); + + ui->PM3_pathBox->clear(); + for(const QString& clientPath : qAsConst(m_clientPathList)) + ui->PM3_pathBox->addItem(clientPath); +} + +void MainWindow::saveClientPathList() +{ + settings->beginGroup("Client_Path"); + if(settings->contains("path")) + { + qDebug() << "Upgrading client path storage"; + QString oldPath = settings->value("path").toString(); + if(!oldPath.isEmpty() && !m_clientPathList.contains(oldPath)) + m_clientPathList.append(oldPath); + settings->remove("path"); + } + + settings->beginWriteArray("pathList"); + for(int i = 0; i < m_clientPathList.size(); i++) + { + settings->setArrayIndex(i); + settings->setValue("path", m_clientPathList[i]); + } + settings->endArray(); settings->endGroup(); } // *********************************************** diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index b66915b..bf4bcb4 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -260,10 +260,14 @@ private: MF_trailerDecoderDialog* decDialog; + QStringList m_clientPathList; + void signalInit(); void MF_widgetReset(); void setTableItem(QTableWidget *widget, int row, int column, const QString& text); - void saveClientPath(const QString& path); + void addClientPath(const QString& path); + void loadClientPathList(); + void saveClientPathList(); void onLFfreqConfChanged(int value, bool isCustomized); void dockInit(); void loadConfig(); diff --git a/src/ui/mainwindow.ui b/src/ui/mainwindow.ui index b001624..967b6e9 100644 --- a/src/ui/mainwindow.ui +++ b/src/ui/mainwindow.ui @@ -58,7 +58,17 @@ - + + + + 0 + 0 + + + + true + +