| 85 | |
| 86 | |
| 87 | void UpdateController::installUpdates() |
| 88 | { |
| 89 | qint64 pid = -1; |
| 90 | QStringList args; |
| 91 | bool started = false; |
| 92 | |
| 93 | qDebug() << "Installing updates."; |
| 94 | #ifdef Q_OS_WIN |
| 95 | QString finishCmd = QApplication::applicationFilePath(); |
| 96 | #elif defined Q_OS_LINUX |
| 97 | QString finishCmd = FS::PathCombine(m_root, BuildConfig.LAUNCHER_NAME); |
| 98 | #elif defined Q_OS_MAC |
| 99 | QString finishCmd = QApplication::applicationFilePath(); |
| 100 | #else |
| 101 | #error Unsupported operating system. |
| 102 | #endif |
| 103 | |
| 104 | QString backupPath = FS::PathCombine(m_root, "update", "backup"); |
| 105 | QDir origin(m_root); |
| 106 | |
| 107 | // clean up the backup folder. it should be empty before we start |
| 108 | if(!FS::deletePath(backupPath)) |
| 109 | { |
| 110 | qWarning() << "couldn't remove previous backup folder" << backupPath; |
| 111 | } |
| 112 | // and it should exist. |
| 113 | if(!FS::ensureFolderPathExists(backupPath)) |
| 114 | { |
| 115 | qWarning() << "couldn't create folder" << backupPath; |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | bool useXPHack = false; |
| 120 | QString exePath; |
| 121 | QString exeOrigin; |
| 122 | QString exeBackup; |
| 123 | |
| 124 | // perform the update operations |
| 125 | for(auto op: m_operations) |
| 126 | { |
| 127 | switch(op.type) |
| 128 | { |
| 129 | // replace = move original out to backup, if it exists, move the new file in its place |
| 130 | case GoUpdate::Operation::OP_REPLACE: |
| 131 | { |
| 132 | #ifdef Q_OS_WIN32 |
| 133 | QString windowsExeName = BuildConfig.LAUNCHER_NAME + ".exe"; |
| 134 | // hack for people renaming the .exe because ... reasons :) |
| 135 | if(op.destination == windowsExeName) |
| 136 | { |
| 137 | op.destination = QFileInfo(QApplication::applicationFilePath()).fileName(); |
| 138 | } |
| 139 | #endif |
| 140 | QFileInfo destination (FS::PathCombine(m_root, op.destination)); |
| 141 | #ifdef Q_OS_WIN32 |
| 142 | if(QSysInfo::windowsVersion() < QSysInfo::WV_VISTA) |
| 143 | { |
| 144 | if(destination.fileName() == windowsExeName) |
no test coverage detected