コード例 #1
0
        private void LoadStoredProfiles()
        {
            try
            {
                storedProfiles = new ProfileTable();
                if (System.IO.File.Exists(ProfileStoragePath))
                {
                    ConfigNode stored = ConfigNode.Load(ProfileStoragePath);
                    if (stored != null && stored.HasNode(STORED_NODE_NAME))
                    {
                        stored = stored.GetNode(STORED_NODE_NAME); // to avoid having an empty cfg, which will cause KSP to hang at load
                        var profiles = stored.GetNodes("PROFILE");

                        foreach (var profileNode in profiles)
                        {
                            try
                            {
                                Profile p = new Profile(profileNode);
                                p.modified = false; // by definition, stored profiles haven't been modified
                                storedProfiles.Add(p.name, p);
                                Log.Normal("[ScienceAlert]Loaded profile '{0}' successfully!", p.name);
                            }
                            catch (Exception e)
                            {
                                Log.Error("ProfileManager: profile '{0}' failed to parse; {1}", name, e);
                            }
                        }
                    }
                }
                if (DefaultProfile == null)
                {
                    storedProfiles.Add("default", Profile.MakeDefault());
                }
            }
            catch (Exception e)
            {
                Log.Error("ProfileManager: Exception loading stored profiles: {0}", e);
                storedProfiles = new ProfileTable();
            }
        }
コード例 #2
0
        /// <summary>
        /// Load stored profiles from a ConfigNode in the ScienceAlert
        /// directory
        /// </summary>
        private void LoadStoredProfiles()
        {
            try
            {
                storedProfiles = new ProfileTable();

                if (!System.IO.File.Exists(ProfileStoragePath))
                {
                    Log.Warning("ProfileManager: Profile config not found at '{0}'", ProfileStoragePath);
                }
                else
                {
                    Log.Debug("ProfileManager: Loading profile config from '{0}'", ProfileStoragePath);

                    ConfigNode stored = ConfigNode.Load(ProfileStoragePath);

                    if (stored == null || !stored.HasNode(STORED_NODE_NAME))
                    {
                        Log.Error("ProfileManager: Failed to load config");
                    }
                    else
                    {
                        stored = stored.GetNode(STORED_NODE_NAME); // to avoid having an empty cfg, which will
                        // cause KSP to hang at load

                        var profiles = stored.GetNodes("PROFILE");
                        Log.Verbose("Found {0} stored profiles to load", profiles.Length);

                        foreach (var profileNode in profiles)
                        {
                            try
                            {
                                Profile p = new Profile(profileNode);
                                p.modified = false; // by definition, stored profiles haven't been modified

                                storedProfiles.Add(p.name, p);
                                Log.Verbose("Loaded profile '{0}' successfully!", p.name);
                            }
                            catch (Exception e)
                            {
                                Log.Error("ProfileManager: profile '{0}' failed to parse; {1}", name, e);
                            }
                        }
                    }
                }

                // make sure there's a "default" config in there. Ideally the
                // user has created and saved over one but if not, we need
                // at least a default to give to vessels that are missing their
                // profiles
                if (DefaultProfile == null)
                {
                    storedProfiles.Add("default", Profile.MakeDefault());
                }
            } catch (Exception e)
            {
                Log.Error("ProfileManager: Exception loading stored profiles: {0}", e);

                // don't keep anything that might have been loaded; something's
                // gone seriously wrong but we might manage to salvage things if
                // we accept the loss of stored data and use the vessel-specific
                // profiles instead
                storedProfiles = new ProfileTable();
            }
        }