V0.1
This commit is contained in:
parent
6e2a0e6e3c
commit
d0a368a17a
@ -1,2 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module classpath="CMake" type="CPP_MODULE" version="4" />
|
||||
<module classpath="CIDR" type="CPP_MODULE" version="4" />
|
||||
@ -21,7 +21,7 @@
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatTooManyArgs/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCStyleCast/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCVQualifierCanNotBeAppliedToReference/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassCanBeFinal/@EntryIndexedValue" value="HINT" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassCanBeFinal/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassIsIncomplete/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeedsConstructorBecauseOfUninitializedMember/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
@ -60,6 +60,7 @@
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultInitializationWithNoUserConstructor/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultIsUsedAsIdentifier/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultedSpecialMemberFunctionIsImplicitlyDeleted/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefinitionsOrder/@EntryIndexedValue" value="HINT" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeletingVoidPointer/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDependentTemplateWithoutTemplateKeyword/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDependentTypeWithoutTypenameKeyword/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
@ -121,6 +122,7 @@
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMismatchedClassTags/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMissingIncludeGuard/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMissingKeywordThrow/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppModulePartitionWithSeveralPartitionUnits/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtAddressOfClassRValue/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtBindingRValueToLvalueReference/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtCopyElisionInCopyInitDeclarator/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
|
||||
@ -24,10 +24,11 @@ find_package(Qt5 COMPONENTS Widgets REQUIRED)
|
||||
|
||||
if(ANDROID)
|
||||
add_library(USB_Config_Vendor SHARED
|
||||
main.cpp
|
||||
widget.cpp
|
||||
widget.h
|
||||
widget.ui
|
||||
main.cpp
|
||||
widget.cpp
|
||||
widget.h
|
||||
widget.ui
|
||||
Resources/png.qrc
|
||||
)
|
||||
else()
|
||||
add_executable(USB_Config_Vendor
|
||||
@ -36,6 +37,7 @@ else()
|
||||
widget.cpp
|
||||
widget.h
|
||||
widget.ui
|
||||
Resources/png.qrc
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
BIN
Resources/media/test_display.png
Normal file
BIN
Resources/media/test_display.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.0 KiB |
BIN
Resources/media/test_no_display.png
Normal file
BIN
Resources/media/test_no_display.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.7 KiB |
66
widget.cpp
66
widget.cpp
@ -5,6 +5,32 @@
|
||||
Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget){
|
||||
AES_USB::init();
|
||||
ui->setupUi(this);
|
||||
checkBox_R_PIN = new QCheckBox(ui->R_PIN);
|
||||
checkBox_R_PIN->setStyleSheet("QCheckBox {spacing: 5px;border: none;background-color: transparent;}"
|
||||
"QCheckBox::indicator {width: 20px;height: 20px;border: none;image: url(:/file/media/test_no_display.png);}"
|
||||
"QCheckBox::indicator:checked {image: url(:/file/media/test_display.png);}");
|
||||
checkBox_R_PIN->setGeometry(ui->R_PIN->pos().x() + 460,ui->R_PIN->pos().y() + 8,20,20);
|
||||
connect(checkBox_R_PIN, &QPushButton::clicked,[this]() {
|
||||
if (checkBox_R_PIN->isChecked()) {
|
||||
ui->R_PIN->setEchoMode(QLineEdit::Normal);
|
||||
}
|
||||
else {
|
||||
ui->R_PIN->setEchoMode(QLineEdit::Password);
|
||||
}
|
||||
});
|
||||
checkBox_S_PIN = new QCheckBox(ui->S_PIN);
|
||||
checkBox_S_PIN->setStyleSheet("QCheckBox {spacing: 5px;border: none;background-color: transparent;}"
|
||||
"QCheckBox::indicator {width: 20px;height: 20px;border: none;image: url(:/file/media/test_no_display.png);}"
|
||||
"QCheckBox::indicator:checked {image: url(:/file/media/test_display.png);}");
|
||||
checkBox_S_PIN->setGeometry(ui->S_PIN->pos().x() + 280,ui->S_PIN->pos().y() + 8,20,20);
|
||||
connect(checkBox_S_PIN, &QPushButton::clicked,[this]() {
|
||||
if (checkBox_S_PIN->isChecked()) {
|
||||
ui->S_PIN->setEchoMode(QLineEdit::Normal);
|
||||
}
|
||||
else {
|
||||
ui->S_PIN->setEchoMode(QLineEdit::Password);
|
||||
}
|
||||
});
|
||||
this->setWindowFlags(windowFlags()& ~Qt::WindowMaximizeButtonHint);
|
||||
CTL::Thread::addTask([this]() {
|
||||
CTL::Thread::SleepMS(1000);
|
||||
@ -26,6 +52,8 @@ Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget){
|
||||
Widget::~Widget(){
|
||||
loop_running = false;
|
||||
AES_USB::release();
|
||||
delete checkBox_R_PIN;
|
||||
delete checkBox_S_PIN;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@ -55,7 +83,11 @@ bool Widget::readInit() {
|
||||
ui->S_PID->setText(PID.c_str());
|
||||
ui->S_VID->setText(VID.c_str());
|
||||
ui->R_PIN->clear();
|
||||
ui->R_PIN->setText((char*)key.PIN);
|
||||
char PIN[21] = {0};
|
||||
std::memcpy(PIN, key.PIN, sizeof key.PIN);
|
||||
PIN[20] = '\0';
|
||||
const QString str = QString::fromLocal8Bit(PIN);
|
||||
ui->R_PIN->setText(str);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
@ -84,7 +116,11 @@ void Widget::readClick() {
|
||||
ui->S_PID->setText(PID.c_str());
|
||||
ui->S_VID->setText(VID.c_str());
|
||||
ui->R_PIN->clear();
|
||||
ui->R_PIN->setText((char*)key.PIN);
|
||||
char PIN[21] = {0};
|
||||
std::memcpy(PIN, key.PIN, sizeof key.PIN);
|
||||
PIN[20] = '\0';
|
||||
const QString str = QString::fromLocal8Bit(PIN);
|
||||
ui->R_PIN->setText(str);
|
||||
});
|
||||
PrintInfo("加密狗配置信息读取完成");
|
||||
}
|
||||
@ -116,10 +152,11 @@ void Widget::LoopRunning() {
|
||||
ui->R_PIN->setText(str.c_str());
|
||||
});
|
||||
CTL::Thread::SleepMS(1000);
|
||||
if (writeInit()) {
|
||||
const int r = writeInit();
|
||||
if (r == 1) {
|
||||
PrintInfo("设置加密狗初始化完成");
|
||||
}
|
||||
else {
|
||||
else if (r == 0){
|
||||
PrintInfo("设置加密狗初始化失败");
|
||||
}
|
||||
PrintInfo("请拔出加密狗...");
|
||||
@ -151,28 +188,32 @@ void Widget::LoopRunning() {
|
||||
PrintInfo("循环初始化加密狗结束");
|
||||
}
|
||||
|
||||
bool Widget::writeInit() {
|
||||
int Widget::writeInit() {
|
||||
CCUniqueLock lock(loop_mutex);
|
||||
if (!ui->B_VID_PID->isChecked() && !ui->B_Data->isChecked() && !ui->B_PIN->isChecked()) {
|
||||
PrintInfo("错误: 请至少选择一个设置项");
|
||||
return -1;
|
||||
}
|
||||
uint16_t PID = hexStringToUint16(ui->R_PID->text().toStdString());
|
||||
uint16_t VID = hexStringToUint16(ui->R_VID->text().toStdString());
|
||||
int ret = aes_usb.open(VID, PID);
|
||||
aes_usb.setUserPIN(ui->R_PIN->text().toStdString());
|
||||
if (ret != 1) {
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
if (ui->B_VID_PID->isChecked() && !ui->S_PID->text().isEmpty() && !ui->S_VID->text().isEmpty()) {
|
||||
PID = hexStringToUint16(ui->S_PID->text().toStdString());
|
||||
VID = hexStringToUint16(ui->S_VID->text().toStdString());
|
||||
ret = aes_usb.set_vid_pid(VID, PID);
|
||||
if (ret < 0) {
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (ui->B_Data->isChecked() && !ui->S_Data->text().isEmpty()) {
|
||||
const CTL::String data = ui->S_Data->text().toStdString();
|
||||
ret = aes_usb.write((uint8_t*)data.c_str(),data.length());
|
||||
if (ret < 0) {
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
aes_usb.close();
|
||||
@ -187,17 +228,18 @@ bool Widget::writeInit() {
|
||||
std::memcpy(key.PIN, pin.c_str(), pin.length() > 20 ? 20 : pin.length());
|
||||
ret = AES_USB::writeID_Pin(&key);
|
||||
if (ret != 1) {
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Widget::writeClick() {
|
||||
if (writeInit()) {
|
||||
const int r = writeInit();
|
||||
if (r == 1) {
|
||||
PrintInfo("设置加密狗完成");
|
||||
}
|
||||
else {
|
||||
else if (r == 0){
|
||||
PrintInfo("设置加密狗失败");
|
||||
}
|
||||
}
|
||||
|
||||
7
widget.h
7
widget.h
@ -1,6 +1,7 @@
|
||||
#ifndef WIDGET_H
|
||||
#define WIDGET_H
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QWidget>
|
||||
#include "AES_USB.h"
|
||||
#include "CCString.h"
|
||||
@ -17,17 +18,19 @@ class Widget : public QWidget
|
||||
std::mutex loop_mutex;
|
||||
public:
|
||||
Widget(QWidget *parent = nullptr);
|
||||
~Widget();
|
||||
~Widget() override;
|
||||
void PrintInfo(const CTL::String& info);
|
||||
bool readInit();
|
||||
void readClick();
|
||||
void LoopRunning();
|
||||
bool writeInit();
|
||||
int writeInit();
|
||||
void writeClick();
|
||||
static uint16_t hexStringToUint16(const std::string& hexStr);
|
||||
bool readData(uint8_t* data, int length);
|
||||
|
||||
private:
|
||||
Ui::Widget *ui;
|
||||
QCheckBox *checkBox_R_PIN = nullptr;
|
||||
QCheckBox *checkBox_S_PIN = nullptr;
|
||||
};
|
||||
#endif // WIDGET_H
|
||||
|
||||
Loading…
Reference in New Issue
Block a user