From f86cba8d561f7411bc536efb6bc8da92c153331c Mon Sep 17 00:00:00 2001 From: wh201906 Date: Tue, 1 Mar 2022 11:13:07 +0800 Subject: [PATCH] New project structure Load translation file in the executable. --- .gitignore | 73 +--------- README.md | 9 +- doc/README/README_zh_CN.md | 9 +- lang/languages.ini | 3 - src/.gitignore | 72 ++++++++++ Proxmark3GUI.pro => src/Proxmark3GUI.pro | 10 +- {common => src/common}/myeventfilter.cpp | 0 {common => src/common}/myeventfilter.h | 0 {common => src/common}/pm3process.cpp | 0 {common => src/common}/pm3process.h | 0 {common => src/common}/util.cpp | 2 +- {common => src/common}/util.h | 0 {lang => src/i18n}/en_US.qm | Bin {lang => src/i18n}/en_US.ts | 0 src/i18n/language.qrc | 7 + src/i18n/languages.ini | 4 + {lang => src/i18n}/zh_CN.qm | Bin {lang => src/i18n}/zh_CN.ts | 2 +- main.cpp => src/main.cpp | 126 +++++++++--------- {module => src/module}/lf.cpp | 0 {module => src/module}/lf.h | 0 {module => src/module}/mifare.cpp | 0 {module => src/module}/mifare.h | 0 src/module/t55xxtab.cpp | 14 ++ src/module/t55xxtab.h | 22 +++ {ui => src/ui}/mainwindow.cpp | 0 {ui => src/ui}/mainwindow.h | 0 {ui => src/ui}/mainwindow.ui | 2 +- {ui => src/ui}/mf_attack_hardnesteddialog.cpp | 0 {ui => src/ui}/mf_attack_hardnesteddialog.h | 0 {ui => src/ui}/mf_attack_hardnesteddialog.ui | 0 {ui => src/ui}/mf_sim_simdialog.cpp | 0 {ui => src/ui}/mf_sim_simdialog.h | 0 {ui => src/ui}/mf_sim_simdialog.ui | 0 {ui => src/ui}/mf_trailerdecoderdialog.cpp | 0 {ui => src/ui}/mf_trailerdecoderdialog.h | 0 {ui => src/ui}/mf_trailerdecoderdialog.ui | 0 {ui => src/ui}/mf_uid_parameterdialog.cpp | 0 {ui => src/ui}/mf_uid_parameterdialog.h | 0 {ui => src/ui}/mf_uid_parameterdialog.ui | 0 src/ui/t55xxtab.ui | 21 +++ 41 files changed, 221 insertions(+), 155 deletions(-) delete mode 100644 lang/languages.ini create mode 100644 src/.gitignore rename Proxmark3GUI.pro => src/Proxmark3GUI.pro (92%) rename {common => src/common}/myeventfilter.cpp (100%) rename {common => src/common}/myeventfilter.h (100%) rename {common => src/common}/pm3process.cpp (100%) rename {common => src/common}/pm3process.h (100%) rename {common => src/common}/util.cpp (97%) rename {common => src/common}/util.h (100%) rename {lang => src/i18n}/en_US.qm (100%) rename {lang => src/i18n}/en_US.ts (100%) create mode 100644 src/i18n/language.qrc create mode 100644 src/i18n/languages.ini rename {lang => src/i18n}/zh_CN.qm (100%) rename {lang => src/i18n}/zh_CN.ts (99%) rename main.cpp => src/main.cpp (88%) rename {module => src/module}/lf.cpp (100%) rename {module => src/module}/lf.h (100%) rename {module => src/module}/mifare.cpp (100%) rename {module => src/module}/mifare.h (100%) create mode 100644 src/module/t55xxtab.cpp create mode 100644 src/module/t55xxtab.h rename {ui => src/ui}/mainwindow.cpp (100%) rename {ui => src/ui}/mainwindow.h (100%) rename {ui => src/ui}/mainwindow.ui (99%) rename {ui => src/ui}/mf_attack_hardnesteddialog.cpp (100%) rename {ui => src/ui}/mf_attack_hardnesteddialog.h (100%) rename {ui => src/ui}/mf_attack_hardnesteddialog.ui (100%) rename {ui => src/ui}/mf_sim_simdialog.cpp (100%) rename {ui => src/ui}/mf_sim_simdialog.h (100%) rename {ui => src/ui}/mf_sim_simdialog.ui (100%) rename {ui => src/ui}/mf_trailerdecoderdialog.cpp (100%) rename {ui => src/ui}/mf_trailerdecoderdialog.h (100%) rename {ui => src/ui}/mf_trailerdecoderdialog.ui (100%) rename {ui => src/ui}/mf_uid_parameterdialog.cpp (100%) rename {ui => src/ui}/mf_uid_parameterdialog.h (100%) rename {ui => src/ui}/mf_uid_parameterdialog.ui (100%) create mode 100644 src/ui/t55xxtab.ui diff --git a/.gitignore b/.gitignore index fb50266..28ed25c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,72 +1 @@ -# This file is used to ignore files which are generated -# ---------------------------------------------------------------------------- - -*~ -*.autosave -*.a -*.core -*.moc -*.o -*.obj -*.orig -*.rej -*.so -*.so.* -*_pch.h.cpp -*_resource.rc -.#* -*.*# -core -!core/ -tags -.DS_Store -.directory -*.debug -Makefile* -*.prl -*.app -moc_*.cpp -ui_*.h -qrc_*.cpp -Thumbs.db -*.res -*.rc -/.qmake.cache -/.qmake.stash - -# qtcreator generated files -*.pro.user* - -# xemacs temporary files -*.flc - -# Vim temporary files -.*.swp - -# Visual Studio generated files -*.ib_pdb_index -*.idb -*.ilk -*.pdb -*.sln -*.suo -*.vcproj -*vcproj.*.*.user -*.ncb -*.sdf -*.opensdf -*.vcxproj -*vcxproj.* - -# MinGW generated files -*.Debug -*.Release - -# Python byte code -*.pyc - -# Binaries -# -------- -*.dll -*.exe - +/build* \ No newline at end of file diff --git a/README.md b/README.md index 7324f09..74b998e 100644 --- a/README.md +++ b/README.md @@ -55,12 +55,9 @@ Great thanks to him. sudo apt-get install qt5-default libqt5serialport5 libqt5serialport5-dev git clone https://github.com/wh201906/Proxmark3GUI.git --depth=1 cd Proxmark3GUI - mkdir build - cd build - qmake ../ - make - make clean - cp -r ../lang ./ + mkdir build && cd build + qmake ../src + make -j4 && make clean cp -r ../config ./ ./Proxmark3GUI diff --git a/doc/README/README_zh_CN.md b/doc/README/README_zh_CN.md index 980ea88..3eb9513 100644 --- a/doc/README/README_zh_CN.md +++ b/doc/README/README_zh_CN.md @@ -54,12 +54,9 @@ release页面中有含客户端的GUI。这个GUI也可以搭配你自己的客 sudo apt-get install qt5-default libqt5serialport5 libqt5serialport5-dev git clone https://github.com/wh201906/Proxmark3GUI.git --depth=1 cd Proxmark3GUI - mkdir build - cd build - qmake ../ - make - make clean - cp -r ../lang ./ + mkdir build && cd build + qmake ../src + make -j4 && make clean cp -r ../config ./ ./Proxmark3GUI diff --git a/lang/languages.ini b/lang/languages.ini deleted file mode 100644 index d9a11e4..0000000 --- a/lang/languages.ini +++ /dev/null @@ -1,3 +0,0 @@ -[Languages] -en_US=English -zh_CN=简体中文 \ No newline at end of file diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..6e844ee --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,72 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + diff --git a/Proxmark3GUI.pro b/src/Proxmark3GUI.pro similarity index 92% rename from Proxmark3GUI.pro rename to src/Proxmark3GUI.pro index 4c9b689..9e1a073 100644 --- a/Proxmark3GUI.pro +++ b/src/Proxmark3GUI.pro @@ -22,6 +22,7 @@ SOURCES += \ common/util.cpp \ module/lf.cpp \ module/mifare.cpp \ + module/t55xxtab.cpp \ ui/mf_trailerdecoderdialog.cpp \ ui/mf_sim_simdialog.cpp \ ui/mf_uid_parameterdialog.cpp \ @@ -34,6 +35,7 @@ HEADERS += \ common/util.h \ module/lf.h \ module/mifare.h \ + module/t55xxtab.h \ ui/mf_trailerdecoderdialog.h \ ui/mf_sim_simdialog.h \ ui/mf_uid_parameterdialog.h \ @@ -41,6 +43,7 @@ HEADERS += \ ui/mf_attack_hardnesteddialog.h \ FORMS += \ + ui/t55xxtab.ui \ ui/mf_trailerdecoderdialog.ui \ ui/mf_sim_simdialog.ui \ ui/mf_uid_parameterdialog.ui \ @@ -48,8 +51,8 @@ FORMS += \ ui/mf_attack_hardnesteddialog.ui TRANSLATIONS += \ - lang/zh_CN.ts \ - lang/en_US.ts + i18n/zh_CN.ts \ + i18n/en_US.ts # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin @@ -60,3 +63,6 @@ VERSION = 0.2.3 QMAKE_TARGET_PRODUCT = "Proxmark3GUI" QMAKE_TARGET_DESCRIPTION = "Proxmark3GUI" QMAKE_TARGET_COMPANY = "wh201906" + +RESOURCES += \ + i18n/language.qrc diff --git a/common/myeventfilter.cpp b/src/common/myeventfilter.cpp similarity index 100% rename from common/myeventfilter.cpp rename to src/common/myeventfilter.cpp diff --git a/common/myeventfilter.h b/src/common/myeventfilter.h similarity index 100% rename from common/myeventfilter.h rename to src/common/myeventfilter.h diff --git a/common/pm3process.cpp b/src/common/pm3process.cpp similarity index 100% rename from common/pm3process.cpp rename to src/common/pm3process.cpp diff --git a/common/pm3process.h b/src/common/pm3process.h similarity index 100% rename from common/pm3process.h rename to src/common/pm3process.h diff --git a/common/util.cpp b/src/common/util.cpp similarity index 97% rename from common/util.cpp rename to src/common/util.cpp index ef8c692..93657b9 100644 --- a/common/util.cpp +++ b/src/common/util.cpp @@ -106,7 +106,7 @@ void Util::setRunningState(bool st) bool Util::chooseLanguage(QSettings* guiSettings, QMainWindow* window) { // make sure the GUISettings is not in any group - QSettings* langSettings = new QSettings("lang/languages.ini", QSettings::IniFormat); + QSettings* langSettings = new QSettings(":/i18n/languages.ini", QSettings::IniFormat); QMap langMap; langSettings->setIniCodec("UTF-8"); langSettings->beginGroup("Languages"); diff --git a/common/util.h b/src/common/util.h similarity index 100% rename from common/util.h rename to src/common/util.h diff --git a/lang/en_US.qm b/src/i18n/en_US.qm similarity index 100% rename from lang/en_US.qm rename to src/i18n/en_US.qm diff --git a/lang/en_US.ts b/src/i18n/en_US.ts similarity index 100% rename from lang/en_US.ts rename to src/i18n/en_US.ts diff --git a/src/i18n/language.qrc b/src/i18n/language.qrc new file mode 100644 index 0000000..1207c10 --- /dev/null +++ b/src/i18n/language.qrc @@ -0,0 +1,7 @@ + + + en_US.qm + languages.ini + zh_CN.qm + + diff --git a/src/i18n/languages.ini b/src/i18n/languages.ini new file mode 100644 index 0000000..10c2e3f --- /dev/null +++ b/src/i18n/languages.ini @@ -0,0 +1,4 @@ +[Languages] +en_US=English +zh_CN=简体中文 +ext=Load from external file diff --git a/lang/zh_CN.qm b/src/i18n/zh_CN.qm similarity index 100% rename from lang/zh_CN.qm rename to src/i18n/zh_CN.qm diff --git a/lang/zh_CN.ts b/src/i18n/zh_CN.ts similarity index 99% rename from lang/zh_CN.ts rename to src/i18n/zh_CN.ts index ebe5e59..7b6098b 100644 --- a/lang/zh_CN.ts +++ b/src/i18n/zh_CN.ts @@ -694,7 +694,7 @@ Use this to get raw data from a tag. If the antenna voltage has a obvious drop after putting card on the antenna, it is likely that the tag is a LF tag. On Iceman/RRG repo, press the button on PM3 to stop measuring 测量低频天线谐振频率。 -如果天线电压在放置卡片后出现明显下降,则该卡片很可能是低频卡。 +如果天线电压在放置卡片后明显下降,则该卡片很可能是低频卡。 在冰人版固件下,如果需要停止测量,请按下PM3侧面的按钮 diff --git a/main.cpp b/src/main.cpp similarity index 88% rename from main.cpp rename to src/main.cpp index 7ac5c30..40b577b 100644 --- a/main.cpp +++ b/src/main.cpp @@ -1,63 +1,63 @@ -#include "ui/mainwindow.h" - -#include -#include -#include -#include -#include -#include - -int main(int argc, char *argv[]) -{ - // A trick to handle non-ascii path - // The application cannot find the plugins when the path contains non ascii characters. - // However, the plugins will be load after creating MainWindow(or QApplication?). - // QDir will handle the path correctly. - QDir* pluginDir = new QDir; - if(pluginDir->cd("plugins")) // has plugins folder - { - qputenv("QT_PLUGIN_PATH", pluginDir->absolutePath().toLocal8Bit()); - } - delete pluginDir; - - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); - QDir *langPath = new QDir(); - QApplication a(argc, argv); - MainWindow w; - - QSettings* settings = new QSettings("GUIsettings.ini", QSettings::IniFormat); - settings->setIniCodec("UTF-8"); - settings->beginGroup("lang"); - QString currLang = settings->value("language", "").toString(); - settings->endGroup(); - if(currLang == "") - { - if(Util::chooseLanguage(settings, &w)) - { - settings->beginGroup("lang"); - currLang = settings->value("language", "").toString(); - settings->endGroup(); - } - else - currLang = "en_US"; - } - currLang += ".qm"; - langPath->cd("lang"); - QTranslator* translator = new QTranslator(&w); - if(translator->load(currLang, langPath->absolutePath())) - { - a.installTranslator(translator); - } - else - { - QMessageBox::information(&w, "Error", "Can't load " + currLang + " as translation file."); - } - delete settings; - delete langPath; - w.initUI(); - w.show(); - return a.exec(); -} - - +#include "ui/mainwindow.h" + +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + // A trick to handle non-ascii path + // The application cannot find the plugins when the path contains non ascii characters. + // However, the plugins will be load after creating MainWindow(or QApplication?). + // QDir will handle the path correctly. + QDir* pluginDir = new QDir; + if(pluginDir->cd("plugins")) // has plugins folder + { + qputenv("QT_PLUGIN_PATH", pluginDir->absolutePath().toLocal8Bit()); + } + delete pluginDir; + + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); + QApplication a(argc, argv); + MainWindow w; + + QSettings* settings = new QSettings("GUIsettings.ini", QSettings::IniFormat); + settings->setIniCodec("UTF-8"); + settings->beginGroup("lang"); + QString currLang = settings->value("language", "").toString(); + settings->endGroup(); + if(currLang == "") + { + if(Util::chooseLanguage(settings, &w)) + { + settings->beginGroup("lang"); + currLang = settings->value("language", "").toString(); + settings->endGroup(); + } + else + currLang = "en_US"; + } + if(currLang == "ext") + currLang = QFileDialog::getOpenFileName(nullptr, "Select the translation file:"); + else + currLang = ":/i18n/" + currLang + ".qm"; + QTranslator* translator = new QTranslator(&w); + if(translator->load(currLang)) + { + a.installTranslator(translator); + } + else + { + QMessageBox::information(&w, "Error", "Can't load " + currLang + " as translation file."); + } + delete settings; + w.initUI(); + w.show(); + return a.exec(); +} + + diff --git a/module/lf.cpp b/src/module/lf.cpp similarity index 100% rename from module/lf.cpp rename to src/module/lf.cpp diff --git a/module/lf.h b/src/module/lf.h similarity index 100% rename from module/lf.h rename to src/module/lf.h diff --git a/module/mifare.cpp b/src/module/mifare.cpp similarity index 100% rename from module/mifare.cpp rename to src/module/mifare.cpp diff --git a/module/mifare.h b/src/module/mifare.h similarity index 100% rename from module/mifare.h rename to src/module/mifare.h diff --git a/src/module/t55xxtab.cpp b/src/module/t55xxtab.cpp new file mode 100644 index 0000000..d4247ef --- /dev/null +++ b/src/module/t55xxtab.cpp @@ -0,0 +1,14 @@ +#include "t55xxtab.h" +#include "ui_t55xxtab.h" + +T55xxTab::T55xxTab(QWidget *parent) : + QWidget(parent), + ui(new Ui::T55xxTab) +{ + ui->setupUi(this); +} + +T55xxTab::~T55xxTab() +{ + delete ui; +} diff --git a/src/module/t55xxtab.h b/src/module/t55xxtab.h new file mode 100644 index 0000000..49abd95 --- /dev/null +++ b/src/module/t55xxtab.h @@ -0,0 +1,22 @@ +#ifndef T55XXTAB_H +#define T55XXTAB_H + +#include + +namespace Ui { +class T55xxTab; +} + +class T55xxTab : public QWidget +{ + Q_OBJECT + +public: + explicit T55xxTab(QWidget *parent = nullptr); + ~T55xxTab(); + +private: + Ui::T55xxTab *ui; +}; + +#endif // T55XXTAB_H diff --git a/ui/mainwindow.cpp b/src/ui/mainwindow.cpp similarity index 100% rename from ui/mainwindow.cpp rename to src/ui/mainwindow.cpp diff --git a/ui/mainwindow.h b/src/ui/mainwindow.h similarity index 100% rename from ui/mainwindow.h rename to src/ui/mainwindow.h diff --git a/ui/mainwindow.ui b/src/ui/mainwindow.ui similarity index 99% rename from ui/mainwindow.ui rename to src/ui/mainwindow.ui index b6e380e..0138a0a 100644 --- a/ui/mainwindow.ui +++ b/src/ui/mainwindow.ui @@ -136,7 +136,7 @@ - 0 + 2 diff --git a/ui/mf_attack_hardnesteddialog.cpp b/src/ui/mf_attack_hardnesteddialog.cpp similarity index 100% rename from ui/mf_attack_hardnesteddialog.cpp rename to src/ui/mf_attack_hardnesteddialog.cpp diff --git a/ui/mf_attack_hardnesteddialog.h b/src/ui/mf_attack_hardnesteddialog.h similarity index 100% rename from ui/mf_attack_hardnesteddialog.h rename to src/ui/mf_attack_hardnesteddialog.h diff --git a/ui/mf_attack_hardnesteddialog.ui b/src/ui/mf_attack_hardnesteddialog.ui similarity index 100% rename from ui/mf_attack_hardnesteddialog.ui rename to src/ui/mf_attack_hardnesteddialog.ui diff --git a/ui/mf_sim_simdialog.cpp b/src/ui/mf_sim_simdialog.cpp similarity index 100% rename from ui/mf_sim_simdialog.cpp rename to src/ui/mf_sim_simdialog.cpp diff --git a/ui/mf_sim_simdialog.h b/src/ui/mf_sim_simdialog.h similarity index 100% rename from ui/mf_sim_simdialog.h rename to src/ui/mf_sim_simdialog.h diff --git a/ui/mf_sim_simdialog.ui b/src/ui/mf_sim_simdialog.ui similarity index 100% rename from ui/mf_sim_simdialog.ui rename to src/ui/mf_sim_simdialog.ui diff --git a/ui/mf_trailerdecoderdialog.cpp b/src/ui/mf_trailerdecoderdialog.cpp similarity index 100% rename from ui/mf_trailerdecoderdialog.cpp rename to src/ui/mf_trailerdecoderdialog.cpp diff --git a/ui/mf_trailerdecoderdialog.h b/src/ui/mf_trailerdecoderdialog.h similarity index 100% rename from ui/mf_trailerdecoderdialog.h rename to src/ui/mf_trailerdecoderdialog.h diff --git a/ui/mf_trailerdecoderdialog.ui b/src/ui/mf_trailerdecoderdialog.ui similarity index 100% rename from ui/mf_trailerdecoderdialog.ui rename to src/ui/mf_trailerdecoderdialog.ui diff --git a/ui/mf_uid_parameterdialog.cpp b/src/ui/mf_uid_parameterdialog.cpp similarity index 100% rename from ui/mf_uid_parameterdialog.cpp rename to src/ui/mf_uid_parameterdialog.cpp diff --git a/ui/mf_uid_parameterdialog.h b/src/ui/mf_uid_parameterdialog.h similarity index 100% rename from ui/mf_uid_parameterdialog.h rename to src/ui/mf_uid_parameterdialog.h diff --git a/ui/mf_uid_parameterdialog.ui b/src/ui/mf_uid_parameterdialog.ui similarity index 100% rename from ui/mf_uid_parameterdialog.ui rename to src/ui/mf_uid_parameterdialog.ui diff --git a/src/ui/t55xxtab.ui b/src/ui/t55xxtab.ui new file mode 100644 index 0000000..e770b68 --- /dev/null +++ b/src/ui/t55xxtab.ui @@ -0,0 +1,21 @@ + + + + + T55xxTab + + + + 0 + 0 + 400 + 300 + + + + Form + + + + +