Quellcode durchsuchen

Generate license code through hard disk partition identification code

dongjunhong vor 8 Monaten
Ursprung
Commit
23b87c5293
1 geänderte Dateien mit 20 neuen und 8 gelöschten Zeilen
  1. 20 8
      src/common/common/license_local/adclicense.cpp

+ 20 - 8
src/common/common/license_local/adclicense.cpp

@@ -77,16 +77,28 @@ QString ADCLicenseServ::readLicense()
     QString filePath = "./license";
 
     QFile file(filePath);
-    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
-       qDebug() << "Failed to open file.";
-       return "1";
+    if (!QFile::exists(filePath)){
+        if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+           QTextStream out(&file);
+           out << " " << endl;
+           file.close();
+           qDebug() << "File created and written successfully.";
+           return "0";
+        }
+    }
+    else{
+        if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+           qDebug() << "Failed to open file.";
+           return "1";
+        }
+        QTextStream in(&file);
+
+        QString fileContent = in.readAll();
+        fileContent=fileContent.remove(QChar('\n'));
+        file.close();
+        return fileContent;
     }
-    QTextStream in(&file);
 
-    QString fileContent = in.readAll();
-    fileContent=fileContent.remove(QChar('\n'));
-    file.close();
-    return fileContent;
 }
 
 void ADCLicenseServ::creatMachFile(const QString &str)