summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-06-10 02:31:34 +0200
committerPetr Mrázek <peterix@gmail.com>2015-06-10 03:06:29 +0200
commitdd97ea80294ecd1cf8f9a68d3dd58a658ea74963 (patch)
tree6c4a2cb47767b6367d51061504144be8969d20d5
parent88f5c8d347a3f32802eb2f770d61369988ed9570 (diff)
downloadMultiMC-dd97ea80294ecd1cf8f9a68d3dd58a658ea74963.tar
MultiMC-dd97ea80294ecd1cf8f9a68d3dd58a658ea74963.tar.gz
MultiMC-dd97ea80294ecd1cf8f9a68d3dd58a658ea74963.tar.lz
MultiMC-dd97ea80294ecd1cf8f9a68d3dd58a658ea74963.tar.xz
MultiMC-dd97ea80294ecd1cf8f9a68d3dd58a658ea74963.zip
GH-1060 ugly XP hack is ugly
-rw-r--r--application/MultiMC.cpp52
-rw-r--r--application/MultiMC.h3
2 files changed, 55 insertions, 0 deletions
diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp
index feda6ec3..c76a171f 100644
--- a/application/MultiMC.cpp
+++ b/application/MultiMC.cpp
@@ -694,6 +694,11 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi
QList <BackupEntry> backups;
QList <BackupEntry> trashcan;
+ bool useXPHack = false;
+ QString exePath;
+ QString exeOrigin;
+ QString exeBackup;
+
// perform the update operations
for(auto op: operations)
{
@@ -703,6 +708,20 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi
case GoUpdate::Operation::OP_REPLACE:
{
QFileInfo replaced (PathCombine(root(), op.dest));
+#ifdef Q_OS_WIN32
+ if(QSysInfo::windowsVersion() < QSysInfo::WV_VISTA)
+ {
+ if(replaced.fileName() == "MultiMC.exe")
+ {
+ QDir rootDir(root());
+ exeOrigin = rootDir.relativeFilePath(op.file);
+ exePath = rootDir.relativeFilePath(op.dest);
+ exeBackup = rootDir.relativeFilePath(PathCombine(backupPath, replaced.fileName()));
+ useXPHack = true;
+ continue;
+ }
+ }
+#endif
if(replaced.exists())
{
QString backupName = op.dest;
@@ -766,6 +785,39 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi
// try to start the new binary
args = qApp->arguments();
args.removeFirst();
+
+ // on old Windows, do insane things... no error checking here, this is just to have something.
+ if(useXPHack)
+ {
+ QString script;
+ auto nativePath = QDir::toNativeSeparators(exePath);
+ auto nativeOriginPath = QDir::toNativeSeparators(exeOrigin);
+ auto nativeBackupPath = QDir::toNativeSeparators(exeBackup);
+
+ // so we write this vbscript thing...
+ QTextStream out(&script);
+ out << "WScript.Sleep 1000\n";
+ out << "Set fso=CreateObject(\"Scripting.FileSystemObject\")\n";
+ out << "Set shell=CreateObject(\"WScript.Shell\")\n";
+ out << "fso.MoveFile \"" << nativePath << "\", \"" << nativeBackupPath << "\"\n";
+ out << "fso.MoveFile \"" << nativeOriginPath << "\", \"" << nativePath << "\"\n";
+ out << "shell.Run \"" << nativePath << "\"\n";
+
+ QString scriptPath = PathCombine(root(), "update", "update.vbs");
+
+ // we save it
+ QFile scriptFile(scriptPath);
+ scriptFile.open(QIODevice::WriteOnly);
+ scriptFile.write(script.toLocal8Bit().replace("\n", "\r\n"));
+ scriptFile.close();
+
+ // we run it
+ started = QProcess::startDetached("wscript", {scriptPath}, root());
+
+ // and we quit. conscious thought.
+ qApp->quit();
+ return;
+ }
started = QProcess::startDetached(finishCmd, args, QDir::currentPath(), &pid);
// failed to start... ?
if(!started || pid == -1)
diff --git a/application/MultiMC.h b/application/MultiMC.h
index 9edf0596..7389dc8b 100644
--- a/application/MultiMC.h
+++ b/application/MultiMC.h
@@ -106,7 +106,10 @@ public:
}
// APPLICATION ONLY
+ QString getFinishCmd();
void installUpdates(const QString updateFilesDir, GoUpdate::OperationList operations);
+ void updateXP(const QString updateFilesDir, GoUpdate::OperationList operations);
+ void updateModern(const QString updateFilesDir, GoUpdate::OperationList operations);
/*!
* Opens a json file using either a system default editor, or, if note empty, the editor