diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionPage.java index 233a70231..bb328b7ea 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionPage.java @@ -33,6 +33,7 @@ import org.jackhuang.hmcl.event.EventBus; import org.jackhuang.hmcl.event.EventPriority; import org.jackhuang.hmcl.event.RefreshedVersionsEvent; import org.jackhuang.hmcl.game.GameRepository; +import org.jackhuang.hmcl.game.HMCLGameRepository; import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.SVG; @@ -164,9 +165,11 @@ public class VersionPage extends DecoratorAnimatedPage implements DecoratorPage } private void clearAssets() { - File baseDirectory = getProfile().getRepository().getBaseDirectory(); - FileUtils.deleteDirectoryQuietly(new File(baseDirectory, "assets")); - FileUtils.deleteDirectoryQuietly(new File(baseDirectory, "resources")); + HMCLGameRepository baseDirectory = getProfile().getRepository(); + FileUtils.deleteDirectoryQuietly(new File(baseDirectory.getBaseDirectory(), "assets")); + if (version.get() != null) { + FileUtils.deleteDirectoryQuietly(new File(baseDirectory.getRunDirectory(version.get().getVersion()), "resources")); + } } private void clearJunkFiles() { diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/game/DefaultGameRepository.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/game/DefaultGameRepository.java index 4aaa59775..115b79c33 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/game/DefaultGameRepository.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/game/DefaultGameRepository.java @@ -21,14 +21,7 @@ import com.google.gson.JsonParseException; import com.google.gson.reflect.TypeToken; import org.jackhuang.hmcl.download.MaintainTask; import org.jackhuang.hmcl.download.game.VersionJsonSaveTask; -import org.jackhuang.hmcl.event.Event; -import org.jackhuang.hmcl.event.EventBus; -import org.jackhuang.hmcl.event.GameJsonParseFailedEvent; -import org.jackhuang.hmcl.event.LoadedOneVersionEvent; -import org.jackhuang.hmcl.event.RefreshedVersionsEvent; -import org.jackhuang.hmcl.event.RefreshingVersionsEvent; -import org.jackhuang.hmcl.event.RemoveVersionEvent; -import org.jackhuang.hmcl.event.RenameVersionEvent; +import org.jackhuang.hmcl.event.*; import org.jackhuang.hmcl.game.tlauncher.TLauncherVersion; import org.jackhuang.hmcl.mod.ModManager; import org.jackhuang.hmcl.mod.ModpackConfiguration; @@ -45,13 +38,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.InvalidPathException; import java.nio.file.Path; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.TreeMap; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Stream; @@ -126,9 +113,12 @@ public class DefaultGameRepository implements GameRepository { @Override public File getRunDirectory(String id) { switch (getGameDirectoryType(id)) { - case VERSION_FOLDER: return getVersionRoot(id); - case ROOT_FOLDER: return getBaseDirectory(); - default: throw new IllegalStateException(); + case VERSION_FOLDER: + return getVersionRoot(id); + case ROOT_FOLDER: + return getBaseDirectory(); + default: + throw new IllegalStateException(); } } @@ -458,7 +448,7 @@ public class DefaultGameRepository implements GameRepository { return assetsDir; if (index.isVirtual()) { - Path resourcesDir = getBaseDirectory().toPath().resolve("resources"); + Path resourcesDir = getRunDirectory(version).toPath().resolve("resources"); int cnt = 0; int tot = index.getObjects().entrySet().size(); @@ -507,18 +497,20 @@ public class DefaultGameRepository implements GameRepository { /** * read modpack configuration for a version. + * * @param version version installed as modpack - * @param manifest type of ModpackConfiguration + * @param manifest type of ModpackConfiguration * @return modpack configuration object, or null if this version is not a modpack. * @throws VersionNotFoundException if version does not exist. - * @throws IOException if an i/o error occurs. + * @throws IOException if an i/o error occurs. */ @Nullable public ModpackConfiguration readModpackConfiguration(String version) throws IOException, VersionNotFoundException { if (!hasVersion(version)) throw new VersionNotFoundException(version); File file = getModpackConfiguration(version); if (!file.exists()) return null; - return JsonUtils.GSON.fromJson(FileUtils.readText(file), new TypeToken>(){}.getType()); + return JsonUtils.GSON.fromJson(FileUtils.readText(file), new TypeToken>() { + }.getType()); } public boolean isModpack(String version) {