Cleanup ZipLibrary class

This commit is contained in:
TfT_02 2013-11-01 16:28:42 +01:00
parent 408b8b2107
commit cdfd81a67a
2 changed files with 22 additions and 22 deletions

View File

@ -209,7 +209,7 @@ public class mcMMO extends JavaPlugin {
if (Config.getInstance().getBackupsEnabled()) { if (Config.getInstance().getBackupsEnabled()) {
// Remove other tasks BEFORE starting the Backup, or we just cancel it straight away. // Remove other tasks BEFORE starting the Backup, or we just cancel it straight away.
try { try {
ZipLibrary.mcMMObackup(); ZipLibrary.mcMMOBackup();
} }
catch (IOException e) { catch (IOException e) {
getLogger().severe(e.toString()); getLogger().severe(e.toString());

View File

@ -16,24 +16,24 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
public class ZipLibrary { public class ZipLibrary {
private static String BackupDirectory = mcMMO.getMainDirectory() + "backup" + File.separator; private static String BACKUP_DIRECTORY = mcMMO.getMainDirectory() + "backup" + File.separator;
private static File BackupDir = new File(BackupDirectory); private static File BACKUP_DIR = new File(BACKUP_DIRECTORY);
private static File FlatFileDirectory = new File(mcMMO.getFlatFileDirectory()); private static File FLAT_FILE_DIRECTORY = new File(mcMMO.getFlatFileDirectory());
private static File ModFileDirectory = new File(mcMMO.getModDirectory()); private static File MOD_FILE_DIRECTORY = new File(mcMMO.getModDirectory());
private static File ConfigFile = new File(mcMMO.getMainDirectory() + "config.yml"); private static File CONFIG_FILE = new File(mcMMO.getMainDirectory() + "config.yml");
private static File ExperienceFile = new File(mcMMO.getMainDirectory() + "experience.yml"); private static File EXPERIENCE_FILE = new File(mcMMO.getMainDirectory() + "experience.yml");
private static File TreasuresFile = new File(mcMMO.getMainDirectory() + "treasures.yml"); private static File TREASURE_FILE = new File(mcMMO.getMainDirectory() + "treasures.yml");
private static File AdvancedConfigFile = new File(mcMMO.getMainDirectory() + "advanced.yml"); private static File ADVANCED_FILE = new File(mcMMO.getMainDirectory() + "advanced.yml");
private static File RepairFile = new File(mcMMO.getMainDirectory() + "repair.vanilla.yml"); private static File REPAIR_FILE = new File(mcMMO.getMainDirectory() + "repair.vanilla.yml");
public static void mcMMObackup() throws IOException { public static void mcMMOBackup() throws IOException {
if (Config.getInstance().getUseMySQL()) { if (Config.getInstance().getUseMySQL()) {
mcMMO.p.debug("This server is running in SQL Mode."); mcMMO.p.debug("This server is running in SQL Mode.");
mcMMO.p.debug("Only config files will be backed up."); mcMMO.p.debug("Only config files will be backed up.");
} }
try { try {
if (BackupDir.mkdir()) { if (BACKUP_DIR.mkdir()) {
mcMMO.p.debug("Created Backup Directory."); mcMMO.p.debug("Created Backup Directory.");
} }
} }
@ -44,20 +44,20 @@ public class ZipLibrary {
// Generate the proper date for the backup filename // Generate the proper date for the backup filename
Date date = new Date(); Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
File fileZip = new File(BackupDirectory + File.separator + dateFormat.format(date) + ".zip"); File fileZip = new File(BACKUP_DIRECTORY + File.separator + dateFormat.format(date) + ".zip");
// Create the Source List, and add directories/etc to the file. // Create the Source List, and add directories/etc to the file.
List<File> sources = new ArrayList<File>(); List<File> sources = new ArrayList<File>();
sources.add(FlatFileDirectory); sources.add(FLAT_FILE_DIRECTORY);
sources.add(ConfigFile); sources.add(CONFIG_FILE);
sources.add(ExperienceFile); sources.add(EXPERIENCE_FILE);
sources.add(TreasuresFile); sources.add(TREASURE_FILE);
sources.add(AdvancedConfigFile); sources.add(ADVANCED_FILE);
sources.add(RepairFile); sources.add(REPAIR_FILE);
if (ModFileDirectory.exists()) { if (MOD_FILE_DIRECTORY.exists()) {
sources.add(ModFileDirectory); sources.add(MOD_FILE_DIRECTORY);
} }
// Actually do something // Actually do something
@ -121,7 +121,7 @@ public class ZipLibrary {
FileInputStream fis = new FileInputStream(file); FileInputStream fis = new FileInputStream(file);
byte[] buffer = new byte[4092]; byte[] buffer = new byte[4092];
int byteCount = 0; int byteCount;
while ((byteCount = fis.read(buffer)) != -1) { while ((byteCount = fis.read(buffer)) != -1) {
zos.write(buffer, 0, byteCount); zos.write(buffer, 0, byteCount);