-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathclass_logfile.cpp
More file actions
93 lines (67 loc) · 2.64 KB
/
class_logfile.cpp
File metadata and controls
93 lines (67 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "class_logfile.h"
Class_LogFile::Class_LogFile(QObject *parent) : QObject(parent)
{
appPath = QDir::currentPath();
//qDebug()<<" appPath Path: "<<appPath;
logDir.setPath(QString(appPath+"/Log/"));
if(!logDir.exists()) logDir.mkdir(QString(appPath+"/Log/"));
filePath = QString(QString(appPath+"/Log/MotoTool_MTK_LogFile_"+QDate::currentDate().toString("dd:MM:yyyy").replace(":","_")+".txt"));
//()<<" Log File Path: "<<filePath;
}
void Class_LogFile::rx_initialFileFolders()
{
//qDebug()<<"rx_initialFileFolders ";
if(!QFile::exists(filePath)){
//qDebug()<<"rx_initialFileFolders ";
logFile = new QFile(filePath);
if(logFile->open(QIODevice::WriteOnly))
{
// qDebug()<<" New File is generated ";
QByteArray baa("Welcom to MOTO TOOL MTK Software \n +++++++++++++++++++++++++++++++++++++++++++ \n");
logFile->write(baa);
logFile->close();
}
}
else
{
logFile = new QFile(filePath);
}
}
void Class_LogFile::writeToLog(QByteArray ba)
{
if(logFile->open(QIODevice::Append))
{
QByteArray info("System Time: ");
info.append(QTime::currentTime().toString("HH:mm:ss").toUtf8());
info.append("\n");
logFile->write(info);
logFile->write(ba);
logFile->write("\n========================================================\n\n");
logFile->close();
}
QByteArray postdata;// = data.toJson();
/*
postdata.append(QString("OperationId="+ GlobalVars::operationID+"&").toUtf8());
postdata.append(QString("Log="+ ba).toUtf8());
qDebug()<<" \n\n ByteArray:"<<postdata<<"\n\n"; */
QJsonObject obj;
obj["OperationId"] = GlobalVars::operationID;
obj["Log"] = QString(ba);
QJsonDocument doc(obj);
postdata = doc.toJson();
qDebug()<<" \n\n Logs to server ByteArray:"<<postdata<<" Base64:"<<postdata.toBase64()<<" ";
QEventLoop loop;
QNetworkAccessManager nam;
QNetworkRequest req;
req.setUrl(QUrl(GlobalVars::api_LogQString));
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
req.setRawHeader(QByteArray("Authorization"), GlobalVars::authorizedToken.toUtf8());
QNetworkReply *reply = nam.post(req, postdata.toBase64());
connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
//qDebug()<<" Reply:: "<<reply->readAll();
QJsonDocument document = QJsonDocument::fromJson(QByteArray::fromBase64(reply->readAll()));
QJsonObject buffer = document.object();
qDebug()<<"Log Histor reply from Server:: "<<buffer;
qDebug()<<"\n\n ";
}