summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-01-05 13:17:42 +0100
committerPetr Mrázek <peterix@gmail.com>2014-01-05 13:17:42 +0100
commit613c01dab5222a99fa642a466ce37ade53f1c072 (patch)
tree76e7397ed67679d168a40b36035d898b406b1430
parent76f58eb42ccc2c19f6952cbae501c17c06c3671b (diff)
downloadMultiMC-613c01dab5222a99fa642a466ce37ade53f1c072.tar
MultiMC-613c01dab5222a99fa642a466ce37ade53f1c072.tar.gz
MultiMC-613c01dab5222a99fa642a466ce37ade53f1c072.tar.lz
MultiMC-613c01dab5222a99fa642a466ce37ade53f1c072.tar.xz
MultiMC-613c01dab5222a99fa642a466ce37ade53f1c072.zip
Some more updater fixes
Paths were wrong - still used work directory instead of root
-rw-r--r--MultiMC.cpp37
-rw-r--r--MultiMC.h38
-rw-r--r--gui/MainWindow.cpp8
-rw-r--r--logic/updater/DownloadUpdateTask.cpp44
-rw-r--r--main.cpp8
-rw-r--r--mmc_updater/src/UpdateInstaller.cpp14
-rw-r--r--mmc_updater/src/UpdateScript.h1
7 files changed, 82 insertions, 68 deletions
diff --git a/MultiMC.cpp b/MultiMC.cpp
index 1b915542..2bc77e0f 100644
--- a/MultiMC.cpp
+++ b/MultiMC.cpp
@@ -261,6 +261,7 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &data_dir_override)
return;
}
*/
+ connect(this, SIGNAL(aboutToQuit()), SLOT(onExit()));
m_status = MultiMC::Initialized;
}
@@ -510,8 +511,21 @@ std::shared_ptr<JavaVersionList> MultiMC::javalist()
return m_javalist;
}
-void MultiMC::installUpdates(const QString &updateFilesDir, bool restartOnFinish)
+void MultiMC::installUpdates(const QString updateFilesDir, UpdateFlags flags)
{
+ // if we are going to update on exit, save the params now
+ if(flags & OnExit)
+ {
+ m_updateOnExitPath = updateFilesDir;
+ m_updateOnExitFlags = flags & ~OnExit;
+ return;
+ }
+ // otherwise if there already were some params for on exit update, clear them and continue
+ else if(m_updateOnExitPath.size())
+ {
+ m_updateOnExitFlags = None;
+ m_updateOnExitPath.clear();
+ }
QLOG_INFO() << "Installing updates.";
#ifdef WINDOWS
QString finishCmd = MMC->applicationFilePath();
@@ -533,16 +547,15 @@ void MultiMC::installUpdates(const QString &updateFilesDir, bool restartOnFinish
args << "--package-dir" << updateFilesDir;
args << "--script" << PathCombine(updateFilesDir, "file_list.xml");
args << "--wait" << QString::number(MMC->applicationPid());
-#ifdef MultiMC_UPDATER_DRY_RUN
- args << "--dry-run";
-#endif
- if (restartOnFinish)
+ if(flags & DryRun)
+ args << "--dry-run";
+ if (flags & RestartOnFinish)
args << "--finish-cmd" << finishCmd;
QLOG_INFO() << "Running updater with command" << updaterBinary << args.join(" ");
QFile::setPermissions(updaterBinary, (QFileDevice::Permission)0x7755);
- if (!QProcess::startDetached(updaterBinary, args))
+ if (!QProcess::startDetached(updaterBinary, args/*, root()*/))
{
QLOG_ERROR() << "Failed to start the updater process!";
return;
@@ -552,14 +565,12 @@ void MultiMC::installUpdates(const QString &updateFilesDir, bool restartOnFinish
MMC->quit();
}
-void MultiMC::setUpdateOnExit(const QString &updateFilesDir)
+void MultiMC::onExit()
{
- m_updateOnExitPath = updateFilesDir;
-}
-
-QString MultiMC::getExitUpdatePath() const
-{
- return m_updateOnExitPath;
+ if(m_updateOnExitPath.size())
+ {
+ installUpdates(m_updateOnExitPath, m_updateOnExitFlags);
+ }
}
bool MultiMC::openJsonEditor(const QString &filename)
diff --git a/MultiMC.h b/MultiMC.h
index 8e711f10..ea3034b0 100644
--- a/MultiMC.h
+++ b/MultiMC.h
@@ -6,6 +6,7 @@
#include <memory>
#include "logger/QsLog.h"
#include "logger/QsLogDest.h"
+#include <QFlag>
class MinecraftVersionList;
class LWJGLVersionList;
@@ -32,9 +33,19 @@ enum InstSortMode
// Sort alphabetically by name.
Sort_Name,
// Sort by which instance was launched most recently.
- Sort_LastLaunch,
+ Sort_LastLaunch
};
+enum UpdateFlag
+{
+ None = 0x0,
+ RestartOnFinish = 0x1,
+ DryRun = 0x2,
+ OnExit = 0x4
+};
+Q_DECLARE_FLAGS(UpdateFlags, UpdateFlag);
+Q_DECLARE_OPERATORS_FOR_FLAGS(UpdateFlags);
+
class MultiMC : public QApplication
{
Q_OBJECT
@@ -43,7 +54,7 @@ public:
{
Failed,
Succeeded,
- Initialized,
+ Initialized
};
public:
@@ -110,21 +121,7 @@ public:
std::shared_ptr<JavaVersionList> javalist();
- /*!
- * Installs update from the given update files directory.
- */
- void installUpdates(const QString &updateFilesDir, bool restartOnFinish = false);
-
- /*!
- * Sets MultiMC to install updates from the given directory when it exits.
- */
- void setUpdateOnExit(const QString &updateFilesDir);
-
- /*!
- * Gets the path to install updates from on exit.
- * If this is an empty string, no updates should be installed on exit.
- */
- QString getExitUpdatePath() const;
+ void installUpdates(const QString updateFilesDir, UpdateFlags flags = None);
/*!
* Opens a json file using either a system default editor, or, if note empty, the editor
@@ -155,6 +152,12 @@ public:
return origcwdPath;
}
+private slots:
+ /**
+ * Do all the things that should be done before we exit
+ */
+ void onExit();
+
private:
void initLogger();
@@ -187,6 +190,7 @@ private:
QsLogging::DestinationPtr m_debugDestination;
QString m_updateOnExitPath;
+ UpdateFlags m_updateOnExitFlags = None;
QString rootPath;
QString binPath;
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp
index cb9171f1..35c4ee15 100644
--- a/gui/MainWindow.cpp
+++ b/gui/MainWindow.cpp
@@ -568,10 +568,14 @@ void MainWindow::downloadUpdates(QString repo, int versionId, bool installOnExit
// If the task succeeds, install the updates.
if (updateDlg.exec(&updateTask))
{
+ UpdateFlags baseFlags = None;
+ #ifdef MultiMC_UPDATER_DRY_RUN
+ baseFlags |= DryRun;
+ #endif
if (installOnExit)
- MMC->setUpdateOnExit(updateTask.updateFilesDir());
+ MMC->installUpdates(updateTask.updateFilesDir(), baseFlags | OnExit);
else
- MMC->installUpdates(updateTask.updateFilesDir(), true);
+ MMC->installUpdates(updateTask.updateFilesDir(), baseFlags | RestartOnFinish);
}
}
diff --git a/logic/updater/DownloadUpdateTask.cpp b/logic/updater/DownloadUpdateTask.cpp
index b82574f7..6f9d7189 100644
--- a/logic/updater/DownloadUpdateTask.cpp
+++ b/logic/updater/DownloadUpdateTask.cpp
@@ -290,12 +290,11 @@ DownloadUpdateTask::processFileLists(NetJob *job,
// delete anything in the current one version's list that isn't in the new version's list.
for (VersionFileEntry entry : currentVersion)
{
- QFileInfo toDelete(entry.path);
+ QFileInfo toDelete(PathCombine(MMC->root(), entry.path));
if (!toDelete.exists())
{
QLOG_ERROR() << "Expected file " << toDelete.absoluteFilePath()
<< " doesn't exist!";
- QLOG_ERROR() << "CWD: " << QDir::currentPath();
}
bool keep = false;
@@ -314,7 +313,6 @@ DownloadUpdateTask::processFileLists(NetJob *job,
// If the loop reaches the end and we didn't find a match, delete the file.
if (!keep)
{
- QFileInfo toDelete(entry.path);
if (toDelete.exists())
ops.append(UpdateOperation::DeleteOp(entry.path));
}
@@ -326,8 +324,9 @@ DownloadUpdateTask::processFileLists(NetJob *job,
// TODO: Let's not MD5sum a ton of files on the GUI thread. We should probably find a
// way to do this in the background.
QString fileMD5;
- QFile entryFile(entry.path);
- QFileInfo entryInfo(entry.path);
+ QString realEntryPath = PathCombine(MMC->root(), entry.path);
+ QFile entryFile(realEntryPath);
+ QFileInfo entryInfo(realEntryPath);
bool needs_upgrade = false;
if (!entryFile.exists())
@@ -339,49 +338,52 @@ DownloadUpdateTask::processFileLists(NetJob *job,
bool pass = true;
if (!entryInfo.isReadable())
{
- QLOG_ERROR() << "File " << entry.path << " is not readable.";
+ QLOG_ERROR() << "File " << realEntryPath << " is not readable.";
pass = false;
}
if (!entryInfo.isWritable())
{
- QLOG_ERROR() << "File " << entry.path << " is not writable.";
+ QLOG_ERROR() << "File " << realEntryPath << " is not writable.";
pass = false;
}
if (!entryFile.open(QFile::ReadOnly))
{
- QLOG_ERROR() << "File " << entry.path << " cannot be opened for reading.";
+ QLOG_ERROR() << "File " << realEntryPath << " cannot be opened for reading.";
pass = false;
}
if (!pass)
{
- QLOG_ERROR() << "CWD: " << QDir::currentPath();
+ QLOG_ERROR() << "ROOT: " << MMC->root();
ops.clear();
return false;
}
}
- QCryptographicHash hash(QCryptographicHash::Md5);
- auto foo = entryFile.readAll();
-
- hash.addData(foo);
- fileMD5 = hash.result().toHex();
- if ((fileMD5 != entry.md5))
+ if(!needs_upgrade)
{
- QLOG_DEBUG() << "MD5Sum does not match!";
- QLOG_DEBUG() << "Expected:'" << entry.md5 << "'";
- QLOG_DEBUG() << "Got: '" << fileMD5 << "'";
- needs_upgrade = true;
+ QCryptographicHash hash(QCryptographicHash::Md5);
+ auto foo = entryFile.readAll();
+
+ hash.addData(foo);
+ fileMD5 = hash.result().toHex();
+ if ((fileMD5 != entry.md5))
+ {
+ QLOG_DEBUG() << "MD5Sum does not match!";
+ QLOG_DEBUG() << "Expected:'" << entry.md5 << "'";
+ QLOG_DEBUG() << "Got: '" << fileMD5 << "'";
+ needs_upgrade = true;
+ }
}
// skip file. it doesn't need an upgrade.
if (!needs_upgrade)
{
- QLOG_DEBUG() << "File" << entry.path << " does not need updating.";
+ QLOG_DEBUG() << "File" << realEntryPath << " does not need updating.";
continue;
}
// yep. this file actually needs an upgrade. PROCEED.
- QLOG_DEBUG() << "Found file" << entry.path << " that needs updating.";
+ QLOG_DEBUG() << "Found file" << realEntryPath << " that needs updating.";
// if it's the updater we want to treat it separately
bool isUpdater = entry.path.endsWith("updater") || entry.path.endsWith("updater.exe");
diff --git a/main.cpp b/main.cpp
index 89eef72f..57131942 100644
--- a/main.cpp
+++ b/main.cpp
@@ -10,13 +10,7 @@ int main_gui(MultiMC &app)
mainWin.show();
mainWin.checkMigrateLegacyAssets();
mainWin.checkSetDefaultJava();
- auto exitCode = app.exec();
-
- // Update if necessary.
- if (!app.getExitUpdatePath().isEmpty())
- app.installUpdates(app.getExitUpdatePath(), false);
-
- return exitCode;
+ return app.exec();
}
int main(int argc, char *argv[])
diff --git a/mmc_updater/src/UpdateInstaller.cpp b/mmc_updater/src/UpdateInstaller.cpp
index 29cda0dc..aca23ff7 100644
--- a/mmc_updater/src/UpdateInstaller.cpp
+++ b/mmc_updater/src/UpdateInstaller.cpp
@@ -271,15 +271,15 @@ void UpdateInstaller::installFile(const UpdateScriptFile& file)
{
std::string sourceFile = file.source;
std::string destPath = file.dest;
- std::string target = file.linkTarget;
+ std::string absDestPath = FileUtils::makeAbsolute(destPath.c_str(), m_installDir.c_str());
- LOG(Info,"Installing file " + sourceFile + " to " + destPath);
+ LOG(Info,"Installing file " + sourceFile + " to " + absDestPath);
// backup the existing file if any
- backupFile(destPath);
+ backupFile(absDestPath);
// create the target directory if it does not exist
- std::string destDir = FileUtils::dirname(destPath.c_str());
+ std::string destDir = FileUtils::dirname(absDestPath.c_str());
if (!FileUtils::fileExists(destDir.c_str()))
{
LOG(Info,"Destination path missing. Creating " + destDir);
@@ -295,10 +295,10 @@ void UpdateInstaller::installFile(const UpdateScriptFile& file)
}
if(!m_dryRun)
{
- FileUtils::copyFile(sourceFile.c_str(),destPath.c_str());
+ FileUtils::copyFile(sourceFile.c_str(),absDestPath.c_str());
// set the permissions on the newly extracted file
- FileUtils::chmod(destPath.c_str(),file.permissions);
+ FileUtils::chmod(absDestPath.c_str(),file.permissions);
}
}
@@ -326,7 +326,7 @@ void UpdateInstaller::uninstallFiles()
std::vector<std::string>::const_iterator iter = m_script->filesToUninstall().begin();
for (;iter != m_script->filesToUninstall().end();iter++)
{
- std::string path = m_installDir + '/' + iter->c_str();
+ std::string path = FileUtils::makeAbsolute(iter->c_str(), m_installDir.c_str());
if (FileUtils::fileExists(path.c_str()))
{
LOG(Info,"Uninstalling " + path);
diff --git a/mmc_updater/src/UpdateScript.h b/mmc_updater/src/UpdateScript.h
index 5c863ff4..f55c7236 100644
--- a/mmc_updater/src/UpdateScript.h
+++ b/mmc_updater/src/UpdateScript.h
@@ -41,7 +41,6 @@ class UpdateScriptFile
std::string source;
/// The path to copy to.
std::string dest;
- std::string linkTarget;
/** The permissions for this file, specified
* using the standard Unix mode_t values.