Exemplo n.º 1
0
        private void LoadLayout(string file, string dir, List <Layout> layouts)
        {
            string layoutName = Path.GetFileNameWithoutExtension(file);

            file = Path.Combine(dir, file);             // Another leaked abstraction. I should not be handling unabstracted file names anymore!
            try
            {
                ConfigNode node = ConfigNode.Load(file).GetNode("KSEA_HISTORIAN_LAYOUT");

                if (layouts.FindIndex(layout => layout.Name == layoutName) < 0)
                {
                    Layout layout = KSEA.Historian.Layout.Load(layoutName, node);
                    layouts.Add(layout);

                    Log.trace("Found layout '{0}'.", layoutName);
                }
                else
                {
                    Log.warn("Layout with name '{0}' already exists. Unable to load duplicate.", layoutName);
                }
            }
            catch (Exception e)
            {
                Log.err("Failed to load layout '{0}' due {1}.", layoutName, e.Message);
            }
        }
Exemplo n.º 2
0
        private ConfigNode[] LoadTraits(string dir, string traitConfigFileName)
        {
            // Leaked abstraction. I should not be using System.IO and real pathnames here...
            traitConfigFileName = Path.Combine(dir, traitConfigFileName);
            if (!System.IO.File.Exists(traitConfigFileName))
            {
                return(null);
            }

            Historian.Print($"Loading traits from '{traitConfigFileName}'");
            return(ConfigNode.Load(traitConfigFileName).GetNodes("TRAIT"));
        }
Exemplo n.º 3
0
        public static void Load()
        {
            try
            {
                // Hack. I should had implemented a Directory<T> thingy already...
                Directory.CreateDirectory(LayoutsDirectoryUser);
                Log.dbg("{0} is assured to exist.", LayoutsDirectoryUser);
            }
            catch (Exception e)
            {
                Log.err("Could not initialise user data on {0} due {1}. Things will not work as expected!", LayoutsDirectoryUser, e.Message);
            }

            try
            {
                HISTORIANCFG.Clear();
                ConfigNode    node          = (HISTORIANCFG.IsLoadable ? HISTORIANCFG.Load().Node : HISTORIANCFG.Node);
                Configuration configuration = new Configuration();

                System.Version version = node.GetVersion("Version", new System.Version());

                configuration.Layout
                    = node.GetString("Layout", Defaults.Layout);
                configuration.EnableLauncherButton
                    = node.GetBoolean("EnableLauncherButton", Defaults.EnableLauncherButton);
                configuration.EnableToolbarButton
                    = node.GetBoolean("EnableToolbarButton", Defaults.EnableToolbarButton);
                configuration.AutoHideUI
                    = node.GetBoolean("AutoHideUI", Defaults.AutoHideUI);
                configuration.CustomText
                    = node.GetString("CustomText", Defaults.CustomText);
                configuration.DefaultSpaceCenterName
                    = node.GetString("DefaultSpaceCenterName", Defaults.DefaultSpaceCenterName);
                configuration.PersistentCustomText
                    = node.GetBoolean("PersistentCustomText", Defaults.PersistentCustomText);
                configuration.PersistentConfigurationWindow
                    = node.GetBoolean("PersistentConfigurationWindow", Defaults.PersistentConfigurationWindow);
                configuration.TimeToRememberLastAction
                    = node.GetInteger("TimeToRememberLastAction", Defaults.TimeToRememberLastAction);
                configuration.KerbinDayNames
                    = node.TryReadStringArray("KerbinDayNames", Defaults.KerbinDayNames);
                configuration.KerbinMonthNames
                    = node.TryReadStringArray("KerbinMonthNames", Defaults.KerbinMonthNames);
                configuration.RightClickAction
                    = node.GetEnum("RightClickAction", RightClickAction.Suppress);
                configuration.DefaultNoCrewLabel
                    = node.GetString("DefaultNoCrewLabel", Defaults.DefaultNoCrewLabel);
                configuration.DefaultUnmannedLabel
                    = node.GetString("DefaultUnmannedLabel", Defaults.DefaultUnmannedLabel);

                if (!String.IsNullOrEmpty(configuration.CustomText))
                {
                    configuration.TokenizedCustomText = Parser.GetTokens(configuration.CustomText);
                }

                if (version != CurrentVersion)
                {
                    configuration.Save();
                }

                instance = configuration;
            }
            catch
            {
                Historian.Print($"Failed to load configuration file '{HISTORIANCFG}'. Attempting recovery ...");

                // ensure save directory exists.
                string dir = HISTORIANCFG.KspPath;
                Directory.CreateDirectory(Path.Combine(dir, LAYOUTS_DIR));

                Historian.Print("Creating configuration from default values");
                HISTORIANCFG.Clear();
                Configuration configuration = new Configuration(fromDefaults: true);
                Historian.Print("Saving configuration file");
                configuration.Save();

                instance = configuration;
            }
        }