Startup warning when War files take over 100MB

Temp files tend to accumulate rapidly if some zonemakers are
particularly trigger happy with /savezone. Added a warning. Should
probably add a real limit on number of oldversions that can be saved.
This commit is contained in:
taoneill 2012-06-20 22:56:08 -04:00
parent 7a90119c97
commit 4835d0f37d
2 changed files with 42 additions and 0 deletions

View File

@ -52,6 +52,7 @@ import com.tommytony.war.structure.HubLobbyMaterials;
import com.tommytony.war.structure.ZoneLobby;
import com.tommytony.war.utility.ChatFixUtil;
import com.tommytony.war.utility.PlayerState;
import com.tommytony.war.utility.SizeCounter;
import com.tommytony.war.utility.WarLogFormatter;
/**
@ -264,6 +265,14 @@ public class War extends JavaPlugin {
} catch (IOException e) {
this.getLogger().log(Level.WARNING, "Failed to create War log file");
}
// Size check
long datSize = SizeCounter.getFileOrDirectorySize(new File(this.getDataFolder() + "/dat/")) / 1024 / 1024;
long tempSize = SizeCounter.getFileOrDirectorySize(new File(this.getDataFolder() + "/temp/")) / 1024 / 1024;
if (datSize + tempSize > 100) {
this.log("War data files are taking " + datSize + "MB and its temp files " + tempSize + "MB. Consider permanently deleting old warzone versions and backups in /plugins/War/temp/.", Level.WARNING);
}
this.log("War v" + this.desc.getVersion() + " is on.", Level.INFO);
}

View File

@ -0,0 +1,33 @@
package com.tommytony.war.utility;
import java.io.File;
import java.io.FileFilter;
// Credit: http://sanjaal.com/java/48/java-utilities/calculating-folder-size/
public class SizeCounter implements FileFilter
{
private long total = 0;
public SizeCounter(){};
public boolean accept(File pathname) {
if (pathname.isFile()) {
total += pathname.length();
} else {
pathname.listFiles(this);
}
return false;
}
public long getTotal()
{
return total;
}
public static long getFileOrDirectorySize(File file) {
SizeCounter counter = new SizeCounter();
file.listFiles(counter);
return counter.getTotal();
}
}