static ImageBoxProperties() { //load up config and check out the imagebox properties try{ Sluggy.Utility.XmlParser parser = new Sluggy.Utility.XmlParser(Globals.Files.ConfigFile); //List<Sluggy.Utility.Tag> items = parser.FindAll(null,"imageboxes"); Sluggy.Utility.Tag items = parser.Contents.Children[0]; //add default if (items != null && items.Children != null) { foreach (Sluggy.Utility.Tag tag in items.Children) { //config global image properties if (tag.Name == "imageboxes") { if (tag.Attributes.ContainsKey("width")) { width = System.Convert.ToInt32(tag.Attributes["width"]); } if (tag.Attributes.ContainsKey("height")) { height = System.Convert.ToInt32(tag.Attributes["height"]); } } if (tag.Name == "exitlinewidth") { if (tag.Attributes.ContainsKey("width")) { ExitLineWidth = System.Convert.ToInt32(tag.Attributes["width"]); } } } //end if } //end foreach } //end try catch (Sluggy.Utility.XMLParserException e) { MessageBox.Show(e.Message); } catch (System.IO.FileNotFoundException e) { //swallow exception } catch (System.IO.DirectoryNotFoundException e) { //swallow exception } //try to load the default image file Utility.ConfirmRequiredFile(Dirs.Bitmaps + DefaultBitmapFile); try { DefaultImage = new Bitmap(Dirs.Bitmaps + DefaultBitmapFile); } catch (Exception) { DefaultImage = new Bitmap(width, height); } RoomIcons.Add(DefaultBitmapFile, DefaultImage); }
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; }
static public Dictionary <string, System.Drawing.Bitmap> LoadIconsFromConfig(string configFile) { Dictionary <string, Bitmap> roomIcons = new Dictionary <string, Bitmap>(); try { Sluggy.Utility.XmlParser parser = new Sluggy.Utility.XmlParser(configFile); List <Sluggy.Utility.Tag> items = parser.FindAll(null, "icon"); if (items != null) { foreach (Sluggy.Utility.Tag tag in items) { //config global bitmaps if (tag.Attributes.ContainsKey("file") && tag.Attributes.ContainsKey("desc")) { Utility.ConfirmRequiredFile(Globals.Dirs.Bitmaps + tag.Attributes["file"]); try{ Bitmap image = new Bitmap(Globals.Dirs.Bitmaps + tag.Attributes["file"]); roomIcons.Add(tag.Attributes["desc"], image); } catch (System.IO.FileNotFoundException e) { //swallow exception } catch (System.IO.DirectoryNotFoundException e) { //swallow exception } } } //end if } //end foreach } //end try catch (Sluggy.Utility.XMLParserException e) { System.Windows.Forms.MessageBox.Show(e.Message); } catch (System.IO.FileNotFoundException e) { //swallow exception } catch (System.IO.DirectoryNotFoundException e) { //swallow exception } return(roomIcons); }
static Model() { //load up config and check out the model properties try { Sluggy.Utility.XmlParser parser = new Sluggy.Utility.XmlParser(Globals.Files.ConfigFile); List <Sluggy.Utility.Tag> items = parser.FindAll(null, "baseroom"); items.AddRange(parser.FindAll(null, "startroom")); //add default if (items != null) { foreach (Sluggy.Utility.Tag tag in items) { if (tag.Name == "baseroom") { if (tag.Attributes.ContainsKey("name")) { BaseRoomName = tag.Attributes["name"]; } } if (tag.Name == "startroom") { if (tag.Attributes.ContainsKey("name")) { CustomStartRoomName = tag.Attributes["name"]; } } } //end if } //end foreach } //end try catch (Sluggy.Utility.XMLParserException e) { MessageBox.Show(e.Message); } catch (System.IO.FileNotFoundException e) { //swallow exception } catch (System.IO.DirectoryNotFoundException e) { //swallow exception } }
static NodeProperties() { Sluggy.Utility.XmlParser parser = new Sluggy.Utility.XmlParser(Globals.Files.ConfigFile); List <Sluggy.Utility.Tag> items = parser.FindAll(null, "nodeboxes"); try { //add default if (items != null) { foreach (Sluggy.Utility.Tag tag in items) { //config global image properties if (tag.Name == "nodeboxes") { if (tag.Attributes.ContainsKey("width")) { Globals.NodeProperties.width = System.Convert.ToInt32(tag.Attributes["width"]); } if (tag.Attributes.ContainsKey("height")) { Globals.NodeProperties.height = System.Convert.ToInt32(tag.Attributes["height"]); } } } //end if } //end foreach } //end try catch (Sluggy.Utility.XMLParserException e) { MessageBox.Show(e.Message); } catch (System.IO.FileNotFoundException e) { //swallow exception } catch (System.IO.DirectoryNotFoundException e) { //swallow exception } CreateNodeProperties(); }
static DefinedLists() { try{ Sluggy.Utility.XmlParser parser = new Sluggy.Utility.XmlParser(Stellarmap.Globals.Files.ConfigFile); foreach (Sluggy.Utility.Tag tag in parser.Contents.Children[0].Children) { if (tag.Name == "list") { if (tag.Attributes.ContainsKey("type")) { List <string> entries = new List <string>(); foreach (Sluggy.Utility.Tag child in tag.Children) { if (child.Name == "entry") { entries.Add(child.Value); } } typeLists.Add(tag.Attributes["type"], entries); } } } } //en try catch (Sluggy.Utility.XMLParserException e) { System.Windows.Forms.MessageBox.Show(e.Message); } catch (System.IO.FileNotFoundException e) { //swallow exception } catch (System.IO.DirectoryNotFoundException e) { //swallow exception } return; }
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; }
private DomainReference ParseXmlFileReferences(string domainFileName) { DomainReference domRef = new DomainReference(domainFileName); //the workspace was already reset so the root directory should be good to go //find the master XML file and begin disecting the directory layout and file locations string masterFile = Globals.Dirs.DomainReferences + "\\" + domainFileName + ".xml"; if (!System.IO.File.Exists(masterFile)) { throw new DomainModelException("External domain reference " + domainFileName + " is missing."); } Sluggy.Utility.XmlParser xml; try{ bool validFile = false; xml = new Sluggy.Utility.XmlParser(masterFile); if (xml.Contents.Children[0].Name == "domain") { validFile = true; Sluggy.Utility.Tag domainTag = xml.Contents.Children[0]; foreach (Sluggy.Utility.Tag tag in domainTag.Children) { //HACK ALERT - might as well just hardcode a giant ugly-ass switch while I'm at it //remember, this is for a domain reference file. We aren't loading an files, just getting their //names and importing them into the workspace. #region room tag parsing if (tag.Name == "directory" && tag.Attributes["name"] == "room") { foreach (Sluggy.Utility.Tag roomTag in tag.Children) { string roomName; if (roomTag.Attributes.ContainsKey("name")) { roomName = roomTag.Attributes["name"]; } else { throw new DomainModelException("Missing room name in external domain " + domainFileName + "."); } domRef.Rooms.Add(domRef.ConvertRoomNameToFullPath(roomName), new FileReferenceModel(roomName, ItemSaveType.Room, Include, domainFileName)); } //break; } #endregion #region item tag parsing if (tag.Name == "directory" && tag.Attributes["name"] == "inventory") { foreach (Sluggy.Utility.Tag itemTag in tag.Children) { if (itemTag.Attributes.ContainsKey("name") && itemTag.Attributes.ContainsKey("class")) { string name = itemTag.Attributes["name"]; string itemClass = itemTag.Attributes["class"]; domRef.Inventory.Add(domRef.ConvertRoomNameToFullPath(name), new FileReferenceModel(name, Include.DetermineSaveType(itemClass), Include, domainFileName)); } } } #endregion //break; } } if (!validFile) { throw new DomainModelException("Invalid master XML file. Could not load domain."); } } catch (Sluggy.Utility.XMLParserException exception) { throw new DomainModelException("Failed to parse domain master XML file.\n\n" + exception.Message); } catch (System.IndexOutOfRangeException exception) { throw new DomainModelException("Corrupted master XML file. Could not load domain.", exception); } catch (System.ArgumentOutOfRangeException exception) { throw new DomainModelException("Corrupted master XML file. Could not load domain.", exception); } return(domRef); }
private bool Deserialize(VirtualDomain vd) { //the workspace was already reset so the root directory should be good to go //find the master XML file and begin disecting the directory layout and file locations string masterFile = this.RootDirectory + "\\" + this.Name + ".xml"; if (!System.IO.File.Exists(masterFile)) { throw new DomainModelException("No domain master file found. Cannot load domain."); } Sluggy.Utility.XmlParser xml; try{ bool validFile = false; xml = new Sluggy.Utility.XmlParser(masterFile); if (xml.Contents.Children[0].Name == "domain") { validFile = true; Sluggy.Utility.Tag domainTag = xml.Contents.Children[0]; foreach (Sluggy.Utility.Tag tag in domainTag.Children) { //HACK ALERT - might as well just hardcode a giant ugly-ass switch while I'm at it //look for the 'room' directory tag #region room tag parsing if (tag.Name == "directory" && tag.Attributes["name"] == "room") { //we now have the room directory, start loading room files foreach (Sluggy.Utility.Tag roomTag in tag.Children) { string roomName, iconName; int xPos, yPos; if (roomTag.Attributes.ContainsKey("name")) { roomName = roomTag.Attributes["name"]; } else { throw new DomainModelException("Missing room name in domain master file. Canceling domain laoding. Please manually edit the master xml file to reflect all room files."); } if (roomTag.Attributes.ContainsKey("x")) { xPos = System.Convert.ToInt32(roomTag.Attributes["x"]); } else { xPos = 0; } if (roomTag.Attributes.ContainsKey("y")) { yPos = System.Convert.ToInt32(roomTag.Attributes["y"]); } else { yPos = 0; } if (roomTag.Attributes.ContainsKey("icon")) { iconName = roomTag.Attributes["icon"]; } else { iconName = Globals.ImageBoxProperties.DefaultIconDesc; } //failure to load a room does not necesitate failure to load the domain try{ this.LoadRoom(roomName); } catch (Sluggy.Utility.XMLParserException exception) { //throw new DomainModelException("Invalid master XML file. Could not load domain.",exception); System.Windows.Forms.MessageBox.Show("Failure loading room file '" + roomName + "' due to parsing error.\n\n" + exception.Message); } catch (DomainModelException exception) { System.Windows.Forms.MessageBox.Show(exception.Message); } vd.AddImage(new System.Drawing.Point(xPos, yPos), Globals.ImageBoxProperties.DefaultImage, this.DomainFileReferences[THIS_DOMAIN].ConvertRoomNameToFullPath(roomName), iconName); //the room object still needs it's iocn bitmap to be set //however, the bitmaps loaded from the config file are only //available to the DomainViewForm so it will have to deal with this } //break; } #endregion #region door tag parsing if (tag.Name == "directory" && tag.Attributes["name"] == "doors") { foreach (Sluggy.Utility.Tag doorTag in tag.Children) { if (doorTag.Attributes.ContainsKey("name") && doorTag.Attributes.ContainsKey("class")) { string name = doorTag.Attributes["name"]; string doorClass = doorTag.Attributes["class"]; if (!DomainFileReferences[THIS_DOMAIN].Inventory.ContainsKey(name)) { FileReferenceModel mod = new FileReferenceModel(name, Include.DetermineSaveType(doorClass), Include, this.Name); DomainFileReferences[THIS_DOMAIN].Doors.Add(name, mod); } } } } #endregion #region item tag parsing if (tag.Name == "directory" && tag.Attributes["name"] == "inventory") { foreach (Sluggy.Utility.Tag itemTag in tag.Children) { if (itemTag.Attributes.ContainsKey("name") && itemTag.Attributes.ContainsKey("class")) { string name = itemTag.Attributes["name"]; string itemClass = itemTag.Attributes["class"]; if (!DomainFileReferences[THIS_DOMAIN].Inventory.ContainsKey(name)) { FileReferenceModel mod = new FileReferenceModel(name, Include.DetermineSaveType(itemClass), Include, this.Name); DomainFileReferences[THIS_DOMAIN].Inventory.Add(name, mod); } } } } #endregion #region domain references if (tag.Name == "directory" && tag.Attributes["name"] == "references") { foreach (Sluggy.Utility.Tag itemTag in tag.Children) { if (itemTag.Attributes.ContainsKey("name")) { string name = itemTag.Attributes["name"]; if (name != this.Name && name != "domain") { this.AddDomainReference(name); } } } } #endregion //break; } } if (!validFile) { throw new DomainModelException("Invalid master XML file. Could not load domain."); } } catch (Sluggy.Utility.XMLParserException exception) { throw new DomainModelException("Failed to parse domain master XML file.\n\n" + exception.Message); } catch (System.IndexOutOfRangeException exception) { throw new DomainModelException("Corrupted master XML file. Could not load domain.", exception); } catch (System.ArgumentOutOfRangeException exception) { throw new DomainModelException("Corrupted master XML file. Could not load domain.", exception); } return(true); }