public override void Load() { if (!File.Exists(SettingsPath)) { var definition = new GameplaySettingsDefinition(); switch (GeneralSettings.SettingsStore.GameDifficulty) { case GameDifficulty.Easy: definition.SetEasy(); break; case GameDifficulty.Normal: definition.SetNormal(); break; case GameDifficulty.Moderate: definition.SetModerate(); break; case GameDifficulty.Hard: definition.SetHard(); break; case GameDifficulty.Custom: definition.SetNormal(); break; } LunaXmlSerializer.WriteToXmlFile(definition, Path.Combine(ServerContext.ConfigDirectory, Filename)); } base.Load(); }
/// <summary> /// Regenerates all the translation xml files. /// Usefull when you add a new string to a new text class as you don't need to edit all the xml files in every language /// </summary> public static void RegenerateTranslations() { var currentLanguage = CurrentLanguage.Clone() as string; foreach (var language in Languages) { LoadLanguage(language); LunaXmlSerializer.WriteToXmlFile(AdminWindowText, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(AdminWindowText)}.xml")); LunaXmlSerializer.WriteToXmlFile(BannedPartsResourcesWindowText, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(BannedPartsResourcesWindowText)}.xml")); LunaXmlSerializer.WriteToXmlFile(ChatWindowText, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(ChatWindowText)}.xml")); LunaXmlSerializer.WriteToXmlFile(ConnectionWindowText, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(ConnectionWindowText)}.xml")); LunaXmlSerializer.WriteToXmlFile(CraftLibraryWindowText, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(CraftLibraryWindowText)}.xml")); LunaXmlSerializer.WriteToXmlFile(ModWindowText, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(ModWindowText)}.xml")); LunaXmlSerializer.WriteToXmlFile(OptionsWindowText, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(OptionsWindowText)}.xml")); LunaXmlSerializer.WriteToXmlFile(ServerListWindowText, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(ServerListWindowText)}.xml")); LunaXmlSerializer.WriteToXmlFile(StatusWindowText, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(StatusWindowText)}.xml")); LunaXmlSerializer.WriteToXmlFile(DisclaimerDialogText, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(DisclaimerDialogText)}.xml")); LunaXmlSerializer.WriteToXmlFile(InstallDialogText, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(InstallDialogText)}.xml")); LunaXmlSerializer.WriteToXmlFile(ScreenshotWindowText, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(ScreenshotWindowText)}.xml")); LunaXmlSerializer.WriteToXmlFile(ScreenText, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(ScreenText)}.xml")); LunaXmlSerializer.WriteToXmlFile(ButtonTooltips, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(ButtonTooltips)}.xml")); LunaXmlSerializer.WriteToXmlFile(UpdateWindowText, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(UpdateWindowText)}.xml")); LunaXmlSerializer.WriteToXmlFile(CompatibleDialogText, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(CompatibleDialogText)}.xml")); LunaXmlSerializer.WriteToXmlFile(RevertDialogText, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(RevertDialogText)}.xml")); LunaXmlSerializer.WriteToXmlFile(ServerListFiltersText, CommonUtil.CombinePaths(LocalizationFolder, language, $"{nameof(ServerListFiltersText)}.xml")); } LoadLanguage(currentLanguage); }
public void Load() { if (!File.Exists(SettingsPath)) { LunaXmlSerializer.WriteToXmlFile(Activator.CreateInstance(SettingsHolderType), SettingsPath); } SettingsHolder = LunaXmlSerializer.ReadXmlFromPath(SettingsHolderType, SettingsPath); }
public static void SaveGroups() { lock (FileLock) { if (FileHandler.FolderExists(GroupsPath)) { LunaXmlSerializer.WriteToXmlFile(Groups.Values.ToList(), GroupsFilePath); } } }
private static void LoadWindowTexts <T>(object lang, ref T classToReplace) where T : class, new() { var filePath = CommonUtil.CombinePaths(LocalizationFolder, $"{classToReplace.GetType().Name}_{lang}.xml"); if (!File.Exists(filePath)) { LunaXmlSerializer.WriteToXmlFile(new T(), filePath); } classToReplace = LunaXmlSerializer.ReadXmlFromPath <T>(filePath); }
private static void CreateDefaultSettingsFile() { var defaultSettings = new SettingStructure(); var newKey = GenerateNewKeypair(); defaultSettings.PrivateKey = newKey.Key; defaultSettings.PublicKey = newKey.Value; LunaXmlSerializer.WriteToXmlFile(defaultSettings, SettingsFilePath); }
public void Load() { if (!File.Exists(SettingsPath)) { LunaXmlSerializer.WriteToXmlFile(Activator.CreateInstance(SettingsHolderType), SettingsPath); } try { SettingsHolder = LunaXmlSerializer.ReadXmlFromPath(SettingsHolderType, SettingsPath); } catch (Exception) { LunaLog.Fatal($"Error while trying to read {SettingsPath}. Default settings will be used. Please remove the file so a new one can be generated"); } }
public virtual void Load() { if (!File.Exists(SettingsPath)) { LunaXmlSerializer.WriteToXmlFile(Activator.CreateInstance(typeof(T)), Path.Combine(ServerContext.ConfigDirectory, Filename)); } try { SettingsStore = LunaXmlSerializer.ReadXmlFromPath(typeof(T), SettingsPath) as T; Save(); //We call the save to add the new settings into the file } catch (Exception) { LunaLog.Fatal($"Error while trying to read {SettingsPath}. Default settings will be used. Please remove the file so a new one can be generated"); } }
private static void LoadWindowTexts <T>(string language, ref T classToReplace) where T : class, new() { try { var filePath = CommonUtil.CombinePaths(LocalizationFolder, language, $"{classToReplace.GetType().Name}.xml"); if (!File.Exists(filePath)) { LunaXmlSerializer.WriteToXmlFile(new T(), filePath); } classToReplace = LunaXmlSerializer.ReadXmlFromPath <T>(filePath); } catch (Exception e) { LunaLog.LogError($"Error reading '{classToReplace.GetType().Name}.xml' for language '{language}' Details: {e}"); } }
public void GenerateModControlFile(bool appendSha) { var modCtrlStructure = new ModControlStructure { RequiredExpansions = GetInstalledExpansions() }; modCtrlStructure.AllowedParts.AddRange(PartLoader.LoadedPartsList.Select(p => p.name)); modCtrlStructure.AllowedResources.AddRange(PartResourceLibrary.Instance.resourceDefinitions.Cast <PartResourceDefinition>().Select(r => r.name)); foreach (var modFile in GetModFiles()) { modCtrlStructure.MandatoryPlugins.Add(new MandatoryDllFile { FilePath = GetRelativePath(modFile), Sha = appendSha ? Common.CalculateSha256FileHash(modFile) : string.Empty, Text = $"{Path.GetFileNameWithoutExtension(modFile)}. Version: {FileVersionInfo.GetVersionInfo(modFile).FileVersion}" }); } LunaXmlSerializer.WriteToXmlFile(modCtrlStructure, CommonUtil.CombinePaths(MainSystem.KspPath, "LMPModControl.xml")); LunaScreenMsg.PostScreenMessage(LocalizationContainer.ScreenText.ModFileGenerated, 5f, ScreenMessageStyle.UPPER_CENTER); }
public void GenerateModControlFile(bool appendSha) { var modFile = new ModControlStructure { RequiredExpansions = GetInstalledExpansions() }; var extraParts = PartLoader.LoadedPartsList.Where(p => !modFile.AllowedParts.Contains(p.name)).Select(p => p.name); modFile.AllowedParts.AddRange(extraParts); var gameDataDir = CommonUtil.CombinePaths(MainSystem.KspPath, "GameData"); foreach (var modDirectory in Directory.GetDirectories(gameDataDir)) { var relPathFolder = modDirectory.Substring(modDirectory.ToLower().IndexOf("gamedata", StringComparison.Ordinal) + 9).Replace("\\", "/"); if (relPathFolder.StartsWith("squad", StringComparison.OrdinalIgnoreCase) || relPathFolder.StartsWith("lunamultiplayer", StringComparison.OrdinalIgnoreCase)) { continue; } var filesInModFolder = Directory.GetFiles(modDirectory, "*.dll", SearchOption.AllDirectories); foreach (var file in filesInModFolder) { var relativeFilePath = file.Substring(file.ToLower().IndexOf("gamedata", StringComparison.Ordinal) + 9).Replace("\\", "/"); modFile.MandatoryPlugins.Add(new MandatoryDllFile { FilePath = relativeFilePath, Sha = appendSha ? Common.CalculateSha256FileHash(file) : string.Empty, Text = $"{Path.GetFileNameWithoutExtension(file)}. Version: {FileVersionInfo.GetVersionInfo(file).FileVersion}" }); } } LunaXmlSerializer.WriteToXmlFile(modFile, CommonUtil.CombinePaths(MainSystem.KspPath, "LMPModControl.xml")); LunaScreenMsg.PostScreenMessage(LocalizationContainer.ScreenText.ModFileGenerated, 5f, ScreenMessageStyle.UPPER_CENTER); }
/// <summary> /// Reads the PartsBehaviour.xml /// </summary> public static void ReadCustomizationXml() { var filePath = CommonUtil.CombinePaths(CustomPartSyncFolder, "PartsBehaviour.xml"); if (!File.Exists(filePath)) { LunaXmlSerializer.WriteToXmlFile(Resources.PartsBehaviour, filePath); } List <CustomModuleDefinition> moduleValues; try { moduleValues = LunaXmlSerializer.ReadXmlFromPath <List <CustomModuleDefinition> >(filePath); if (moduleValues.Select(m => m.ModuleName).Distinct().Count() != moduleValues.Count) { LunaLog.LogError("Duplicate modules found in PartsBehaviour.xml. Loading default values"); moduleValues = LoadDefaults(); } foreach (var moduleVal in moduleValues) { if (moduleVal.Fields.Select(m => m.FieldName).Distinct().Count() != moduleVal.Fields.Count) { LunaLog.LogError($"Duplicate fields found in module {moduleVal.ModuleName} of PartsBehaviour.xml. Loading default values"); moduleValues = LoadDefaults(); break; } } } catch (Exception e) { LunaLog.LogError($"Error reading PartsBehaviour.xml. Loading default values. Details {e}"); moduleValues = LoadDefaults(); } CustomizedModuleFieldsBehaviours = moduleValues.ToDictionary(m => m.ModuleName, v => v); }
public void Save() { LunaXmlSerializer.WriteToXmlFile(SettingsHolder, SettingsPath); }
private static void SaveCurrentModConfigurationFile() { var tempModFilePath = CommonUtil.CombinePaths(MainSystem.KspPath, "GameData", "LunaMultiplayer", "Data", "LMPModControl.xml"); LunaXmlSerializer.WriteToXmlFile(System.ModControlData, tempModFilePath); }
public static void SaveSettings(SettingStructure currentSettings) { CheckDataDirectory(); LunaXmlSerializer.WriteToXmlFile(currentSettings, SettingsFilePath); File.Copy(SettingsFilePath, BackupSettingsFilePath, true); }
private static void CreateDefaultSettingsFile() { var defaultSettings = new SettingStructure(); LunaXmlSerializer.WriteToXmlFile(defaultSettings, SettingsFilePath); }