dialog.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include "dialog.h"
  2. #include "QtCore/qdir.h"
  3. #include "QtCore/qjsonarray.h"
  4. #include "ui_dialog.h"
  5. #include "QMessageBox"
  6. #include <QPushButton>
  7. Dialog::Dialog(QWidget *parent) :
  8. QDialog(parent),
  9. ui(new Ui::Dialog)
  10. {
  11. ui->setupUi(this);
  12. }
  13. Dialog::~Dialog()
  14. {
  15. delete ui;
  16. }
  17. void Dialog::addDataToJsonFile(const QString& path, const QJsonObject& newData) {
  18. QString config_path=path+"/config.json";
  19. QString Hotupdate_path=path+"/Hotupdate.json";
  20. QFile file(config_path);
  21. QJsonDocument jsonDoc(newData);
  22. if (file.open(QIODevice::WriteOnly)) {
  23. file.write(jsonDoc.toJson());
  24. file.close();
  25. qDebug() << "JSON file created successfully.";
  26. } else {
  27. qDebug() << "Failed to create JSON file.";
  28. }
  29. //创建hot
  30. QJsonArray childrenArray;
  31. // 创建包含 "children" 数组的 JSON 对象
  32. QJsonObject jsonObject;
  33. jsonObject["children"] = childrenArray;
  34. QFile file1(config_path);
  35. QJsonDocument jsonDoc1(jsonObject);
  36. if (file1.open(QIODevice::WriteOnly)) {
  37. file1.write(jsonDoc1.toJson());
  38. file1.close();
  39. qDebug() << "JSON file created successfully.";
  40. } else {
  41. qDebug() << "Failed to create JSON file.";
  42. }
  43. }
  44. void Dialog::on_pushButton_clicked()
  45. {
  46. this->close();
  47. }
  48. void Dialog::on_pushButton_2_clicked()
  49. {
  50. // 执行相应的操作
  51. QString dirPath = "/users/lal/documents/RedInterstitialData/HotUpdate2/";
  52. QJsonObject newData;
  53. QString pro_name=ui->pro_name->toPlainText();
  54. QString app_id=ui->app_id->toPlainText();
  55. QString config_server_pre=ui->config_server_pre->toPlainText();
  56. QString file_serverpre=ui->file_serverpre->toPlainText();
  57. // if(pro_name.isEmpty())
  58. // { qDebug()<<"1111";
  59. // ui->pro_name->setStyleSheet("QLineEdit{border:2px solid rgb(255, 0, 0);}");
  60. // QString str = QString::fromLocal8Bit("Must Not Null");
  61. // ui->pro_name->setToolTip(str);
  62. // return;
  63. // }
  64. if(pro_name.isEmpty()||app_id.isEmpty()||config_server_pre.isEmpty()||file_serverpre.isEmpty())
  65. {
  66. QMessageBox messageBox;
  67. messageBox.setModal(false);
  68. messageBox.setText("请将信息填写完整");
  69. messageBox.exec();
  70. return;
  71. }
  72. QDir dir;
  73. if (!dir.mkpath(dirPath+pro_name)) {
  74. qDebug() << "Failed to create folder";
  75. }
  76. QString filePath = dirPath+pro_name;
  77. newData.insert("pro_name", pro_name);
  78. newData.insert("app_id", app_id);
  79. newData.insert("config_server_pre", config_server_pre);
  80. newData.insert("file_serverpre", file_serverpre);
  81. addDataToJsonFile(filePath,newData);
  82. QJsonObject rootObject;
  83. QJsonArray childrenArray;
  84. QJsonObject childObject;
  85. rootObject["children"] = childrenArray;
  86. QFile file(filePath+"/hotupdate.json");
  87. if (file.open(QIODevice::WriteOnly)) {
  88. QJsonDocument jsonDocument(rootObject);
  89. file.write(jsonDocument.toJson());
  90. file.close();
  91. }
  92. emit _mySignal();
  93. this->close();
  94. }