Optimize texture pack listing

This commit is contained in:
ayunami2000 2024-12-13 20:31:35 -05:00
parent 3459233886
commit 1e4d74a48c
2 changed files with 32 additions and 15 deletions

View File

@ -3,7 +3,6 @@ package net.minecraft.src;
import net.lax1dude.eaglercraft.EPKDecompiler; import net.lax1dude.eaglercraft.EPKDecompiler;
import net.lax1dude.eaglercraft.EaglerAdapter; import net.lax1dude.eaglercraft.EaglerAdapter;
import net.lax1dude.eaglercraft.EaglerInputStream; import net.lax1dude.eaglercraft.EaglerInputStream;
import net.lax1dude.eaglercraft.EaglerMisc;
import net.lax1dude.eaglercraft.adapter.teavm.vfs.VFile; import net.lax1dude.eaglercraft.adapter.teavm.vfs.VFile;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -28,6 +27,8 @@ public class GuiTexturePacks extends GuiScreen {
private GuiTexturePackSlot guiTexturePackSlot; private GuiTexturePackSlot guiTexturePackSlot;
private GameSettings field_96146_n; private GameSettings field_96146_n;
protected static final VFile texturePackListFile = new VFile("__LIST__");
public GuiTexturePacks(GuiScreen par1, GameSettings par2) { public GuiTexturePacks(GuiScreen par1, GameSettings par2) {
this.guiScreen = par1; this.guiScreen = par1;
this.field_96146_n = par2; this.field_96146_n = par2;
@ -107,6 +108,11 @@ public class GuiTexturePacks extends GuiScreen {
isSelectingPack = false; isSelectingPack = false;
String name = EaglerAdapter.getFileChooserResultName(); String name = EaglerAdapter.getFileChooserResultName();
String safeName = name.replaceAll("[^A-Za-z0-9_]", "_"); String safeName = name.replaceAll("[^A-Za-z0-9_]", "_");
if (texturePackListFile.exists()) {
texturePackListFile.setAllChars(texturePackListFile.getAllChars() + "\n" + safeName);
} else {
texturePackListFile.setAllChars(safeName);
}
try { try {
if (name.toLowerCase().endsWith(".zip")) { if (name.toLowerCase().endsWith(".zip")) {
try(ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(EaglerAdapter.getFileChooserResult()))) { try(ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(EaglerAdapter.getFileChooserResult()))) {
@ -138,10 +144,19 @@ public class GuiTexturePacks extends GuiScreen {
List var3 = this.mc.texturePackList.availableTexturePacks(); List var3 = this.mc.texturePackList.availableTexturePacks();
if (par1) { if (par1) {
new VFile(fileLocation, ((ITexturePack) var3.get(par2)).getTexturePackFileName()).deleteAll();
this.mc.texturePackList.setTexturePack((ITexturePack) var3.get(0)); this.mc.texturePackList.setTexturePack((ITexturePack) var3.get(0));
this.mc.renderEngine.refreshTextures(); this.mc.renderEngine.refreshTextures();
this.mc.renderGlobal.loadRenderers(); this.mc.renderGlobal.loadRenderers();
String safeName = ((ITexturePack) var3.get(par2)).getTexturePackFileName();
new VFile(fileLocation, safeName).deleteAll();
if (texturePackListFile.exists()) {
String res = texturePackListFile.getAllChars().replaceFirst(safeName, "").replace("\n\n", "\n");
if (res.isEmpty()) {
texturePackListFile.delete();
} else {
texturePackListFile.setAllChars(res);
}
}
} else { } else {
try { try {
this.mc.texturePackList.setTexturePack((ITexturePack) var3.get(par2)); this.mc.texturePackList.setTexturePack((ITexturePack) var3.get(par2));
@ -152,7 +167,16 @@ public class GuiTexturePacks extends GuiScreen {
this.mc.texturePackList.setTexturePack((ITexturePack) var3.get(0)); this.mc.texturePackList.setTexturePack((ITexturePack) var3.get(0));
this.mc.renderEngine.refreshTextures(); this.mc.renderEngine.refreshTextures();
this.mc.renderGlobal.loadRenderers(); this.mc.renderGlobal.loadRenderers();
new VFile(fileLocation, ((ITexturePack) var3.get(par2)).getTexturePackFileName()).deleteAll(); String safeName = ((ITexturePack) var3.get(par2)).getTexturePackFileName();
new VFile(fileLocation, safeName).deleteAll();
if (texturePackListFile.exists()) {
String res = texturePackListFile.getAllChars().replaceFirst(safeName, "").replace("\n\n", "\n");
if (res.isEmpty()) {
texturePackListFile.delete();
} else {
texturePackListFile.setAllChars(res);
}
}
} }
} }
} }

View File

@ -53,6 +53,7 @@ public class TexturePackList
this.mc = par2Minecraft; this.mc = par2Minecraft;
this.texturePackDir = new VFile("texturepacks"); this.texturePackDir = new VFile("texturepacks");
this.mpTexturePackFolder = new VFile("texturepacks-mp-cache"); this.mpTexturePackFolder = new VFile("texturepacks-mp-cache");
this.mpTexturePackFolder.deleteAll();
this.updateAvaliableTexturePacks(); this.updateAvaliableTexturePacks();
} }
@ -204,20 +205,12 @@ public class TexturePackList
*/ */
private List getTexturePackDirContents() private List getTexturePackDirContents()
{ {
// TODO: MAKE THIS MORE EFFICIENT!! THIS IS A TEMPORARY FIX BC IM TIRED if (!GuiTexturePacks.texturePackListFile.exists()) return Collections.emptyList();
List<String> strings = this.texturePackDir.list(); String[] lines = GuiTexturePacks.texturePackListFile.getAllLines();
List<String> strings2 = new ArrayList<>();
List<VFile> files = new ArrayList<>(); List<VFile> files = new ArrayList<>();
for (String name : strings) { for (String line : lines) {
name = name.substring(this.texturePackDir.getPath().length() + 1); files.add(new VFile(this.texturePackDir, line));
name = name.substring(0, name.indexOf('/'));
name = this.texturePackDir.getPath() + "/" + name;
if (strings2.contains(name)) continue;
strings2.add(name);
files.add(new VFile(name));
} }
strings2.clear();
strings.clear();
return files; return files;
} }