23 #include "updateinstaller.h" 25 #include "configuration/doomseekerconfig.h" 26 #include "datapaths.h" 29 #include "strings.hpp" 30 #include "updater/autoupdater.h" 35 #include <QTemporaryFile> 38 const QString UPDATER_EXECUTABLE_FILENAME =
"updater.exe";
40 const QString UPDATER_EXECUTABLE_FILENAME =
"updater";
43 UpdateInstaller::UpdateInstaller(QObject *pParent)
48 UpdateInstaller::~UpdateInstaller()
52 QString UpdateInstaller::copyUpdaterExecutableToTemporarySpace()
58 QCoreApplication::applicationDirPath(),
59 UPDATER_EXECUTABLE_FILENAME);
65 QString updaterCloneFilename = QString(
"%1-%2").arg(
66 DataPaths::UPDATE_PACKAGE_FILENAME_PREFIX).arg(
67 UPDATER_EXECUTABLE_FILENAME);
69 AutoUpdater::updateStorageDirPath(), updaterCloneFilename);
71 if (QFile::copy(updaterProgramPath, clonePath))
73 bool bPermissionsSet = QFile::setPermissions(clonePath,
74 QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner
75 | QFile::ExeGroup | QFile::ReadGroup | QFile::ReadOther);
81 gLog << tr(
"Failed to copy the updater executable to a temporary" 82 " space: \"%1\" -> \"%2\".").arg(updaterProgramPath, clonePath);
86 QString UpdateInstaller::errorCodeToStr(ErrorCode code)
92 case EC_NothingToUpdate:
93 return tr(
"Nothing to update.");
94 case EC_UpdatePackageMissing:
95 return tr(
"Update package or script are not found. Check log for details.");
96 case EC_ProcessStartFailure:
97 return tr(
"Failed to start updater process.");
99 return tr(
"Unknown error: %1.").arg(code);
103 QString UpdateInstaller::getPercentEncodedCurrentProcessArgs()
105 QStringList argsEncoded;
106 if (gDefaultDataPaths->isPortableModeOn())
108 argsEncoded << QUrl::toPercentEncoding(
"--portable");
110 if (!Main::argDataDir.isEmpty())
112 argsEncoded << QUrl::toPercentEncoding(
"--datadir");
113 argsEncoded << QUrl::toPercentEncoding(Main::argDataDir);
115 return argsEncoded.join(
" ");
118 QString UpdateInstaller::processErrorCodeToStr(ProcessErrorCode code)
124 case PEC_UnableToReadUpdateScript:
125 return tr(
"Unable to read update script.");
126 case PEC_NoInstallationDirectorySpecified:
127 return tr(
"No installation directory specified.");
128 case PEC_UnableToDeterminePathOfUpdater:
129 return tr(
"Unable to determine path of updater.");
130 case PEC_GeneralFailure:
131 return tr(
"General failure.");
133 return tr(
"Unknown process error code: %1.").arg(code);
140 QFile fileScript(scriptPath);
141 if (fileScript.exists())
143 gLog << tr(
"Installing update.");
144 QString packagesDirPath = AutoUpdater::updateStorageDirPath();
145 QDir packagesDir(packagesDirPath);
148 bool isPackageOk = packagesDir.exists();
151 if (!startUpdaterProcess(packagesDirPath, scriptPath))
153 return EC_ProcessStartFailure;
158 gLog << tr(
"Package directory \"%1\" doesn't exist.").arg(packagesDirPath);
159 return EC_UpdatePackageMissing;
164 gLog << tr(
"Update was about to be installed but " 165 "update script \"%1\" is missing.").arg(scriptPath);
166 return EC_UpdatePackageMissing;
171 bool UpdateInstaller::startUpdaterProcess(
const QString &packagesDir,
172 const QString &scriptFilePath)
174 QString updaterProgramPath = copyUpdaterExecutableToTemporarySpace();
175 if (updaterProgramPath.isEmpty())
179 qDebug() <<
"Updater program is located at path: " << updaterProgramPath;
180 QFile updaterProgramFile(updaterProgramPath);
181 QFileInfo programFileInfo(QCoreApplication::applicationFilePath());
185 args <<
"--install-dir" << (QCoreApplication::applicationDirPath() +
"/../..");
187 args <<
"--install-dir" << QCoreApplication::applicationDirPath();
189 args <<
"--package-dir" << packagesDir;
190 args <<
"--script" << scriptFilePath;
191 args <<
"--exec" << QDir::toNativeSeparators(programFileInfo.absoluteFilePath());
192 QString currentProcessArgs = getPercentEncodedCurrentProcessArgs();
193 if (!currentProcessArgs.isEmpty())
195 args <<
"--args" << currentProcessArgs;
197 bool bStarted = QProcess::startDetached(updaterProgramPath, args);
200 gLog << tr(
"Failed to start updater process: %1 %2")
201 .arg(updaterProgramPath).arg(args.join(
" "));
static QString combinePaths(QString pathFront, QString pathEnd)
static QString updaterScriptPath()
Path to updater script XML file.
ErrorCode startInstallation()
Starts update process.