Exemplo n.º 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();
                }
            }
        }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 3
0
        public ArrayList ImportDesigns()
        {
            ArrayList designs = new ArrayList();

            string[] filenames = GetImportFileNames();

            if (filenames == null)
            {
                return(designs);
            }

            foreach (string filename in filenames)
            {
                if (!File.Exists(filename))
                {
                    continue;
                }

                BinaryFileReader reader = new BinaryFileReader(File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read));

                short version = reader.ReadShort();

                switch (version)
                {
                case 1:
                    // file contains only one design (old format)
                    designs.Add(ImportDesign(reader, version));
                    break;

                case 2:
                    // file may contain multiple designs
                    int designCount = reader.ReadShort();

                    for (int i = 0; i < designCount; ++i)
                    {
                        designs.Add(ImportDesign(reader, version));
                    }

                    break;
                }

                reader.Close();
            }

            return(designs);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        private static void WriteBinFile()
        {
            bool             fileExists = File.Exists(BIN_FILE);
            BinaryFileWriter binWriter  = new BinaryFileWriter(File.Open(TMP_BIN_FILE, FileMode.Create, FileAccess.Write, FileShare.None));

            if (fileExists)
            {
                BinaryFileReader oldBinReader = new BinaryFileReader(File.Open(BIN_FILE, FileMode.Open, FileAccess.Read, FileShare.None));
                WriteSavedComponentData(oldBinReader, binWriter);
                oldBinReader.Close();
            }

            foreach (DesignData unsavedDesign in m_UnsavedDesigns)
            {
                unsavedDesign.FilePosition = binWriter.Position;
                unsavedDesign.RecordCount  = unsavedDesign.Items.Count;
                WriteUpdatedDesignComponentData(unsavedDesign.Items, binWriter);
                m_DesignHeaders.Add(unsavedDesign);
            }

            m_UnsavedDesigns.Clear();

            binWriter.Close();
        }