Exemple #1
0
        public static ITargetable TargetDeserialize(String strInput)
        {
            ITargetable tReturn = null;

            String[] TargetParts = strInput.Split(",".ToCharArray());
            switch (TargetParts[0])
            {
            case "Vessel":
                if (KACWorker.StoredVesselExists(TargetParts[1]))
                {
                    tReturn = KACWorker.StoredVessel(TargetParts[1]);
                }
                break;

            case "CelestialBody":
                if (KACWorker.CelestialBodyExists(TargetParts[1]))
                {
                    tReturn = KACWorker.CelestialBody(TargetParts[1]);
                }
                break;

            default:
                break;
            }
            return(tReturn);
        }
Exemple #2
0
        public static Boolean LoadModelPoints()
        {
            KACWorker.DebugLogFormatted("Loading Transfer Modelling Data");
            Boolean blnReturn = false;

            try
            {
                lstXferModelPoints = new List <KACXFerModelPoint>();

                //read in the data file
                String strData = KSP.IO.File.ReadAllText <KerbalAlarmClock>("data_TransferModelData.csv");
                //split to lines
                String[] strLines = strData.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                String[] strFields;
                for (int intLine = 1; intLine < strLines.Length; intLine++)
                {
                    strFields = strLines[intLine].Split(",".ToCharArray());
                    lstXferModelPoints.Add(new KACXFerModelPoint(
                                               Convert.ToDouble(strFields[0]),
                                               Convert.ToInt32(strFields[1]),
                                               Convert.ToInt32(strFields[2]),
                                               Convert.ToDouble(strFields[3])
                                               ));
                }
                blnReturn = true;
                KACWorker.DebugLogFormatted("Transfer Modelling Data Load Complete");
            }
            catch (Exception ex)
            {
                KACWorker.DebugLogFormatted("Transfer Modelling Data Failed - is the data file there and correct\r\n{0}", ex.Message);
            }
            return(blnReturn);
        }
Exemple #3
0
        void bwVersionCheck_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {
                //get the response from the variable and work with it
                //Parse it for the version String
                String strFile = wwwVersionCheck.text;
                KACWorker.DebugLogFormatted("Response Length:" + strFile.Length);

                Match matchVersion;
                matchVersion = Regex.Match(strFile, "(?<=\\|LATESTVERSION\\|).+(?=\\|LATESTVERSION\\|)", System.Text.RegularExpressions.RegexOptions.Singleline);
                KACWorker.DebugLogFormatted("Got Version '" + matchVersion.ToString() + "'");

                String strVersionWeb = matchVersion.ToString();
                if (strVersionWeb != "")
                {
                    this.VersionCheckResult       = "Success";
                    this.VersionCheckDate_Success = DateTime.Now;
                    this.VersionWeb = strVersionWeb;
                }
                else
                {
                    this.VersionCheckResult = "Unable to parse web service";
                }
            }
            catch (Exception ex)
            {
                KACWorker.DebugLogFormatted("Failed to read Version info from web");
                KACWorker.DebugLogFormatted(ex.Message);
            }
            KACWorker.DebugLogFormatted("Version Check result:" + VersionCheckResult);

            this.Save();
            VersionAttentionFlag = VersionAvailable;
        }
Exemple #4
0
        /// <summary>
        /// Check to see if the Toolbar is available
        /// </summary>
        /// <returns>True if the Toolbar.ToolbarManager class is loaded in an existing assembly</returns>
        internal Boolean HookToolbar()
        {
            //Is the Dll in memory
            Boolean blnReturn = ToolbarDLL.Loaded;

            KACWorker.DebugLogFormatted("Blizzy's Toolbar Loaded:{0}", blnReturn);
            return(blnReturn);
        }
Exemple #5
0
 /// <summary>
 /// Destroys theToolbarButtonWrapper object
 /// </summary>
 /// <param name="btnToDestroy">Object to Destroy</param>
 internal void DestroyToolbarButton(ToolbarButtonWrapper btnToDestroy)
 {
     if (btnToDestroy != null)
     {
         KACWorker.DebugLogFormatted("Destroying Toolbar Button");
         btnToDestroy.Destroy();
     }
     btnToDestroy = null;
 }
Exemple #6
0
 public void SaveLoadObjects()
 {
     KACWorker.DebugLogFormatted("Saving Load Objects");
     KSP.IO.PluginConfiguration configfile = KSP.IO.PluginConfiguration.CreateForType <KerbalAlarmClock>();
     configfile.load();
     configfile.SetValue("LoadManNode", this.LoadManNode);
     configfile.SetValue("LoadVesselTarget", this.LoadVesselTarget);
     configfile.save();
     KACWorker.DebugLogFormatted("Saved Load Objects");
 }
Exemple #7
0
        public void LoadFromString2(String AlarmDetails)
        {
            String[] vars = AlarmDetails.Split("|".ToCharArray(), StringSplitOptions.None);
            SaveName        = HighLogic.CurrentGame.Title;
            VesselID        = vars[0];
            Name            = vars[1];
            Notes           = vars[2];
            AlarmTime.UT    = Convert.ToDouble(vars[3]);
            AlarmMarginSecs = Convert.ToDouble(vars[4]);
            TypeOfAlarm     = (KACAlarm.AlarmType)Enum.Parse(typeof(KACAlarm.AlarmType), vars[5]);
            Enabled         = Convert.ToBoolean(vars[6]);
            HaltWarp        = Convert.ToBoolean(vars[7]);
            PauseGame       = Convert.ToBoolean(vars[8]);

            String strOptions = vars[9];

            switch (TypeOfAlarm)
            {
            case AlarmType.Maneuver:
                //Generate the Nodes List from the string
                ManNodes = ManNodeDeserializeList(strOptions);
                break;

            case AlarmType.Transfer:
                try
                {
                    String[] XferParts = strOptions.Split(",".ToCharArray());
                    XferOriginBodyName = XferParts[0];
                    XferTargetBodyName = XferParts[1];
                }
                catch (Exception ex)
                {
                    KACWorker.DebugLogFormatted("Unable to load transfer details for {0}", Name);
                    KACWorker.DebugLogFormatted(ex.Message);
                }
                break;

            case AlarmType.AscendingNode:
            case AlarmType.DescendingNode:
            case AlarmType.LaunchRendevous:
                if (strOptions != "")
                {
                    //find the targetable object and set it
                    TargetObject = TargetDeserialize(strOptions);
                    if (TargetObject == null && strOptions.StartsWith("Vessel,"))
                    {
                        TargetLoader = strOptions;
                    }
                }
                break;

            default:
                break;
            }
        }
Exemple #8
0
        /// <summary>
        /// Does some logic to see if a check is needed, and returns true if there is a different version
        /// </summary>
        /// <param name="ForceCheck">Ignore all logic and simply do a check</param>
        /// <returns></returns>
        public Boolean VersionCheck(Boolean ForceCheck)
        {
            Boolean blnReturn  = false;
            Boolean blnDoCheck = false;

            try
            {
                if (ForceCheck)
                {
                    blnDoCheck = true;
                    KACWorker.DebugLogFormatted("Starting Version Check-Forced");
                }
                //else if (this.VersionWeb=="")
                //{
                //    blnDoCheck = true;
                //    KACWorker.DebugLogFormatted("Starting Version Check-No current web version stored");
                //}
                else if (this.VersionCheckDate_Attempt < DateTime.Now.AddYears(-9))
                {
                    blnDoCheck = true;
                    KACWorker.DebugLogFormatted("Starting Version Check-No current date stored");
                }
                else if (this.VersionCheckDate_Attempt.Date != DateTime.Now.Date)
                {
                    blnDoCheck = true;
                    KACWorker.DebugLogFormatted("Starting Version Check-stored date is not today");
                }
                else
                {
                    KACWorker.DebugLogFormatted("Skipping version check");
                }


                if (blnDoCheck)
                {
                    //prep the background thread
                    bwVersionCheck                     = new BackgroundWorker();
                    bwVersionCheck.DoWork             += bwVersionCheck_DoWork;
                    bwVersionCheck.RunWorkerCompleted += bwVersionCheck_RunWorkerCompleted;

                    //fire the worker
                    bwVersionCheck.RunWorkerAsync();
                }
                blnReturn = true;
            }
            catch (Exception ex)
            {
                KACWorker.DebugLogFormatted("Failed to run the update test");
                KACWorker.DebugLogFormatted(ex.Message);
            }
            return(blnReturn);
        }
Exemple #9
0
        public static Boolean BackupSaves()
        {
            if (!KerbalAlarmClock.Settings.BackupSaves)
            {
                return(true);
            }

            Boolean blnReturn = false;

            KACWorker.DebugLogFormatted("Backing up saves");

            if (!System.IO.Directory.Exists(SavePath))
            {
                KACWorker.DebugLogFormatted("Saves Path not found: {0}");
            }
            else
            {
                if (!System.IO.File.Exists(String.Format("{0}/persistent.sfs", SavePath)))
                {
                    KACWorker.DebugLogFormatted("Persistent.sfs file not found: {0}/persistent.sfs", SavePath);
                }
                else
                {
                    try
                    {
                        System.IO.File.Copy(String.Format("{0}/persistent.sfs", SavePath),
                                            String.Format("{0}/KACBACKUP{1:yyyyMMddHHmmss}-persistent.sfs", SavePath, DateTime.Now),
                                            true);
                        KACWorker.DebugLogFormatted("Backed Up Persistent.sfs as: {0}/KACBACKUP{1:yyyyMMddHHmmss}-persistent.sfs", SavePath, DateTime.Now);

                        //Now go for the quicksave
                        if (System.IO.File.Exists(String.Format("{0}/quicksave.sfs", SavePath)))
                        {
                            System.IO.File.Copy(String.Format("{0}/quicksave.sfs", SavePath),
                                                String.Format("{0}/KACBACKUP{1:yyyyMMddHHmmss}-quicksave.sfs", SavePath, DateTime.Now),
                                                true);
                            KACWorker.DebugLogFormatted("Backed Up quicksave.sfs as: {0}/KACBACKUP{1:yyyyMMddHHmmss}-quicksave.sfs", SavePath, DateTime.Now);
                        }
                        blnReturn = true;

                        PurgeOldBackups();
                    }
                    catch (Exception ex)
                    {
                        KACWorker.DebugLogFormatted("Unable to backup: {0}/persistent.sfs\r\n\t{1}", SavePath, ex.Message);
                    }
                }
            }

            return(blnReturn);
        }
Exemple #10
0
 public void SaveAlarms2()
 {
     KACWorker.DebugLogFormatted("Saving Alarms");
     KSP.IO.TextWriter tw = KSP.IO.TextWriter.CreateForType <KerbalAlarmClock>(String.Format("Alarms-{0}.txt", HighLogic.CurrentGame.Title));
     //Write the header
     tw.WriteLine("VesselID|Name|Notes|AlarmTime.UT|AlarmMarginSecs|Type|Enabled|HaltWarp|PauseGame|Options-Manuever/Xfer/Target|<ENDLINE>");
     foreach (KACAlarm tmpAlarm in Alarms.BySaveName(HighLogic.CurrentGame.Title))
     {
         //Now Write Each alarm
         //tw.WriteLine(tmpAlarm.SerializeString2() + "|<ENDLINE>");
         tw.WriteLine(tmpAlarm.SerializeString3() + "|<ENDLINE>");
     }
     //And close the file
     tw.Close();
     KACWorker.DebugLogFormatted("Saved Alarms");
 }
Exemple #11
0
        public static List <ManeuverNode> ManNodeDeserializeList(String strInput)
        {
            List <ManeuverNode> lstReturn = new List <ManeuverNode>();

            String[] strInputParts = strInput.Split(",".ToCharArray());
            KACWorker.DebugLogFormatted("Found {0} Maneuver Nodes to deserialize", strInputParts.Length / 8);

            //There are 8 parts per mannode
            for (int iNode = 0; iNode < strInputParts.Length / 8; iNode++)
            {
                String strTempNode = String.Join(",", strInputParts.Skip(iNode * 8).Take(8).ToArray());
                lstReturn.Add(ManNodeDeserialize(strTempNode));
            }

            return(lstReturn);
        }
Exemple #12
0
        private static void PurgeOldBackups(String OriginalName)
        {
            //Now delete any old ones greater than the list to keep
            List <System.IO.FileInfo> SaveBackups = new System.IO.DirectoryInfo(SavePath).GetFiles(string.Format("KACBACKUP*{0}", OriginalName)).ToList <System.IO.FileInfo>();

            KACWorker.DebugLogFormatted("{0} KACBackup...{1} Saves found", SaveBackups.Count, OriginalName);

            List <System.IO.FileInfo> SaveBackupsToDelete = SaveBackups.OrderByDescending(fi => fi.CreationTime).Skip(KerbalAlarmClock.Settings.BackupSavesToKeep).ToList <System.IO.FileInfo>();

            KACWorker.DebugLogFormatted("{0} KACBackup...{1} Saves to purge", SaveBackupsToDelete.Count, OriginalName);
            for (int i = SaveBackupsToDelete.Count - 1; i >= 0; i--)
            {
                KACWorker.DebugLogFormatted("\tDeleting {0}", SaveBackupsToDelete[i].Name);
                SaveBackupsToDelete[i].Delete();
            }
        }
Exemple #13
0
        void bwVersionCheck_DoWork(object sender, DoWorkEventArgs e)
        {
            //set initial stuff and save it
            VersionCheckRunning           = true;
            this.VersionCheckResult       = "Unknown - check again later";
            this.VersionCheckDate_Attempt = DateTime.Now;
            this.Save();

            //now do the download
            KACWorker.DebugLogFormatted("Reading version from Web");
            wwwVersionCheck = new WWW("https://sites.google.com/site/kerbalalarmclock/latestversion");
            while (!wwwVersionCheck.isDone)
            {
            }
            KACWorker.DebugLogFormatted("Download complete:{0}", wwwVersionCheck.text.Length);
            VersionCheckRunning = false;
        }
Exemple #14
0
        public void SaveAlarms(Boolean BypassLogging = false)
        {
            if (!BypassLogging)
            {
                KACWorker.DebugLogFormatted("Saving Alarms-v3");
            }

            KSP.IO.TextWriter tw = KSP.IO.TextWriter.CreateForType <KerbalAlarmClock>(String.Format("Alarms-{0}.txt", HighLogic.CurrentGame.Title));
            //Write the header
            tw.WriteLine("AlarmsFileVersion|3|<ENDLINE>");
            tw.WriteLine("VesselID|Name|Notes|AlarmTime.UT|AlarmMarginSecs|Type|Enabled|HaltWarp|PauseGame|ActionedAt|Manuever|Xfer|Target|Options|<ENDLINE>");
            foreach (KACAlarm tmpAlarm in Alarms.BySaveName(HighLogic.CurrentGame.Title))
            {
                //Now Write Each alarm
                tw.WriteLine(tmpAlarm.SerializeString3() + "|<ENDLINE>");
            }
            //And close the file
            tw.Close();
        }
Exemple #15
0
        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);
                }
            }
        }
Exemple #16
0
        /// <summary>
        /// initialises a Toolbar Button for this mod
        /// </summary>
        /// <returns>The ToolbarButtonWrapper that was created</returns>
        internal ToolbarButtonWrapper InitToolbarButton()
        {
            ToolbarButtonWrapper btnReturn = null;

            try
            {
                KACWorker.DebugLogFormatted("Initialising the Toolbar Icon");
                btnReturn             = new ToolbarButtonWrapper("KerbalAlarmClock", "btnToolbarIcon");
                btnReturn.TexturePath = "TriggerTech/ToolbarIcons/KACIcon-Norm";
                btnReturn.ToolTip     = "Kerbal Alarm Clock";
                btnReturn.AddButtonClickHandler((e) =>
                {
                    WorkerObjectInstance.WindowVisibleByActiveScene = !WorkerObjectInstance.WindowVisibleByActiveScene;
                    Settings.Save();
                });
            }
            catch (Exception ex)
            {
                DestroyToolbarButton(btnReturn);
                KACWorker.DebugLogFormatted("Error Initialising Toolbar Button: {0}", ex.Message);
            }
            return(btnReturn);
        }
Exemple #17
0
        //public static Byte[] LoadFileToArray(String Filename)
        //{
        //    Byte[] arrBytes;

        //    arrBytes = KSP.IO.File.ReadAllBytes<KerbalAlarmClock>(Filename);

        //    return arrBytes;
        //}

        //public static void SaveFileFromArray(Byte[] data, String Filename)
        //{
        //    KSP.IO.File.WriteAllBytes<KerbalAlarmClock>(data, Filename);
        //}


        //public static void LoadImageIntoTexture(ref Texture2D tex, String FileName)
        //{

        //    try
        //    {
        //        //KACWorker.DebugLogFormatted("Loading: TriggerTech/Textures/KerbalAlarmClock/{0}", FileName);
        //        //tex = GameDatabase.Instance.GetTexture("TriggerTech/Textures/KerbalAlarmClock/" + FileName.Replace(".png", ""), false);
        //        //if (tex == null) KACWorker.DebugLogFormat GetTextureted("Textures Empty");

        //        tex.LoadImage(LoadFileToArray(FileName));
        //    }
        //    catch (Exception)
        //    {
        //        KACWorker.DebugLogFormatted("Failed to load (are you missing a file):{0}", FileName);
        //    }
        //}

        //stop using unity www object as some clients get timeouts searching via the url address

        //public static void LoadImageIntoTexture(ref Texture2D tex, String FileName)
        //{
        //    WWW img1 = new WWW(String.Format("file://{0}Icons/{1}", PlugInPath, FileName));
        //    img1.LoadImageIntoTexture(tex);
        //}

        //public static void LoadImageIntoTexture(ref Texture2D tex, String FolderName, String FileName)
        //{
        //    WWW img1 = new WWW(String.Format("file://{0}{1}/{2}", PlugInPath, FolderName,FileName));
        //    img1.LoadImageIntoTexture(tex);
        //}

        /// <summary>
        /// Loads texture from GameDatabase
        /// If texture is a TGA then its quality is affected by the game settings
        /// If texture is a PNG then its quality is affetced by texture compression in game
        /// </summary>
        /// <param name="tex"></param>
        /// <param name="FileName"></param>
        /// <param name="FolderPath"></param>
        /// <returns></returns>
        //public static Boolean LoadImageFromGameDB(ref Texture2D tex, String FileName, String FolderPath = "")
        //{
        //    //DebugLogFormatted("{0},{1}",FileName, FolderPath);
        //    Boolean blnReturn = false;
        //    try
        //    {
        //        if (FileName.ToLower().EndsWith(".png")) FileName = FileName.Substring(0, FileName.Length - 4);
        //        if (FileName.ToLower().EndsWith(".tga")) FileName = FileName.Substring(0, FileName.Length - 4);
        //        if (FolderPath == "") FolderPath = DBPathTextures;
        //        KACWorker.DebugLogFormatted("Loading {0}", String.Format("{0}/{1}", FolderPath, FileName));
        //        tex = GameDatabase.Instance.GetTexture(String.Format("{0}/{1}", FolderPath, FileName), false);
        //        blnReturn = true;
        //    }
        //    catch (Exception)
        //    {
        //        KACWorker.DebugLogFormatted("Failed to load (are you missing a file):{0}/{1}", String.Format("{0}/{1}", FolderPath, FileName));
        //    }
        //    return blnReturn;
        //}

        /// <summary>
        /// Loads a texture from the file system directly
        /// </summary>
        /// <param name="tex">Unity Texture to Load</param>
        /// <param name="FileName">Image file name</param>
        /// <param name="FolderPath">Optional folder path of image</param>
        /// <returns></returns>
        public static Boolean LoadImageFromFile(ref Texture2D tex, String FileName, String FolderPath = "")
        {
            //DebugLogFormatted("{0},{1}",FileName, FolderPath);
            Boolean blnReturn = false;

            try
            {
                if (FolderPath == "")
                {
                    FolderPath = PathTextures;
                }

                //File Exists check
                if (System.IO.File.Exists(String.Format("{0}/{1}", FolderPath, FileName)))
                {
                    try
                    {
                        KACWorker.DebugLogFormatted("Loading: {0}", String.Format("{0}/{1}", FolderPath, FileName));
                        tex.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", FolderPath, FileName)));
                        blnReturn = true;
                    }
                    catch (Exception ex)
                    {
                        KACWorker.DebugLogFormatted("Failed to load the texture:{0} ({1})", String.Format("{0}/{1}", FolderPath, FileName), ex.Message);
                    }
                }
                else
                {
                    KACWorker.DebugLogFormatted("Cannot find texture to load:{0}", String.Format("{0}/{1}", FolderPath, FileName));
                }
            }
            catch (Exception ex)
            {
                KACWorker.DebugLogFormatted("Failed to load (are you missing a file):{0} ({1})", String.Format("{0}/{1}", FolderPath, FileName), ex.Message);
            }
            return(blnReturn);
        }
Exemple #18
0
        public void SaveConfig()
        {
            KACWorker.DebugLogFormatted("Saving Config");

            KSP.IO.PluginConfiguration configfile = KSP.IO.PluginConfiguration.CreateForType <KerbalAlarmClock>();
            configfile.load();

            configfile.SetValue("DailyUpdateCheck", this.DailyVersionCheck);
            configfile.SetValue("VersionCheckDate_Attempt", this.VersionCheckDate_AttemptString);
            configfile.SetValue("VersionCheckDate_Success", this.VersionCheckDate_SuccessString);
            configfile.SetValue("VersionWeb", this.VersionWeb);

            configfile.SetValue("WindowVisible", this.WindowVisible);
            configfile.SetValue("WindowMinimized", this.WindowMinimized);
            configfile.SetValue("WindowPos", this.WindowPos);

            configfile.SetValue("WindowVisible_SpaceCenter", this.WindowVisible_SpaceCenter);
            configfile.SetValue("WindowMinimized_SpaceCenter", this.WindowMinimized_SpaceCenter);
            configfile.SetValue("WindowPos_SpaceCenter", this.WindowPos_SpaceCenter);

            configfile.SetValue("WindowVisible_TrackingStation", this.WindowVisible_TrackingStation);
            configfile.SetValue("WindowMinimized_TrackingStation", this.WindowMinimized_TrackingStation);
            configfile.SetValue("WindowPos_TrackingStation", this.WindowPos_TrackingStation);

            configfile.SetValue("IconPos", this.IconPos);
            configfile.SetValue("IconPos_SpaceCenter", this.IconPos_SpaceCenter);
            configfile.SetValue("IconShow_SpaceCenter", this.IconShow_SpaceCenter);
            configfile.SetValue("IconPos_TrackingStation", this.IconPos_TrackingStation);
            configfile.SetValue("IconShow_TrackingStation", this.IconShow_TrackingStation);

            configfile.SetValue("UseBlizzyToolbarIfAvailable", this.UseBlizzyToolbarIfAvailable);
            configfile.SetValue("WindowMinimizedType", (int)this.WindowMinimizedType);

            configfile.SetValue("UIBlockersEnabled", this.KSCUIBlockersEnabled);

            configfile.SetValue("BehaviourChecksPerSec", this.BehaviourChecksPerSec);

            configfile.SetValue("BackupSaves", this.BackupSaves);
            configfile.SetValue("BackupSavesToKeep", this.BackupSavesToKeep);
            configfile.SetValue("CancelFlightModeJumpOnBackupFailure", this.CancelFlightModeJumpOnBackupFailure);

            configfile.SetValue("AllowJumpFromViewOnly", this.AllowJumpFromViewOnly);
            configfile.SetValue("AllowJumpToAsteroid", this.AllowJumpToAsteroid);

            configfile.SetValue("AlarmListMaxAlarms", this.AlarmListMaxAlarms);
            configfile.SetValue("AlarmPosition", this.AlarmPosition);
            configfile.SetValue("AlarmDefaultAction", this.AlarmDefaultAction);
            configfile.SetValue("AlarmDefaultMargin", this.AlarmDefaultMargin);
            configfile.SetValue("AlarmDeleteOnClose", this.AlarmDeleteOnClose);
            configfile.SetValue("ShowTooltips", this.ShowTooltips);
            configfile.SetValue("ShowEarthTime", this.ShowEarthTime);
            configfile.SetValue("HideOnPause", this.HideOnPause);
            configfile.SetValue("TimeFormat", Enum.GetName(typeof(KACTime.PrintTimeFormat), this.TimeFormat));

            configfile.SetValue("AlarmXferRecalc", this.AlarmXferRecalc);
            configfile.SetValue("AlarmXferRecalcThreshold", this.AlarmXferRecalcThreshold);
            configfile.SetValue("AlarmXferDisplayList", this.AlarmXferDisplayList);
            configfile.SetValue("XferUseModelData", this.XferUseModelData);

            configfile.SetValue("AlarmNodeRecalc", this.AlarmNodeRecalc);
            configfile.SetValue("AlarmNodeRecalcThreshold", this.AlarmNodeRecalcThreshold);

            configfile.SetValue("AlarmAddSOIAuto", this.AlarmAddSOIAuto);
            configfile.SetValue("AlarmAddSOIAutoThreshold", this.AlarmAddSOIAutoThreshold);
            //configfile.SetValue("AlarmAddSOIMargin", this.AlarmAddSOIMargin);
            configfile.SetValue("AlarmAutoSOIMargin", this.AlarmAutoSOIMargin);
            configfile.SetValue("AlarmAddSOIAuto_ExcludeEVA", this.AlarmAddSOIAuto_ExcludeEVA);
            configfile.SetValue("AlarmOnSOIChange", this.AlarmCatchSOIChange);
            configfile.SetValue("AlarmOnSOIChange_Action", this.AlarmOnSOIChange_Action);

            configfile.SetValue("AlarmSOIRecalc", this.AlarmSOIRecalc);
            configfile.SetValue("AlarmSOIRecalcThreshold", this.AlarmSOIRecalcThreshold);

            configfile.SetValue("AlarmAddManAuto", this.AlarmAddManAuto);
            configfile.SetValue("AlarmAddManAuto_andRemove", this.AlarmAddManAuto_andRemove);
            configfile.SetValue("AlarmAddManAutoThreshold", this.AlarmAddManAutoThreshold);
            configfile.SetValue("AlarmAddManAutoMargin", this.AlarmAddManAutoMargin);
            configfile.SetValue("AddManAutoMargin", this.AlarmAddManAutoMargin.ToString());
            configfile.SetValue("AlarmAddManAuto_Action", this.AlarmAddManAuto_Action);

            configfile.SetValue("AlarmCrewDefaultStoreNode", this.AlarmCrewDefaultStoreNode);

            configfile.save();
            KACWorker.DebugLogFormatted("Saved Config");
        }
Exemple #19
0
        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);
            }
        }
Exemple #20
0
        public static void loadGUIAssets()
        {
            KACWorker.DebugLogFormatted("Loading Textures");

            try
            {
                KACUtils.LoadImageFromFile(ref iconNorm, "img_iconNorm.png");
                KACUtils.LoadImageFromFile(ref iconNormShow, "img_iconNormShow.png");
                KACUtils.LoadImageFromFile(ref iconAlarm, "img_iconAlarm.png");
                KACUtils.LoadImageFromFile(ref iconAlarmShow, "img_iconAlarmShow.png");
                KACUtils.LoadImageFromFile(ref iconWarpEffect100, "img_iconWarpEffect2_100.png");
                KACUtils.LoadImageFromFile(ref iconWarpEffect080, "img_iconWarpEffect2_080.png");
                KACUtils.LoadImageFromFile(ref iconWarpEffect060, "img_iconWarpEffect2_060.png");
                KACUtils.LoadImageFromFile(ref iconWarpEffect040, "img_iconWarpEffect2_040.png");
                KACUtils.LoadImageFromFile(ref iconWarpEffect020, "img_iconWarpEffect2_020.png");
                KACUtils.LoadImageFromFile(ref iconWarpEffect000, "img_iconWarpEffect2_000.png");
                KACUtils.LoadImageFromFile(ref iconPauseEffect100, "img_iconPauseEffect_100.png");
                KACUtils.LoadImageFromFile(ref iconPauseEffect080, "img_iconPauseEffect_080.png");
                KACUtils.LoadImageFromFile(ref iconPauseEffect060, "img_iconPauseEffect_060.png");
                KACUtils.LoadImageFromFile(ref iconPauseEffect040, "img_iconPauseEffect_040.png");
                KACUtils.LoadImageFromFile(ref iconPauseEffect020, "img_iconPauseEffect_020.png");
                KACUtils.LoadImageFromFile(ref iconPauseEffect000, "img_iconPauseEffect_000.png");


                KACUtils.LoadImageFromFile(ref iconRaw, "img_listiconRaw.png");
                KACUtils.LoadImageFromFile(ref iconSOI, "img_listiconSOI.png");
                KACUtils.LoadImageFromFile(ref iconMNode, "img_listiconMNode.png");
                KACUtils.LoadImageFromFile(ref iconAp, "img_listiconAp.png");
                KACUtils.LoadImageFromFile(ref iconPe, "img_listiconPe.png");
                KACUtils.LoadImageFromFile(ref iconAN, "img_listiconAN.png");
                KACUtils.LoadImageFromFile(ref iconDN, "img_listiconDN.png");
                KACUtils.LoadImageFromFile(ref iconXFer, "img_listiconXfer.png");
                KACUtils.LoadImageFromFile(ref iconClosest, "img_listiconClosest.png");
                KACUtils.LoadImageFromFile(ref iconCrew, "img_listiconCrew.png");
                KACUtils.LoadImageFromFile(ref iconEarth, "img_listiconEarth.png");
                KACUtils.LoadImageFromFile(ref iconLaunchRendezvous, "img_listiconLaunchRendezvous.png");
                KACUtils.LoadImageFromFile(ref iconWarpList100, "img_listiconWarpList_100.png");
                KACUtils.LoadImageFromFile(ref iconWarpList080, "img_listiconWarpList_080.png");
                KACUtils.LoadImageFromFile(ref iconWarpList060, "img_listiconWarpList_060.png");
                KACUtils.LoadImageFromFile(ref iconWarpList040, "img_listiconWarpList_040.png");
                KACUtils.LoadImageFromFile(ref iconWarpList020, "img_listiconWarpList_020.png");
                KACUtils.LoadImageFromFile(ref iconWarpList000, "img_listiconWarpList_000.png");

                KACUtils.LoadImageFromFile(ref iconPauseList100, "img_listiconPauseList_100.png");
                KACUtils.LoadImageFromFile(ref iconPauseList080, "img_listiconPauseList_080.png");
                KACUtils.LoadImageFromFile(ref iconPauseList060, "img_listiconPauseList_060.png");
                KACUtils.LoadImageFromFile(ref iconPauseList040, "img_listiconPauseList_040.png");
                KACUtils.LoadImageFromFile(ref iconPauseList020, "img_listiconPauseList_020.png");
                KACUtils.LoadImageFromFile(ref iconPauseList000, "img_listiconPauseList_000.png");

                KACUtils.LoadImageFromFile(ref iconNone, "img_listiconNone.png");
                KACUtils.LoadImageFromFile(ref iconEdit, "img_listiconEdit.png");

                //KACUtils.LoadImageFromFile(ref iconstatusSOI, "img_statusiconSOI.png");

                KACUtils.LoadImageFromFile(ref btnRaw, "img_buttonTypeRaw.png");
                KACUtils.LoadImageFromFile(ref btnMNode, "img_buttonTypeMNode.png");
                KACUtils.LoadImageFromFile(ref btnAp, "img_buttonTypeAp.png");
                KACUtils.LoadImageFromFile(ref btnPe, "img_buttonTypePe.png");
                KACUtils.LoadImageFromFile(ref btnApPe, "img_buttonTypeApPe.png");
                KACUtils.LoadImageFromFile(ref btnAN, "img_buttonTypeAN.png");
                KACUtils.LoadImageFromFile(ref btnDN, "img_buttonTypeDN.png");
                KACUtils.LoadImageFromFile(ref btnANDN, "img_buttonTypeANDN.png");
                KACUtils.LoadImageFromFile(ref btnSOI, "img_buttonTypeSOI.png");
                KACUtils.LoadImageFromFile(ref btnXfer, "img_buttonTypeXfer.png");
                KACUtils.LoadImageFromFile(ref btnClosest, "img_buttonTypeClosest.png");
                KACUtils.LoadImageFromFile(ref btnCrew, "img_buttonTypeCrew.png");

                KACUtils.LoadImageFromFile(ref btnChevronUp, "img_buttonChevronUp.png");
                KACUtils.LoadImageFromFile(ref btnChevronDown, "img_buttonChevronDown.png");
                KACUtils.LoadImageFromFile(ref btnChevLeft, "img_buttonChevronLeft.png");
                KACUtils.LoadImageFromFile(ref btnChevRight, "img_buttonChevronRight.png");

                KACUtils.LoadImageFromFile(ref btnRedCross, "img_buttonRedCross.png");
                KACUtils.LoadImageFromFile(ref btnSettings, "img_buttonSettings.png");
                KACUtils.LoadImageFromFile(ref btnSettingsAttention, "img_buttonSettingsAttention.png");
                KACUtils.LoadImageFromFile(ref btnAdd, "img_buttonAdd.png");

                KACUtils.LoadImageFromFile(ref txtTooltipBackground, "txt_TooltipBackground.png");


                //KACUtils.LoadImageFromFile(ref txtRedTint, "Textures", "RedOverlay.png");

                //KACUtils.LoadImageFromFile(ref txtBlackSquare, "Textures", "BlackSquare.png");
                //KACUtils.LoadImageFromFile(ref txtWhiteSquare, "Textures", "WhiteSquare.png");

                txtUIBlocker.SetPixels(new Color[] { new Color(1f, 1f, 1f, 0.0f) }); // white, but transparent
#if DEBUG
                txtUIBlocker.SetPixels(new Color[] { new Color(1f, 0f, 0f, 0.1f) }); // red to find it for debugging
#endif
                txtUIBlocker.Apply();

                KACWorker.DebugLogFormatted("Loaded Textures");
            }
            catch (Exception)
            {
                KACWorker.DebugLogFormatted("Failed to Load Textures - are you missing a file?");
            }
        }
Exemple #21
0
        public void LoadFromString3(String AlarmDetails, Double CurrentUT)
        {
            //String is "VesselID|Name|Notes|AlarmTime.UT|AlarmMarginSecs|Type|Enabled|HaltWarp|PauseGame|ActionedAt|Manuever|Xfer|Target|Options|<ENDLINE>");

            String[] vars = AlarmDetails.Split("|".ToCharArray(), StringSplitOptions.None);
            this.SaveName        = HighLogic.CurrentGame.Title;
            this.VesselID        = vars[0];
            this.Name            = KACUtils.DecodeVarStrings(vars[1]);
            this.Notes           = KACUtils.DecodeVarStrings(vars[2]);
            this.AlarmTime.UT    = Convert.ToDouble(vars[3]);
            this.AlarmMarginSecs = Convert.ToDouble(vars[4]);
            this.TypeOfAlarm     = (KACAlarm.AlarmType)Enum.Parse(typeof(KACAlarm.AlarmType), vars[5]);
            this.Enabled         = Convert.ToBoolean(vars[6]);
            this.HaltWarp        = Convert.ToBoolean(vars[7]);
            this.PauseGame       = Convert.ToBoolean(vars[8]);
            this.ActionedAt      = Convert.ToDouble(vars[9]);

            if (vars[10] != "")
            {
                this.ManNodes = ManNodeDeserializeList(vars[10]);
            }

            if (vars[11] != "")
            {
                try
                {
                    String[] XferParts = vars[11].Split(",".ToCharArray());
                    this.XferOriginBodyName = XferParts[0];
                    this.XferTargetBodyName = XferParts[1];
                }
                catch (Exception ex)
                {
                    KACWorker.DebugLogFormatted("Unable to load transfer details for {0}", Name);
                    KACWorker.DebugLogFormatted(ex.Message);
                }
            }
            if (vars[12] != "")
            {
                //find the targetable object and set it
                this.TargetObject = TargetDeserialize(vars[12]);
                if (this.TargetObject == null && vars[12].StartsWith("Vessel,"))
                {
                    this.TargetLoader = vars[12];
                }
            }

            //Now do the work to set Actioned/triggered/etc if needed
            //KACWorker.DebugLogFormatted("A:{0},T:{1:0},Act:{2:0}", this.Name, CurrentUT, this.ActionedAt);
            if (ActionedAt > 0 && CurrentUT > ActionedAt)
            {
                KACWorker.DebugLogFormatted("Suppressing Alarm on Load:{0}", this.Name);
                this.Triggered         = true;
                this.Actioned          = true;
                this.AlarmWindowClosed = true;
            }
            else if (ActionedAt > CurrentUT)
            {
                KACWorker.DebugLogFormatted("Reenabling Alarm on Load:{0}", this.Name);
                this.Triggered         = false;
                this.Actioned          = false;
                this.ActionedAt        = 0;
                this.AlarmWindowClosed = false;
            }
        }
 //Constructor to set KACWorker parent object to this and access to the settings
 public KerbalAlarmClock()
 {
     switch (KACWorkerGameState.CurrentGUIScene)
     {
         case GameScenes.SPACECENTER:
         case GameScenes.TRACKSTATION:
             WorkerObjectInstance = new KACWorker_ViewOnly(this);
             break;
         default:
             WorkerObjectInstance = new KACWorker(this);
             break;
     }
     //Set the saves path
     KACUtils.SavePath=string.Format("{0}saves/{1}",KACUtils.PathApp,HighLogic.SaveFolder);
 }