mirror of
https://github.com/MultiMC/MultiMC5.git
synced 2024-12-29 00:20:21 +00:00
GH-1060 ugly XP hack is ugly
This commit is contained in:
parent
88f5c8d347
commit
dd97ea8029
@ -694,6 +694,11 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi
|
|||||||
QList <BackupEntry> backups;
|
QList <BackupEntry> backups;
|
||||||
QList <BackupEntry> trashcan;
|
QList <BackupEntry> trashcan;
|
||||||
|
|
||||||
|
bool useXPHack = false;
|
||||||
|
QString exePath;
|
||||||
|
QString exeOrigin;
|
||||||
|
QString exeBackup;
|
||||||
|
|
||||||
// perform the update operations
|
// perform the update operations
|
||||||
for(auto op: operations)
|
for(auto op: operations)
|
||||||
{
|
{
|
||||||
@ -703,6 +708,20 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi
|
|||||||
case GoUpdate::Operation::OP_REPLACE:
|
case GoUpdate::Operation::OP_REPLACE:
|
||||||
{
|
{
|
||||||
QFileInfo replaced (PathCombine(root(), op.dest));
|
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())
|
if(replaced.exists())
|
||||||
{
|
{
|
||||||
QString backupName = op.dest;
|
QString backupName = op.dest;
|
||||||
@ -766,6 +785,39 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi
|
|||||||
// try to start the new binary
|
// try to start the new binary
|
||||||
args = qApp->arguments();
|
args = qApp->arguments();
|
||||||
args.removeFirst();
|
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);
|
started = QProcess::startDetached(finishCmd, args, QDir::currentPath(), &pid);
|
||||||
// failed to start... ?
|
// failed to start... ?
|
||||||
if(!started || pid == -1)
|
if(!started || pid == -1)
|
||||||
|
@ -106,7 +106,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// APPLICATION ONLY
|
// APPLICATION ONLY
|
||||||
|
QString getFinishCmd();
|
||||||
void installUpdates(const QString updateFilesDir, GoUpdate::OperationList operations);
|
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
|
* Opens a json file using either a system default editor, or, if note empty, the editor
|
||||||
|
Loading…
Reference in New Issue
Block a user