Maybe break updater even more?
This commit is contained in:
parent
695ad1474e
commit
997be947c9
23
MultiMC.cpp
23
MultiMC.cpp
@ -32,6 +32,16 @@
|
|||||||
#include <logger/QsLogDest.h>
|
#include <logger/QsLogDest.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#ifdef WINDOWS
|
||||||
|
#define UPDATER_BIN "updater.exe"
|
||||||
|
#elif LINUX
|
||||||
|
#define UPDATER_BIN "updater"
|
||||||
|
#elif OSX
|
||||||
|
#define UPDATER_BIN "updater"
|
||||||
|
#else
|
||||||
|
#error Unsupported operating system.
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace Util::Commandline;
|
using namespace Util::Commandline;
|
||||||
|
|
||||||
MultiMC::MultiMC(int &argc, char **argv, const QString &root)
|
MultiMC::MultiMC(int &argc, char **argv, const QString &root)
|
||||||
@ -432,6 +442,7 @@ void MultiMC::initHttpMetaCache()
|
|||||||
m_metacache->addBase("libraries", QDir("libraries").absolutePath());
|
m_metacache->addBase("libraries", QDir("libraries").absolutePath());
|
||||||
m_metacache->addBase("minecraftforge", QDir("mods/minecraftforge").absolutePath());
|
m_metacache->addBase("minecraftforge", QDir("mods/minecraftforge").absolutePath());
|
||||||
m_metacache->addBase("skins", QDir("accounts/skins").absolutePath());
|
m_metacache->addBase("skins", QDir("accounts/skins").absolutePath());
|
||||||
|
m_metacache->addBase("root", QDir(".").absolutePath());
|
||||||
m_metacache->Load();
|
m_metacache->Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -480,16 +491,6 @@ std::shared_ptr<JavaVersionList> MultiMC::javalist()
|
|||||||
return m_javalist;
|
return m_javalist;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WINDOWS
|
|
||||||
#define UPDATER_BIN "updater.exe"
|
|
||||||
#elif LINUX
|
|
||||||
#define UPDATER_BIN "updater"
|
|
||||||
#elif OSX
|
|
||||||
#define UPDATER_BIN "updater"
|
|
||||||
#else
|
|
||||||
#error Unsupported operating system.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void MultiMC::installUpdates(const QString &updateFilesDir, bool restartOnFinish)
|
void MultiMC::installUpdates(const QString &updateFilesDir, bool restartOnFinish)
|
||||||
{
|
{
|
||||||
QLOG_INFO() << "Installing updates.";
|
QLOG_INFO() << "Installing updates.";
|
||||||
@ -527,8 +528,8 @@ void MultiMC::installUpdates(const QString &updateFilesDir, bool restartOnFinish
|
|||||||
args << "--finish-cmd" << finishCmd;
|
args << "--finish-cmd" << finishCmd;
|
||||||
|
|
||||||
QLOG_INFO() << "Running updater with command" << updaterBinary << args.join(" ");
|
QLOG_INFO() << "Running updater with command" << updaterBinary << args.join(" ");
|
||||||
|
QFile::setPermissions(updaterBinary, (QFileDevice::Permission) 0x7755);
|
||||||
|
|
||||||
QFile::setPermissions(updaterBinary, (QFileDevice::Permission) 0755);
|
|
||||||
if(!QProcess::startDetached(updaterBinary, args))
|
if(!QProcess::startDetached(updaterBinary, args))
|
||||||
{
|
{
|
||||||
QLOG_ERROR() << "Failed to start the updater process!";
|
QLOG_ERROR() << "Failed to start the updater process!";
|
||||||
|
@ -213,12 +213,11 @@ bool DownloadUpdateTask::parseVersionInfo(const QByteArray &data, VersionFileLis
|
|||||||
// basically, anything that isn't in the .app folder is ignored.
|
// basically, anything that isn't in the .app folder is ignored.
|
||||||
// everything else is changed so the code that processes the files actually finds
|
// everything else is changed so the code that processes the files actually finds
|
||||||
// them and puts the replacements in the right spots.
|
// them and puts the replacements in the right spots.
|
||||||
if(!fixPathForOSX(file_path))
|
if (!fixPathForOSX(file_path))
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
VersionFileEntry file{
|
VersionFileEntry file{file_path, fileObj.value("Perms").toVariant().toInt(),
|
||||||
file_path , fileObj.value("Perms").toVariant().toInt(),
|
FileSourceList(), fileObj.value("MD5").toString(), };
|
||||||
FileSourceList(), fileObj.value("MD5").toString(), };
|
|
||||||
QLOG_DEBUG() << "File" << file.path << "with perms" << file.mode;
|
QLOG_DEBUG() << "File" << file.path << "with perms" << file.mode;
|
||||||
|
|
||||||
QJsonArray sourceArray = fileObj.value("Sources").toArray();
|
QJsonArray sourceArray = fileObj.value("Sources").toArray();
|
||||||
@ -234,9 +233,9 @@ bool DownloadUpdateTask::parseVersionInfo(const QByteArray &data, VersionFileLis
|
|||||||
}
|
}
|
||||||
else if (type == "httpc")
|
else if (type == "httpc")
|
||||||
{
|
{
|
||||||
file.sources.append(FileSource("httpc",
|
file.sources.append(
|
||||||
fixPathForTests(sourceObj.value("Url").toString()),
|
FileSource("httpc", fixPathForTests(sourceObj.value("Url").toString()),
|
||||||
sourceObj.value("CompressionType").toString()));
|
sourceObj.value("CompressionType").toString()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -401,25 +400,23 @@ DownloadUpdateTask::processFileLists(NetJob *job,
|
|||||||
QString dlPath =
|
QString dlPath =
|
||||||
PathCombine(m_updateFilesDir.path(), QString(entry.path).replace("/", "_"));
|
PathCombine(m_updateFilesDir.path(), QString(entry.path).replace("/", "_"));
|
||||||
|
|
||||||
if (job)
|
if (isUpdater)
|
||||||
|
{
|
||||||
|
auto cache_entry = MMC->metacache()->resolveEntry("root", entry.path);
|
||||||
|
QLOG_DEBUG() << "Updater will be in " << cache_entry->getFullPath();
|
||||||
|
if(cache_entry->stale)
|
||||||
|
{
|
||||||
|
auto download = CacheDownload::make(QUrl(source.url), cache_entry);
|
||||||
|
job->addNetAction(download);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// We need to download the file to the updatefiles folder and add a task
|
// We need to download the file to the updatefiles folder and add a task
|
||||||
// to copy it to its install path.
|
// to copy it to its install path.
|
||||||
auto download = MD5EtagDownload::make(source.url, dlPath);
|
auto download = MD5EtagDownload::make(source.url, dlPath);
|
||||||
download->m_expected_md5 = entry.md5;
|
download->m_expected_md5 = entry.md5;
|
||||||
job->addNetAction(download);
|
job->addNetAction(download);
|
||||||
|
|
||||||
if (isUpdater)
|
|
||||||
{
|
|
||||||
download->setProperty("finalPath", entry.path);
|
|
||||||
download->setProperty("finalPerms", entry.mode);
|
|
||||||
connect(download.get(), &MD5EtagDownload::succeeded, this, &DownloadUpdateTask::directDeployFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isUpdater)
|
|
||||||
{
|
|
||||||
// Now add a copy operation to our operations list to install the file.
|
|
||||||
ops.append(UpdateOperation::CopyOp(dlPath, entry.path, entry.mode));
|
ops.append(UpdateOperation::CopyOp(dlPath, entry.path, entry.mode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -503,7 +500,7 @@ bool DownloadUpdateTask::writeInstallScript(UpdateOperationList &opsList, QStrin
|
|||||||
|
|
||||||
QString DownloadUpdateTask::fixPathForTests(const QString &path)
|
QString DownloadUpdateTask::fixPathForTests(const QString &path)
|
||||||
{
|
{
|
||||||
if(path.startsWith("$PWD"))
|
if (path.startsWith("$PWD"))
|
||||||
{
|
{
|
||||||
QString foo = path;
|
QString foo = path;
|
||||||
foo.replace("$PWD", qApp->applicationDirPath());
|
foo.replace("$PWD", qApp->applicationDirPath());
|
||||||
@ -514,10 +511,10 @@ QString DownloadUpdateTask::fixPathForTests(const QString &path)
|
|||||||
|
|
||||||
bool DownloadUpdateTask::fixPathForOSX(QString &path)
|
bool DownloadUpdateTask::fixPathForOSX(QString &path)
|
||||||
{
|
{
|
||||||
if(path.startsWith("MultiMC.app/"))
|
if (path.startsWith("MultiMC.app/"))
|
||||||
{
|
{
|
||||||
// remove the prefix and add a new, more appropriate one.
|
// remove the prefix and add a new, more appropriate one.
|
||||||
path.remove(0,12);
|
path.remove(0, 12);
|
||||||
path = QString("../../") + path;
|
path = QString("../../") + path;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -528,7 +525,6 @@ bool DownloadUpdateTask::fixPathForOSX(QString &path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DownloadUpdateTask::fileDownloadFinished()
|
void DownloadUpdateTask::fileDownloadFinished()
|
||||||
{
|
{
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
@ -546,26 +542,6 @@ void DownloadUpdateTask::fileDownloadProgressChanged(qint64 current, qint64 tota
|
|||||||
setProgress((int)(((float)current / (float)total) * 100));
|
setProgress((int)(((float)current / (float)total) * 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadUpdateTask::directDeployFile(const int index)
|
|
||||||
{
|
|
||||||
Md5EtagDownloadPtr download = std::dynamic_pointer_cast<MD5EtagDownload>(m_filesNetJob->operator[](index));
|
|
||||||
const QString finalPath = download->property("finalPath").toString();
|
|
||||||
bool ok = true;
|
|
||||||
int finalMode = download->property("finalPerms").toInt(&ok);
|
|
||||||
if(!ok)
|
|
||||||
finalMode = 0755;
|
|
||||||
QLOG_INFO() << "Replacing" << finalPath << "with" << download->m_output_file.fileName();
|
|
||||||
if (QFile::remove(finalPath))
|
|
||||||
{
|
|
||||||
if (download->m_output_file.copy(finalPath))
|
|
||||||
{
|
|
||||||
QFile::setPermissions(finalPath, (QFileDevice::Permission) finalMode);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
emitFailed("Couldn't copy updater files");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DownloadUpdateTask::updateFilesDir()
|
QString DownloadUpdateTask::updateFilesDir()
|
||||||
{
|
{
|
||||||
return m_updateFilesDir.path();
|
return m_updateFilesDir.path();
|
||||||
|
@ -221,7 +221,5 @@ protected slots:
|
|||||||
void fileDownloadFinished();
|
void fileDownloadFinished();
|
||||||
void fileDownloadFailed();
|
void fileDownloadFailed();
|
||||||
void fileDownloadProgressChanged(qint64 current, qint64 total);
|
void fileDownloadProgressChanged(qint64 current, qint64 total);
|
||||||
|
|
||||||
void directDeployFile(const int index);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user