/// <summary> /// @args: Takes two arguments - first the name of the directory containing the world and second the new name for /// that world. @desc: Renames the world by storing the new name in level.dat. It does *not* rename the directory /// containing the world data. /// </summary> public virtual void RenameWorld(string par1Str, string par2Str) { string file = IOPath.Combine(SavesDirectory, par1Str); if (!File.Exists(file)) { return; } string file1 = IOPath.Combine(file, "level.dat"); if (File.Exists(file1)) { try { NBTTagCompound nbttagcompound = CompressedStreamTools.ReadCompressed(new FileStream(file1, FileMode.Open)); NBTTagCompound nbttagcompound1 = nbttagcompound.GetCompoundTag("Data"); nbttagcompound1.SetString("LevelName", par2Str); CompressedStreamTools.WriteCompressed(nbttagcompound, new FileStream(file1, FileMode.Create)); } catch (Exception exception) { Console.WriteLine(exception.ToString()); Console.Write(exception.StackTrace); } } }
/// <summary> /// gets the world info /// </summary> public virtual WorldInfo GetWorldInfo(string par1Str) { string file = IOPath.Combine(SavesDirectory, par1Str); if (!Directory.Exists(file)) { return(null); } string file1 = IOPath.Combine(file, "level.dat"); if (File.Exists(file1)) { try { MemoryStream stream = new MemoryStream(); using (var fs = new FileStream(file1, FileMode.Open)) { fs.CopyTo(stream); } stream.Seek(0, SeekOrigin.Begin); NBTTagCompound nbttagcompound = CompressedStreamTools.ReadCompressed(stream); NBTTagCompound nbttagcompound2 = nbttagcompound.GetCompoundTag("Data"); return(new WorldInfo(nbttagcompound2)); } catch (Exception exception) { Utilities.LogException(exception); } } file1 = IOPath.Combine(file, "level.dat_old"); if (File.Exists(file1)) { try { NBTTagCompound nbttagcompound1 = CompressedStreamTools.ReadCompressed(new FileStream(file1, FileMode.Open)); NBTTagCompound nbttagcompound3 = nbttagcompound1.GetCompoundTag("Data"); return(new WorldInfo(nbttagcompound3)); } catch (Exception exception1) { Utilities.LogException(exception1); } } return(null); }
/// <summary> /// Loads an existing MapDataBase corresponding to the given String id from disk, instantiating the given Class, or /// returns null if none such file exists. args: Class to instantiate, String dataid /// </summary> public virtual WorldSavedData LoadData(Type par1Class, string par2Str) { WorldSavedData worldsaveddata = LoadedDataMap[par2Str]; if (worldsaveddata != null) { return(worldsaveddata); } if (SaveHandler != null) { try { string file = SaveHandler.GetMapFileFromName(par2Str); if (file != null && File.Exists(file)) { try { worldsaveddata = (WorldSavedData)Activator.CreateInstance(par1Class, new object[] { par2Str }); } catch (Exception exception1) { throw new Exception(new StringBuilder().Append("Failed to instantiate ").Append(par1Class.ToString()).ToString(), exception1); } FileStream fileinputstream = new FileStream(file, FileMode.Open); NBTTagCompound nbttagcompound = CompressedStreamTools.ReadCompressed(fileinputstream); fileinputstream.Close(); worldsaveddata.ReadFromNBT(nbttagcompound.GetCompoundTag("data")); } } catch (Exception exception) { Utilities.LogException(exception); } } if (worldsaveddata != null) { LoadedDataMap[par2Str] = worldsaveddata; LoadedDataList.Add(worldsaveddata); } return(worldsaveddata); }
/// <summary> /// Loads and returns the world info /// </summary> public virtual WorldInfo LoadWorldInfo() { string file = IOPath.Combine(SaveDirectory, "level.dat"); if (File.Exists(file)) { try { NBTTagCompound nbttagcompound = CompressedStreamTools.ReadCompressed(new FileStream(file, FileMode.Open)); NBTTagCompound nbttagcompound2 = nbttagcompound.GetCompoundTag("Data"); return(new WorldInfo(nbttagcompound2)); } catch (Exception exception) { Console.WriteLine(exception.ToString()); Console.Write(exception.StackTrace); } } file = IOPath.Combine(SaveDirectory, "level.dat_old"); if (File.Exists(file)) { try { NBTTagCompound nbttagcompound1 = CompressedStreamTools.ReadCompressed(new FileStream(file, FileMode.Open)); NBTTagCompound nbttagcompound3 = nbttagcompound1.GetCompoundTag("Data"); return(new WorldInfo(nbttagcompound3)); } catch (Exception exception1) { Console.WriteLine(exception1.ToString()); Console.Write(exception1.StackTrace); } } return(null); }