Fixed delete world button
This commit is contained in:
parent
7d78af5b4c
commit
f9fea9dfbf
|
@ -3,6 +3,7 @@ package net.PeytonPlayz585.io;
|
|||
import java.util.Collection;
|
||||
|
||||
import net.PeytonPlayz585.opengl.LWJGLMain;
|
||||
import net.minecraft.src.IProgressUpdate;
|
||||
|
||||
public class FileSystemUtils {
|
||||
|
||||
|
@ -21,4 +22,29 @@ public class FileSystemUtils {
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -5,5 +5,7 @@ public interface IProgressUpdate {
|
|||
|
||||
void displayLoadingString(String var1);
|
||||
|
||||
void displayLoadingString(String var1, String var2);
|
||||
|
||||
void setLoadingProgress(int var1);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
if(!this.mc.running) {
|
||||
if(!this.printText) {
|
||||
|
|
|
@ -67,10 +67,8 @@ public class World implements IBlockAccess {
|
|||
}
|
||||
|
||||
public static void deleteWorld(String var1) {
|
||||
String dir = "saves/" + var1;
|
||||
if(LWJGLMain.directoryExists(dir)) {
|
||||
FileSystemUtils.recursiveDeleteDirectory(dir);
|
||||
}
|
||||
String dir = var1 + "/";
|
||||
FileSystemUtils.recursiveDeleteDirectoryWithProgress(dir, "Deleting World!", "Please Wait...", Minecraft.getMinecraft().loadingScreen);
|
||||
}
|
||||
|
||||
public World(String var2) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user