summaryrefslogtreecommitdiffstats
path: root/backend/LegacyUpdate.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-08-14 08:13:41 +0200
committerPetr Mrázek <peterix@gmail.com>2013-08-14 08:13:41 +0200
commit77e80665422c4e97e2286418ab55e20c4030023b (patch)
treefe8b8d19de00e07f6bb8908a0be1973f9e93dd9a /backend/LegacyUpdate.cpp
parentff33d4a1a48abf1442cde77c2253f071d0870d50 (diff)
downloadMultiMC-77e80665422c4e97e2286418ab55e20c4030023b.tar
MultiMC-77e80665422c4e97e2286418ab55e20c4030023b.tar.gz
MultiMC-77e80665422c4e97e2286418ab55e20c4030023b.tar.lz
MultiMC-77e80665422c4e97e2286418ab55e20c4030023b.tar.xz
MultiMC-77e80665422c4e97e2286418ab55e20c4030023b.zip
Working on legacy support, incomplete.
Diffstat (limited to 'backend/LegacyUpdate.cpp')
-rw-r--r--backend/LegacyUpdate.cpp119
1 files changed, 119 insertions, 0 deletions
diff --git a/backend/LegacyUpdate.cpp b/backend/LegacyUpdate.cpp
index 8580a2f2..a748bad3 100644
--- a/backend/LegacyUpdate.cpp
+++ b/backend/LegacyUpdate.cpp
@@ -212,6 +212,13 @@ void LegacyUpdate::jarStart()
return;
}
+ // nuke the backup file, we are replacing the base jar anyway
+ QFile mc_backup(inst->mcBackup());
+ if (mc_backup.exists())
+ {
+ mc_backup.remove();
+ }
+
// Get a pointer to the version object that corresponds to the instance's version.
auto targetVersion = MinecraftVersionList::getMainList().findVersion(intended_version_id);
@@ -260,3 +267,115 @@ void LegacyUpdate::jarFailed()
// bad, bad
emitFailed("Failed to download the minecraft jar. Try again later.");
}
+
+void LegacyUpdate::ModTheJar()
+{
+ /*
+ LegacyInstance * inst = (LegacyInstance *) m_inst;
+ // Get the mod list
+ auto modList = inst->getJarModList();
+
+ QFileInfo mcBin(inst->binDir());
+ QFileInfo mcJar(inst->mcJar());
+ QFileInfo mcBackup(inst->mcBackup());
+
+ // Nothing to do if there are no jar mods to install, no backup and just the mc jar
+ if(mcJar.isFile() && !mcBackup.exists() && modList->empty())
+ {
+ inst->setShouldRebuild(false);
+ emitSucceeded();
+ return;
+ }
+
+ setStatus("Installing mods - backing up minecraft.jar...");
+ if (!mcBackup.exists() && !QFile::copy(mcJar.absoluteFilePath(), mcBackup.absoluteFilePath()) )
+ {
+ emitFailed("Failed to back up minecraft.jar");
+ return;
+ }
+
+ if (mcJar.isFile() && !QFile::remove(mcJar.absoluteFilePath()))
+ {
+ emitFailed("Failed to delete old minecraft.jar");
+ return;
+ }
+
+ setStatus("Installing mods - Opening minecraft.jar");
+
+ wxFFileOutputStream jarStream(mcJar.absoluteFilePath());
+ wxZipOutputStream zipOut(jarStream);
+
+ // Files already added to the jar.
+ // These files will be skipped.
+ QSet<QString> addedFiles;
+
+ // Modify the jar
+ setStatus("Installing mods - Adding mod files...");
+ for (ModList::const_reverse_iterator iter = modList->rbegin(); iter != modList->rend(); iter++)
+ {
+ wxFileName modFileName = iter->GetFileName();
+ setStatus("Installing mods - Adding " + modFileName.GetFullName());
+ if (iter->GetModType() == Mod::ModType::MOD_ZIPFILE)
+ {
+ wxFFileInputStream modStream(modFileName.GetFullPath());
+ wxZipInputStream zipStream(modStream);
+ std::unique_ptr<wxZipEntry> entry;
+ while (entry.reset(zipStream.GetNextEntry()), entry.get() != NULL)
+ {
+ if (entry->IsDir())
+ continue;
+
+ wxString name = entry->GetName();
+ if (addedFiles.count(name) == 0)
+ {
+ if (!zipOut.CopyEntry(entry.release(), zipStream))
+ break;
+ addedFiles.insert(name);
+ }
+ }
+ }
+ else
+ {
+ wxFileName destFileName = modFileName;
+ destFileName.MakeRelativeTo(m_inst->GetInstModsDir().GetFullPath());
+ wxString destFile = destFileName.GetFullPath();
+
+ if (addedFiles.count(destFile) == 0)
+ {
+ wxFFileInputStream input(modFileName.GetFullPath());
+ zipOut.PutNextEntry(destFile);
+ zipOut.Write(input);
+
+ addedFiles.insert(destFile);
+ }
+ }
+ }
+
+ {
+ wxFFileInputStream inStream(mcBackup.GetFullPath());
+ wxZipInputStream zipIn(inStream);
+
+ std::auto_ptr<wxZipEntry> entry;
+ while (entry.reset(zipIn.GetNextEntry()), entry.get() != NULL)
+ {
+ wxString name = entry->GetName();
+
+ if (!name.Matches("META-INF*") &&
+ addedFiles.count(name) == 0)
+ {
+ if (!zipOut.CopyEntry(entry.release(), zipIn))
+ break;
+ addedFiles.insert(name);
+ }
+ }
+ }
+
+ // Recompress the jar
+ TaskStep(); // STEP 3
+ SetStatus(_("Installing mods - Recompressing jar..."));
+
+ inst->SetNeedsRebuild(false);
+ inst->UpdateVersion(true);
+ return (ExitCode)1;
+ */
+} \ No newline at end of file