public static void LoadModFile() { try { ModControl = LunaXmlSerializer.ReadXmlFromPath <ModControlStructure>(ServerContext.ModFilePath); } catch (Exception) { LunaLog.Error("Cannot read LMPModControl file. Will load the default one. Please regenerate it"); ModControl = LunaXmlSerializer.ReadXmlFromString <ModControlStructure>(LunaCommon.Properties.Resources.LMPModControl); } }
public static ModControlStructure ReadModFileFromPath(string filePath) { try { if (!File.Exists(filePath)) { File.WriteAllText(filePath, Resources.LMPModControl); } return(LunaXmlSerializer.ReadXmlFromPath <ModControlStructure>(filePath)); } catch (Exception) { return(LunaXmlSerializer.ReadXmlFromString <ModControlStructure>(Resources.LMPModControl)); } }
public void CheckCommonStockParts() { var missingPartsCount = 0; LunaLog.Log("[LMP]: Missing parts start"); var modFile = LunaXmlSerializer.ReadXmlFromString <ModControlStructure>(LunaCommon.Properties.Resources.LMPModControl); var missingParts = PartLoader.LoadedPartsList.Where(p => !modFile.AllowedParts.Contains(p.name)); foreach (var part in missingParts) { missingPartsCount++; LunaLog.Log($"[LMP]: Missing '{part.name}'"); } LunaLog.Log("[LMP]: Missing parts end"); LunaScreenMsg.PostScreenMessage( missingPartsCount > 0 ? $"{missingPartsCount} missing part(s) from Common.dll printed to debug log ({PartLoader.LoadedPartsList.Count} total)" : $"No missing parts out of from Common.dll ({PartLoader.LoadedPartsList.Count} total)", 5f, ScreenMessageStyle.UPPER_CENTER); }
public void GenerateModControlFile(bool appendSha) { var modFile = LunaXmlSerializer.ReadXmlFromString <ModControlStructure>(LunaCommon.Properties.Resources.LMPModControl); modFile.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); }
public static ModControlStructure ReadModFileFromString(string contents) { return(LunaXmlSerializer.ReadXmlFromString <ModControlStructure>(contents)); }
private static List <CustomModuleDefinition> LoadDefaults() { return(LunaXmlSerializer.ReadXmlFromString <List <CustomModuleDefinition> >(Resources.PartsBehaviour)); }