/// <summary> /// Get a filtered list of alarms for a specirfic save file /// </summary> /// <param name="SaveName"></param> /// <returns></returns> public KACAlarmList BySaveName(String SaveName) { KACAlarmList lstreturn = new KACAlarmList(); foreach (KACAlarm tmpAlarm in this) { if (tmpAlarm.SaveName.ToLower() == SaveName.ToLower()) { lstreturn.Add(tmpAlarm); } } return(lstreturn); }
private void LoadAlarms() { string AlarmsFileVersion = "2"; Alarms = new KACAlarmList(); KSP.IO.TextReader tr = KSP.IO.TextReader.CreateForType <KerbalAlarmClock>(String.Format("Alarms-{0}.txt", HighLogic.CurrentGame.Title)); String strFile = tr.ReadToEnd(); tr.Close(); while (strFile.Contains("|<ENDLINE>")) { String strAlarm = strFile.Substring(0, strFile.IndexOf("|<ENDLINE>")); strFile = strFile.Substring(strAlarm.Length + "|<ENDLINE>".Length).TrimStart("\r\n".ToCharArray()); if (strAlarm.StartsWith("AlarmsFileVersion|")) { AlarmsFileVersion = strAlarm.Split("|".ToCharArray())[1]; KACWorker.DebugLogFormatted("AlarmsFileVersion:{0}", AlarmsFileVersion); } else if (!strAlarm.StartsWith("VesselID|")) { KACAlarm tmpAlarm = new KACAlarm(); switch (AlarmsFileVersion) { case "3": tmpAlarm.LoadFromString3(strAlarm, KACWorkerGameState.CurrentTime.UT); break; default: tmpAlarm.LoadFromString2(strAlarm); break; } Alarms.Add(tmpAlarm); } } }
public void Load() { try { KACWorker.DebugLogFormatted("Loading Config"); KSP.IO.PluginConfiguration configfile = KSP.IO.PluginConfiguration.CreateForType <KerbalAlarmClock>(); configfile.load(); this.DailyVersionCheck = configfile.GetValue("DailyUpdateCheck", true); try { this.VersionCheckDate_Attempt = DateTime.ParseExact(configfile.GetValue("VersionCheckDate_Attempt", ""), "yyyy-MM-dd", CultureInfo.CurrentCulture); } catch (Exception) { this.VersionCheckDate_Attempt = new DateTime(); } try { this.VersionCheckDate_Success = DateTime.ParseExact(configfile.GetValue("VersionCheckDate_Success", ""), "yyyy-MM-dd", CultureInfo.CurrentCulture); } catch (Exception) { this.VersionCheckDate_Success = new DateTime(); } this.VersionWeb = configfile.GetValue("VersionWeb", ""); this.WindowVisible = configfile.GetValue("WindowVisible", false); this.WindowMinimized = configfile.GetValue("WindowMinimized", false); this.WindowPos = configfile.GetValue <Rect>("WindowPos", new Rect(3, 55, 300, 45)); this.WindowVisible_SpaceCenter = configfile.GetValue("WindowVisible_SpaceCenter", false); this.WindowMinimized_SpaceCenter = configfile.GetValue("WindowMinimized_SpaceCenter", false); this.WindowPos_SpaceCenter = configfile.GetValue <Rect>("WindowPos_SpaceCenter", new Rect(3, 36, 300, 45)); this.WindowVisible_TrackingStation = configfile.GetValue("WindowVisible_TrackingStation", false); this.WindowMinimized_TrackingStation = configfile.GetValue("WindowMinimized_TrackingStation", false); this.WindowPos_TrackingStation = configfile.GetValue <Rect>("WindowPos_TrackingStation", new Rect(202, 45, 300, 45)); this.IconPos = configfile.GetValue <Rect>("IconPos", new Rect(152, 0, 32, 32)); this.IconPos.height = 32; this.IconPos.width = 32; this.IconPos_SpaceCenter = configfile.GetValue <Rect>("IconPos_SpaceCenter", new Rect(3, 3, 32, 32)); this.IconPos_SpaceCenter.height = 32; this.IconPos_TrackingStation.width = 32; this.IconPos_TrackingStation = configfile.GetValue <Rect>("IconPos_TrackingStation", new Rect(196, 0, 32, 32)); this.IconPos_TrackingStation.height = 32; this.IconPos_TrackingStation.width = 32; this.IconShow_SpaceCenter = configfile.GetValue("IconShow_SpaceCenter", true); this.IconShow_TrackingStation = configfile.GetValue("IconShow_TrackingStation", true); this.UseBlizzyToolbarIfAvailable = configfile.GetValue <Boolean>("UseBlizzyToolbarIfAvailable", true); this.WindowMinimizedType = (MiminalDisplayType)configfile.GetValue("WindowMinimizedType", 0); this.KSCUIBlockersEnabled = configfile.GetValue <Boolean>("UIBlockersEnabled", true); this.BehaviourChecksPerSec = configfile.GetValue("BehaviourChecksPerSec", 10); this.BehaviourChecksPerSec_Custom = configfile.GetValue("BehaviourChecksPerSecCustom", 40); this.BackupSaves = configfile.GetValue("BackupSaves", true); this.BackupSavesToKeep = configfile.GetValue("BackupSavesToKeep", 20); this.CancelFlightModeJumpOnBackupFailure = configfile.GetValue("CancelFlightModeJumpOnBackupFailure", false); this.AllowJumpFromViewOnly = configfile.GetValue("AllowJumpFromViewOnly", true); this.AllowJumpToAsteroid = configfile.GetValue("AllowJumpToAsteroid", false); this.AlarmListMaxAlarms = configfile.GetValue("AlarmListMaxAlarms", "10"); this.AlarmDefaultAction = configfile.GetValue <int>("AlarmDefaultAction", 1); this.AlarmDefaultMargin = configfile.GetValue <Double>("AlarmDefaultMargin", 60); this.AlarmPosition = configfile.GetValue <int>("AlarmPosition", 1); this.AlarmDeleteOnClose = configfile.GetValue("AlarmDeleteOnClose", false); this.ShowTooltips = configfile.GetValue("ShowTooltips", true); this.ShowEarthTime = configfile.GetValue("ShowEarthTime", false); this.HideOnPause = configfile.GetValue("HideOnPause", true); String strTimeFormat = configfile.GetValue("TimeFormat", "KSPString"); //KACWorker.DebugLogFormatted("{0}",strTimeFormat); this.TimeFormat = (KACTime.PrintTimeFormat)Enum.Parse(typeof(KACTime.PrintTimeFormat), strTimeFormat); //this.TimeFormat = configfile.GetValue<KACTime.PrintTimeFormat>("TimeFormat", KACTime.PrintTimeFormat.KSPString); //KACWorker.DebugLogFormatted("{0}",this.TimeFormat.ToString()); if (configfile.GetValue <bool>("TimeAsUT", false) == true) { KACWorker.DebugLogFormatted("Forcing New Format"); this.TimeFormat = KACTime.PrintTimeFormat.TimeAsUT; configfile.SetValue("TimeAsUT", false); configfile.SetValue("TimeFormat", Enum.GetName(typeof(KACTime.PrintTimeFormat), this.TimeFormat)); configfile.save(); } this.AlarmXferRecalc = configfile.GetValue("AlarmXferRecalc", true); this.AlarmXferRecalcThreshold = configfile.GetValue <Double>("AlarmXferRecalcThreshold", 180); this.AlarmXferDisplayList = configfile.GetValue("AlarmXferDisplayList", false); this.XferUseModelData = configfile.GetValue("XferUseModelData", false); this.AlarmNodeRecalc = configfile.GetValue("AlarmNodeRecalc", false); this.AlarmNodeRecalcThreshold = configfile.GetValue <Double>("AlarmNodeRecalcThreshold", 180); this.AlarmAddSOIAuto = configfile.GetValue("AlarmAddSOIAuto", false); this.AlarmAddSOIAutoThreshold = configfile.GetValue <Double>("AlarmAddSOIAutoThreshold", 180); //this.AlarmAddSOIMargin = configfile.GetValue("AlarmAddSOIMargin", 120); this.AlarmAutoSOIMargin = configfile.GetValue <Double>("AlarmAutoSOIMargin", 900); this.AlarmAddSOIAuto_ExcludeEVA = configfile.GetValue("AlarmAddSOIAuto_ExcludeEVA", true); this.AlarmCatchSOIChange = configfile.GetValue("AlarmOnSOIChange", false); this.AlarmOnSOIChange_Action = configfile.GetValue("AlarmOnSOIChange_Action", 1); this.AlarmSOIRecalc = configfile.GetValue("AlarmSOIRecalc", false); this.AlarmSOIRecalcThreshold = configfile.GetValue <Double>("AlarmSOIRecalcThreshold", 180); this.AlarmAddManAuto = configfile.GetValue("AlarmAddManAuto", false); this.AlarmAddManAuto_andRemove = configfile.GetValue("AlarmAddManAuto_andRemove", false); this.AlarmAddManAutoThreshold = configfile.GetValue <Double>("AlarmAddManAutoThreshold", 180); this.AlarmAddManAutoMargin = configfile.GetValue <Double>("AlarmAddManAutoMargin", 180); this.AlarmAddManAuto_Action = configfile.GetValue("AlarmAddManAuto_Action", 1); this.AlarmCrewDefaultStoreNode = configfile.GetValue("AlarmCrewDefaultStoreNode", false); this.LoadManNode = configfile.GetValue("LoadManNode", ""); this.LoadVesselTarget = configfile.GetValue("LoadVesselTarget", ""); if (KSP.IO.File.Exists <KerbalAlarmClock>(String.Format("Alarms-{0}.txt", HighLogic.CurrentGame.Title))) { KACWorker.DebugLogFormatted("Trying New Alarms file..."); LoadAlarms(); } else { //Loop through numbers to Load Alarms Alarms = new KACAlarmList(); int intAlarm = 0; String strAlarm = ""; do { strAlarm = configfile.GetValue("Alarm_" + intAlarm, ""); KACWorker.DebugLogFormatted(strAlarm); if (strAlarm != "") { KACAlarm tmpAlarm = new KACAlarm(); tmpAlarm.LoadFromString(strAlarm); Alarms.Add(tmpAlarm); intAlarm++; } } while (strAlarm != ""); } KACWorker.DebugLogFormatted("Config Loaded Successfully"); } catch (Exception ex) { KACWorker.DebugLogFormatted("Failed To Load Config"); KACWorker.DebugLogFormatted(ex.Message); } }
internal static Boolean Loadv2Alarms(out String LoadMessage, out KACAlarmList oldAlarms) { oldAlarms = new KACAlarmList(); Boolean blnReturn = false; try { //Find old files String[] AlarmFiles = System.IO.Directory.GetFiles(KACUtils.PathTriggerTech, "Alarms-*.txt", System.IO.SearchOption.AllDirectories); String FileToLoad = ""; foreach (String item in AlarmFiles) { System.IO.FileInfo File = new System.IO.FileInfo(item); MonoBehaviourExtended.LogFormatted_DebugOnly("File:{0}", File.Name); if (File.Name == String.Format("Alarms-{0}.txt", HighLogic.CurrentGame.Title)) { FileToLoad = File.FullName; break; } } if (FileToLoad != "") { //parse it to a new list MonoBehaviourExtended.LogFormatted("Loading {0}", FileToLoad); String strFile = System.IO.File.ReadAllText(FileToLoad); String AlarmsFileVersion = ""; while (strFile.Contains("|<ENDLINE>")) { String strAlarm = strFile.Substring(0, strFile.IndexOf("|<ENDLINE>")); strFile = strFile.Substring(strAlarm.Length + "|<ENDLINE>".Length).TrimStart("\r\n".ToCharArray()); if (strAlarm.StartsWith("AlarmsFileVersion|")) { AlarmsFileVersion = strAlarm.Split("|".ToCharArray())[1]; MonoBehaviourExtended.LogFormatted("AlarmsFileVersion:{0}", AlarmsFileVersion); } else if (!strAlarm.StartsWith("VesselID|")) { KACAlarm tmpAlarm; switch (AlarmsFileVersion) { case "3": MonoBehaviourExtended.LogFormatted_DebugOnly("Loading Alarm via v3 loader"); tmpAlarm = UtilitiesLegacy.LoadFromString3(strAlarm, KACWorkerGameState.CurrentTime.UT); break; default: MonoBehaviourExtended.LogFormatted_DebugOnly("Loading Alarm via v2 loader"); tmpAlarm = UtilitiesLegacy.LoadFromString2(strAlarm); break; } oldAlarms.Add(tmpAlarm); } } blnReturn = true; LoadMessage = "Successfully parsed Alarm File"; } else { MonoBehaviourExtended.LogFormatted("Could not find alarms file for: {0}", HighLogic.CurrentGame.Title); LoadMessage = "File not found in TriggerTech Folder"; } } catch (Exception ex) { MonoBehaviourExtended.LogFormatted("Error occured:{0}\r\n{1}", ex.Message, ex.StackTrace); LoadMessage = "Unknown error occured trying to load old file\r\n\r\nError details in output_log.txt"; } return(blnReturn); }