diff options
author | Petr Mrázek <peterix@gmail.com> | 2013-09-18 00:08:42 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2013-09-18 00:08:42 +0200 |
commit | 930b07afd4229e952d0cd47ca62cd94235499a0c (patch) | |
tree | 34cd74c3652da4b3ad0fd008faa2ab67adb4901f /logic/OneSixUpdate.cpp | |
parent | 5cd3420c46e0b54f1479ddf720a8c9131c460a5e (diff) | |
parent | b979d0ce5da515793a02802a6421ef607a498323 (diff) | |
download | MultiMC-930b07afd4229e952d0cd47ca62cd94235499a0c.tar MultiMC-930b07afd4229e952d0cd47ca62cd94235499a0c.tar.gz MultiMC-930b07afd4229e952d0cd47ca62cd94235499a0c.tar.lz MultiMC-930b07afd4229e952d0cd47ca62cd94235499a0c.tar.xz MultiMC-930b07afd4229e952d0cd47ca62cd94235499a0c.zip |
Merge branch 'feature_library_model' into develop
Diffstat (limited to 'logic/OneSixUpdate.cpp')
-rw-r--r-- | logic/OneSixUpdate.cpp | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp index ce71bde0..298ad28a 100644 --- a/logic/OneSixUpdate.cpp +++ b/logic/OneSixUpdate.cpp @@ -28,6 +28,7 @@ #include "lists/MinecraftVersionList.h" #include "VersionFactory.h" #include "OneSixVersion.h" +#include "OneSixLibrary.h" #include "OneSixInstance.h" #include "pathutils.h" @@ -48,7 +49,7 @@ void OneSixUpdate::executeTask() } // Get a pointer to the version object that corresponds to the instance's version. - targetVersion = MinecraftVersionList::getMainList().findVersion(intendedVersion).dynamicCast<MinecraftVersion>(); + targetVersion = MMC->minecraftlist()->findVersion(intendedVersion).dynamicCast<MinecraftVersion>(); if(targetVersion == nullptr) { // don't do anything if it was invalid @@ -71,44 +72,59 @@ void OneSixUpdate::versionFileStart() setStatus("Getting the version files from Mojang."); QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/"); - urlstr += targetVersion->descriptor + "/" + targetVersion->descriptor + ".json"; + urlstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".json"; auto job = new DownloadJob("Version index"); job->add(QUrl(urlstr)); specificVersionDownloadJob.reset(job); connect(specificVersionDownloadJob.data(), SIGNAL(succeeded()), SLOT(versionFileFinished())); connect(specificVersionDownloadJob.data(), SIGNAL(failed()), SLOT(versionFileFailed())); - connect(specificVersionDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); + connect(specificVersionDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); specificVersionDownloadJob->start(); } void OneSixUpdate::versionFileFinished() { DownloadPtr DlJob = specificVersionDownloadJob->first(); + OneSixInstance * inst = (OneSixInstance *) m_inst; - QString version_id = targetVersion->descriptor; + QString version_id = targetVersion->descriptor(); QString inst_dir = m_inst->instanceRoot(); // save the version file in $instanceId/version.json { QString version1 = PathCombine(inst_dir, "/version.json"); ensureFilePathExists(version1); // FIXME: detect errors here, download to a temp file, swap - QFile vfile1 (version1); - vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly ); - vfile1.write(DlJob.dynamicCast<ByteArrayDownload>()->m_data); - vfile1.close(); + QSaveFile vfile1 (version1); + if(!vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly )) + { + emitFailed("Can't open " + version1 + " for writing."); + return; + } + auto data = DlJob.dynamicCast<ByteArrayDownload>()->m_data; + qint64 actual = 0; + if((actual = vfile1.write(data)) != data.size()) + { + emitFailed("Failed to write into " + version1 + ". Written " + actual + " out of " + data.size() + '.'); + return; + } + if(!vfile1.commit()) + { + emitFailed("Can't commit changes to " + version1); + return; + } } // the version is downloaded safely. update is 'done' at this point m_inst->setShouldUpdate(false); - // save the version file in versions/$version/$version.json - /* - //QString version2 = QString("versions/") + version_id + "/" + version_id + ".json"; - //ensurePathExists(version2); - //QFile vfile2 (version2); - //vfile2.open(QIODevice::Truncate | QIODevice::WriteOnly ); - //vfile2.write(DlJob->m_data); - //vfile2.close(); - */ + + // delete any custom version inside the instance (it's no longer relevant, we did an update) + QString custom = PathCombine(inst_dir, "/custom.json"); + QFile finfo(custom); + if(finfo.exists()) + { + finfo.remove(); + } + inst->reloadFullVersion(); jarlibStart(); } @@ -155,7 +171,7 @@ void OneSixUpdate::jarlibStart() } connect(jarlibDownloadJob.data(), SIGNAL(succeeded()), SLOT(jarlibFinished())); connect(jarlibDownloadJob.data(), SIGNAL(failed()), SLOT(jarlibFailed())); - connect(jarlibDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); + connect(jarlibDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); jarlibDownloadJob->start(); } |