Example #1
0
        protected override bool OnExecute()
        {
            World world = ExoEngine.ActiveWorld;

            // serialize World -> XML
            //Debug2.Push( "XmlSerializer.Serialize( world )" );
            try {
                StreamWriter  sOut   = new StreamWriter(world.FileName, false, System.Text.Encoding.Default, 1);
                XmlSerializer xmlOut = new System.Xml.Serialization.XmlSerializer(typeof(World));
                xmlOut.Serialize(sOut, world, new XmlSerializerNamespaces());
                sOut.Close();
            }
            catch (Exception e) {
                string fileName = BugTracking.WriteExceptionRecord(e);
                ExoEngine.Error("Error save World to file '" + world.FileName + "'.\n" +
                                "Please send this bug report to [email protected]:\n" +
                                fileName);
                return(false);
            }
            //Debug2.Pop();

            ExoEngine.ActiveWorld.Dirty = false;
            ExoEngine.UpdateAll();

            return(true);
        }
Example #2
0
        protected void OnBeforeExpand(object sender, System.Windows.Forms.TreeViewCancelEventArgs e)
        {
            // Set cursor as wait
            Cursor.Current = Cursors.WaitCursor;

            // Populate sub directory in depth 2
            try {
                PopulateSubDirectory(e.Node, 2);
                Cursor.Current = Cursors.Default;

                // Set icon as opened
                if (e.Node.Parent != null)
                {
                    //e.node.ImageIndex = e.node.SelectedImageIndex = 1;
                }
            }
            catch (Exception excpt) {
                // Show error message and cancel expand
                BugTracking.WriteExceptionRecord(excpt);
                MessageBox.Show(excpt.Message, "Device Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
            }

            // Set cursor as default
            Cursor.Current = Cursors.Default;
        }
Example #3
0
        private void PopulateSubDirectory(TreeNode curNode, int depth)
        {
            //Debug.WriteLine( "scanning directory '" + curNode.FullPath + "'" );
            if (--depth < 0)
            {
                return;
            }

            if (curNode.Nodes.Count == 1 && curNode.Nodes[0].Text == "")
            {
                try {
                    // Get sub directory list
                    //Directory[] DirectoryList;
                    string[] DirectoryList = Directory.GetDirectories(curNode.FullPath + "\\");
                    Array.Sort((Array)DirectoryList);

                    // Clear dummy node and Populate TreeView
                    curNode.Nodes.Clear();

                    // Populate sub directory list
                    foreach (string dir in DirectoryList)
                    {
                        DirectoryInfo mDir = new DirectoryInfo(dir);
                        if ((mDir.Attributes & System.IO.FileAttributes.Hidden) == 0)                                   // Hidden = 0x2
                        // Add each directory
                        {
                            TreeNode node;
                            node            = curNode.Nodes.Add(mDir.Name);
                            node.ImageIndex = node.SelectedImageIndex = 0;

                            // Add dummy child node to make node expandable
                            node.Nodes.Add("");

                            // Populate sub directory
                            PopulateSubDirectory(node, depth);
                        }
                    }
                }
                catch (Exception e) {
                    BugTracking.WriteExceptionRecord(e);
                    throw new Exception(e.Message);
                }
            }
            else
            {
                foreach (TreeNode node in curNode.Nodes)
                {
                    // Populate sub directory
                    PopulateSubDirectory(node, depth);
                }
            }
        }
Example #4
0
        // Initialize DirectoryTreeView with current logical drive list
        // It dosen't support OS specific drive list yet. (eg. My Documents, Network Neighborhood)
        private void InitializeShellTree()
        {
            this.PathSeparator = "\\";

            // Get Logical Drive List
            try {
                string[] strDriveList;
                strDriveList = Directory.GetLogicalDrives();

                foreach (string strDrive in strDriveList)
                {
                    // Add each drive
                    TreeNode node;
                    node = this.Nodes.Add(strDrive.Substring(0, strDrive.Length - 1));

                    switch (GetDriveType(strDrive))
                    {
                    case DriveType.Removable:
                        node.ImageIndex = node.SelectedImageIndex = 2;
                        break;

                    case DriveType.Fixed:
                        node.ImageIndex = node.SelectedImageIndex = 3;
                        break;

                    case DriveType.CdRom:
                        node.ImageIndex = node.SelectedImageIndex = 4;
                        break;

                    case DriveType.Remote:
                        node.ImageIndex = node.SelectedImageIndex = 5;
                        break;

                    default:
                        node.ImageIndex = node.SelectedImageIndex = 3;
                        break;
                    }

                    // Add dummy child node to make node expandable
                    node.Nodes.Add("");
                }
            }
            catch (Exception e) {
                BugTracking.WriteExceptionRecord(e);
                MessageBox.Show(e.Message, "Can't initialize device list", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Example #5
0
        protected override bool OnExecute()
        {
            if (ExoEngine.ActiveWorld != null)
            {
                if (ExoEngine.Commands.Execute(typeof(FileClose)) != true)
                {
                    return(false);
                }
            }

            string strFileName = null;

            if (this.Params != null)
            {
                if (this.Params[0] is string)
                {
                    strFileName = (string)this.Params[0];
                }
            }
            else
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Multiselect      = false;
                ofd.Title            = "Open World";
                ofd.Filter           = ExoEngine.sWorldFileFilter;
                ofd.InitialDirectory = ExoEngine.sWorldPath;

                DialogResult result = ofd.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return(false);
                }

                strFileName = ofd.FileName;
            }

            if (strFileName == null || File.Exists(strFileName) == false)
            {
                return(false);
            }

            // deserialize XML -> World
            //Debug2.Push( "XmlSerializer.Deserialize( world )" );
            World world = null;

            try {
                FileStream    sIn   = new FileStream(strFileName, FileMode.Open);
                XmlSerializer xmlIn = new System.Xml.Serialization.XmlSerializer(typeof(World));
                world = (World)xmlIn.Deserialize(sIn);
                sIn.Close();
            }
            catch (Exception e) {
                string fileName = BugTracking.WriteExceptionRecord(e);
                ExoEngine.Error("Error loading World from file '" + strFileName + "'.\n" +
                                "Please send this bug report to [email protected]:\n" +
                                fileName);
                return(false);
            }
            //Debug2.Pop();

            world.FileName = strFileName;
            world.Dirty    = false;
            world.Reset();

            ExoEngine.ActiveWorld = world;
            ExoEngine.UpdateAll();

            return(true);
        }