From 29a6985a66bb3c5a3a44718f0181d13a1e0129b6 Mon Sep 17 00:00:00 2001 From: Kilobyte22 Date: Mon, 26 Oct 2020 00:14:16 +0100 Subject: [PATCH] Add init_only flag --- build.sbt | 4 ++-- .../at/chaosfield/packupdate/common/ComponentFlag.java | 10 ++++++++-- .../scala/at/chaosfield/packupdate/common/Update.scala | 6 ++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/build.sbt b/build.sbt index 7e758e6..b4d38f4 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,6 @@ name := "PackUpdate" -version := "3.0" +version := "3.1-rc1" scalaVersion := "2.12.8" @@ -11,4 +11,4 @@ libraryDependencies += "net.sourceforge.argparse4j" % "argparse4j" % "0.8.1" libraryDependencies += "org.json4s" % "json4s-jackson_2.12" % "3.6.7" libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "1.2.0" -Compile / mainClass := Some("at.chaosfield.packupdate.Main") \ No newline at end of file +Compile / mainClass := Some("at.chaosfield.packupdate.Main") diff --git a/src/main/java/at/chaosfield/packupdate/common/ComponentFlag.java b/src/main/java/at/chaosfield/packupdate/common/ComponentFlag.java index 485c4f1..115e08c 100644 --- a/src/main/java/at/chaosfield/packupdate/common/ComponentFlag.java +++ b/src/main/java/at/chaosfield/packupdate/common/ComponentFlag.java @@ -29,8 +29,9 @@ public enum ComponentFlag { * * It is undefined behaviour to set both this option and no_integrity (current implementation will ignore this option * in that case) + * + * Will be ignored if init_only is set. */ - // TODO: handle properly when upgrading from legacy ForceOverwrite("force_overwrite"), /** @@ -56,7 +57,12 @@ public enum ComponentFlag { * It is undefined behaviour to set both this option and force_overwrite (current implementation will ignore this option * in that case) */ - NoIntegrity("no_integrity") + NoIntegrity("no_integrity"), + + /** + * Only initializes the files. It will neither overwrite any existing files nor delete any files after removing the component. + */ + InitOnly("init_only") ; diff --git a/src/main/scala/at/chaosfield/packupdate/common/Update.scala b/src/main/scala/at/chaosfield/packupdate/common/Update.scala index 69d2004..e0366ee 100644 --- a/src/main/scala/at/chaosfield/packupdate/common/Update.scala +++ b/src/main/scala/at/chaosfield/packupdate/common/Update.scala @@ -67,7 +67,7 @@ object Update { runDownload(component, file, ui) ui.subStatusUpdate(Some("Extracting...")) configDir.mkdirs() - val files = FileManager.extractZip(file, configDir, component.hasFlag(ComponentFlag.ForceOverwrite), ui) + val files = FileManager.extractZip(file, configDir, !component.hasFlag(ComponentFlag.InitOnly) && component.hasFlag(ComponentFlag.ForceOverwrite), ui) file.deleteOnExit() ui.subStatusUpdate(None) files.map(f => InstalledFile(Util.absoluteToRelativePath(f._1, config.minecraftDir), f._2)).toArray @@ -255,7 +255,9 @@ object Update { } else { newComponent.flags.contains(ComponentFlag.Disabled) } - RemovedComponent(oldComponent).execute(config, ui) + if (!newComponent.flags.contains(ComponentFlag.InitOnly)) { + RemovedComponent(oldComponent).execute(config, ui) + } NewComponent(newComponent).executeInternal(config, disabled, ui) } }