forked from aeagean/DeployQt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVersionModel.cpp
163 lines (132 loc) · 4.51 KB
/
VersionModel.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
156
157
158
159
160
161
162
163
/**********************************************************
Author: Qt君
微信公众号: Qt君(首发)
QQ群: 732271126
Email: 2088201923@qq.com
LICENSE: MIT
**********************************************************/
#include "VersionModel.h"
#include <QDir>
#include <QProcess>
#include <QtGlobal>
#include <QDebug>
static const QString PROGRAMS_PATH = QDir::homePath() + "/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/";
static QString qtEnvPath(const QString &envPath)
{
QString result;
QFile file(envPath + "/qtenv2.bat");
if (!file.open(QIODevice::ReadOnly)) {
qDebug()<<"[Info] "<<"Qt Env Path: "<<result;
return result;
}
while (!file.atEnd()) {
QString line = QString(file.readLine());
int index = line.indexOf("set PATH=");
if (index != -1) {
result = line.mid(9).remove("%PATH%").trimmed();
}
}
file.close();
qDebug()<<"[Info] "<<"Qt Env Path: "<<result;
return result;
}
VersionModel::VersionModel()
{
m_sourceEnvPath = qgetenv("PATH");
}
bool VersionModel::create()
{
m_testProcess.kill();
qDebug()<<"[Info] "<<"Exe File: "<<m_exeFile;
qDebug()<<"[Info] "<<"Qt Version: "<<m_qtVersion;
qDebug()<<"[Info] "<<"Compiler Version: "<<m_compilerVersion;
QDir dir(PROGRAMS_PATH + m_qtVersion + "/" + m_qtVersionDirName + "/" + m_compilerVersion);
QStringList dirs = dir.entryList(QDir::Files);
QString qtBinPath;
if (! dirs.empty()) {
QFileInfo info(dir.path() + "/" + dirs.first());
QFileInfo sourceFile(info.symLinkTarget());
qtBinPath = sourceFile.path();
QDir qtDir = sourceFile.dir();
qtDir.cdUp();
QString qtPath = qtDir.path();
qDebug()<<"[Info] "<<"Qt Path"<<qtPath;
qDebug()<<"[Info] "<<qtBinPath;
QStringList arguments;
arguments<<"--qmldir"<<qtPath + "/qml"<<m_exeFile<<"--release";
QProcess process;
QString path = qtEnvPath(qtBinPath) + ";" + m_sourceEnvPath;
qputenv("PATH", path.toStdString().c_str());
process.start("windeployqt.exe", arguments);
process.waitForStarted();
process.waitForFinished();
qDebug()<<"[Info]"<<"Result Output: "<<process.readAllStandardOutput().toStdString().c_str();
qDebug()<<"[Info]"<<"Error Output: "<<process.readAllStandardError().toStdString().c_str();
qDebug()<<"[Info]"<<"Status: "<<process.exitCode()<<process.exitStatus();
return process.exitCode() == 0 && process.exitStatus() == QProcess::NormalExit;
}
return true;
}
bool VersionModel::test()
{
qDebug()<<"[Info]"<<"testing"<<m_exeFile;
QFileInfo testFileInfo(m_exeFile);
m_testProcess.setProgram(m_exeFile);
m_testProcess.start();
if (! m_testProcess.waitForStarted())
return false;
if (! m_testProcess.waitForFinished())
return false;
qDebug()<<"[Info]"<<"Test Process Output: "<<m_testProcess.readAllStandardOutput();
qDebug()<<"[Info]"<<"Test Process Input: "<<m_testProcess.readAllStandardError();
qDebug()<<"[Info]"<<"Test status: "<<m_testProcess.exitCode()<<m_testProcess.exitStatus()<<m_testProcess.errorString();
return m_testProcess.exitCode() == 0 && m_testProcess.exitStatus() == QProcess::NormalExit;
}
QStringList VersionModel::qtVersionList()
{
QDir dir(PROGRAMS_PATH);
QStringList filter = QStringList()<<"Qt*";
return dir.entryList(filter, QDir::NoFilter, QDir::Name);
}
QStringList VersionModel::compilerVersionList()
{
QString qtVersionPath = PROGRAMS_PATH + m_qtVersion;
QDir dir(qtVersionPath);
int index = dir.entryList(dir.filter() | QDir::Dirs).indexOf(QRegExp("^[5]+(\\.\\d+)*$"));
if (index != -1) {
m_qtVersionDirName = dir.entryList().at(index);
dir.cd(m_qtVersionDirName);
}
QStringList compilerList = dir.entryList(dir.filter() | QDir::NoDotAndDotDot);
if (! compilerList.isEmpty())
m_compilerVersion = compilerList.first();
return compilerList;
}
QString VersionModel::qtVersion()
{
return m_qtVersion;
}
void VersionModel::setQtVersion(const QString &version)
{
m_qtVersion = version;
emit statusChanged();
emit listChanged();
}
QString VersionModel::compilerVersion()
{
return m_compilerVersion;
}
void VersionModel::setCompilerVersion(const QString &version)
{
m_compilerVersion = version;
emit statusChanged();
}
QString VersionModel::exeFile()
{
return m_exeFile;
}
void VersionModel::setExeFile(const QString &file)
{
m_exeFile = file;
emit statusChanged();
}