Пример #1
0
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Show the dialog and get result.
            if (pack_status == packed.packed)
            {
                saveFileDialog1.FilterIndex = 2;
            }
            else
            {
                saveFileDialog1.FilterIndex = 1;
            }
            DialogResult result = saveFileDialog1.ShowDialog();

            if (result == DialogResult.OK) // Test result.
            {
                save_path = saveFileDialog1.FileName;
                switch (saveFileDialog1.FilterIndex)
                {
                case 1:
                    exportToXml(treeView1, saveFileDialog1.FileName);
                    break;

                case 2:
                    exportToXml(treeView1, saveFileDialog1.FileName);
                    Unity_Asset_Handler.Save_Asset(saveFileDialog1.FileName, active_dialog);
                    break;
                }
            }
            System.Diagnostics.Debug.WriteLine(result); // <-- For debugging use.
        }
Пример #2
0
        private void openraildef2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Show the dialog and get result.
            DialogResult result = openFileDialog3.ShowDialog();

            if (result == DialogResult.OK) // Test result.
            {
                using (FileStream fs = new FileStream(openFileDialog3.FileName, FileMode.Open, FileAccess.Read))
                {
                    byte[] header = new byte[System.Runtime.InteropServices.Marshal.SizeOf(magic_unity)];
                    fs.Seek(0L, SeekOrigin.Begin);
                    fs.Read(header, 0, 4);
                    if (BitConverter.ToUInt32(header.Reverse().ToArray(), 0) != magic_unity)
                    {
                        byte[] bytes = Encoding.GetEncoding(ENCODE_TYPE).GetBytes(ID_rail);
                        byte[] array = new byte[bytes.Length];
                        fs.Seek(0L, SeekOrigin.Begin);
                        fs.Read(array, 0, bytes.Length);
                        for (int i = 0; i < bytes.Length; i++)
                        {
                            if (bytes[i] != array[i])
                            {
                                throw new Exception("File ID is invalid. \"" + Encoding.UTF8.GetString(array, 0, array.Length) + "\"");
                            }
                        }
                        save_path     = null;
                        pack_status   = packed.unpacked;
                        active_dialog = dialog.rail_def_2;
                        populateTreeview(openFileDialog3.FileName);
                    }
                    else
                    {
                        save_path     = null;
                        pack_status   = packed.packed;
                        active_dialog = dialog.rail_def_2;
                        populateTreeview(Unity_Asset_Handler.Load_Asset(openFileDialog3.FileName));
                    }
                }
            }
            System.Diagnostics.Debug.WriteLine(result); // <-- For debugging use.
        }