#include "mycfg.h" #include #include #include #include #include #include "QDebug" #include "base/file.h" #include #include // 配置路径 #define CFG_PATH QString("/home/root/config/") //#define CFG_PATH qApp->applicationDirPath()+"/config/" // 配置文件 #define CFG_FILE_NAME CFG_PATH+"cfg.json" // 自启动路径 #define AUTO_START_PATH "/usr/local/QDesktop-fb" // 方案配置文件关键字段,用于生成默认方案文件名 #define CHECK_CFG_FILE_KEY "checker_ye_cfg" // mcu程序关键字段,用于生成默认程序文件名 #define MCU_APP_FILE_KEY "JQChecker" // shell脚本关键字段,用于运行shell脚本 #define SHELL_FILE_KEY "checker_app_pre" // 程序信息 #define APP_INFO_FILE "info.json" // 判断脚本 #define APP_JUDGE_FILE "judge.lua" // 软件版本 #define SOFT_VERSION "unknown" #define HARD_VERSION "unknown" QList jarray_to_intlist(QJsonValue j){ QJsonArray arr; if(j.isArray()){ arr= j.toArray(); } QList intl; for(int i=0;i jarray_to_strlist(QJsonValue j){ QJsonArray arr; if(j.isArray()){ arr= j.toArray(); } QList strl; for(int i=0;i intl) { QJsonArray a; for(int i=0;i privates; }; mycfg::mycfg() { } void mycfg::to_class(mystring str) { QJsonParseError err; QJsonDocument doc = QJsonDocument::fromJson(str.toUtf8(),&err); QJsonObject j; if(err.error != QJsonParseError::NoError) { qWarning()<<"parse json failed:"<applicationFilePath()); QByteArray d; d=app.get_file(APP_INFO_FILE); QJsonParseError err; QJsonDocument doc = QJsonDocument::fromJson(d,&err); if(err.error != QJsonParseError::NoError) { qWarning()<<"parse json failed:"< list_files=app.get_file_list(); for(int i=0;iapplicationFilePath()); if(file_dst.exists()) { if(file_dst.open(QIODevice::ReadOnly)&&file_src.open(QIODevice::ReadOnly)) { QByteArray c1=file_src.readAll(); QByteArray c2=file_dst.readAll(); QByteArray md5_1=QCryptographicHash::hash(c1, QCryptographicHash::Md5); QByteArray md5_2=QCryptographicHash::hash(c2, QCryptographicHash::Md5); if(md5_1!=md5_2) { if(file_dst.remove()!=true) qWarning()<<"remove file "< data) { production_info.clear(); for(int i=0;i