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 boolean deleteWorldDirectory(String par1Str)
137 {
138 File var2 = new File(this.savesDirectory, par1Str);
139
140 if (!var2.exists())
141 {
142 return true;
143 }
144 else
145 {
146 System.out.println("Deleting level " + par1Str);
147
148 for (int var3 = 1; var3 <= 5; ++var3)
149 {
150 System.out.println("Attempt " + var3 + "...");
151
152 if (deleteFiles(var2.listFiles()))
153 {
154 break;
155 }
156
157 System.out.println("Unsuccessful in deleting contents.");
158
159 if (var3 < 5)
160 {
161 try
162 {
163 Thread.sleep(500L);
164 }
165 catch (InterruptedException var5)
166 {
167 ;
168 }
169 }
170 }
171
172 return var2.delete();
173 }
174 }
175
176 /**
177 * @args: Takes one argument - the list of files and directories to delete. @desc: Deletes the files and directory
178 * listed in the list recursively.
179 */
180 protected static boolean deleteFiles(File[] par0ArrayOfFile)
181 {
182 File[] var1 = par0ArrayOfFile;
183 int var2 = par0ArrayOfFile.length;
184
185 for (int var3 = 0; var3 < var2; ++var3)
186 {
187 File var4 = var1[var3];
188 System.out.println("Deleting " + var4);
189
190 if (var4.isDirectory() && !deleteFiles(var4.listFiles()))
191 {
192 System.out.println("Couldn\'t delete directory " + var4);
193 return false;
194 }
195
196 if (!var4.delete())
197 {
198 System.out.println("Couldn\'t delete file " + var4);
199 return false;
200 }
201 }
202
203 return true;
204 }
205
206 /**
207 * Returns back a loader for the specified save directory
208 */
209 public ISaveHandler getSaveLoader(String par1Str, boolean par2)
210 {
211 return new SaveHandler(this.savesDirectory, par1Str, par2);
212 }
213
214 /**
215 * Checks if the save directory uses the old map format
216 */
217 public boolean isOldMapFormat(String par1Str)
218 {
219 return false;
220 }
221
222 /**
223 * Converts the specified map to the new map format. Args: worldName, loadingScreen
224 */
225 public boolean convertMapFormat(String par1Str, IProgressUpdate par2IProgressUpdate)
226 {
227 return false;
228 }
229 }