Selaa lähdekoodia

Generate license code through hard disk partition identification code

dongjunhong 8 kuukautta sitten
vanhempi
commit
23b87c5293
1 muutettua tiedostoa jossa 20 lisäystä ja 8 poistoa
  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)