#include #include #include #include #include #include bool gVideoCompress = true; bool gVideoTranscoding = true; bool gTextAntialiasing = false; bool gShowLoraScreen = false; bool gWidthSplit = false; QString replyErr(QNetworkReply *reply) { reply->deleteLater(); auto error = reply->error(); if(error != QNetworkReply::NoError) { auto errStr = reply->errorString(); if(error!=QNetworkReply::InternalServerError || ! errStr.endsWith("replied: Unknown")) { if(error==QNetworkReply::OperationCanceledError) { error = QNetworkReply::TimeoutError; errStr = QCoreApplication::translate("Def","Connection Timeout"); } return QString(QMetaEnum::fromType().valueToKey(error))+" ("+QString::number(error)+") "+errStr; } } auto status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if(status != 200) return QString::number(status)+" "+reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString(); return ""; } QString checkReply(QNetworkReply *reply, QJsonDocument *outJson) { auto err = replyErr(reply); if(! err.isEmpty()) { auto data = reply->readAll(); if(! data.isEmpty()) err = err+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data; return err; } if(outJson) { auto data = reply->readAll(); QJsonParseError jsonErr; *outJson = QJsonDocument::fromJson(data, &jsonErr); if(jsonErr.error != QJsonParseError::NoError) return "Json error: "+jsonErr.errorString()+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data; } return ""; } QString checkReplyForJson(QNetworkReply *reply, QJsonDocument *outJson, QByteArray *outData) { auto err = replyErr(reply); auto data = reply->readAll(); if(outData) *outData = data; if(! err.isEmpty()) { if(! data.isEmpty()) err = err+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data; return err; } QJsonParseError jsonErr; QJsonDocument json = QJsonDocument::fromJson(data, &jsonErr); if(jsonErr.error != QJsonParseError::NoError) return "Json error: "+jsonErr.errorString()+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data; if(! json["success"].toBool()) return QCoreApplication::translate("Def","Fail")+". "+QCoreApplication::translate("Def","Device replied")+": "+data; if(outJson) outJson->swap(json); return ""; } QString getRandomString(int len) { static const char table[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; static const int tableSize = sizeof(table) - 1; QString str; str.resize(len); for(int i=0; ihttpPost(strUrl, QJsonDocument(json).toJson(QJsonDocument::Compact)); } bool copyDir(const QString &source, const QString &destination, bool override) { QDir directory(source); if (!directory.exists()) { return false; } QString srcPath = QDir::toNativeSeparators(source); if (!srcPath.endsWith(QDir::separator())) srcPath += QDir::separator(); QString dstPath = QDir::toNativeSeparators(destination); if (!dstPath.endsWith(QDir::separator())) dstPath += QDir::separator(); bool error = false; QStringList fileNames = directory.entryList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden); for (QStringList::size_type i=0; i != fileNames.size(); ++i) { QString fileName = fileNames.at(i); QString srcFilePath = srcPath + fileName; QString dstFilePath = dstPath + fileName; QFileInfo fileInfo(srcFilePath); if (fileInfo.isFile() || fileInfo.isSymLink()) { if (override) { QFile::setPermissions(dstFilePath, QFile::WriteOwner); } QFile::copy(srcFilePath, dstFilePath); } else if (fileInfo.isDir()) { QDir dstDir(dstFilePath); dstDir.mkpath(dstFilePath); if (!copyDir(srcFilePath, dstFilePath, override)) { error = true; } } } return !error; } unsigned char GetCheckCodeIn8(unsigned char * pBuffer,unsigned int uiSize) { unsigned int i=0; unsigned char ucCheckCode=0; for (i=0;i