public override bool Load(string fileName)
        {
            try
            {
                if (!fileName.isUrl() && new FileInfo(fileName).Length == 0)
                {
                    // this is an empty file, probably thanks to our Explorer New->Trizbort Map menu option.
                    Settings.Reset();
                    return(true);
                }

                var doc = new XmlDocument();
                doc.Load(fileName);
                var root = new XmlElementReader(doc.DocumentElement);

                if (!root.HasName("trizbort"))
                {
                    throw new InvalidDataException($"Not a {System.Windows.Forms.Application.ProductName} map file.");
                }

                //reset checks: we may make this into a function if we ever wish to verify a Trizbort file first.
                Settings.StartRoomLoaded = false;
                Settings.EndRoomLoaded   = false;

                // file version
                var versionNumber = root.Attribute("version").Text;
                project.SetVersion(versionNumber);
                project.CheckDocVersion();

                // load info
                project.Title       = root["info"]["title"].Text;
                project.Author      = root["info"]["author"].Text;
                project.Description = root["info"]["description"].Text;
                project.History     = root["info"]["history"].Text;

                // load all elements
                var map = root["map"];
                var mapConnectionToLoadState = new Dictionary <Connection, object>();
                foreach (var element in map.Children)
                {
                    if (element.HasName("room"))
                    {
                        // Changed the constructor used for elements when loading a file for a significant speed increase
                        var room = new Room(project, project.Elements.Count + 1);
                        room.ID = element.Attribute("id").ToInt(room.ID);
                        room.Load(element);
                        project.Elements.Add(room);
                    }
                    else if (element.HasName("line"))
                    {
                        // Changed the constructor used for elements when loading a file for a significant speed increase
                        var connection = new Connection(project, project.Elements.Count + 1);
                        connection.ID = element.Attribute("id").ToInt(connection.ID);
                        var loadState = connection.BeginLoad(element);
                        if (loadState != null)
                        {
                            mapConnectionToLoadState.Add(connection, loadState);
                        }
                        project.Elements.Add(connection);
                    }
                }

                // connect them together
                foreach (var pair in mapConnectionToLoadState)
                {
                    var connection = pair.Key;
                    var state      = pair.Value;
                    connection.EndLoad(state);
                }

                // load settings last, since their load can't be undone
                Settings.Reset();
                Settings.Load(root["settings"]);

                // setup filewatcher.
                if (!fileName.isUrl())
                {
                    project.InitFileWWatcher(fileName);
                }

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(Program.MainForm, $"There was a problem loading the map:{Environment.NewLine}{Environment.NewLine}{ex.Message}", System.Windows.Forms.Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
        public object BeginLoad(XmlElementReader element)
        {
            if (element.Attribute("door").Text == "yes")
            {
                Door          = new Door();
                Door.Lockable = element.Attribute("lockable").Text == "yes";
                Door.Locked   = element.Attribute("locked").Text == "yes";
                Door.Open     = element.Attribute("open").Text == "yes";
                Door.Openable = element.Attribute("openable").Text == "yes";
            }

            switch (element.Attribute("style").Text)
            {
            default:
                Style = ConnectionStyle.Solid;
                break;

            case "dashed":
                Style = ConnectionStyle.Dashed;
                break;
            }
            switch (element.Attribute("flow").Text)
            {
            default:
                Flow = ConnectionFlow.TwoWay;
                break;

            case "oneWay":
                Flow = ConnectionFlow.OneWay;
                break;
            }
            Name        = element.Attribute("name").Text;
            Description = element.Attribute("description").Text;
            StartText   = element.Attribute("startText").Text;
            MidText     = element.Attribute("midText").Text;
            EndText     = element.Attribute("endText").Text;
            if (element.Attribute("color").Text != "")
            {
                ConnectionColor = ColorTranslator.FromHtml(element.Attribute("color").Text);
            }

            var vertexElementList = new List <XmlElementReader>();

            vertexElementList.AddRange(element.Children);
            vertexElementList.Sort((a, b) => a.Attribute("index").ToInt().CompareTo(b.Attribute("index").ToInt()));

            foreach (var vertexElement in vertexElementList)
            {
                if (vertexElement.HasName("point"))
                {
                    var vertex = new Vertex {
                        Position = new Vector(vertexElement.Attribute("x").ToFloat(), vertexElement.Attribute("y").ToFloat())
                    };
                    VertexList.Add(vertex);
                }
                else if (vertexElement.HasName("dock"))
                {
                    var vertex = new Vertex();
                    // temporarily leave this vertex as a positional vertex;
                    // we can't safely dock it to a port until EndLoad().
                    VertexList.Add(vertex);
                }
            }

            return(vertexElementList);
        }
        private static void loadLegacyAppSettings()
        {
            try
            {
                if (File.Exists(legacyAppSettingsPath))
                {
                    var doc = new XmlDocument();
                    doc.Load(legacyAppSettingsPath);
                    var root = new XmlElementReader(doc.DocumentElement);
                    if (root.Name == "settings")
                    {
                        var versionText = root["dontCareAboutVersion"].Text;
                        if (!string.IsNullOrEmpty(versionText))
                        {
                            settings.DontCareAboutVersion = new Version(versionText);
                        }
                        settings.InfiniteScrollBounds = root["infiniteScrollBounds"].ToBool(settings.InfiniteScrollBounds);
                        settings.ShowMiniMap          = root["showMiniMap"].ToBool(settings.ShowMiniMap);

                        settings.LoadLastProjectOnStart    = root["loadLastProjectOnStart"].ToBool(settings.LoadLastProjectOnStart);
                        settings.LastProjectFileName       = root["lastProjectFileName"].Text;
                        settings.LastExportImageFileName   = root["lastExportedImageFileName"].Text;
                        settings.LastExportInform7FileName = root["lastExportedInform7FileName"].Text;
                        settings.LastExportInform6FileName = root["lastExportedInform6FileName"].Text;
                        settings.LastExportTadsFileName    = root["lastExportedTadsFileName"].Text;
                        settings.LastExportHugoFileName    = root["lastExportedHugoFileName"].Text;
                        settings.LastExportZilFileName     = root["lastExportedZilFileName"].Text;

                        settings.InvertMouseWheel = root["invertMouseWheel"].ToBool(settings.InvertMouseWheel);
                        settings.PortAdjustDetail = root["portAdjustDetail"].ToInt(settings.PortAdjustDetail);
                        settings.DefaultFontName  = root["defaultFontName"].Text;

                        if (settings.DefaultFontName.Length == 0)
                        {
                            settings.DefaultFontName = "Arial";                             // important for compatibility with 1.5.9.3 and before. Otherwise it's set to MS Sans Serif
                        }
                        settings.DefaultImageType      = root["defaultImageType"].ToInt(settings.DefaultImageType);
                        settings.SaveToImage           = root["saveToImage"].ToBool(settings.SaveToImage);
                        settings.SaveToPDF             = root["saveToPDF"].ToBool(settings.SaveToPDF);
                        settings.SaveTadstoAdv3Lite    = root["saveTADSToADV3Lite"].ToBool(settings.SaveTadstoAdv3Lite);
                        settings.SaveAt100             = root["saveAt100"].ToBool(settings.SaveAt100);
                        settings.SpecifyGenMargins     = root["specifyMargins"].ToBool(settings.SpecifyGenMargins);
                        settings.GenHorizontalMargin   = root["horizontalMargin"].ToInt(settings.GenHorizontalMargin);
                        settings.GenVerticalMargin     = root["verticalMargin"].ToInt(settings.GenVerticalMargin);
                        settings.HandDrawnGlobal       = root["handDrawnDefault"].ToBool(settings.HandDrawnGlobal);
                        settings.ShowToolTipsOnObjects = root["showToolTipsOnObjects"].ToBool(true);

                        settings.CanvasWidth  = root["canvasWidth"].ToInt(settings.CanvasWidth);
                        settings.CanvasHeight = root["canvasHeight"].ToInt(settings.CanvasHeight);
                        if (settings.CanvasWidth == 0)
                        {
                            settings.CanvasWidth = 624;
                        }
                        if (settings.CanvasHeight == 0)
                        {
                            settings.CanvasHeight = 450;
                        }

                        var    recentProjects = root["recentProjects"];
                        string fileName;
                        var    index = 0;
                        do
                        {
                            fileName = recentProjects[$"fileName{index++}"].Text;
                            if (!string.IsNullOrEmpty(fileName))
                            {
                                settings.RecentProjects.Append(fileName);
                            }
                        } while (!string.IsNullOrEmpty(fileName));

                        var automap         = root["automap"];
                        var settingsAutomap = settings.Automap;
                        settingsAutomap.FileName          = automap["transcriptFileName"].ToText(settings.Automap.FileName);
                        settingsAutomap.VerboseTranscript = automap["verboseTranscript"].ToBool(settings.Automap.VerboseTranscript);
                        settingsAutomap.AssumeRoomsWithSameNameAreSameRoom = automap["assumeRoomsWithSameNameAreSameRoom"].ToBool(settings.Automap.AssumeRoomsWithSameNameAreSameRoom);
                        settingsAutomap.GuessExits       = automap["guessExits"].ToBool(settings.Automap.GuessExits);
                        settingsAutomap.AddObjectCommand = automap["addObjectCommand"].ToText(settings.Automap.AddObjectCommand);
                        settingsAutomap.AddRegionCommand = automap["addRegionCommand"].ToText(settings.Automap.AddRegionCommand);
                        settings.Automap = settingsAutomap;
                    }
                }
            }
            catch (Exception)
            {
                // ignored
            }
        }