Fix #3026: resources 目录应该跟随游戏目录 (#3027)

This commit is contained in:
Burning_TNT 2024-05-31 22:48:19 +08:00 committed by GitHub
parent 6b78f56298
commit 35ce95857a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 25 deletions

View File

@ -33,6 +33,7 @@ import org.jackhuang.hmcl.event.EventBus;
import org.jackhuang.hmcl.event.EventPriority; import org.jackhuang.hmcl.event.EventPriority;
import org.jackhuang.hmcl.event.RefreshedVersionsEvent; import org.jackhuang.hmcl.event.RefreshedVersionsEvent;
import org.jackhuang.hmcl.game.GameRepository; import org.jackhuang.hmcl.game.GameRepository;
import org.jackhuang.hmcl.game.HMCLGameRepository;
import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.setting.Profile;
import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.SVG; import org.jackhuang.hmcl.ui.SVG;
@ -164,9 +165,11 @@ public class VersionPage extends DecoratorAnimatedPage implements DecoratorPage
} }
private void clearAssets() { private void clearAssets() {
File baseDirectory = getProfile().getRepository().getBaseDirectory(); HMCLGameRepository baseDirectory = getProfile().getRepository();
FileUtils.deleteDirectoryQuietly(new File(baseDirectory, "assets")); FileUtils.deleteDirectoryQuietly(new File(baseDirectory.getBaseDirectory(), "assets"));
FileUtils.deleteDirectoryQuietly(new File(baseDirectory, "resources")); if (version.get() != null) {
FileUtils.deleteDirectoryQuietly(new File(baseDirectory.getRunDirectory(version.get().getVersion()), "resources"));
}
} }
private void clearJunkFiles() { private void clearJunkFiles() {

View File

@ -21,14 +21,7 @@ import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import org.jackhuang.hmcl.download.MaintainTask; import org.jackhuang.hmcl.download.MaintainTask;
import org.jackhuang.hmcl.download.game.VersionJsonSaveTask; import org.jackhuang.hmcl.download.game.VersionJsonSaveTask;
import org.jackhuang.hmcl.event.Event; import org.jackhuang.hmcl.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.game.tlauncher.TLauncherVersion; import org.jackhuang.hmcl.game.tlauncher.TLauncherVersion;
import org.jackhuang.hmcl.mod.ModManager; import org.jackhuang.hmcl.mod.ModManager;
import org.jackhuang.hmcl.mod.ModpackConfiguration; import org.jackhuang.hmcl.mod.ModpackConfiguration;
@ -45,13 +38,7 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.InvalidPathException; import java.nio.file.InvalidPathException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays; import java.util.*;
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.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -126,9 +113,12 @@ public class DefaultGameRepository implements GameRepository {
@Override @Override
public File getRunDirectory(String id) { public File getRunDirectory(String id) {
switch (getGameDirectoryType(id)) { switch (getGameDirectoryType(id)) {
case VERSION_FOLDER: return getVersionRoot(id); case VERSION_FOLDER:
case ROOT_FOLDER: return getBaseDirectory(); return getVersionRoot(id);
default: throw new IllegalStateException(); case ROOT_FOLDER:
return getBaseDirectory();
default:
throw new IllegalStateException();
} }
} }
@ -458,7 +448,7 @@ public class DefaultGameRepository implements GameRepository {
return assetsDir; return assetsDir;
if (index.isVirtual()) { if (index.isVirtual()) {
Path resourcesDir = getBaseDirectory().toPath().resolve("resources"); Path resourcesDir = getRunDirectory(version).toPath().resolve("resources");
int cnt = 0; int cnt = 0;
int tot = index.getObjects().entrySet().size(); int tot = index.getObjects().entrySet().size();
@ -507,6 +497,7 @@ public class DefaultGameRepository implements GameRepository {
/** /**
* read modpack configuration for a version. * read modpack configuration for a version.
*
* @param version version installed as modpack * @param version version installed as modpack
* @param <M> manifest type of ModpackConfiguration * @param <M> manifest type of ModpackConfiguration
* @return modpack configuration object, or null if this version is not a modpack. * @return modpack configuration object, or null if this version is not a modpack.
@ -518,7 +509,8 @@ public class DefaultGameRepository implements GameRepository {
if (!hasVersion(version)) throw new VersionNotFoundException(version); if (!hasVersion(version)) throw new VersionNotFoundException(version);
File file = getModpackConfiguration(version); File file = getModpackConfiguration(version);
if (!file.exists()) return null; if (!file.exists()) return null;
return JsonUtils.GSON.fromJson(FileUtils.readText(file), new TypeToken<ModpackConfiguration<M>>(){}.getType()); return JsonUtils.GSON.fromJson(FileUtils.readText(file), new TypeToken<ModpackConfiguration<M>>() {
}.getType());
} }
public boolean isModpack(String version) { public boolean isModpack(String version) {