001 package net.minecraft.src; 002 003 import cpw.mods.fml.common.Side; 004 import cpw.mods.fml.common.asm.SideOnly; 005 import java.io.File; 006 import java.io.FileInputStream; 007 import java.io.FileOutputStream; 008 import java.util.ArrayList; 009 import java.util.List; 010 011 public class SaveFormatOld implements ISaveFormat 012 { 013 /** 014 * Reference to the File object representing the directory for the world saves 015 */ 016 protected final File savesDirectory; 017 018 public SaveFormatOld(File par1File) 019 { 020 if (!par1File.exists()) 021 { 022 par1File.mkdirs(); 023 } 024 025 this.savesDirectory = par1File; 026 } 027 028 @SideOnly(Side.CLIENT) 029 public List getSaveList() 030 { 031 ArrayList var1 = new ArrayList(); 032 033 for (int var2 = 0; var2 < 5; ++var2) 034 { 035 String var3 = "World" + (var2 + 1); 036 WorldInfo var4 = this.getWorldInfo(var3); 037 038 if (var4 != null) 039 { 040 var1.add(new SaveFormatComparator(var3, "", var4.getLastTimePlayed(), var4.getSizeOnDisk(), var4.getGameType(), false, var4.isHardcoreModeEnabled(), var4.areCommandsAllowed())); 041 } 042 } 043 044 return var1; 045 } 046 047 public void flushCache() {} 048 049 /** 050 * gets the world info 051 */ 052 public WorldInfo getWorldInfo(String par1Str) 053 { 054 File var2 = new File(this.savesDirectory, par1Str); 055 056 if (!var2.exists()) 057 { 058 return null; 059 } 060 else 061 { 062 File var3 = new File(var2, "level.dat"); 063 NBTTagCompound var4; 064 NBTTagCompound var5; 065 066 if (var3.exists()) 067 { 068 try 069 { 070 var4 = CompressedStreamTools.readCompressed(new FileInputStream(var3)); 071 var5 = var4.getCompoundTag("Data"); 072 return new WorldInfo(var5); 073 } 074 catch (Exception var7) 075 { 076 var7.printStackTrace(); 077 } 078 } 079 080 var3 = new File(var2, "level.dat_old"); 081 082 if (var3.exists()) 083 { 084 try 085 { 086 var4 = CompressedStreamTools.readCompressed(new FileInputStream(var3)); 087 var5 = var4.getCompoundTag("Data"); 088 return new WorldInfo(var5); 089 } 090 catch (Exception var6) 091 { 092 var6.printStackTrace(); 093 } 094 } 095 096 return null; 097 } 098 } 099 100 @SideOnly(Side.CLIENT) 101 102 /** 103 * @args: Takes two arguments - first the name of the directory containing the world and second the new name for 104 * that world. @desc: Renames the world by storing the new name in level.dat. It does *not* rename the directory 105 * containing the world data. 106 */ 107 public void renameWorld(String par1Str, String par2Str) 108 { 109 File var3 = new File(this.savesDirectory, par1Str); 110 111 if (var3.exists()) 112 { 113 File var4 = new File(var3, "level.dat"); 114 115 if (var4.exists()) 116 { 117 try 118 { 119 NBTTagCompound var5 = CompressedStreamTools.readCompressed(new FileInputStream(var4)); 120 NBTTagCompound var6 = var5.getCompoundTag("Data"); 121 var6.setString("LevelName", par2Str); 122 CompressedStreamTools.writeCompressed(var5, new FileOutputStream(var4)); 123 } 124 catch (Exception var7) 125 { 126 var7.printStackTrace(); 127 } 128 } 129 } 130 } 131 132 /** 133 * @args: Takes one argument - the name of the directory of the world to delete. @desc: Delete the world by deleting 134 * the associated directory recursively. 135 */ 136 public void deleteWorldDirectory(String par1Str) 137 { 138 File var2 = new File(this.savesDirectory, par1Str); 139 140 if (var2.exists()) 141 { 142 deleteFiles(var2.listFiles()); 143 var2.delete(); 144 } 145 } 146 147 /** 148 * @args: Takes one argument - the list of files and directories to delete. @desc: Deletes the files and directory 149 * listed in the list recursively. 150 */ 151 protected static void deleteFiles(File[] par0ArrayOfFile) 152 { 153 File[] var1 = par0ArrayOfFile; 154 int var2 = par0ArrayOfFile.length; 155 156 for (int var3 = 0; var3 < var2; ++var3) 157 { 158 File var4 = var1[var3]; 159 160 if (var4.isDirectory()) 161 { 162 System.out.println("Deleting " + var4); 163 deleteFiles(var4.listFiles()); 164 } 165 166 var4.delete(); 167 } 168 } 169 170 /** 171 * Returns back a loader for the specified save directory 172 */ 173 public ISaveHandler getSaveLoader(String par1Str, boolean par2) 174 { 175 return new SaveHandler(this.savesDirectory, par1Str, par2); 176 } 177 178 /** 179 * Checks if the save directory uses the old map format 180 */ 181 public boolean isOldMapFormat(String par1Str) 182 { 183 return false; 184 } 185 186 /** 187 * Converts the specified map to the new map format. Args: worldName, loadingScreen 188 */ 189 public boolean convertMapFormat(String par1Str, IProgressUpdate par2IProgressUpdate) 190 { 191 return false; 192 } 193 }