/// <summary> /// Disposes object. /// </summary> public void Dispose() { lock (syncRoot) { mulFile = null; indexFile.Dispose(); dataStream.Close(); changeList.Clear(); } }
/// <summary> /// Loads skills from files. /// </summary> /// <param name="idxFile">Index file.</param> /// <param name="mulFile">Data file.</param> /// <returns>New Skills object with loaded data.</returns> public static Skills Load(string idxFile, string mulFile) { IndexFile indexFile = null; Stream stream = null; BinaryReader reader = null; try { indexFile = IndexFile.Load(idxFile); stream = File.OpenRead(mulFile); reader = new BinaryReader(stream); Skills skills = new Skills(); IndexData indexData; SkillData skillData = new SkillData(); for (int i = 0; i < indexFile.Count; i++) { indexData = indexFile[i]; if (indexData.IsValid) { stream.Seek(indexData.Lookup, SeekOrigin.Begin); skillData.Action = reader.ReadByte() != 0; skillData.Extra = indexData.Extra; byte[] nameBytes = reader.ReadBytes((int)indexData.Lenght - 1); skillData.Name = Encoding.ASCII.GetString(nameBytes).TrimEnd(' ', '\0'); skills.list.Add(skillData); } else { Trace.WriteLine("Skills: Found " + i.ToString() + " skills.", "MulLib"); break; } } Trace.WriteLine(String.Format("Skills: File \"{0}\" succesfully loaded.", mulFile), "MulLib"); return(skills); } catch (Exception e) { throw new Exception("Error loading Skills.", e); } finally { if (indexFile != null) { indexFile.Dispose(); } if (reader != null) { reader.Close(); } if (stream != null) { stream.Close(); } } }
/// <summary> /// Stores this object to specified files. /// </summary> /// <param name="idxFile">Index file.</param> /// <param name="mulFile">Data file.</param> /// <exception cref="System.ObjectDisposedException">Object has been disposed.</exception> public void Save(string idxFile, string mulFile) { lock (syncRoot) { if (Disposed) { throw new ObjectDisposedException("Skills"); } IndexFile indexFile = null; Stream stream = null; BinaryWriter writer = null; Stream indexStream = null; try { indexStream = File.Open(idxFile, FileMode.Create, FileAccess.Write, FileShare.None); indexFile = new IndexFile(); stream = File.OpenWrite(mulFile); writer = new BinaryWriter(stream); IndexData indexData = new IndexData(); foreach (SkillData skillData in list) { indexData.Lookup = (uint)stream.Position; indexData.Lenght = (uint)skillData.Name.Length + 1; indexData.Extra = skillData.Extra; writer.Write(skillData.Action); writer.Write(Encoding.ASCII.GetBytes(skillData.Name)); indexFile.Add(indexData); } indexFile.Resize(256); indexFile.Save(indexStream); Trace.WriteLine(String.Format("IndexFile: File \"{0}\" succesfully saved.", idxFile), "MulLib"); writer.Flush(); Trace.WriteLine(String.Format("Skills: File \"{0}\" succesfully saved.", mulFile), "MulLib"); } catch (Exception e) { throw new Exception("Error saving Skills.", e); } finally { if (indexFile != null) { indexFile.Dispose(); } if (indexStream != null) { indexStream.Close(); } if (writer != null) { writer.Close(); } if (stream != null) { stream.Close(); } } } }
public static Multi Load(string idxFile, string mulFile, MulFileAccessMode mode) { IndexFile indexFile = null; Stream stream = null; BinaryReader reader = null; try { indexFile = IndexFile.Load(idxFile); stream = File.OpenRead(mulFile); reader = new BinaryReader(stream); Multi multi = new Multi(); IndexData indexData; for (int i = 0; i < indexFile.Count; i++) { indexData = indexFile[i]; if (indexData.IsValid) { stream.Seek(indexData.Lookup, SeekOrigin.Begin); MultiData multiData = new MultiData(); multiData.Id = (ushort)i; multiData.Tiles = new MultiTile[indexData.Lenght / 12]; for (int j = 0; j < indexData.Lenght / 12; j++) { MultiTile tile = new MultiTile { ItemID = reader.ReadUInt16(), X = reader.ReadInt16(), Y = reader.ReadInt16(), Z = reader.ReadInt16(), Flags = reader.ReadInt32() }; multiData.Tiles[j] = tile; } multi.data.Add(multiData.Id, multiData); } } Trace.WriteLine(String.Format("Multi: File \"{0}\" succesfully loaded.", mulFile), "MulLib"); return(multi); } catch (Exception e) { throw new Exception("Error loading Multi.", e); } finally { if (indexFile != null) { indexFile.Dispose(); } if (reader != null) { reader.Close(); } if (stream != null) { stream.Close(); } } }