MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / installUpdates

Method installUpdates

launcher/UpdateController.cpp:87–344  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85
86
87void 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) || defined(Q_OS_FREEBSD) || defined (Q_OS_OPENBSD)
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 if(destination.exists())
142 {
143 QString backupName = op.destination;
144 backupName.replace('/', '_');

Callers 1

downloadUpdatesMethod · 0.80

Calls 13

PathCombineFunction · 0.85
deletePathFunction · 0.85
ensureFolderPathExistsFunction · 0.85
ensureFilePathExistsFunction · 0.85
unixModeToPermissionsFunction · 0.85
readFunction · 0.85
existsMethod · 0.80
appendMethod · 0.80
openMethod · 0.80
isClientMethod · 0.80
replaceMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected