コード例 #1
0
        internal ModSelectionViewInfo GetModSelectionViewInfo()
        {
            ModSelectionViewInfo vInfo = new ModSelectionViewInfo();

            if (splitContainer1.SplitterDistance > 0)
            {
                double d = splitContainer1.SplitterDistance / (double)splitContainer1.Width;
                vInfo.ModInfosSplitterPos = d;
            }

            vInfo.ModSelectionColumnsInfo = new ModSelectionColumnsInfo(tvModSelection);

            foreach (ColumnHeader column in lvModSelection.Columns)
            {
                vInfo.ModInfosColumnWidths.Add(column.Width);
            }

            return(vInfo);
        }
コード例 #2
0
        internal void SetModSelectionViewInfo(ModSelectionViewInfo vInfo)
        {
            if (vInfo.ModInfosSplitterPos > 0)
            {
                double d = (double)splitContainer1.Width * vInfo.ModInfosSplitterPos;
                splitContainer1.SplitterDistance = (int)d + 1;
            }

            if (vInfo.ModSelectionColumnsInfo != null && vInfo.ModSelectionColumnsInfo.Columns.Count > 0)
            {
                vInfo.ModSelectionColumnsInfo.ToTreeViewAdv(tvModSelection);
            }

            for (int i = 0; i < vInfo.ModInfosColumnWidths.Count; ++i)
            {
                var width = vInfo.ModInfosColumnWidths[i];
                if (i < lvModSelection.Columns.Count && width > 0)
                {
                    lvModSelection.Columns[i].Width = width;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// v1.0 load function.
        /// </summary>
        /// <returns>True on success.</returns>
        private static bool LoadV1_0(XmlDocument doc)
        {
            XmlNodeList language = doc.GetElementsByTagName(Constants.LANGUAGE);

            Localizer.GlobalInstance.CurrentLanguage = (language.Count >= 1) ? language[0].Attributes[Constants.NAME].Value : Localizer.DEFAULT_LANGUAGE;

            XmlNodeList maxim = doc.GetElementsByTagName(Constants.WINDOWSTATE);

            if (maxim.Count >= 1)
            {
                foreach (XmlAttribute att in maxim[0].Attributes)
                {
                    if (att.Name == Constants.MAXIM && att.Value != null)
                    {
                        MainController.View.WindowState = (att.Value.Equals(Constants.TRUE, StringComparison.CurrentCultureIgnoreCase) ? FormWindowState.Maximized : FormWindowState.Normal);
                    }
                }
            }

            XmlNodeList size = doc.GetElementsByTagName(Constants.SIZE);

            if (size.Count >= 1 && MainController.View.WindowState != FormWindowState.Maximized)
            {
                MainController.View.Width  = int.Parse(size[0].Attributes[Constants.WIDTH].Value);
                MainController.View.Height = int.Parse(size[0].Attributes[Constants.HEIGHT].Value);
            }

            XmlNodeList pos = doc.GetElementsByTagName(Constants.POSITION);

            if (pos.Count >= 1)
            {
                int x = 0;
                int y = 0;
                foreach (XmlAttribute att in pos[0].Attributes)
                {
                    if (att.Name == Constants.X)
                    {
                        int.TryParse(att.Value, out x);
                    }
                    else if (att.Name == Constants.Y)
                    {
                        int.TryParse(att.Value, out y);
                    }
                }

                int width  = Screen.PrimaryScreen.Bounds.Width;
                int height = Screen.PrimaryScreen.Bounds.Height;

                Point position = new Point(x, y);
                if (position.X < 0 || position.Y < 0 ||
                    position.X > width || position.X + MainController.View.Width > width ||
                    position.Y > height || position.Y + MainController.View.Height > height)
                {
                    position = Point.Empty;
                }

                if (position != Point.Empty)
                {
                    MainController.View.Location = position;
                }
            }

            ModSelectionViewInfo vInfo = new ModSelectionViewInfo();

            vInfo.ModSelectionColumnsInfo = new ModSelectionColumnsInfo(doc);

            XmlNodeList colWidths = doc.GetElementsByTagName(Constants.MODINFOCOLUMNS);

            if (colWidths.Count >= 1)
            {
                var columns = colWidths[0];
                foreach (XmlNode col in columns.ChildNodes)
                {
                    int id    = -1;
                    int width = 0;
                    foreach (XmlAttribute att in col.Attributes)
                    {
                        if (att.Name == Constants.ID && !string.IsNullOrEmpty(att.Value))
                        {
                            id = int.Parse(att.Value);
                        }
                        else if (att.Name == Constants.WIDTH && !string.IsNullOrEmpty(att.Value))
                        {
                            width = int.Parse(att.Value);
                        }
                    }

                    if (width > 0)
                    {
                        vInfo.ModInfosColumnWidths.Add(width);
                    }
                }
            }

            XmlNodeList splitterPos = doc.GetElementsByTagName(Constants.MODINFOSSPLITTERPOS);

            if (splitterPos.Count >= 1)
            {
                foreach (XmlAttribute att in splitterPos[0].Attributes)
                {
                    if (att.Name == Constants.POSITION && att.Value != null)
                    {
                        vInfo.ModInfosSplitterPos = double.Parse(att.Value);
                    }
                }
            }

            if (!vInfo.IsEmpty)
            {
                ModSelectionController.View.SetModSelectionViewInfo(vInfo);
            }

            XmlNodeList destinationDetectionNode = doc.GetElementsByTagName(Constants.DESTINATIONDETECTIONOPTIONS);

            if (destinationDetectionNode.Count >= 1)
            {
                foreach (XmlAttribute att in destinationDetectionNode[0].Attributes)
                {
                    if (att.Name == Constants.TYPE && att.Value != null)
                    {
                        OptionsController.DestinationDetectionType = (DestinationDetectionType)int.Parse(att.Value);
                    }
                    else if (att.Name == Constants.FALLBACK && att.Value != null)
                    {
                        OptionsController.CopyToGameData = (att.Value.Equals(Constants.TRUE, StringComparison.CurrentCultureIgnoreCase));
                    }
                }
            }

            XmlNodeList ttOptions = doc.GetElementsByTagName(Constants.TOOLTIPOPTIONS);

            if (ttOptions.Count >= 1)
            {
                foreach (XmlAttribute att in ttOptions[0].Attributes)
                {
                    if (att.Name == Constants.ONOFF && att.Value != null)
                    {
                        OptionsController.ToolTipOnOff = (att.Value.Equals(Constants.TRUE, StringComparison.CurrentCultureIgnoreCase));
                    }
                    else if (att.Name == Constants.DELAY && att.Value != null)
                    {
                        OptionsController.ToolTipDelay = decimal.Parse(att.Value);
                    }
                    else if (att.Name == Constants.DISPLAYTIME && att.Value != null)
                    {
                        OptionsController.ToolTipDisplayTime = decimal.Parse(att.Value);
                    }
                }
            }

            XmlNodeList conflictDetectionOnnOff = doc.GetElementsByTagName(Constants.CONFLICTDETECTIONOPTIONS);

            if (conflictDetectionOnnOff.Count >= 1)
            {
                foreach (XmlAttribute att in conflictDetectionOnnOff[0].Attributes)
                {
                    if (att.Name == Constants.ONOFF && att.Value != null)
                    {
                        OptionsController.ConflictDetectionOnOff = (att.Value.Equals(Constants.TRUE, StringComparison.CurrentCultureIgnoreCase));
                    }
                }
            }

            XmlNodeList avcSupportOnOff = doc.GetElementsByTagName(Constants.AVCSUPPORT);

            if (avcSupportOnOff.Count >= 1)
            {
                foreach (XmlAttribute att in avcSupportOnOff[0].Attributes)
                {
                    if (att.Name == Constants.ONOFF && att.Value != null)
                    {
                        OptionsController.AVCSupportOnOff = (att.Value.Equals(Constants.TRUE, StringComparison.CurrentCultureIgnoreCase));
                    }
                }
            }

            XmlNodeList avcIgnoreName = doc.GetElementsByTagName(Constants.AVCIGNORENAME);

            if (avcIgnoreName.Count >= 1)
            {
                foreach (XmlAttribute att in avcIgnoreName[0].Attributes)
                {
                    if (att.Name == Constants.ONOFF && att.Value != null)
                    {
                        OptionsController.AVCIgnoreName = (att.Value.Equals(Constants.TRUE, StringComparison.CurrentCultureIgnoreCase));
                    }
                }
            }

            XmlNodeList avcIgnoreURL = doc.GetElementsByTagName(Constants.AVCIGNOREURL);

            if (avcIgnoreURL.Count >= 1)
            {
                foreach (XmlAttribute att in avcIgnoreURL[0].Attributes)
                {
                    if (att.Name == Constants.ONOFF && att.Value != null)
                    {
                        OptionsController.AVCIgnoreURL = (att.Value.Equals(Constants.TRUE, StringComparison.CurrentCultureIgnoreCase));
                    }
                }
            }

            XmlNodeList colorDestinationDetected = doc.GetElementsByTagName(Constants.DESTINATIONDETECTED);

            if (colorDestinationDetected.Count >= 1)
            {
                foreach (XmlAttribute att in colorDestinationDetected[0].Attributes)
                {
                    if (att.Name == Constants.COLOR && att.Value != null)
                    {
                        OptionsController.ColorDestinationDetected = GetColor(att.Value);
                    }
                }
            }

            XmlNodeList colorDestinationMissing = doc.GetElementsByTagName(Constants.DESTINATIONMISSING);

            if (colorDestinationMissing.Count >= 1)
            {
                foreach (XmlAttribute att in colorDestinationMissing[0].Attributes)
                {
                    if (att.Name == Constants.COLOR && att.Value != null)
                    {
                        OptionsController.ColorDestinationMissing = GetColor(att.Value);
                    }
                }
            }

            XmlNodeList colorDestinationConflict = doc.GetElementsByTagName(Constants.DESTINATIONCONFLICT);

            if (colorDestinationConflict.Count >= 1)
            {
                foreach (XmlAttribute att in colorDestinationConflict[0].Attributes)
                {
                    if (att.Name == Constants.COLOR && att.Value != null)
                    {
                        OptionsController.ColorDestinationConflict = GetColor(att.Value);
                    }
                }
            }

            XmlNodeList colorModInstalled = doc.GetElementsByTagName(Constants.MODINSTALLED);

            if (colorModInstalled.Count >= 1)
            {
                foreach (XmlAttribute att in colorModInstalled[0].Attributes)
                {
                    if (att.Name == Constants.COLOR && att.Value != null)
                    {
                        OptionsController.ColorModInstalled = GetColor(att.Value);
                    }
                }
            }

            XmlNodeList colorModArchiveMissing = doc.GetElementsByTagName(Constants.MODARCHIVEMISSING);

            if (colorModArchiveMissing.Count >= 1)
            {
                foreach (XmlAttribute att in colorModArchiveMissing[0].Attributes)
                {
                    if (att.Name == Constants.COLOR && att.Value != null)
                    {
                        OptionsController.ColorModArchiveMissing = GetColor(att.Value);
                    }
                }
            }

            XmlNodeList colorModOutdated = doc.GetElementsByTagName(Constants.MODOUTDATED);

            if (colorModOutdated.Count >= 1)
            {
                foreach (XmlAttribute att in colorModOutdated[0].Attributes)
                {
                    if (att.Name == Constants.COLOR && att.Value != null)
                    {
                        OptionsController.ColorModOutdated = GetColor(att.Value);
                    }
                }
            }

            XmlNodeList nodes = doc.GetElementsByTagName(Constants.KNOWN_KSP_PATH);

            if (nodes.Count >= 1)
            {
                List <NoteNode> knownPaths = new List <NoteNode>();
                foreach (XmlNode node in nodes)
                {
                    string kspPath   = string.Empty;
                    string noteValue = string.Empty;
                    foreach (XmlAttribute att in node.Attributes)
                    {
                        if (att.Name == Constants.FULLPATH)
                        {
                            kspPath = att.Value;
                        }
                        else if (att.Name == Constants.NOTE)
                        {
                            noteValue = att.Value;
                        }
                    }

                    if (KSPPathHelper.IsKSPInstallFolder(kspPath))
                    {
                        knownPaths.Add(new NoteNode(kspPath, kspPath, noteValue));
                    }
                }

                if (knownPaths.Count > 0)
                {
                    OptionsController.KnownKSPPaths = knownPaths;
                }
            }

            nodes = doc.GetElementsByTagName(Constants.KSP_PATH);
            if (nodes.Count >= 1)
            {
                foreach (XmlAttribute att in nodes[0].Attributes)
                {
                    if (att.Name == Constants.NAME && !string.IsNullOrEmpty(att.Value))
                    {
                        if (KSPPathHelper.IsKSPInstallFolder(att.Value) && OptionsController.SelectedKSPPath != att.Value)
                        {
                            OptionsController.SelectedKSPPath = att.Value;
                        }
                        break;
                    }
                }
            }

            if (string.IsNullOrEmpty(OptionsController.SelectedKSPPath) && OptionsController.KnownKSPPaths.Count > 0)
            {
                OptionsController.SelectedKSPPath = OptionsController.KnownKSPPaths[0].FullPath;
            }

            nodes = doc.GetElementsByTagName(Constants.POSTDOWNLOADACTION);
            if (nodes.Count >= 1)
            {
                foreach (XmlAttribute att in nodes[0].Attributes)
                {
                    if (att.Name == Constants.VALUE)
                    {
                        try
                        {
                            switch (int.Parse(att.Value))
                            {
                            case (int)PostDownloadAction.Ask:
                                OptionsController.PostDownloadAction = PostDownloadAction.Ask;
                                break;

                            case (int)PostDownloadAction.AutoUpdate:
                                OptionsController.PostDownloadAction = PostDownloadAction.AutoUpdate;
                                break;

                            case (int)PostDownloadAction.Ignore:
                                OptionsController.PostDownloadAction = PostDownloadAction.Ignore;
                                break;
                            }
                        }
                        catch
                        {
                            OptionsController.PostDownloadAction = PostDownloadAction.Ask;
                        }
                    }
                }
            }

            nodes = doc.GetElementsByTagName(Constants.CHECKFORUPDATES);
            if (nodes.Count >= 1)
            {
                foreach (XmlAttribute att in nodes[0].Attributes)
                {
                    if ((att.Name == Constants.VALUE || att.Name == Constants.CHECKFORUPDATES) && att.Value != null)
                    {
                        OptionsController.VersionCheck = (att.Value.Equals(Constants.TRUE, StringComparison.CurrentCultureIgnoreCase));
                    }
                }
            }

            nodes = doc.GetElementsByTagName(Constants.LASTMODUPDATETRY);
            if (nodes.Count >= 1)
            {
                foreach (XmlAttribute att in nodes[0].Attributes)
                {
                    if (att.Name == Constants.VALUE && att.Value != null)
                    {
                        try { OptionsController.LastModUpdateTry = DateTime.Parse(att.Value); }
                        catch { }
                    }
                }
            }

            nodes = doc.GetElementsByTagName(Constants.MODUPDATEINTERVAL);
            if (nodes.Count >= 1)
            {
                foreach (XmlAttribute att in nodes[0].Attributes)
                {
                    if (att.Name == Constants.VALUE && att.Value != null)
                    {
                        try { OptionsController.ModUpdateInterval = (ModUpdateInterval)int.Parse(att.Value); }
                        catch { }
                    }
                }
            }

            nodes = doc.GetElementsByTagName(Constants.MODUPDATEBEHAVIOR);
            if (nodes.Count >= 1)
            {
                foreach (XmlAttribute att in nodes[0].Attributes)
                {
                    if (att.Name == Constants.VALUE && att.Value != null)
                    {
                        try { OptionsController.ModUpdateBehavior = (ModUpdateBehavior)int.Parse(att.Value); }
                        catch { }
                    }
                }
            }

            nodes = doc.GetElementsByTagName(Constants.DELETEOLDARCHIVES);
            if (nodes.Count >= 1)
            {
                foreach (XmlAttribute att in nodes[0].Attributes)
                {
                    if (att.Name == Constants.VALUE && att.Value != null)
                    {
                        OptionsController.DeleteOldArchivesAfterUpdate = (att.Value.Equals(Constants.TRUE, StringComparison.CurrentCultureIgnoreCase));
                    }
                }
            }

            nodes = doc.GetElementsByTagName(Constants.COLOR4OUTDATEDMODS);
            if (nodes.Count >= 1)
            {
                foreach (XmlAttribute att in nodes[0].Attributes)
                {
                    if (att.Name == Constants.VALUE && att.Value != null)
                    {
                        OptionsController.Color4OutdatedMods = (att.Value.Equals(Constants.TRUE, StringComparison.CurrentCultureIgnoreCase));
                    }
                }
            }

            var tabOrder = new List <string>();

            nodes = doc.GetElementsByTagName(Constants.TAB);
            foreach (XmlNode n in nodes)
            {
                foreach (XmlAttribute att in n.Attributes)
                {
                    if (att.Name == Constants.UNIQUEIDENTIFIER && att.Value != null)
                    {
                        tabOrder.Add(att.Value);
                    }
                }
            }
            if (tabOrder.Count > 0)
            {
                MainController.LastTabOrder = tabOrder;
            }


            OptionsController.OtherAppOptions = new Dictionary <string, string>();
            nodes = doc.GetElementsByTagName(Constants.OTHERAPPOPTION);
            if (nodes.Count >= 1)
            {
                foreach (XmlNode node in nodes)
                {
                    var name  = string.Empty;
                    var value = string.Empty;
                    foreach (XmlAttribute att in node.Attributes)
                    {
                        if (att.Name == Constants.NAME && att.Value != null)
                        {
                            name = att.Value;
                        }
                        if (att.Name == Constants.VALUE && att.Value != null)
                        {
                            value = att.Value;
                        }
                    }
                    if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(value))
                    {
                        OptionsController.OtherAppOptions.Add(name, value);
                    }
                }
            }

            return(true);
        }