Beispiel #1
0
 /// <summary>
 /// Loads the global configuration file if it exists, otherwise creates a new one.
 /// </summary>
 public void LoadSettings()
 {
     MyPluginLog.Log("Loading the global config file");
     if (MyFileUtils.FileExistsInGlobalStorage(FILENAME))
     {
         try
         {
             using (var reader = MyFileUtils.ReadFileInGlobalStorage(FILENAME))
             {
                 MyPluginLog.Log("Reading global config file");
                 MyObjectBuilder_GlobalSettings saveFile = MyFileUtils.SerializeFromXml <MyObjectBuilder_GlobalSettings>(reader.ReadToEnd());
                 if (saveFile != null)
                 {
                     MyPluginLog.Log("Serialized global config file");
                     Settings = saveFile;
                 }
             }
         }
         catch (Exception e)
         {
             MyPluginLog.Log("Couldnt load Plugin config file.", LogLevel.ERROR);
             MyPluginLog.Log(e.Message + "\n" + e.StackTrace, LogLevel.ERROR);
             MyFileUtils.DeleteFileInGlobalStorage(FILENAME);
             Settings = new MyObjectBuilder_GlobalSettings();
             Settings.MoonDefinitions.Add("Moon");
             Settings.MoonDefinitions.Add("Titan");
             Settings.MoonDefinitions.Add("Europa");
             Settings.MoonDefinitions.Add("Triton");
             Settings.BlacklistedPlanetDefinitions.Add("EarthLikeTutorial");
             Settings.BlacklistedPlanetDefinitions.Add("MarsTutorial");
             Settings.BlacklistedPlanetDefinitions.Add("MoonTutorial");
             Settings.BlacklistedPlanetDefinitions.Add("SystemTestMap");
             Settings.BlacklistedPlanetDefinitions.Add("EarthLikeModExample");
         }
     }
     else
     {
         MyPluginLog.Log("Config does not exist, creating default one");
         Settings = new MyObjectBuilder_GlobalSettings();
         Settings.MoonDefinitions.Add("Moon");
         Settings.MoonDefinitions.Add("Titan");
         Settings.MoonDefinitions.Add("Europa");
         Settings.MoonDefinitions.Add("Triton");
         Settings.BlacklistedPlanetDefinitions.Add("EarthLikeTutorial");
         Settings.BlacklistedPlanetDefinitions.Add("MarsTutorial");
         Settings.BlacklistedPlanetDefinitions.Add("MoonTutorial");
         Settings.BlacklistedPlanetDefinitions.Add("SystemTestMap");
         Settings.BlacklistedPlanetDefinitions.Add("EarthLikeModExample");
     }
     Settings.Verify();
     MyPluginLog.Log("Config loaded");
 }
Beispiel #2
0
        /// <summary>
        /// Saves the global configuration file
        /// </summary>
        public void SaveSettings()
        {
            MyFileUtils.DeleteFileInGlobalStorage(FILENAME);

            string xml = MyFileUtils.SerializeToXml(Settings);

            MyPluginLog.Log("Saving global SEWorldGenPlugin config file: " + xml);

            using (var writer = MyFileUtils.WriteFileInGlobalStorage(FILENAME))
            {
                writer.Write(xml);
                writer.Close();
            }
        }