123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #include "dialog.h"
- #include "QtCore/qdir.h"
- #include "QtCore/qjsonarray.h"
- #include "ui_dialog.h"
- #include "QMessageBox"
- #include <QPushButton>
- Dialog::Dialog(QWidget *parent) :
- QDialog(parent),
- ui(new Ui::Dialog)
- {
- ui->setupUi(this);
- }
- Dialog::~Dialog()
- {
- delete ui;
- }
- void Dialog::addDataToJsonFile(const QString& path, const QJsonObject& newData) {
- QString config_path=path+"/config.json";
- QString Hotupdate_path=path+"/Hotupdate.json";
- QFile file(config_path);
- QJsonDocument jsonDoc(newData);
- if (file.open(QIODevice::WriteOnly)) {
- file.write(jsonDoc.toJson());
- file.close();
- qDebug() << "JSON file created successfully.";
- } else {
- qDebug() << "Failed to create JSON file.";
- }
- //创建hot
- QJsonArray childrenArray;
- // 创建包含 "children" 数组的 JSON 对象
- QJsonObject jsonObject;
- jsonObject["children"] = childrenArray;
- QFile file1(config_path);
- QJsonDocument jsonDoc1(jsonObject);
- if (file1.open(QIODevice::WriteOnly)) {
- file1.write(jsonDoc1.toJson());
- file1.close();
- qDebug() << "JSON file created successfully.";
- } else {
- qDebug() << "Failed to create JSON file.";
- }
- }
- void Dialog::on_pushButton_clicked()
- {
- this->close();
- }
- void Dialog::on_pushButton_2_clicked()
- {
- // 执行相应的操作
- QString dirPath = "/users/lal/documents/RedInterstitialData/HotUpdate2/";
- QJsonObject newData;
- QString pro_name=ui->pro_name->toPlainText();
- QString app_id=ui->app_id->toPlainText();
- QString config_server_pre=ui->config_server_pre->toPlainText();
- QString file_serverpre=ui->file_serverpre->toPlainText();
- // if(pro_name.isEmpty())
- // { qDebug()<<"1111";
- // ui->pro_name->setStyleSheet("QLineEdit{border:2px solid rgb(255, 0, 0);}");
- // QString str = QString::fromLocal8Bit("Must Not Null");
- // ui->pro_name->setToolTip(str);
- // return;
- // }
- if(pro_name.isEmpty()||app_id.isEmpty()||config_server_pre.isEmpty()||file_serverpre.isEmpty())
- {
- QMessageBox messageBox;
- messageBox.setModal(false);
- messageBox.setText("请将信息填写完整");
- messageBox.exec();
- return;
- }
- QDir dir;
- if (!dir.mkpath(dirPath+pro_name)) {
- qDebug() << "Failed to create folder";
- }
- QString filePath = dirPath+pro_name;
- newData.insert("pro_name", pro_name);
- newData.insert("app_id", app_id);
- newData.insert("config_server_pre", config_server_pre);
- newData.insert("file_serverpre", file_serverpre);
- addDataToJsonFile(filePath,newData);
- QJsonObject rootObject;
- QJsonArray childrenArray;
- QJsonObject childObject;
- rootObject["children"] = childrenArray;
- QFile file(filePath+"/hotupdate.json");
- if (file.open(QIODevice::WriteOnly)) {
- QJsonDocument jsonDocument(rootObject);
- file.write(jsonDocument.toJson());
- file.close();
- }
- emit _mySignal();
- this->close();
- }
|