add config file to resource system
move language folder
master
wh201906 2 years ago
parent 757fdcfc21
commit 9c89df4519
No known key found for this signature in database

@ -58,7 +58,6 @@ Great thanks to him.
mkdir build && cd build mkdir build && cd build
qmake ../src qmake ../src
make -j4 && make clean make -j4 && make clean
cp -r ../config ./
./Proxmark3GUI ./Proxmark3GUI
*** ***

@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/config">
<file>config_official.json</file>
<file>config_rrgv4.13.json</file>
</qresource>
</RCC>

@ -57,7 +57,6 @@ release页面中有含客户端的GUI。这个GUI也可以搭配你自己的客
mkdir build && cd build mkdir build && cd build
qmake ../src qmake ../src
make -j4 && make clean make -j4 && make clean
cp -r ../config ./
./Proxmark3GUI ./Proxmark3GUI
*** ***

@ -1,4 +1,4 @@
[Languages] [Languages]
en_US=English en_US=English
zh_CN=简体中文 zh_CN=简体中文
ext=Load from external file (ext)=Load from external file

@ -65,4 +65,5 @@ QMAKE_TARGET_DESCRIPTION = "Proxmark3GUI"
QMAKE_TARGET_COMPANY = "wh201906" QMAKE_TARGET_COMPANY = "wh201906"
RESOURCES += \ RESOURCES += \
i18n/language.qrc ../i18n/language.qrc \
../config/config.qrc

@ -28,7 +28,7 @@ void PM3Process::connectPM3(const QString& path, const QStringList args)
currArgs = args; currArgs = args;
// using "-f" option to make the client output flushed after every print. // using "-f" option to make the client output flushed after every print.
// single '\r' might appears. Don't use QProcess::Text there or '\r' is ignored. // single '\r' might appear. Don't use QProcess::Text there or '\r' is ignored.
start(path, args, QProcess::Unbuffered | QProcess::ReadWrite); start(path, args, QProcess::Unbuffered | QProcess::ReadWrite);
if(waitForStarted(10000)) if(waitForStarted(10000))
{ {

@ -123,13 +123,24 @@ bool Util::chooseLanguage(QSettings* guiSettings, QMainWindow* window)
delete langSettings; delete langSettings;
bool isOk = false; bool isOk = false;
QString selectedText = QInputDialog::getItem(window, "", "Choose a language:", langMap.keys(), 0, false, &isOk); QString selectedText = QInputDialog::getItem(window, "", "Choose a language:", langMap.keys(), 0, false, &isOk);
if(isOk) if(!isOk)
return false;
if(langMap[selectedText] == "(ext)")
{ {
guiSettings->beginGroup("lang"); QString extPath = QFileDialog::getOpenFileName(nullptr, "Select the translation file:");
guiSettings->setValue("language", langMap[selectedText]); if(extPath.isEmpty())
return false;
guiSettings->beginGroup("language");
guiSettings->setValue("extPath", extPath);
guiSettings->endGroup(); guiSettings->endGroup();
guiSettings->sync();
} }
guiSettings->beginGroup("language");
guiSettings->setValue("name", langMap[selectedText]);
guiSettings->endGroup();
guiSettings->sync();
return isOk; return isOk;
} }

@ -13,6 +13,7 @@
#include <QSettings> #include <QSettings>
#include <QMainWindow> #include <QMainWindow>
#include <QInputDialog> #include <QInputDialog>
#include <QFileDialog>
#include <QDockWidget> #include <QDockWidget>
#include "ui_mainwindow.h" #include "ui_mainwindow.h"

@ -27,33 +27,34 @@ int main(int argc, char *argv[])
QSettings* settings = new QSettings("GUIsettings.ini", QSettings::IniFormat); QSettings* settings = new QSettings("GUIsettings.ini", QSettings::IniFormat);
settings->setIniCodec("UTF-8"); settings->setIniCodec("UTF-8");
settings->beginGroup("lang"); settings->beginGroup("language");
QString currLang = settings->value("language", "").toString(); QString languageFile = settings->value("extPath").toString();
QString languageName = settings->value("name").toString();
settings->endGroup(); settings->endGroup();
if(currLang == "") if(languageName == "")
{ {
if(Util::chooseLanguage(settings, &w)) if(Util::chooseLanguage(settings, &w))
{ {
settings->beginGroup("lang"); settings->beginGroup("language");
currLang = settings->value("language", "").toString(); languageName = settings->value("name").toString();
settings->endGroup(); settings->endGroup();
} }
else else
currLang = "en_US"; languageName = "en_US";
}
if(languageName == "(ext)")
{
settings->beginGroup("language");
languageFile = settings->value("extPath").toString();
settings->endGroup();
} }
if(currLang == "ext")
currLang = QFileDialog::getOpenFileName(nullptr, "Select the translation file:");
else else
currLang = ":/i18n/" + currLang + ".qm"; languageFile = ":/i18n/" + languageName + ".qm";
QTranslator* translator = new QTranslator(&w); QTranslator* translator = new QTranslator(&w);
if(translator->load(currLang)) if(translator->load(languageFile))
{
a.installTranslator(translator); a.installTranslator(translator);
}
else else
{ QMessageBox::information(&w, "Error", "Can't load " + languageFile + " as translation file.");
QMessageBox::information(&w, "Error", "Can't load " + currLang + " as translation file.");
}
delete settings; delete settings;
w.initUI(); w.initUI();
w.show(); w.show();

@ -2,6 +2,7 @@
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include <QJsonDocument> #include <QJsonDocument>
#include <QDirIterator>
MainWindow::MainWindow(QWidget *parent): MainWindow::MainWindow(QWidget *parent):
QMainWindow(parent) QMainWindow(parent)
@ -79,7 +80,11 @@ MainWindow::~MainWindow()
void MainWindow::loadConfig() void MainWindow::loadConfig()
{ {
QFile configList(ui->Set_Client_configPathEdit->text()); QString filename = ui->Set_Client_configFileBox->currentData().toString();
if(filename == "(ext)")
filename = ui->Set_Client_configPathEdit->text();
qDebug() << "config file:" << filename;
QFile configList(filename);
if(!configList.open(QFile::ReadOnly | QFile::Text)) if(!configList.open(QFile::ReadOnly | QFile::Text))
{ {
QMessageBox::information(this, tr("Info"), tr("Failed to load config file")); QMessageBox::information(this, tr("Info"), tr("Failed to load config file"));
@ -1106,11 +1111,27 @@ void MainWindow::uiInit()
ui->Set_Client_keepClientActiveBox->setChecked(keepClientActive); ui->Set_Client_keepClientActiveBox->setChecked(keepClientActive);
settings->endGroup(); settings->endGroup();
QDirIterator configFiles(":/config/");
ui->Set_Client_configFileBox->blockSignals(true);
while(configFiles.hasNext())
{
configFiles.next();
ui->Set_Client_configFileBox->addItem(configFiles.fileName(), configFiles.filePath());
}
ui->Set_Client_configFileBox->addItem(tr("External file"), "(ext)");
int configId = -1;
settings->beginGroup("Client_Env"); settings->beginGroup("Client_Env");
ui->Set_Client_envScriptEdit->setText(settings->value("scriptPath").toString()); ui->Set_Client_envScriptEdit->setText(settings->value("scriptPath").toString());
ui->Set_Client_workingDirEdit->setText(settings->value("workingDir", "../data").toString()); ui->Set_Client_workingDirEdit->setText(settings->value("workingDir", "../data").toString());
ui->Set_Client_configPathEdit->setText(settings->value("configPath", "config.json").toString()); configId = ui->Set_Client_configFileBox->findData(settings->value("configFile"));
ui->Set_Client_configPathEdit->setText(settings->value("extConfigFilePath", "config.json").toString());
settings->endGroup(); settings->endGroup();
if(configId != -1)
ui->Set_Client_configFileBox->setCurrentIndex(configId);
ui->Set_Client_configFileBox->blockSignals(false);
on_Set_Client_configFileBox_currentIndexChanged(ui->Set_Client_configFileBox->currentIndex());
ui->MF_RW_keyTypeBox->addItem("A", Mifare::KEY_A); ui->MF_RW_keyTypeBox->addItem("A", Mifare::KEY_A);
ui->MF_RW_keyTypeBox->addItem("B", Mifare::KEY_B); ui->MF_RW_keyTypeBox->addItem("B", Mifare::KEY_B);
@ -1314,7 +1335,7 @@ void MainWindow::on_Set_Client_workingDirEdit_editingFinished()
void MainWindow::on_Set_Client_configPathEdit_editingFinished() void MainWindow::on_Set_Client_configPathEdit_editingFinished()
{ {
settings->beginGroup("Client_Env"); settings->beginGroup("Client_Env");
settings->setValue("configPath", ui->Set_Client_configPathEdit->text()); settings->setValue("extConfigFilePath", ui->Set_Client_configPathEdit->text());
settings->endGroup(); settings->endGroup();
} }
@ -1452,3 +1473,11 @@ void MainWindow::on_LF_LFConf_resetButton_clicked()
setState(true); setState(true);
} }
void MainWindow::on_Set_Client_configFileBox_currentIndexChanged(int index)
{
ui->Set_Client_configPathEdit->setVisible(ui->Set_Client_configFileBox->itemData(index).toString() == "(ext)");
settings->beginGroup("Client_Env");
settings->setValue("configFile", ui->Set_Client_configFileBox->currentData());
settings->endGroup();
}

@ -51,7 +51,7 @@ public:
~MainWindow(); ~MainWindow();
void initUI(); void initUI();
bool eventFilter(QObject *watched, QEvent *event); bool eventFilter(QObject *watched, QEvent *event) override;
public slots: public slots:
void refreshOutput(const QString& output); void refreshOutput(const QString& output);
void refreshCMD(const QString& cmd); void refreshCMD(const QString& cmd);
@ -209,6 +209,9 @@ private slots:
void on_Set_Client_configPathEdit_editingFinished(); void on_Set_Client_configPathEdit_editingFinished();
void setState(bool st); void setState(bool st);
void on_Set_Client_configFileBox_currentIndexChanged(int index);
private: private:
Ui::MainWindow* ui; Ui::MainWindow* ui;
QButtonGroup* MFCardTypeBtnGroup; QButtonGroup* MFCardTypeBtnGroup;

@ -2763,10 +2763,34 @@ or the communication between a tag and a reader.</string>
<item> <item>
<widget class="QLabel" name="label_63"> <widget class="QLabel" name="label_63">
<property name="text"> <property name="text">
<string>Config file path(Reconnect to apply):</string> <string>Config file(Reconnect to apply):</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_15">
<item>
<widget class="QComboBox" name="Set_Client_configFileBox">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_13">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item> <item>
<widget class="QLineEdit" name="Set_Client_configPathEdit"> <widget class="QLineEdit" name="Set_Client_configPathEdit">
<property name="text"> <property name="text">

Loading…
Cancel
Save