Fixed delete world button

This commit is contained in:
PeytonPlayz595 2024-02-03 20:34:15 -05:00 committed by GitHub
parent 7d78af5b4c
commit f9fea9dfbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 47 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package net.PeytonPlayz585.io;
import java.util.Collection; import java.util.Collection;
import net.PeytonPlayz585.opengl.LWJGLMain; import net.PeytonPlayz585.opengl.LWJGLMain;
import net.minecraft.src.IProgressUpdate;
public class FileSystemUtils { public class FileSystemUtils {
@ -21,4 +22,29 @@ public class FileSystemUtils {
LWJGLMain.deleteFile(dir); LWJGLMain.deleteFile(dir);
} }
public static void recursiveDeleteDirectoryWithProgress(String dir, String title, String subText, IProgressUpdate progress) {
progress.displayLoadingString(title, "(please wait)");
Collection<LWJGLMain.FileEntry> lst = LWJGLMain.listFiles(dir, true, true);
int totalDeleted = 0;
int lastTotalDeleted = 0;
for(LWJGLMain.FileEntry t : lst) {
if(!t.isDirectory) {
LWJGLMain.deleteFile(t.path);
++totalDeleted;
if(totalDeleted - lastTotalDeleted >= 10) {
lastTotalDeleted = totalDeleted;
int percentage = (int) Math.ceil(((double) totalDeleted / lst.size()) * 100);
progress.displayLoadingString(title, subText.replace("%i", "" + totalDeleted));
progress.setLoadingProgress(percentage);
}
}
}
for(LWJGLMain.FileEntry t : lst) {
if(t.isDirectory) {
LWJGLMain.deleteFile(t.path);
}
}
LWJGLMain.deleteFile(dir);
}
} }

View File

@ -5,5 +5,7 @@ public interface IProgressUpdate {
void displayLoadingString(String var1); void displayLoadingString(String var1);
void displayLoadingString(String var1, String var2);
void setLoadingProgress(int var1); void setLoadingProgress(int var1);
} }

View File

@ -57,6 +57,23 @@ public class LoadingScreenRenderer implements IProgressUpdate {
} }
} }
public void displayLoadingString(String s, String s1) {
if (!mc.running) {
if (printText) {
return;
} else {
throw new MinecraftError();
}
} else {
systemTime = 0L;
currentlyDisplayedProgress = s1;
currentlyDisplayedText = s;
setLoadingProgress(-1);
systemTime = 0L;
return;
}
}
public void setLoadingProgress(int var1) { public void setLoadingProgress(int var1) {
if(!this.mc.running) { if(!this.mc.running) {
if(!this.printText) { if(!this.printText) {

View File

@ -67,10 +67,8 @@ public class World implements IBlockAccess {
} }
public static void deleteWorld(String var1) { public static void deleteWorld(String var1) {
String dir = "saves/" + var1; String dir = var1 + "/";
if(LWJGLMain.directoryExists(dir)) { FileSystemUtils.recursiveDeleteDirectoryWithProgress(dir, "Deleting World!", "Please Wait...", Minecraft.getMinecraft().loadingScreen);
FileSystemUtils.recursiveDeleteDirectory(dir);
}
} }
public World(String var2) { public World(String var2) {