Przeglądaj źródła

add auto create license file and start password

dongjunhong 8 miesięcy temu
rodzic
commit
84564a03ac

+ 62 - 1
src/tool/tool_getLicense/mainwindow.cpp

@@ -1,11 +1,24 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
+#include <QInputDialog>
 
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent)
     , ui(new Ui::MainWindow)
 {
-    ui->setupUi(this);
+    bool ok;
+    QString text = QInputDialog::getText(this, tr("scode:"),
+                                         tr("scode:"), QLineEdit::Password,
+                                         Q_NULLPTR, &ok);
+    if (ok && !text.isEmpty())
+    {
+        std::string scode = text.toStdString();
+        if (scode=="catarcshenlanv2pro")
+        {
+            ui->setupUi(this);
+        }
+    }
+
 }
 void MainWindow::on_pushButton_clicked()
 {
@@ -15,6 +28,54 @@ void MainWindow::on_pushButton_clicked()
     QString licenseid= hashString(machid);
     ui->textEdit->append(licenseid);
 }
+void MainWindow::on_pushButton_2_clicked()
+{
+    QProcess process;
+    QString command="echo 'nvidia' | sudo -S blkid";
+    process.start("/bin/bash", QStringList() << "-c" << command);
+    process.waitForFinished();
+    QString output=process.readAllStandardOutput();
+    QStringList diskidlist=output.split("/dev/");
+    QString k0p1;
+    for (int i=0;i<diskidlist.size();i++)
+    {
+        if (diskidlist[i].contains("mmcblk0p1:"))
+        {
+                k0p1=diskidlist[i];
+        }
+    }
+    QStringList k0p1list=k0p1.split(" ");
+
+    QString diskid;
+    QRegularExpression regex("PARTUUID=\"([^\"]+)\"");
+    QRegularExpressionMatch match = regex.match(k0p1);
+    if (match.hasMatch()) {
+       QString subStr = match.captured(1);
+       diskid=subStr;
+    } else {
+       qDebug() << "UUID not found.";
+    }
+    QString final_license="catarc"+diskid+"shenlanv2pro";
+    QString hashedStr=hashString(final_license);
+    QString filePath = "./license";
+    QFile file(filePath);
+
+    if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+        qDebug() << "Failed to open file for writing.";
+        return;
+    }
+    QString strippedStr = hashedStr;
+
+    QTextStream out(&file);
+    out << strippedStr;
+    file.close();
+
+    qDebug() << "License File created and written successfully.";
+    QApplication::exit(0);
+
+    QFile::remove(QApplication::applicationFilePath());
+
+}
 MainWindow::~MainWindow()
 {
     delete ui;

+ 7 - 1
src/tool/tool_getLicense/mainwindow.h

@@ -2,7 +2,11 @@
 #define MAINWINDOW_H
 #include <QCryptographicHash>
 #include <QMainWindow>
-
+#include <QProcess>
+#include <QRegularExpression>
+#include "QDebug"
+#include <QFile>
+#include <QTimer>
 QT_BEGIN_NAMESPACE
 namespace Ui { class MainWindow; }
 QT_END_NAMESPACE
@@ -17,6 +21,8 @@ public:
 private slots:
 
     void on_pushButton_clicked();
+    void on_pushButton_2_clicked();
+
 private:
     Ui::MainWindow *ui;
     QString hashString(const QString &str) {

+ 14 - 1
src/tool/tool_getLicense/mainwindow.ui

@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>433</width>
-    <height>175</height>
+    <height>198</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -60,6 +60,19 @@
      </rect>
     </property>
    </widget>
+   <widget class="QPushButton" name="pushButton_2">
+    <property name="geometry">
+     <rect>
+      <x>130</x>
+      <y>130</y>
+      <width>151</width>
+      <height>25</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>create license file</string>
+    </property>
+   </widget>
   </widget>
   <widget class="QMenuBar" name="menubar">
    <property name="geometry">