Ejemplo n.º 1
0
        private void EditConfigFile()
        {
            using (ProgressModal progress = new ProgressModal(20))
            {
                progress.Show(this);

                //yeah, reloading the config file just to mod it and save again. Derp!
                //System.Windows.Forms.
                //SUPER LAME PROGRESS BAR AHOY!
                try{
                    Sluggy.Utility.XmlParser parser     = new Sluggy.Utility.XmlParser(Globals.Files.ConfigFile);
                    Sluggy.Utility.Tag       imageboxes = parser.DepthSeekFirst(null, "imageboxes");
                    Sluggy.Utility.Tag       nodeboxes  = parser.DepthSeekFirst(null, "nodeboxes");
                    Sluggy.Utility.Tag       baseroom   = parser.DepthSeekFirst(null, "baseroom");
                    Sluggy.Utility.Tag       startroom  = parser.DepthSeekFirst(null, "startroom");
                    Sluggy.Utility.Tag       exitWidth  = parser.DepthSeekFirst(null, "exitlinewidth");
                    Sluggy.Utility.Tag       lineending = parser.DepthSeekFirst(null, "lpclineending");
                    Sluggy.Utility.Tag       encoding   = parser.DepthSeekFirst(null, "lpcencoding");
                    progress.UpdateProgressBar();

                    if (imageboxes == null || nodeboxes == null || exitWidth == null)
                    {
                        MessageBox.Show("The config file has been corrupted and cannot be altered. The problem may be solved by deleting the file 'config.xml' in the Stellarmap assets folder.");
                        return;
                    }
                    progress.UpdateProgressBar();

                    SetOrCreateAttribute(imageboxes, "width", System.Convert.ToString(Globals.ImageBoxProperties.width), progress);
                    SetOrCreateAttribute(imageboxes, "height", System.Convert.ToString(Globals.ImageBoxProperties.height), progress);
                    SetOrCreateAttribute(nodeboxes, "width", System.Convert.ToString(Globals.NodeProperties.width), progress);
                    SetOrCreateAttribute(nodeboxes, "height", System.Convert.ToString(Globals.NodeProperties.height), progress);
                    SetOrCreateAttribute(baseroom, "name", Globals.Model.BaseRoomName, progress);
                    SetOrCreateAttribute(startroom, "name", Globals.Model.CustomStartRoomName, progress);
                    SetOrCreateAttribute(exitWidth, "width", System.Convert.ToString(Globals.ImageBoxProperties.ExitLineWidth), progress);
                    SetOrCreateAttribute(lineending, "type", Globals.WorkspaceSave.LineEndings, progress);
                    SetOrCreateAttribute(encoding, "type", Globals.WorkspaceSave.LPCEncoding.WebName, progress);

                    parser.Save(parser.FilePath);

                    //TODO: need an option to save Parsed XML data in parser!!!
                }                        //end try
                catch (Sluggy.Utility.XMLParserException exc)
                {
                    MessageBox.Show(exc.Message);
                }
            }                    //end progress modal

            return;
        }
Ejemplo n.º 2
0
            static WorkspaceSave()
            {
                SetupEncodingMap();
                SetupLineEndingMap();

                //load up config and check out the model properties
                try
                {
                    Sluggy.Utility.XmlParser parser      = new Sluggy.Utility.XmlParser(Globals.Files.ConfigFile);
                    Sluggy.Utility.Tag       lastDir     = parser.DepthSeekFirst(null, "lastdiropened");
                    Sluggy.Utility.Tag       encoding    = parser.DepthSeekFirst(null, "lpcencoding");
                    Sluggy.Utility.Tag       lineendings = parser.DepthSeekFirst(null, "lpclineending");
                    Sluggy.Utility.Tag       affFile     = parser.DepthSeekFirst(null, "spellcheck_aff");
                    Sluggy.Utility.Tag       dicFile     = parser.DepthSeekFirst(null, "spellcheck_dic");


                    if (lastDir != null)
                    {
                        if (lastDir.Attributes.ContainsKey("path"))
                        {
                            WorkspaceSave.LastDirectory = lastDir.Attributes["path"];
                        }
                    }

                    if (encoding != null)
                    {
                        if (encoding.Attributes.ContainsKey("type"))
                        {
                            string enc = encoding.Attributes["type"];
                            //if there is no string or the name is not found in the list,
                            //default to UTF-8 encoding
                            if (enc != null)
                            {
                                //if the encoding named in the file exists within the map we assing that value,
                                //othwise we stay with default value.
                                if (EncodingMap.ContainsKey(enc))
                                {
                                    LPCEncoding = EncodingMap[enc];
                                }
                            }
                        }
                    }

                    if (lineendings != null)
                    {
                        if (lineendings.Attributes.ContainsKey("type"))
                        {
                            string enc = lineendings.Attributes["type"];
                            //if there is no string or the name is not found in the list,
                            //default to UTF-8 encoding
                            if (!LineEndingMap.ContainsKey(enc))
                            {
                                LineEndings = "Windows (CR+LF)";
                            }
                            else
                            {
                                LineEndings = enc;
                            }
                        }
                    }

                    if (affFile != null)
                    {
                        if (affFile.Attributes.ContainsKey("name"))
                        {
                            string file = affFile.Attributes["name"];
                            if (file.Length > 0)
                            {
                                pAffFile = file;
                            }
                        }
                    }

                    if (dicFile != null)
                    {
                        if (dicFile.Attributes.ContainsKey("name"))
                        {
                            string file = dicFile.Attributes["name"];
                            if (file.Length > 0)
                            {
                                pDicFile = file;
                            }
                        }
                    }
                }                        //end try
                catch (Sluggy.Utility.XMLParserException e)
                {
                    MessageBox.Show(e.Message);
                }
                catch (System.IO.FileNotFoundException)
                {
                    //swallow exception
                }
                catch (System.IO.DirectoryNotFoundException)
                {
                    //swallow exception
                }

                return;
            }