Krita Source Code Documentation
Loading...
Searching...
No Matches
KisAppimageUpdater.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019 Anna Medonosova <anna.medonosova@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7
9
10#include <QProcess>
11#include <QFileInfo>
12#include <QString>
13#include <QStringList>
14#include <QCoreApplication>
15#include <QDir>
16
17#include <KisUsageLogger.h>
18#include <kritagitversion.h>
19
20#include <klocalizedstring.h>
21
23 : m_checkProcess(new QProcess(this))
24 , m_updateProcess(new QProcess(this))
25{
26 QString updaterPath;
27
28#if defined(KRITA_GIT_SHA1_STRING)
29 if (qEnvironmentVariableIsSet("KRITA_APPIMAGEUPDATER_USE_DUMMY")) {
30 updaterPath = QString("%1%2AppImageUpdateDummy")
31 .arg(QCoreApplication::applicationDirPath())
32 .arg(QDir::separator());
33 } else {
34 updaterPath = QString("%1%2AppImageUpdate")
35 .arg(QCoreApplication::applicationDirPath())
36 .arg(QDir::separator());
37 }
38#else
39 updaterPath = QString("%1%2AppImageUpdate")
40 .arg(QCoreApplication::applicationDirPath())
41 .arg(QDir::separator());
42#endif
43
44 initialize(updaterPath);
45}
46
48 : m_checkProcess(new QProcess(this))
49 , m_updateProcess(new QProcess(this))
50{
51 initialize(dummyUpdaterPath);
52}
53
55{
57 return;
58 }
59
60 if (!m_updateCapability) {
61 return;
62 }
63
64 // reset output for subsequent checks, is this needed?
65 m_checkOutput = QString();
66 m_updateOutput = QString();
68
69 QStringList args = QStringList() << "--check-for-update" << m_appimagePath;
70
71 m_checkProcess->start(m_updaterBinary, args);
73}
74
79
85
86void KisAppimageUpdater::slotUpdateCheckFinished(int result, QProcess::ExitStatus exitStatus)
87{
89 QString("KisAppimageUpdater: update check finished. Result: %1 Exit status: %2\npath: %3\noutput: %4")
90 .arg(result)
91 .arg(exitStatus)
92 .arg(m_appimagePath)
93 .arg(m_updateOutput)
94 );
95
96 UpdaterStatus::StatusID updateStatus;
97
98 if (exitStatus == QProcess::CrashExit) {
100
101 } else {
102 switch (result) {
103 case 0:
105 break;
106 case 1:
108 break;
109 case 2:
111 break;
112 default:
113 // some errors have exit code of 255 (modified by system, when AppImageUpdate returns -1)
114 // one source of 255 is when the AppImage does not contain update information
116 break;
117 }
118 }
119
120 m_updaterInProgress = false;
121
122 m_updaterStatus.setStatus(updateStatus);
124
126}
127
133
134void KisAppimageUpdater::slotUpdateCheckErrorOccurred(QProcess::ProcessError error)
135{
137 QString("KisAppimageUpdater: error occurred during update check: %1\npath: %2\noutput: %3")
138 .arg(error)
139 .arg(m_appimagePath)
140 .arg(m_checkOutput)
141 );
142
143 m_updaterInProgress = false;
144
146
148}
149
150void KisAppimageUpdater::slotUpdateFinished(int result, QProcess::ExitStatus exitStatus)
151{
153 QString("KisAppimageUpdater: update finished. Result: %1\nExit status: %2\npath: %3\noutput: %4")
154 .arg(result)
155 .arg(exitStatus)
156 .arg(m_appimagePath)
157 .arg(m_updateOutput)
158 );
159
160 UpdaterStatus::StatusID updateStatus;
161 QFileInfo finfoAppImagePath(m_appimagePath);
162 QString statusDetails;
163
164 if (exitStatus == QProcess::CrashExit) {
166
167 } else {
168 switch (result) {
169 case 0:
171 statusDetails = i18n("New AppImage was downloaded to %1. To complete the update, close Krita and run the new AppImage.", finfoAppImagePath.path());
172 break;
173 default:
174 // some errors have exit code of 255 (modified by system, when AppImageUpdate returns -1)
176 break;
177 }
178 }
179
180 m_updaterInProgress = false;
181
182 m_updaterStatus.setStatus(updateStatus);
184 m_updaterStatus.setDetails(statusDetails);
185
187}
188
189void KisAppimageUpdater::slotUpdateErrorOccurred(QProcess::ProcessError error)
190{
192 QString("KisAppimageUpdater: error occurred during update: %1\npath: %2\noutput: %3")
193 .arg(error)
194 .arg(m_appimagePath)
195 .arg(m_updateOutput)
196 );
197
198 m_updaterInProgress = false;
199
202
204}
205
207{
208 m_checkOutput.append(m_checkProcess->readAllStandardOutput());
209}
210
212{
213 m_updateOutput.append(m_updateProcess->readAllStandardOutput());
214}
215
216void KisAppimageUpdater::initialize(QString& updaterPath)
217{
218 m_appimagePath = qEnvironmentVariable("APPIMAGE");
219 m_updaterBinary = updaterPath;
220
222
223 m_checkProcess->setProcessChannelMode(QProcess::MergedChannels);
224 m_updateProcess->setProcessChannelMode(QProcess::MergedChannels);
225
226 connect(m_checkProcess.data(), SIGNAL(started()), this, SLOT(slotUpdateCheckStarted()));
227 connect(m_checkProcess.data(), SIGNAL(errorOccurred(QProcess::ProcessError)),
228 this, SLOT(slotUpdateCheckErrorOccurred(QProcess::ProcessError)));
229 connect(m_checkProcess.data(), SIGNAL(finished(int, QProcess::ExitStatus)),
230 this, SLOT(slotUpdateCheckFinished(int, QProcess::ExitStatus)));
231 connect(m_checkProcess.data(), SIGNAL(readyReadStandardOutput()),
232 this, SLOT(slotAppendCheckOutput()));
233
234
235 connect(m_updateProcess.data(), SIGNAL(errorOccurred(QProcess::ProcessError)),
236 this, SLOT(slotUpdateErrorOccurred(QProcess::ProcessError)));
237 connect(m_updateProcess.data(), SIGNAL(finished(int, QProcess::ExitStatus)),
238 this, SLOT(slotUpdateFinished(int, QProcess::ExitStatus)));
239 connect(m_updateProcess.data(), SIGNAL(readyReadStandardOutput()),
240 this, SLOT(slotAppendUpdateOutput()));
241}
242
244{
245 QFileInfo finfo(m_updaterBinary);
246 if (finfo.isExecutable()) {
247 return true;
248 } else {
250 QString("KisAppimageUpdater: AppImageUpdate (%1) was not found within the Krita appimage, or is not executable")
251 .arg(m_updaterBinary)
252 );
253 return false;
254 }
255}
QList< QString > QStringList
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
bool hasUpdateCapability() override
Returns true if this updater can actually perform an update. If it can only check for new versions,...
void slotUpdateErrorOccurred(QProcess::ProcessError error)
void slotUpdateCheckFinished(int result, QProcess::ExitStatus exitStatus)
void doUpdate() override
if the updater has update capability, start the update process When the update is done,...
QScopedPointer< QProcess > m_updateProcess
QScopedPointer< QProcess > m_checkProcess
void initialize(QString &updaterPath)
void slotUpdateCheckErrorOccurred(QProcess::ProcessError error)
void slotUpdateFinished(int result, QProcess::ExitStatus exitStatus)
void checkForUpdate() override
start the process checking whether there is an update available or not When the check is done,...
KisUpdaterStatus m_updaterStatus
void sigUpdateCheckStateChange(KisUpdaterStatus)
void setStatus(const UpdaterStatus::StatusID &status)
void setDetails(const QString &details)
void setUpdaterOutput(const QString &updaterOutput)
static void log(const QString &message)
Logs with date/time.