@@ -13,7 +13,7 @@ Q_LOGGING_CATEGORY(logQtAutoUpdater, "QtAutoUpdater")
1313
1414UpdaterPrivate::UpdaterPrivate(Updater *q_ptr) :
1515 QObject(nullptr ),
16- q_ptr (q_ptr),
16+ q (q_ptr),
1717 toolPath(),
1818 updateInfos(),
1919 normalExit(true ),
@@ -29,19 +29,19 @@ UpdaterPrivate::UpdaterPrivate(Updater *q_ptr) :
2929 connect (qApp, &QCoreApplication::aboutToQuit,
3030 this , &UpdaterPrivate::appAboutToExit,
3131 Qt::DirectConnection);
32- connect (this -> scheduler , &SimpleScheduler::scheduleTriggered,
32+ connect (scheduler, &SimpleScheduler::scheduleTriggered,
3333 this , &UpdaterPrivate::startUpdateCheck);
3434}
3535
3636UpdaterPrivate::~UpdaterPrivate ()
3737{
38- if (this -> runOnExit )
38+ if (runOnExit)
3939 qCWarning (logQtAutoUpdater) << " Updater destroyed with run on exit active before the application quit" ;
4040
41- if (this -> mainProcess &&
42- this -> mainProcess ->state () != QProcess::NotRunning) {
43- this -> mainProcess ->kill ();
44- this -> mainProcess ->waitForFinished (1000 );
41+ if (mainProcess &&
42+ mainProcess->state () != QProcess::NotRunning) {
43+ mainProcess->kill ();
44+ mainProcess->waitForFinished (1000 );
4545 }
4646}
4747
@@ -63,50 +63,49 @@ const QString UpdaterPrivate::toSystemExe(QString basePath)
6363
6464bool UpdaterPrivate::startUpdateCheck ()
6565{
66- if (this -> running )
66+ if (running)
6767 return false ;
6868 else {
69- Q_Q (Updater);
70- this ->updateInfos .clear ();
71- this ->normalExit = true ;
72- this ->lastErrorCode = EXIT_SUCCESS;
73- this ->lastErrorLog .clear ();
74-
75- QFileInfo toolInfo (QCoreApplication::applicationDirPath (), this ->toolPath );
76- this ->mainProcess = new QProcess (this );
77- this ->mainProcess ->setProgram (toolInfo.absoluteFilePath ());
78- this ->mainProcess ->setArguments ({QStringLiteral (" --checkupdates" )});
79-
80- connect (this ->mainProcess , QOverload<int , QProcess::ExitStatus>::of (&QProcess::finished),
69+ updateInfos.clear ();
70+ normalExit = true ;
71+ lastErrorCode = EXIT_SUCCESS;
72+ lastErrorLog.clear ();
73+
74+ QFileInfo toolInfo (QCoreApplication::applicationDirPath (), toolPath);
75+ mainProcess = new QProcess (this );
76+ mainProcess->setProgram (toolInfo.absoluteFilePath ());
77+ mainProcess->setArguments ({QStringLiteral (" --checkupdates" )});
78+
79+ connect (mainProcess, QOverload<int , QProcess::ExitStatus>::of (&QProcess::finished),
8180 this , &UpdaterPrivate::updaterReady, Qt::QueuedConnection);
82- connect (this -> mainProcess , &QProcess::errorOccurred,
81+ connect (mainProcess, &QProcess::errorOccurred,
8382 this , &UpdaterPrivate::updaterError, Qt::QueuedConnection);
8483
85- this -> mainProcess ->start (QIODevice::ReadOnly);
86- this -> running = true ;
84+ mainProcess->start (QIODevice::ReadOnly);
85+ running = true ;
8786
88- emit q->updateInfoChanged (this -> updateInfos );
87+ emit q->updateInfoChanged (updateInfos);
8988 emit q->runningChanged (true );
9089 return true ;
9190 }
9291}
9392
9493void UpdaterPrivate::stopUpdateCheck (int delay, bool async)
9594{
96- if (this -> mainProcess &&
97- this -> mainProcess ->state () != QProcess::NotRunning) {
95+ if (mainProcess &&
96+ mainProcess->state () != QProcess::NotRunning) {
9897 if (delay > 0 ) {
99- this -> mainProcess ->terminate ();
98+ mainProcess->terminate ();
10099 if (async){
101100 QTimer::singleShot (delay, this , [this ](){
102- this -> stopUpdateCheck (0 , false );
101+ stopUpdateCheck (0 , false );
103102 });
104103 } else {
105- if (!this -> mainProcess ->waitForFinished (delay))
106- this -> mainProcess ->kill ();
104+ if (!mainProcess->waitForFinished (delay))
105+ mainProcess->kill ();
107106 }
108107 } else
109- this -> mainProcess ->kill ();
108+ mainProcess->kill ();
110109 }
111110}
112111
@@ -154,78 +153,74 @@ QList<Updater::UpdateInfo> UpdaterPrivate::parseResult(const QByteArray &output)
154153
155154void UpdaterPrivate::updaterReady (int exitCode, QProcess::ExitStatus exitStatus)
156155{
157- if (this -> mainProcess ) {
156+ if (mainProcess) {
158157 if (exitStatus == QProcess::NormalExit) {
159- this ->normalExit = true ;
160- this ->lastErrorCode = exitCode;
161- this ->lastErrorLog = this ->mainProcess ->readAllStandardError ();
162- const auto updateOut = this ->mainProcess ->readAllStandardOutput ();
163- this ->mainProcess ->deleteLater ();
164- this ->mainProcess = nullptr ;
165-
166- Q_Q (Updater);
167- if (this ->lastErrorCode != EXIT_SUCCESS) {
168- this ->running = false ;
158+ normalExit = true ;
159+ lastErrorCode = exitCode;
160+ lastErrorLog = mainProcess->readAllStandardError ();
161+ const auto updateOut = mainProcess->readAllStandardOutput ();
162+ mainProcess->deleteLater ();
163+ mainProcess = nullptr ;
164+
165+ if (lastErrorCode != EXIT_SUCCESS) {
166+ running = false ;
169167 emit q->runningChanged (false );
170168 emit q->checkUpdatesDone (false , true );
171169 } else {
172- this -> running = false ;
170+ running = false ;
173171 emit q->runningChanged (false );
174172 try {
175- this -> updateInfos = this -> parseResult (updateOut);
176- if (!this -> updateInfos .isEmpty ())
177- emit q->updateInfoChanged (this -> updateInfos );
178- emit q->checkUpdatesDone (!this -> updateInfos .isEmpty (), false );
173+ updateInfos = parseResult (updateOut);
174+ if (!updateInfos.isEmpty ())
175+ emit q->updateInfoChanged (updateInfos);
176+ emit q->checkUpdatesDone (!updateInfos.isEmpty (), false );
179177 } catch (NoUpdatesXmlException &) {
180178 emit q->checkUpdatesDone (false , false );
181179 } catch (InvalidXmlException &exc) {
182- this -> lastErrorLog = exc.what ();
180+ lastErrorLog = exc.what ();
183181 emit q->checkUpdatesDone (false , true );
184182 }
185183 }
186184 } else
187- this -> updaterError (QProcess::Crashed);
185+ updaterError (QProcess::Crashed);
188186 }
189187}
190188
191189void UpdaterPrivate::updaterError (QProcess::ProcessError error)
192190{
193- if (this ->mainProcess ) {
194- Q_Q (Updater);
195- this ->normalExit = false ;
196- this ->lastErrorCode = error;
197- this ->lastErrorLog = this ->mainProcess ->errorString ().toUtf8 ();
198- this ->mainProcess ->deleteLater ();
199- this ->mainProcess = nullptr ;
200-
201- this ->running = false ;
191+ if (mainProcess) {
192+ normalExit = false ;
193+ lastErrorCode = error;
194+ lastErrorLog = mainProcess->errorString ().toUtf8 ();
195+ mainProcess->deleteLater ();
196+ mainProcess = nullptr ;
197+
198+ running = false ;
202199 emit q->runningChanged (false );
203200 emit q->checkUpdatesDone (false , true );
204201 }
205202}
206203
207204void UpdaterPrivate::appAboutToExit ()
208205{
209- if (this -> runOnExit ) {
210- QFileInfo toolInfo (QCoreApplication::applicationDirPath (), this -> toolPath );
206+ if (runOnExit) {
207+ QFileInfo toolInfo (QCoreApplication::applicationDirPath (), toolPath);
211208 auto ok = false ;
212- if (this ->adminAuth && !this ->adminAuth ->hasAdminRights ()) {
213- ok = this ->adminAuth ->executeAsAdmin (toolInfo.absoluteFilePath (),
214- this ->runArguments );
215-
216- } else {
209+ if (adminAuth && !adminAuth->hasAdminRights ())
210+ ok = adminAuth->executeAsAdmin (toolInfo.absoluteFilePath (), runArguments);
211+ else {
217212 ok = QProcess::startDetached (toolInfo.absoluteFilePath (),
218- this -> runArguments ,
213+ runArguments,
219214 toolInfo.absolutePath ());
220215 }
221216
222217 if (!ok) {
223218 qCWarning (logQtAutoUpdater) << " Unable to start" << toolInfo.absoluteFilePath ()
224- << " with arguments" << this -> runArguments
225- << " as" << (this -> adminAuth ? " admin/root" : " current user" );
219+ << " with arguments" << runArguments
220+ << " as" << (adminAuth ? " admin/root" : " current user" );
226221 }
227222
228- this -> runOnExit = false ;// prevent warning
223+ runOnExit = false ;// prevent warning
229224 }
230225}
231226
0 commit comments