Beispiel #1
0
 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 = new ModControlStructure();
     }
 }
 public static void LoadGroups()
 {
     lock (FileLock)
     {
         if (File.Exists(GroupsFilePath))
         {
             var values = LunaXmlSerializer.ReadXmlFromPath <List <Group> >(GroupsFilePath);
             foreach (var value in values)
             {
                 Groups.TryAdd(value.Name, value);
             }
         }
     }
 }
Beispiel #3
0
        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");
            }
        }
Beispiel #4
0
        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));
            }
        }
Beispiel #5
0
        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 static SettingStructure ReadSettings()
        {
            CheckDataDirectory();

            RestoreBackupIfNoSettings();

            if (!File.Exists(SettingsFilePath))
            {
                CreateDefaultSettingsFile();
            }

            if (!File.Exists(BackupSettingsFilePath))
            {
                LunaLog.Log("[LMP]: Backing up player token and settings file!");
                File.Copy(SettingsFilePath, BackupSettingsFilePath);
            }

            return(LunaXmlSerializer.ReadXmlFromPath <SettingStructure>(SettingsFilePath));
        }
        /// <summary>
        /// Reads the module customizations xml
        /// </summary>
        public static void ReadCustomizationXml()
        {
            var moduleValues = new List <ModuleDefinition>();

            foreach (var file in Directory.GetFiles(CustomPartSyncFolder, "*.xml"))
            {
                var moduleDefinition = LunaXmlSerializer.ReadXmlFromPath <ModuleDefinition>(file);
                moduleDefinition.ModuleName = Path.GetFileNameWithoutExtension(file);

                if (moduleDefinition.Fields.Select(m => m.FieldName).Distinct().Count() != moduleDefinition.Fields.Count)
                {
                    LunaLog.LogError($"Duplicate fields found in file: {file}. The module will be ignored");
                    continue;
                }

                moduleValues.Add(moduleDefinition);
            }

            CustomizedModuleFieldsBehaviours = moduleValues.ToDictionary(m => m.ModuleName, v => v);
        }
        /// <summary>
        /// Reads the module customizations xml.
        /// Basically it fills up the CustomizedModuleBehaviours dictionary
        /// </summary>
        public static void ReadCustomizationXml()
        {
            var moduleValues = new List <ModuleDefinition>();

            foreach (var file in Directory.GetFiles(CustomPartSyncFolder, "*.xml", SearchOption.AllDirectories))
            {
                var moduleDefinition = LunaXmlSerializer.ReadXmlFromPath <ModuleDefinition>(file);
                moduleDefinition.ModuleName = Path.GetFileNameWithoutExtension(file);

                moduleValues.Add(moduleDefinition);
            }

            CustomizedModuleBehaviours = moduleValues.ToDictionary(m => m.ModuleName, v => v);

            var newChildModulesToAdd = new List <ModuleDefinition>();

            foreach (var value in CustomizedModuleBehaviours.Values)
            {
                var moduleClass = PartModuleTypes.FirstOrDefault(t => t.Name == value.ModuleName);
                if (moduleClass != null)
                {
                    AddParentsCustomizations(value, moduleClass);
                    newChildModulesToAdd.AddRange(GetChildCustomizations(value, moduleClass));
                }
            }

            foreach (var moduleToAdd in newChildModulesToAdd)
            {
                if (!CustomizedModuleBehaviours.ContainsKey(moduleToAdd.ModuleName))
                {
                    CustomizedModuleBehaviours.Add(moduleToAdd.ModuleName, moduleToAdd);
                }
            }

            foreach (var module in CustomizedModuleBehaviours.Values)
            {
                module.Init();
            }
        }
Beispiel #10
0
        /// <summary>
        /// Reads the PartsBehaviour.xml
        /// </summary>
        public static void ReadCustomizationXml()
        {
            var filePath = CommonUtil.CombinePaths(CustomPartSyncFolder, "PartsBehaviour.xml");

            if (!File.Exists(filePath))
            {
                File.WriteAllText(filePath, Resources.PartsBehaviour);
            }

            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);
        }
Beispiel #11
0
 public static void LoadModFile()
 {
     try
     {
         ModControl = LunaXmlSerializer.ReadXmlFromPath <ModControlStructure>(ServerContext.ModFilePath);
     }
     catch (Exception)
     {
         LunaLog.Warning("LMPModControl file was either missing or corrupt, a fresh default copy has been regenerated.");
         GenerateNewModFile();
     }
     string[] DefaultAllowedParts = new string[]
     {
         "StandardCtrlSrf",
         "CanardController",
         "noseCone",
         "AdvancedCanard",
         "airplaneTail",
         "deltaWing",
         "noseConeAdapter",
         "rocketNoseCone",
         "smallCtrlSrf",
         "standardNoseCone",
         "sweptWing",
         "tailfin",
         "wingConnector",
         "winglet",
         "R8winglet",
         "winglet3",
         "Mark1Cockpit",
         "Mark2Cockpit",
         "Mark1-2Pod",
         "advSasModule",
         "asasmodule1-2",
         "avionicsNoseCone",
         "crewCabin",
         "cupola",
         "landerCabinSmall",
         "mark3Cockpit",
         "mk1pod",
         "mk2LanderCabin",
         "probeCoreCube",
         "probeCoreHex",
         "probeCoreOcto",
         "probeCoreOcto2",
         "probeCoreSphere",
         "probeStackLarge",
         "probeStackSmall",
         "sasModule",
         "seatExternalCmd",
         "rtg",
         "batteryBank",
         "batteryBankLarge",
         "batteryBankMini",
         "batteryPack",
         "ksp.r.largeBatteryPack",
         "largeSolarPanel",
         "solarPanels1",
         "solarPanels2",
         "solarPanels3",
         "solarPanels4",
         "solarPanels5",
         "JetEngine",
         "engineLargeSkipper",
         "ionEngine",
         "liquidEngine",
         "liquidEngine1-2",
         "liquidEngine2",
         "liquidEngine2-2",
         "liquidEngine3",
         "liquidEngineMini",
         "microEngine",
         "nuclearEngine",
         "radialEngineMini",
         "radialLiquidEngine1-2",
         "sepMotor1",
         "smallRadialEngine",
         "solidBooster",
         "solidBooster1-1",
         "toroidalAerospike",
         "turboFanEngine",
         "MK1Fuselage",
         "Mk1FuselageStructural",
         "RCSFuelTank",
         "RCSTank1-2",
         "rcsTankMini",
         "rcsTankRadialLong",
         "fuelTank",
         "fuelTank1-2",
         "fuelTank2-2",
         "fuelTank3-2",
         "fuelTank4-2",
         "fuelTankSmall",
         "fuelTankSmallFlat",
         "miniFuelTank",
         "mk2Fuselage",
         "mk2SpacePlaneAdapter",
         "mk3Fuselage",
         "mk3spacePlaneAdapter",
         "radialRCSTank",
         "toroidalFuelTank",
         "xenonTank",
         "xenonTankRadial",
         "adapterLargeSmallBi",
         "adapterLargeSmallQuad",
         "adapterLargeSmallTri",
         "adapterSmallMiniShort",
         "adapterSmallMiniTall",
         "nacelleBody",
         "radialEngineBody",
         "smallHardpoint",
         "stationHub",
         "structuralIBeam1",
         "structuralIBeam2",
         "structuralIBeam3",
         "structuralMiniNode",
         "structuralPanel1",
         "structuralPanel2",
         "structuralPylon",
         "structuralWing",
         "strutConnector",
         "strutCube",
         "strutOcto",
         "trussAdapter",
         "trussPiece1x",
         "trussPiece3x",
         "CircularIntake",
         "landingLeg1",
         "landingLeg1-2",
         "RCSBlock",
         "stackDecoupler",
         "airScoop",
         "commDish",
         "decoupler1-2",
         "dockingPort1",
         "dockingPort2",
         "dockingPort3",
         "dockingPortLarge",
         "dockingPortLateral",
         "fuelLine",
         "ladder1",
         "largeAdapter",
         "largeAdapter2",
         "launchClamp1",
         "linearRcs",
         "longAntenna",
         "miniLandingLeg",
         "parachuteDrogue",
         "parachuteLarge",
         "parachuteRadial",
         "parachuteSingle",
         "radialDecoupler",
         "radialDecoupler1-2",
         "radialDecoupler2",
         "ramAirIntake",
         "roverBody",
         "sensorAccelerometer",
         "sensorBarometer",
         "sensorGravimeter",
         "sensorThermometer",
         "spotLight1",
         "spotLight2",
         "stackBiCoupler",
         "stackDecouplerMini",
         "stackPoint1",
         "stackQuadCoupler",
         "stackSeparator",
         "stackSeparatorBig",
         "stackSeparatorMini",
         "stackTriCoupler",
         "telescopicLadder",
         "telescopicLadderBay",
         "SmallGearBay",
         "roverWheel1",
         "roverWheel2",
         "roverWheel3",
         "wheelMed",
         "flag",
         "kerbalEVA",
         "mediumDishAntenna",
         "GooExperiment",
         "science.module",
         "RAPIER",
         "Large.Crewed.Lab",
         "GrapplingDevice",
         "LaunchEscapeSystem",
         "MassiveBooster",
         "PotatoRoid",
         "Size2LFB",
         "Size3AdvancedEngine",
         "size3Decoupler",
         "Size3EngineCluster",
         "Size3LargeTank",
         "Size3MediumTank",
         "Size3SmallTank",
         "Size3to2Adapter",
         "omsEngine",
         "vernierEngine",
         "delta.small",
         "elevon2",
         "elevon3",
         "elevon5",
         "IntakeRadialLong",
         "MK1IntakeFuselage",
         "mk2.1m.AdapterLong",
         "mk2.1m.Bicoupler",
         "mk2CargoBayL",
         "mk2CargoBayS",
         "mk2Cockpit.Inline",
         "mk2Cockpit.Standard",
         "mk2CrewCabin",
         "mk2DockingPort",
         "mk2DroneCore",
         "mk2FuselageLongLFO",
         "mk2FuselageShortLFO",
         "mk2FuselageShortLiquid",
         "mk2FuselageShortMono",
         "shockConeIntake",
         "structuralWing2",
         "structuralWing3",
         "structuralWing4",
         "sweptWing1",
         "sweptWing2",
         "wingConnector2",
         "wingConnector3",
         "wingConnector4",
         "wingConnector5",
         "wingStrake",
         "adapterMk3-Mk2",
         "adapterMk3-Size2",
         "adapterMk3-Size2Slant",
         "adapterSize2-Mk2",
         "adapterSize2-Size1",
         "adapterSize2-Size1Slant",
         "adapterSize3-Mk3",
         "mk3CargoBayL",
         "mk3CargoBayM",
         "mk3CargoBayS",
         "mk3Cockpit.Shuttle",
         "mk3CrewCabin",
         "mk3FuselageLF.100",
         "mk3FuselageLF.25",
         "mk3FuselageLF.50",
         "mk3FuselageLFO.100",
         "mk3FuselageLFO.25",
         "mk3FuselageLFO.50",
         "mk3FuselageMONO",
         "kerbalEVAfemale",
         "airbrake1",
         "airlinerCtrlSrf",
         "airlinerMainWing",
         "airlinerTailFin",
         "pointyNoseConeA",
         "pointyNoseConeB",
         "airplaneTailB",
         "fairingSize1",
         "fairingSize2",
         "fairingSize3",
         "HeatShield1",
         "HeatShield2",
         "HeatShield3",
         "wingShuttleDelta",
         "elevonMk3",
         "wingShuttleElevon1",
         "wingShuttleElevon2",
         "wingShuttleRudder",
         "wingShuttleStrake",
         "delta.small",
         "mk2Cockpit.Inline",
         "mk2Cockpit.Standard",
         "mk3Cockpit.Shuttle",
         "ksp.r.largeBatteryPack",
         "solidBooster.sm",
         "fuelTank.long",
         "mk2.1m.Bicoupler",
         "mk2.1m.AdapterLong",
         "mk3FuselageLFO.100",
         "mk3FuselageLFO.25",
         "mk3FuselageLFO.50",
         "mk3FuselageLF.100",
         "mk3FuselageLF.25",
         "mk3FuselageLF.50",
         "xenonTankLarge",
         "mk3Cockpit.Shuttle",
         "FuelCell",
         "FuelCellArray",
         "ISRU",
         "LargeTank",
         "OrbitalScanner",
         "RadialDrill",
         "SmallTank",
         "SurfaceScanner",
         "SurveyScanner",
         "sensorAtmosphere",
         "Large.Crewed.Lab",
         "science.module",
         "radialDrogue",
         "ServiceBay.125",
         "ServiceBay.250",
         "GearFixed",
         "GearFree",
         "GearLarge",
         "GearMedium",
         "basicFin",
         "foldingRadLarge",
         "foldingRadMed",
         "foldingRadSmall",
         "radPanelLg",
         "radPanelSm",
         "turboJet",
         "turboFanSize2",
         "miniJetEngine",
         "SSME",
         "adapterEngines",
         "miniFuselage",
         "miniIntake",
         "MK1CrewCabin",
         "MiniISRU",
         "MiniDrill",
         "RadialOreTank",
         "radPanelEdge",
         "mk3CargoRamp",
         "InflatableHeatShield",
         "HECS2.ProbeCore",
         "HighGainAntenna",
         "LgRadialSolarPanel",
         "GearSmall",
         "ScienceBox",
         "SurfAntenna",
         "HighGainAntenna5",
         "RelayAntenna100",
         "RelayAntenna5",
         "RelayAntenna50",
         "HeatShield0",
         "InfraredTelescope",
         "kerbalEVAVintage",
         "kerbalEVAfemaleVintage",
         "mk1-3pod",
         "Decoupler_0",
         "Decoupler_1",
         "Decoupler_2",
         "Decoupler_3",
         "Separator_0",
         "Separator_1",
         "Separator_2",
         "Separator_3",
         "externalTankCapsule",
         "externalTankRound",
         "externalTankToroid",
         "Rockomax16_BW",
         "Rockomax32_BW",
         "Rockomax64_BW",
         "Rockomax8BW",
         "Decoupler.0",
         "Decoupler.1",
         "Decoupler.2",
         "Decoupler.3",
         "Separator.0",
         "Separator.1",
         "Separator.2",
         "Separator.3",
         "Rockomax16.BW",
         "Rockomax32.BW",
         "Rockomax64.BW",
         "Decoupler.1p5",
         "Decoupler.4",
         "EnginePlate1p5",
         "EnginePlate2",
         "EnginePlate3",
         "EnginePlate4",
         "InflatableAirlock",
         "Separator.1p5",
         "Separator.4",
         "Size1p5.Strut.Decoupler",
         "LiquidEngineKE-1",
         "LiquidEngineLV-T91",
         "LiquidEngineLV-TX87",
         "LiquidEngineRE-I2",
         "LiquidEngineRE-J10",
         "LiquidEngineRK-7",
         "LiquidEngineRV-1",
         "monopropMiniSphere",
         "Size1p5.Monoprop",
         "Size1p5.Size0.Adapter.01",
         "Size1p5.Size1.Adapter.01",
         "Size1p5.Size1.Adapter.02",
         "Size1p5.Size2.Adapter.01",
         "Size1p5.Tank.01",
         "Size1p5.Tank.02",
         "Size1p5.Tank.03",
         "Size1p5.Tank.04",
         "Size1p5.Tank.05",
         "Size3.Size4.Adapter.01",
         "Size4.EngineAdapter.01",
         "Size4.Tank.01",
         "Size4.Tank.02",
         "Size4.Tank.03",
         "Size4.Tank.04",
         "roverWheelM1-F",
         "fairingSize1p5",
         "fairingSize4",
         "Size1to0ServiceModule",
         "ServiceModule18",
         "ServiceModule25",
         "kv1Pod",
         "kv2Pod",
         "kv3Pod",
         "Mk2Pod",
         "MEMLander",
         "EquiTriangle0",
         "EquiTriangle1",
         "EquiTriangle1p5",
         "EquiTriangle2",
         "Panel0",
         "Panel1",
         "Panel1p5",
         "Panel2",
         "Triangle0",
         "Triangle1",
         "Triangle1p5",
         "Triangle2",
         "Tube1",
         "Tube1p5",
         "Tube2",
         "Tube3",
         "Tube4",
         "HeatShield1p5",
         "mk1pod.v2",
         "probeCoreHex.v2",
         "probeCoreOcto2.v2",
         "probeCoreOcto.v2",
         "roverBody.v2",
         "probeCoreSphere.v2",
         "solidBooster.v2",
         "solidBooster.sm.v2",
         "rocketNoseCone.v2",
         "mk2LanderCabin.v2",
         "liquidEngineMini.v2",
         "liquidEngine3.v2",
         "liquidEngine2-2.v2",
         "Size3To2Adapter.v2",
         "stackBiCoupler.v2",
         "stackTriCoupler.v2",
         "rocketNoseConeSize3",
         "smallRadialEngine.v2",
         "radialEngineMini.v2",
         "microEngine.v2",
         "RCSBlock.v2",
         "kerbalEVAFuture",
         "kerbalEVAfemaleFuture",
         "rocketNoseConeSize4",
         "cargoContainer",
         "smallCargoContainer",
         "DeployedCentralStation",
         "DeployedGoExOb",
         "DeployedIONExp",
         "DeployedRTG",
         "DeployedSatDish",
         "DeployedSeismicSensor",
         "DeployedSolarPanel",
         "DeployedWeatherStn",
         "hinge.01",
         "hinge.01.s",
         "hinge.03",
         "hinge.03.s",
         "hinge.04",
         "piston.01",
         "piston.02",
         "piston.03",
         "piston.04",
         "rotor.01",
         "rotor.02",
         "rotor.03",
         "rotoServo.00",
         "rotoServo.02",
         "rotoServo.03",
         "rotoServo.04",
         "controller1000",
         "RobotArmScanner.S1",
         "RobotArmScanner.S2",
         "RobotArmScanner.S3",
         "noseconeTiny",
         "noseconeVS",
         "largeHeliBlade",
         "largePropeller",
         "mediumHeliBlade",
         "mediumPropeller",
         "smallHeliBlade",
         "smallPropeller",
         "RotorEngine.02",
         "RotorEngine.03",
         "rotor.01s",
         "rotor.02s",
         "rotor.03s",
         "lGripPad",
         "lGripStrip",
         "mGripPad",
         "sGripPad",
         "sGripStrip",
         "Thoroughbred",
         "Clydesdale",
         "Shrimp",
         "Mite",
         "ServiceBay.125.v2",
         "ServiceBay.250.v2",
         "liquidEngineMainsail.v2",
         "engineLargeSkipper.v2",
         "ReleaseValve",
         "Size.1.5.Cone",
         "Pollux",
         "FanShroud.01",
         "FanShroud.02",
         "FanShroud.03",
         "largeFanBlade",
         "mediumFanBlade",
         "smallFanBlade",
         "Magnetometer",
         "MpoProbe",
         "MtmStage",
         "PotatoComet",
         "flagPartFlat",
         "flagPartSize0",
         "flagPartSize1",
         "flagPartSize2",
         "flagPartSize3",
         "smallClaw",
         "evaCylinder",
         "evaJetpack",
         "evaChute",
         "evaRepairKit",
         "evaScienceKit",
         "CargoStorageUnit",
         "ConformalStorageUnit",
         "Size2LFB.v2",
         "HighGainAntenna5.v2",
         "domeLight1",
         "groundLight1",
         "groundLight2",
         "navLight1",
         "spotLight3",
         "stripLight1",
         "RCSblock.01.small",
         "RCSLinearSmall",
         "flagPartSize1p5",
         "flagPartSize4"
     };
     string[] DefaultAllowedResources = new string[]
     {
         "LiquidFuel",
         "Oxidizer",
         "SolidFuel",
         "MonoPropellant",
         "XenonGas",
         "ElectricCharge",
         "IntakeAir",
         "EVA Propellant",
         "Ore",
         "Ablator"
     };
     foreach (string part in DefaultAllowedParts)
     {
         if (!ModControl.AllowedParts.Contains(part))
         {
             ModControl.AllowedParts.Add(part);
         }
     }
     foreach (string res in DefaultAllowedResources)
     {
         if (!ModControl.AllowedResources.Contains(res))
         {
             ModControl.AllowedResources.Add(res);
         }
     }
 }