Пример #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");
 }
Пример #2
0
 /// <summary>
 /// Creates a new singleton instance of this class
 /// </summary>
 public MySettings()
 {
     Static   = this;
     Settings = new MyObjectBuilder_GlobalSettings();
 }