-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
158 lines (140 loc) · 4.47 KB
/
main.cpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <QCoreApplication>
#include <QTextStream>
#include <iostream>
#include "stdlib.h"
#include "QThread"
#include "QtCore"
#include "QCLoader.h"
#include "QtSerialPort/QSerialPort"
#include "QtSerialPort/QSerialPortInfo"
using namespace std;
//定义在头文件内会提示未定义函数,很奇怪
bool ConnectDevice(DiagInfo &);
void SetLibraryMode();
bool ConnectPort(DiagInfo &);
QString ReadIMEI(DiagInfo &,int);
bool SendSPC(DiagInfo &,QString SPC);
bool SetSIMDual(DiagInfo &,bool dual);
bool BackupQCN(DiagInfo &);
bool RestoreQCN(DiagInfo &);
bool SyncEFS(DiagInfo &);
bool RebootNormal(DiagInfo &);
void Disconnect();
void EnableQcnNvItemCallBacks(DiagInfo &info);
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
//添加命令行参数
QCoreApplication::setApplicationName("QCNTool");
QCoreApplication::setApplicationVersion("1.5.0");
QCommandLineParser parser;
parser.setApplicationDescription("a tool to download/flash qcn from/to your phone");
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption writeqcn(QStringList() << "w" << "write",
"write qcn to your phone");
QCommandLineOption readqcn(QStringList() << "r" << "read",
"backup qcn from your phone");
QCommandLineOption targetport(QStringList() << "p" << "port",
"Set 901D port num",
"int");
QCommandLineOption targetpath(QStringList() << "f" << "file",
"qcn file path",
"string");
parser.addOption(targetport);
parser.addOption(targetpath);
parser.addOption(writeqcn);
parser.addOption(readqcn);
parser.process(a);
int cport= parser.value(targetport).toInt();
QString cpath = parser.value(targetpath);
DiagInfo info;
info.portnum = cport;
if((!parser.isSet(writeqcn))&&(!parser.isSet(readqcn)))
{
std::cout << "Invalid function quest";
QLIB_DisconnectServer(info.hndl);
return 1;
}
if(parser.isSet(writeqcn)&&parser.isSet(readqcn))
{
std::cout << "Invalid function quest";
QLIB_DisconnectServer(info.hndl);
return 1;
}
std::cout << "a small free tool to flash/backup qcn into/from your phone\n"
<< "Modified by Zi_Cai\n";
if (!ConnectDevice(info))
{
QLIB_DisconnectServer(info.hndl);
return 1;
}
if (parser.isSet(writeqcn))
{
if (cpath == "")
{
std::cout << "please input file path";
QLIB_DisconnectServer(info.hndl);
return 1;
}
QFileInfo fi(cpath);
if (!fi.isFile()){
std::cout << "invalid file input";
return 1;
}
std::cout << "\nLoading Data File...";
int get1 = -1;
int get2 = -1;
if (!QLIB_NV_LoadNVsFromQCN(info.hndl,cpath.toLocal8Bit().data(),&get1,&get2))
{
std::cout << " error";
QLIB_DisconnectServer(info.hndl);
return 1;
}else{
std::cout << " OK";
std::cout << "\nWriting Data File to phone...";
int res2;
if (!QLIB_NV_WriteNVsToMobile(info.hndl,&res2))
{
std::cout << " error";
QLIB_DisconnectServer(info.hndl);
return 1;
}else{
std::cout << " OK";
}
}
}
if (parser.isSet(readqcn))
{
QString path;
if (cpath == "")
{
cpath = QDir().currentPath();
QDateTime dteNow = QDateTime::currentDateTime();
QString fnl = dteNow.toString("smh_d_M_yyyy").replace(" ","_").replace(":","_");
path = QDir::cleanPath(cpath +QDir::separator()+ "QCN_"+fnl+".qcn");
}
else
{
std::cout <<"file path should be null";
return 1;
}
int renas2;
std::cout << "\nReading QCN from phone...";
if (!QLIB_BackupNVFromMobileToQCN(info.hndl,path.toLocal8Bit().data(),&renas2))
{
std::cout <<" error";
QLIB_DisconnectServer(info.hndl);
return 1;
}
else
{
std::cout <<" OK";
std::cout <<"\nBackup file : ";
std::cout <<path.toStdString().data();
std::cout <<"\n";
}
}
QLIB_DisconnectServer(info.hndl);
return 0;
}