Example #1
0
        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();
                }
            }
        }
Example #2
0
        private static void WriteSavedComponentData(BinaryFileReader oldBinReader, BinaryFileWriter binWriter)
        {
            for (int i = 0; i < m_DesignHeaders.Count; ++i)
            {
                DesignData header = (DesignData)m_DesignHeaders[i];

                oldBinReader.Seek(header.FilePosition, SeekOrigin.Begin);
                // update record start position
                header.FilePosition = binWriter.Position;

                // write component data
                WriteSavedComponentData(header, oldBinReader, binWriter);
            }
        }