package net.minecraft.src;

import net.lax1dude.eaglercraft.internal.vfs2.VFile2;

import java.util.ArrayList;
import java.util.List;

public class SaveFormatOld implements ISaveFormat {
	protected final VFile2 worldFile;
	private String filename = null;

	public SaveFormatOld(VFile2 var1) {
		if(!var1.exists()) {
			//var1.mkdirs();
		}

		this.worldFile = var1;
	}

	public void setFilename(String name){
		this.filename = name;
	}

	public String formatName() {
		return "Old Format";
	}

	public List getWorldList() {
		ArrayList var1 = new ArrayList();

		for(int var2 = 0; var2 < 5; ++var2) {
			String var3 = "World" + (var2 + 1);
			WorldInfo var4 = this.getWorldInfoForWorld(var3);
			if(var4 != null) {
				var1.add(new SaveFormatComparator(var3, "", var4.getLastTimePlayed(), var4.getSizeOnDisk(), false));
			}
		}

		return var1;
	}

	public void flushCache() {
	}

	public WorldInfo getWorldInfoForWorld(String var1) {
		VFile2 var2 = new VFile2(this.worldFile + "/" + filename, var1);
		System.out.println(var2.getPath());
        if (var2 != null) {
            try {
                NBTTagCompound var4 = CompressedStreamTools.readCompressed(var2.getInputStream());
                NBTTagCompound var5 = var4.getCompoundTag("Data");
                return new WorldInfo(var5);
            } catch (Exception var6) {
                var6.printStackTrace();
            }
        }

        return null;
    }

	public void renameWorldData(String var1, String var2) {
		VFile2 var3 = new VFile2(this.worldFile, var1);
		if(var3.exists()) {
			VFile2 var4 = new VFile2(var3, "level.dat");
			if(var4.exists()) {
				try {
					NBTTagCompound var5 = CompressedStreamTools.readCompressed(var4.getInputStream());
					NBTTagCompound var6 = var5.getCompoundTag("Data");
					var6.setString("LevelName", var2);
					CompressedStreamTools.writeGzippedCompoundToOutputStream(var5, var4.getOutputStream());
				} catch (Exception var7) {
					var7.printStackTrace();
				}
			}

		}
	}

	public void deleteWorldByDirectory(String var1) {
		VFile2 var2 = new VFile2(this.worldFile, var1);
		if(var2.exists()) {
			//func_22179_a(var2.listFiles());
			var2.delete();
		}
	}

	protected static void func_22179_a(VFile2[] var0) {
		for(int var1 = 0; var1 < var0.length; ++var1) {
//			if(var0[var1].isDirectory()) {
//				func_22179_a(var0[var1].listFiles());
//			}

			var0[var1].delete();
		}

	}

	public ISaveHandler getSaveLoader(String var1, boolean var2) {
		return new SaveHandler(this.worldFile, var1, var2);
	}

	public boolean isOldMapFormat(String var1) {
		return false;
	}

	public boolean convertMapFormat(String var1, IProgressUpdate var2) {
		return false;
	}
}
