public override DesignData ImportDesign() { string filename = GetImportFileName(); if (!File.Exists(filename)) { return(null); } BinaryFileReader reader = new BinaryFileReader(File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read)); short version = reader.ReadShort(); DesignData design = new DesignData(); if (version == 1) { design.Name = reader.ReadString(); design.Category = reader.ReadString(); design.Subsection = reader.ReadString(); design.Width = reader.ReadInt(); design.Height = reader.ReadInt(); design.UserWidth = reader.ReadInt(); design.UserHeight = reader.ReadInt(); int count = reader.ReadInt(); for (int i = 0; i < count; ++i) { short index = reader.ReadShort(); short x = reader.ReadShort(); short y = reader.ReadShort(); short z = reader.ReadShort(); short level = reader.ReadShort(); short hue = reader.ReadShort(); design.Items.Add(new DesignItem(index, x, y, z, level, hue)); } } reader.Close(); return(design); }
private DesignData ImportDesign(BinaryFileReader reader, short version) { DesignData design = new DesignData(); switch (version) { case 1: case 2: design.Name = reader.ReadString(); design.Category = reader.ReadString(); design.Subsection = reader.ReadString(); design.Width = reader.ReadInt(); design.Height = reader.ReadInt(); design.UserWidth = reader.ReadInt(); design.UserHeight = reader.ReadInt(); int count = reader.ReadInt(); for (int i = 0; i < count; ++i) { short index = reader.ReadShort(); short x = reader.ReadShort(); short y = reader.ReadShort(); short z = reader.ReadShort(); short level = reader.ReadShort(); short hue = reader.ReadShort(); design.Items.Add(new DesignItem(index, x, y, z, level, hue)); _itemCount++; } break; } return(design); }
public static void LoadDesignHeaders() { if (File.Exists(INDEX_FILE)) { BinaryFileReader reader = new BinaryFileReader(File.Open(INDEX_FILE, FileMode.Open, FileAccess.Read, FileShare.Read)); try { int count = reader.ReadInt(); int version = reader.ReadInt(); m_DesignHeaders = new ArrayList(count); for (int i = 0; i < count; ++i) { DesignData header = new DesignData(); switch (version) { case 0: header.Name = reader.ReadString(); header.Category = reader.ReadString(); header.Subsection = reader.ReadString(); header.Width = reader.ReadInt(); header.Height = reader.ReadInt(); header.UserWidth = reader.ReadInt(); header.UserHeight = reader.ReadInt(); header.FilePosition = reader.ReadLong(); header.RecordCount = reader.ReadInt(); break; } m_DesignHeaders.Add(header); } } catch (Exception e) { m_DesignHeaders.Clear(); System.Windows.Forms.MessageBox.Show("Unable to load the designs\n" + e.Message); } finally { reader.Close(); } } else { m_DesignHeaders = new ArrayList(); } }
public void Deserialize(BinaryFileReader reader) { Version = reader.ReadInt(); switch (Version) { case 0: Index = reader.ReadInt(); X = reader.ReadInt(); Y = reader.ReadInt(); Z = reader.ReadInt(); Level = reader.ReadInt(); break; } }
public static void LoadDesign(DesignData designHeader) { if (File.Exists(BIN_FILE)) { BinaryFileReader reader = new BinaryFileReader(File.Open(BIN_FILE, FileMode.Open, FileAccess.Read, FileShare.Read)); try { reader.Seek(designHeader.FilePosition, SeekOrigin.Begin); int count = designHeader.RecordCount; // load the house components int index, x, y, z, level, hue; for (int i = 0; i < count; ++i) { index = 0; x = 0; y = 0; z = 0; level = 0; hue = 0; int compVersion = reader.ReadInt(); switch (compVersion) { case 0: index = reader.ReadInt(); x = reader.ReadInt(); y = reader.ReadInt(); z = reader.ReadInt(); level = reader.ReadInt(); break; case 1: index = reader.ReadInt(); x = reader.ReadInt(); y = reader.ReadInt(); z = reader.ReadInt(); level = reader.ReadInt(); hue = reader.ReadInt(); break; } designHeader.Items.Add(new DesignItem(index, x, y, z, level, hue)); } } catch (Exception e) { System.Windows.Forms.MessageBox.Show("Unable to load design\n" + e.Message); } finally { reader.Close(); } } }
private static void WriteSavedComponentData(DesignData header, BinaryFileReader oldFileReader, BinaryFileWriter writer) { int count = header.RecordCount; for (int j = 0; j < count; ++j) { int ver = oldFileReader.ReadInt(); switch (ver) { case 0: writer.WriteInt(ver); // version writer.WriteInt(oldFileReader.ReadInt()); // index writer.WriteInt(oldFileReader.ReadInt()); // x writer.WriteInt(oldFileReader.ReadInt()); // y writer.WriteInt(oldFileReader.ReadInt()); // z writer.WriteInt(oldFileReader.ReadInt()); // level break; case 1: writer.WriteInt(ver); // version writer.WriteInt(oldFileReader.ReadInt()); // index writer.WriteInt(oldFileReader.ReadInt()); // x writer.WriteInt(oldFileReader.ReadInt()); // y writer.WriteInt(oldFileReader.ReadInt()); // z writer.WriteInt(oldFileReader.ReadInt()); // level writer.WriteInt(oldFileReader.ReadInt()); // hue break; } } }