public bool setCfgValueStatus(string aircraftDirectory, string attrname, string filename, string sectionname = "", bool active = true) { if (!cfgFileExists(filename)) { filename = "aircraft.cfg"; } CfgFile cfgFile = cfgAircraft.Find(x => x.Name == filename); if (cfgFile != null) { CfgSection ligtsList = cfgFile.Sections.Find(x => x.Name == sectionname); if (ligtsList != null) { CfgLine line = ligtsList.Lines.Find(x => x.Name == attrname); if (line != null) { line.Active = active; if (DEBUG) { Console.WriteLine("setCfgValueStatus: " + filename + " / " + (sectionname != "" ? sectionname : "ANY") + " / " + attrname + " set to " + active); } return(true); } } } if (DEBUG) { Console.WriteLine("setCfgValueStatus: " + filename + " / " + (sectionname != "" ? sectionname : "ANY") + " / " + attrname + " NOT FOUND"); } return(false); }
public CfgFile setCfgSectionStatus(CfgFile cfgFile, string sectionname, bool active = true) { if (cfgFile != null) { CfgSection ligtsList = cfgFile.Sections.Find(x => x.Name == sectionname); if (ligtsList != null) { if (DEBUG) { Console.WriteLine("setCfgValueStatus: " + cfgFile.Name + " / " + sectionname + " set to " + active); } ligtsList.Active = active; foreach (CfgLine line in ligtsList.Lines) { line.Active = active; } return(cfgFile); } } if (DEBUG) { Console.WriteLine("setCfgValueStatus: " + cfgFile.Name + " / " + sectionname + " NOT FOUND"); } return(cfgFile); }
public int getTaxiLights(string aircraftDirectory) { int i = 0; CfgSection section = cfgFileExists("systems.cfg") ? cfgAircraft.Find(x => x.Name == "systems.cfg").Sections.Find(x => x.Name == "[LIGHTS]") : cfgAircraft.Find(x => x.Name == "aircraft.cfg").Sections.Find(x => x.Name == "[LIGHTS]"); if (section != null) { foreach (CfgLine line in section.Lines) { if (line.Active && line.Name.StartsWith("lightdef.") && (line.Value.ToLower().Contains("type:6") || line.Value.ToLower().Contains("type:6"))) { i++; } } } return(i); }
public List <string> getContactPoints(string aircraftDirectory, string type = "") { List <string> contactPointsList = new List <string>(); CfgSection section = cfgFileExists("flight_model.cfg") ? cfgAircraft.Find(x => x.Name == "flight_model.cfg").Sections.Find(x => x.Name == "[CONTACT_POINTS]") : cfgAircraft.Find(x => x.Name == "aircraft.cfg").Sections.Find(x => x.Name == "[CONTACT_POINTS]"); if (section != null) { foreach (CfgLine line in section.Lines) { if (line.Active && line.Name.StartsWith("point.") && (type == "" || line.Value.Contains(',') && (line.Value.Split(',')[0].Trim() == type || line.Value.Split(',')[0].Trim().Contains('.') && line.Value.Split(',')[0].Trim().Split('.')[0] == type))) { contactPointsList.Add(line.Name + " = " + line.Value); } } } return(contactPointsList); }
public string[] getLights(string aircraftDirectory) { string[] lightsList = new string[100]; int i = 0; CfgSection section = cfgFileExists("systems.cfg") ? cfgAircraft.Find(x => x.Name == "systems.cfg").Sections.Find(x => x.Name == "[LIGHTS]") : cfgAircraft.Find(x => x.Name == "aircraft.cfg").Sections.Find(x => x.Name == "[LIGHTS]"); if (section != null) { foreach (CfgLine line in section.Lines) { if (line.Active && line.Name.StartsWith("light.")) { lightsList[i] = line.Name + " = " + line.Value; i++; } } } return(lightsList); }
public void insertSections(string aircraftDirectory, string sourceFilename, string targetFilename, string[] sections, bool active) { if (cfgFileExists(targetFilename) && sections.Length > 0) { string message = ""; CfgFile availableSections = cfgTemplates.Find(x => x.Name == sourceFilename); CfgFile cfgFile = cfgAircraft.Find(x => x.Name == targetFilename); if (availableSections != null) { foreach (var section in sections) { if (String.IsNullOrEmpty(section)) { break; } foreach (var sect in availableSections.Sections) { var pattern = @"\[(.*?)\]"; if (Regex.Matches(sect.Name, pattern)[0].Groups[1].ToString().Trim() == Regex.Matches(section, pattern)[0].Groups[1].ToString().Trim()) { //Console.WriteLine("availableGaugeLines found in section " + sect.Name + " lines " + sect.Lines.Count); List <CfgLine> newLines = new List <CfgLine>(); foreach (var cfgLine in sect.Lines) { // AIRSPEED INDICATOR ADJUSTMENTS if (sect.Name.ToString() == "[AIRSPEED]") { string value = getCfgValue("cruise_speed", "flight_model.cfg"); if (value != "" && int.TryParse(value.Contains('.') ? value.Trim('"').Trim().Split('.')[0] : value.Trim('"').Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out int cruiseSpeed) && cruiseSpeed > 0) { switch (cfgLine.Name.ToString()) { case "white_start": cfgLine.Value = Math.Max(20, cruiseSpeed / 3).ToString(); break; case "white_end": case "green_start": cfgLine.Value = Math.Max(30, cruiseSpeed / 2).ToString();; break; case "green_end": case "highlimit": cfgLine.Value = (cruiseSpeed).ToString(); break; case "max": cfgLine.Value = (1.1 * cruiseSpeed).ToString(); break; } } } newLines.Add(new CfgLine(active, cfgLine.Name, cfgLine.Value, cfgLine.Comment)); } //if (sect.Name.ToString() == "[AIRSPEED]") //message += "AIRSPEED section values was calculated from cruise_speed, you'll need to adjust them manually"; CfgSection newSection = new CfgSection(true, sect.Name, newLines); cfgFile.Sections.Add(newSection); break; } } } saveCfgFile(aircraftDirectory, cfgFile); if (message != "") { MessageBox.Show(message); } } else { Console.WriteLine("availableSections is null: cockpit"); } } }
public void splitCfg(string aircraftDirectory, string singleFile = "", bool addMissing = false) { List <CfgFile> cfgFiles = new List <CfgFile>(); processCfgfiles(aircraftDirectory + "\\", true); if (cfgTemplates.Count > 0 && cfgFileExists("aircraft.cfg")) { foreach (var aircraftSection in cfgAircraft[0].Sections) { CfgSection cfgTempSection = null; string cfgTemplateFile = singleFile == "" ? ".unknown.cfg" : "aircraft.cfg"; // FIND SECTION MATCH IN TEMPLATES foreach (CfgFile tplfiles in cfgTemplates) { if (singleFile != "" && tplfiles.Name != singleFile) { continue; } CfgSection cfgTemplateSection = tplfiles.Sections.Find(x => x.Name == aircraftSection.Name); // NUMERUOUS SECTION FIX if (cfgTemplateSection == null) { cfgTemplateSection = tplfiles.Sections.Find(x => x.Name.Contains(".") && aircraftSection.Name.Contains(".") && x.Name.Split('.')[0] == aircraftSection.Name.Split('.')[0]); } if (cfgTemplateSection != null) { cfgTemplateFile = tplfiles.Name; // DEEP COPY FOR COMPARISON PURPOSE cfgTempSection = new CfgSection(cfgTemplateSection.Active, cfgTemplateSection.Name, new List <CfgLine>()); foreach (var cfgTempLine in cfgTemplateSection.Lines) { cfgTempSection.Lines.Add(new CfgLine(cfgTempLine.Active, cfgTempLine.Name, cfgTempLine.Value, cfgTempLine.Comment)); } break; } } // BUILD MIXED SECTION List <CfgLine> cfgLines = new List <CfgLine>(); // ADD LEGACY LINES cfgLines.Add(new CfgLine(true, "", "", "")); foreach (CfgLine aircraftLine in aircraftSection.Lines) { CfgLine cfgTemplateLine = null; if (cfgTempSection != null) { cfgTemplateLine = cfgTempSection.Lines.Find(x => x.Name == aircraftLine.Name || x.Name.Contains(".") && aircraftLine.Name.Contains(".") && x.Name.Split('.')[0] == aircraftLine.Name.Split('.')[0]); if (cfgTemplateLine != null) // ATTRIBUTE FOUND IN TEMPLATE { cfgTempSection.Lines.Remove(cfgTemplateLine); if (String.IsNullOrEmpty(aircraftLine.Comment)) { aircraftLine.Comment = cfgTemplateLine.Comment; } } // NOT FOUND else if (!String.IsNullOrEmpty(aircraftLine.Name) && !String.IsNullOrEmpty(aircraftLine.Value) && !aircraftLine.Name.Contains(".")) { //aircraftLine.Active = false; aircraftLine.Comment += " ### "; } } // SECTION NOT FOUND else if (singleFile == "") { aircraftLine.Active = false; } cfgLines.Add(aircraftLine); } // ADD MODERN LINES if (addMissing && cfgTempSection != null && cfgTempSection.Lines.Count > 0) { cfgLines[0].Comment = "LEGACY"; cfgLines.Add(new CfgLine(true, "", "", "MODERN")); foreach (CfgLine cfgTemplateLine in cfgTempSection.Lines) { cfgTemplateLine.Active = false; cfgLines.Add(cfgTemplateLine); } } CfgSection cfgSection = new CfgSection(true, aircraftSection.Name, cfgLines); // ADD SECTION TO FILES LIST if (cfgFiles != null && cfgFiles.Find(x => x.Name == cfgTemplateFile) != null) { cfgFiles.Find(x => x.Name == cfgTemplateFile).Sections.Add(cfgSection); } else { List <CfgSection> cfgSections = new List <CfgSection>(); cfgSections.Add(new CfgSection(true, "[VERSION]", new List <CfgLine>())); cfgSections[0].Lines.Add(new CfgLine(true, "major", "1", "")); cfgSections[0].Lines.Add(new CfgLine(true, "minor", "0", "")); cfgSections.Add(cfgSection); cfgFiles.Add(new CfgFile(true, cfgTemplateFile, cfgSections)); } } // RENAME ORIGINAL AIRCRAFT.CFG File.Move(aircraftDirectory + "\\aircraft.cfg", aircraftDirectory + "\\.aircraft.cfg"); // SAVE FILES foreach (CfgFile cfgFile in cfgFiles) { saveCfgFile(aircraftDirectory, cfgFile); } //cfgAircraft = cfgFiles; processCfgfiles(aircraftDirectory + "\\", true); } }