manta rings code + macos fixes

This commit is contained in:
Nayla Hanegan 2025-01-08 15:24:15 -05:00
commit 0a53480f3f
3 changed files with 143 additions and 90 deletions

View file

@ -710,6 +710,14 @@ $Minigame - Fish n' Drips - 3 Players have 2 Less Rounds [Tabitha]
0442D31C 42820000 0442D31C 42820000
E2000001 80008000 E2000001 80008000
$Minigame - Manta Rings - Just Hold A [Tabitha]
281D3CE2 00000009
04005FA4 60000000
E2000001 80000000
2A1D3CE2 00000009
04005FA4 7F83032E
E2000001 80008000
$Minigame - Three Throw - All Hoops Empty [gamemasterplc] $Minigame - Three Throw - All Hoops Empty [gamemasterplc]
20434274 3800000A 20434274 3800000A
04434260 38800000 04434260 38800000

View file

@ -79,8 +79,8 @@ void DownloadUpdateDialog::onDownloadFinished()
installationDirectory = QCoreApplication::applicationDirPath(); // Set the installation directory installationDirectory = QCoreApplication::applicationDirPath(); // Set the installation directory
#endif #endif
#ifdef __APPLE__ #ifdef __APPLE__
installationDirectory = QCoreApplication::applicationDirPath() + "/../../" installationDirectory = QCoreApplication::applicationDirPath() + QStringLiteral("/../../")
#endif #endif
// Use QStandardPaths to get the system's temporary directory // Use QStandardPaths to get the system's temporary directory
temporaryDirectory = QDir::tempPath(); temporaryDirectory = QDir::tempPath();

View file

@ -44,94 +44,122 @@ InstallUpdateDialog::~InstallUpdateDialog(void)
{ {
} }
void InstallUpdateDialog::install(void) void InstallUpdateDialog::install()
{ {
QString fullFilePath = QCoreApplication::applicationDirPath() + QStringLiteral("/") + this->filename; QString fullFilePath = QCoreApplication::applicationDirPath() + QStringLiteral("/") + this->filename;
QString appPath = QCoreApplication::applicationDirPath(); QString appPath = QCoreApplication::applicationDirPath();
QString appPid = QString::number(QCoreApplication::applicationPid()); QString appPid = QString::number(QCoreApplication::applicationPid());
// Convert paths to use the right path separator // Convert paths to native format
this->temporaryDirectory = QDir::toNativeSeparators(this->temporaryDirectory); this->temporaryDirectory = QDir::toNativeSeparators(this->temporaryDirectory);
fullFilePath = QDir::toNativeSeparators(fullFilePath); fullFilePath = QDir::toNativeSeparators(fullFilePath);
appPath = QDir::toNativeSeparators(appPath); appPath = QDir::toNativeSeparators(appPath);
if (this->filename.endsWith(QStringLiteral(".exe"))) if (this->filename.endsWith(QStringLiteral(".exe")))
{ {
this->label->setText(QStringLiteral("Executing %1...").arg(this->filename)); this->label->setText(QStringLiteral("Executing %1...").arg(this->filename));
QStringList scriptLines =
{
QStringLiteral("@echo off"),
QStringLiteral("("),
QStringLiteral(" echo == Attempting to kill PID ") + appPid,
QStringLiteral(" taskkill /F /PID:") + appPid,
QStringLiteral(" echo == Attempting to start '") + fullFilePath + QStringLiteral("'"),
QStringLiteral(" \"") + fullFilePath + QStringLiteral("\" /CLOSEAPPLICATIONS /NOCANCEL /MERGETASKS=\"!desktopicon\" /SILENT /DIR=\"") + appPath + QStringLiteral("\""),
QStringLiteral(")"),
QStringLiteral("IF NOT ERRORLEVEL 0 ("),
QStringLiteral(" start \"\" cmd /c \"echo Update failed, check the log for more information && pause\""),
QStringLiteral(")"),
// Remove temporary directory at last
QStringLiteral("rmdir /S /Q \"") + this->temporaryDirectory + QStringLiteral("\""),
};
this->writeAndRunScript(scriptLines);
this->accept();
return;
}
this->label->setText(QStringLiteral("Extracting %1...").arg(this->filename)); #ifdef _WIN32
this->progressBar->setValue(50); QStringList scriptLines = {
QString extractDirectory = this->temporaryDirectory + QDir::separator() + QStringLiteral("Dolphin-MPN");
// Ensure the extract directory exists before attempting to unzip
QDir dir(this->temporaryDirectory);
if (!QDir(extractDirectory).exists())
{
if (!dir.mkdir(QStringLiteral("Dolphin-MPN")))
{
QMessageBox::critical(this, QStringLiteral("Error"),
QStringLiteral("Failed to create extract directory."));
this->reject();
return;
}
}
// Attempt to unzip files into the extract directory
if (!unzipFile(fullFilePath.toStdString(), extractDirectory.toStdString()))
{
QMessageBox::critical(this, QStringLiteral("Error"),
QStringLiteral("Unzip failed: Unable to extract files."));
this->reject();
return;
}
this->label->setText(QStringLiteral("Executing update script..."));
this->progressBar->setValue(100);
extractDirectory = QDir::toNativeSeparators(extractDirectory);
QStringList scriptLines =
{
QStringLiteral("@echo off"), QStringLiteral("@echo off"),
QStringLiteral("("), QStringLiteral("("),
QStringLiteral(" echo == Attempting to remove '") + fullFilePath + QStringLiteral("'"),
QStringLiteral(" del /F /Q \"") + fullFilePath + QStringLiteral("\""),
QStringLiteral(" echo == Attempting to kill PID ") + appPid, QStringLiteral(" echo == Attempting to kill PID ") + appPid,
QStringLiteral(" taskkill /F /PID:") + appPid, QStringLiteral(" taskkill /F /PID:") + appPid,
QStringLiteral(" echo == Attempting to copy '") + extractDirectory + QStringLiteral("' to '") + appPath + QStringLiteral("'"), QStringLiteral(" echo == Attempting to start '") + fullFilePath + QStringLiteral("'"),
QStringLiteral(" xcopy /S /Y /I \"") + extractDirectory + QStringLiteral("\\*\" \"") + appPath + QStringLiteral("\""), QStringLiteral(" \"") + fullFilePath +
QStringLiteral(" echo == Attempting to start '") + appPath + QStringLiteral("\\Dolphin-MPN.exe'"), QStringLiteral(
QStringLiteral(" start \"\" \"") + appPath + QStringLiteral("\\Dolphin-MPN.exe\""), "\" /CLOSEAPPLICATIONS /NOCANCEL /MERGETASKS=\"!desktopicon\" /SILENT /DIR=\"") +
appPath + QStringLiteral("\""),
QStringLiteral(")"), QStringLiteral(")"),
QStringLiteral("IF NOT ERRORLEVEL 0 ("), QStringLiteral("IF NOT ERRORLEVEL 0 ("),
QStringLiteral(" start \"\" cmd /c \"echo Update failed && pause\""), QStringLiteral(" start \"\" cmd /c \"echo Update failed, check the log for more "
"information && pause\""),
QStringLiteral(")"), QStringLiteral(")"),
// Remove temporary directory at last
QStringLiteral("rmdir /S /Q \"") + this->temporaryDirectory + QStringLiteral("\""), QStringLiteral("rmdir /S /Q \"") + this->temporaryDirectory + QStringLiteral("\""),
}; };
this->writeAndRunScript(scriptLines); this->writeAndRunScript(scriptLines);
this->accept();
#endif
return;
}
this->label->setText(QStringLiteral("Extracting %1...").arg(this->filename));
this->progressBar->setValue(50);
QString extractDirectory =
this->temporaryDirectory + QDir::separator() + QStringLiteral("Dolphin-MPN");
// Ensure the extract directory exists before attempting to unzip
QDir dir(this->temporaryDirectory);
if (!QDir(extractDirectory).exists())
{
if (!dir.mkdir(QStringLiteral("Dolphin-MPN")))
{
QMessageBox::critical(this, QStringLiteral("Error"),
QStringLiteral("Failed to create extract directory."));
this->reject();
return;
}
}
// Attempt to unzip files into the extract directory
if (!unzipFile(fullFilePath.toStdString(), extractDirectory.toStdString()))
{
QMessageBox::critical(this, QStringLiteral("Error"),
QStringLiteral("Unzip failed: Unable to extract files."));
this->reject();
return;
}
this->label->setText(QStringLiteral("Executing update script..."));
this->progressBar->setValue(100);
extractDirectory = QDir::toNativeSeparators(extractDirectory);
#ifdef __APPLE__
QStringList scriptLines = {
QStringLiteral("#!/bin/bash"),
QStringLiteral("echo '== Terminating application with PID ") + appPid + QStringLiteral("'"),
QStringLiteral("kill -9 ") + appPid,
QStringLiteral("echo '== Removing old application files'"),
QStringLiteral("rm -f \"") + fullFilePath + QStringLiteral("\""),
QStringLiteral("echo '== Copying new files to ") + appPath + QStringLiteral("'"),
QStringLiteral("cp -r \"") + extractDirectory + QStringLiteral("/\"* \"") + appPath +
QStringLiteral("\""),
QStringLiteral("echo '== Launching the updated application'"),
QStringLiteral("open \"") + appPath + QStringLiteral("/Dolphin-MPN.app\""),
QStringLiteral("echo '== Cleaning up temporary files'"),
QStringLiteral("rm -rf \"") + this->temporaryDirectory + QStringLiteral("\""),
QStringLiteral("exit 0")};
this->writeAndRunScript(scriptLines);
#endif
#ifdef _WIN32
QStringList scriptLines = {
QStringLiteral("@echo off"),
QStringLiteral("("),
QStringLiteral(" echo == Attempting to remove '") + fullFilePath + QStringLiteral("'"),
QStringLiteral(" del /F /Q \"") + fullFilePath + QStringLiteral("\""),
QStringLiteral(" echo == Attempting to kill PID ") + appPid,
QStringLiteral(" taskkill /F /PID:") + appPid,
QStringLiteral(" echo == Attempting to copy '") + extractDirectory +
QStringLiteral("' to '") + appPath + QStringLiteral("'"),
QStringLiteral(" xcopy /S /Y /I \"") + extractDirectory + QStringLiteral("\\*\" \"") +
appPath + QStringLiteral("\""),
QStringLiteral(" echo == Attempting to start '") + appPath +
QStringLiteral("\\Dolphin-MPN.exe'"),
QStringLiteral(" start \"\" \"") + appPath + QStringLiteral("\\Dolphin-MPN.exe\""),
QStringLiteral(")"),
QStringLiteral("IF NOT ERRORLEVEL 0 ("),
QStringLiteral(" start \"\" cmd /c \"echo Update failed && pause\""),
QStringLiteral(")"),
QStringLiteral("rmdir /S /Q \"") + this->temporaryDirectory + QStringLiteral("\""),
};
this->writeAndRunScript(scriptLines);
#endif
} }
bool InstallUpdateDialog::unzipFile(const std::string& zipFilePath, const std::string& destDir) bool InstallUpdateDialog::unzipFile(const std::string& zipFilePath, const std::string& destDir)
{ {
unzFile zipFile = unzOpen(zipFilePath.c_str()); unzFile zipFile = unzOpen(zipFilePath.c_str());
@ -197,27 +225,44 @@ bool InstallUpdateDialog::unzipFile(const std::string& zipFilePath, const std::s
void InstallUpdateDialog::writeAndRunScript(QStringList stringList) void InstallUpdateDialog::writeAndRunScript(QStringList stringList)
{ {
QString scriptPath = this->temporaryDirectory + QStringLiteral("/update.bat"); #ifdef __APPLE__
QString scriptPath = this->temporaryDirectory + QStringLiteral("/update.sh");
#else
QString scriptPath = this->temporaryDirectory + QStringLiteral("/update.bat");
#endif
QFile scriptFile(scriptPath); QFile scriptFile(scriptPath);
if (!scriptFile.open(QIODevice::WriteOnly | QIODevice::Text)) if (!scriptFile.open(QIODevice::WriteOnly | QIODevice::Text))
{ {
QMessageBox::critical(this, tr("Error"), tr("Failed to open file for writing: %1").arg(filename)); QMessageBox::critical(this, tr("Error"),
return; tr("Failed to open file for writing: %1").arg(filename));
} return;
}
QTextStream textStream(&scriptFile); QTextStream textStream(&scriptFile);
// Write script to file #ifdef __APPLE__
for (const QString& str : stringList) // macOS: Write shell script
{ textStream << QStringLiteral("#!/bin/bash\n");
textStream << str << "\n"; #else
} // Windows: Write batch script
textStream << QStringLiteral("@echo off\n");
#endif
scriptFile.setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner); for (const QString& str : stringList)
scriptFile.close(); {
textStream << str << "\n";
}
this->launchProcess(scriptPath, {}); #ifdef __APPLE__
scriptFile.setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner |
QFileDevice::ExeOwner);
#else
scriptFile.setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner);
#endif
scriptFile.close();
this->launchProcess(scriptPath, {});
} }
void InstallUpdateDialog::launchProcess(QString file, QStringList arguments) void InstallUpdateDialog::launchProcess(QString file, QStringList arguments)