Beispiel #1
0
        private System.Collections.IEnumerator CRVersionCheck()
        {
            WWW wwwVersionCheck;
            {
                //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
                MonoBehaviourExtended.LogFormatted("Reading version from Web");
                wwwVersionCheck = new WWW(VersionCheckURL);
                yield return(wwwVersionCheck);

                if (wwwVersionCheck.error == null)
                {
                    CRVersionCheck_Completed(wwwVersionCheck);
                }
                else
                {
                    MonoBehaviourExtended.LogFormatted("Version Download failed:{0}", wwwVersionCheck.error);
                }
                VersionCheckRunning = false;
            }
        }
Beispiel #2
0
        void CRVersionCheck_Completed(WWW wwwVersionCheck)
        {
            try
            {
                //get the response from the variable and work with it
                //Parse it for the version String
                String strFile = wwwVersionCheck.text;
                MonoBehaviourExtended.LogFormatted("Response Length:" + strFile.Length);

                Match matchVersion;
                matchVersion = Regex.Match(strFile, "(?<=\\|LATESTVERSION\\|).+(?=\\|LATESTVERSION\\|)", System.Text.RegularExpressions.RegexOptions.Singleline);
                MonoBehaviourExtended.LogFormatted("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)
            {
                MonoBehaviourExtended.LogFormatted("Failed to read Version info from web");
                MonoBehaviourExtended.LogFormatted(ex.Message);
            }
            MonoBehaviourExtended.LogFormatted("Version Check result:" + VersionCheckResult);

            this.Save();
            VersionAttentionFlag = VersionAvailable;
        }
Beispiel #3
0
    /// <summary>
    /// Add a style to a skin, if the styleID already exists it will update the style
    /// </summary>
    /// <param name="SkinToAction">The GUISkin we are going to adjust. The name of the Style is its ID</param>
    /// <param name="NewStyle">The GUIStyle to add or update</param>
    internal static void AddStyle(ref GUISkin SkinToAction, GUIStyle NewStyle)
    {
        if (NewStyle.name == null || NewStyle.name == "")
        {
            MonoBehaviourExtended.LogFormatted("No Name Provided in the Style to add to {0}. Cannot add this.", SkinToAction.name);
            return;
        }

        //Convert to a list
        List <GUIStyle> lstTemp = SkinToAction.customStyles.ToList <GUIStyle>();

        //Add or edit the customstyle
        //if (StyleExists(SkinToAction, StyleID))
        if (lstTemp.Any(x => x.name == NewStyle.name))
        {
            // this is weird and probably a bug
            lstTemp.First(x => x.name == NewStyle.name);
        }
        else
        {
            lstTemp.Add(NewStyle);
        }
        //Write the list back to the array
        SkinToAction.customStyles = lstTemp.ToArray <GUIStyle>();
    }
Beispiel #4
0
        internal ApplicationLauncherButton InitAppLauncherButton()
        {
            ApplicationLauncherButton retButton = null;

            ApplicationLauncherButton[] lstButtons = FindObjectsOfType <ApplicationLauncherButton>();
            //LogFormatted("AppLauncher: Creating Button-BEFORE", lstButtons.Length);
            try
            {
                retButton = ApplicationLauncher.Instance.AddModApplication(
                    onAppLaunchToggleOn, onAppLaunchToggleOff,
                    onAppLaunchHoverOn, onAppLaunchHoverOff,
                    null, null,
                    ApplicationLauncher.AppScenes.SPH | ApplicationLauncher.AppScenes.VAB,
                    (Texture)AirshipResources.iconAirshipControlWindow);
            }
            catch (Exception ex)
            {
                MonoBehaviourExtended.LogFormatted("AppLauncher: Failed to set up App Launcher Button\r\n{0}", ex.Message);
                retButton = null;
            }
            lstButtons = FindObjectsOfType <ApplicationLauncherButton>();
            //LogFormatted("AppLauncher: Creating Button-AFTER", lstButtons.Length);

            return(retButton);
        }
        //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
        //    {
        //        //MonoBehaviourExtended.LogFormatted("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)
        //    {
        //        MonoBehaviourExtended.LogFormatted("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;
        //        MonoBehaviourExtended.LogFormatted_DebugOnly("Loading {0}", String.Format("{0}/{1}", FolderPath, FileName));
        //        tex = GameDatabase.Instance.GetTexture(String.Format("{0}/{1}", FolderPath, FileName), false);
        //        blnReturn = true;
        //    }
        //    catch (Exception)
        //    {
        //        MonoBehaviourExtended.LogFormatted("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
                    {
                        //MonoBehaviourExtended.LogFormatted_DebugOnly("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)
                    {
                        MonoBehaviourExtended.LogFormatted("Failed to load the texture:{0} ({1})", String.Format("{0}/{1}", FolderPath, FileName), ex.Message);
                    }
                }
                else
                {
                    MonoBehaviourExtended.LogFormatted("Cannot find texture to load:{0}", String.Format("{0}/{1}", FolderPath, FileName));
                }


            }
            catch (Exception ex)
            {
                MonoBehaviourExtended.LogFormatted("Failed to load (are you missing a file):{0} ({1})", String.Format("{0}/{1}", FolderPath, FileName), ex.Message);
            }
            return blnReturn;
        }
        //internal static Boolean LoadImageFromGameDB(ref Texture2D tex, String FileName, String FolderPath = "")
        //{
        //    Boolean blnReturn = false;
        //    try
        //    {
        //        //trim off the tga and png extensions
        //        if (FileName.ToLower().EndsWith(".png")) FileName = FileName.Substring(0, FileName.Length - 4);
        //        if (FileName.ToLower().EndsWith(".tga")) FileName = FileName.Substring(0, FileName.Length - 4);
        //        //default folder
        //        if (FolderPath == "") FolderPath = DBPathTextures;

        //        //Look for case mismatches
        //        if (!GameDatabase.Instance.ExistsTexture(String.Format("{0}/{1}", FolderPath, FileName)))
        //            throw new Exception();

        //        //now load it
        //        tex = GameDatabase.Instance.GetTexture(String.Format("{0}/{1}", FolderPath, FileName), false);
        //        blnReturn = true;
        //    }
        //    catch (Exception)
        //    {
        //        MonoBehaviourExtended.LogFormatted("Failed to load (are you missing a file - and check case):{0}/{1}", FolderPath, FileName);
        //    }
        //    return blnReturn;
        //}

        internal static Boolean LoadAudioClipFromGameDB(ref AudioClip clip, String FileName, String FolderPath = "")
        {
            Boolean blnReturn = false;

            try
            {
                //trim off the tga and png extensions
                if (FileName.ToLower().EndsWith(".wav"))
                {
                    FileName = FileName.Substring(0, FileName.Length - 4);
                }
                //default folder
                if (FolderPath == "")
                {
                    FolderPath = DBPathPluginSounds;
                }

                //Look for case mismatches
                if (!GameDatabase.Instance.ExistsAudioClip(String.Format("{0}/{1}", FolderPath, FileName)))
                {
                    throw new Exception();
                }

                //now load it
                clip      = GameDatabase.Instance.GetAudioClip(String.Format("{0}/{1}", FolderPath, FileName));
                blnReturn = true;
            }
            catch (Exception)
            {
                MonoBehaviourExtended.LogFormatted("Failed to load (are you missing a file - and check case):{0}/{1}", FolderPath, FileName);
            }
            return(blnReturn);
        }
Beispiel #7
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>();

            SaveBackups.AddRange(new System.IO.DirectoryInfo(SavePath).GetFiles(string.Format("zKACBACKUP*{0}", OriginalName)).ToList <System.IO.FileInfo>());

            MonoBehaviourExtended.LogFormatted("{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>();

            MonoBehaviourExtended.LogFormatted("{0} KACBackup...{1} Saves to purge", SaveBackupsToDelete.Count, OriginalName);
            for (int i = SaveBackupsToDelete.Count - 1; i >= 0; i--)
            {
                MonoBehaviourExtended.LogFormatted("\tDeleting {0}", SaveBackupsToDelete[i].Name);

                //bin the loadmeta if it exists too
                string loadmetaFile = SaveBackupsToDelete[i].DirectoryName + "/" + System.IO.Path.GetFileNameWithoutExtension(SaveBackupsToDelete[i].FullName) + ".loadmeta";
                if (System.IO.File.Exists(loadmetaFile))
                {
                    System.IO.File.Delete(loadmetaFile);
                }

                SaveBackupsToDelete[i].Delete();
            }
        }
Beispiel #8
0
        void onAppLaunchToggleOff()
        {
            MonoBehaviourExtended.LogFormatted_DebugOnly("TOff");

            EditorWindowVisible = false;
            MonoBehaviourExtended.LogFormatted_DebugOnly("{0}", EditorWindowVisible);
        }
        internal static void CalcWarpRateTransitions()
        {
            if (TimeWarp.fetch == null)
            {
                return;
            }
            MonoBehaviourExtended.LogFormatted("WarpRates:{0}", TimeWarp.fetch.warpRates.Length);
            WarpRateTransitionPeriods = new List <WarpTransition>();
            for (int i = 0; i < TimeWarp.fetch.warpRates.Length; i++)
            {
                WarpTransition newRate = new WarpTransition(i, TimeWarp.fetch.warpRates[i]);

                if (i > 0)
                {
                    newRate.UTToRateDown = (TimeWarp.fetch.warpRates[i] + TimeWarp.fetch.warpRates[i - 1]) / 2;
                }
                if (i < TimeWarp.fetch.warpRates.Length - 1)
                {
                    newRate.UTToRateUp = (TimeWarp.fetch.warpRates[i] + TimeWarp.fetch.warpRates[i + 1]) / 2;
                }

                WarpRateTransitionPeriods.Add(newRate);
            }

            foreach (WarpTransition wt in WarpRateTransitionPeriods)
            {
                List <WarpTransition> warpsTo1Times = WarpRateTransitionPeriods.Where(w => w.Index <= wt.Index).ToList();
                wt.UTTo1Times = warpsTo1Times.Sum(w => w.UTToRateDown);
            }

            //foreach (WarpTransition item in WarpRateTransitionPeriods.OrderBy(w => w.Index))
            //{
            //    MonoBehaviourExtended.LogFormatted_DebugOnly("{0}({1}):Up-{2} Down-{3} To0-{4}", item.Rate, item.Index, item.UTToRateUp, item.UTToRateDown, item.UTTo1Times);
            //}
        }
Beispiel #10
0
        internal ApplicationLauncherButton InitAppLauncherButton()
        {
            ApplicationLauncherButton retButton = null;

            ApplicationLauncherButton[] lstButtons = KerbalAlarmClock.FindObjectsOfType <ApplicationLauncherButton>();
            LogFormatted("AppLauncher: Creating Button-BEFORE", lstButtons.Length);
            try
            {
                retButton = ApplicationLauncher.Instance.AddModApplication(
                    onAppLaunchToggleOn, onAppLaunchToggleOff,
                    onAppLaunchHoverOn, onAppLaunchHoverOff,
                    null, null,
                    ApplicationLauncher.AppScenes.ALWAYS,
                    (Texture)KACResources.toolbariconNorm);

                //AppLauncherButtonMutuallyExclusive(settings.AppLauncherMutuallyExclusive);

                //appButton = ApplicationLauncher.Instance.AddApplication(
                //    onAppLaunchToggleOn, onAppLaunchToggleOff,
                //    onAppLaunchHoverOn, onAppLaunchHoverOff,
                //    null, null,
                //    (Texture)Resources.texAppLaunchIcon);
                //appButton.VisibleInScenes = ApplicationLauncher.AppScenes.FLIGHT;
            }
            catch (Exception ex)
            {
                MonoBehaviourExtended.LogFormatted("AppLauncher: Failed to set up App Launcher Button\r\n{0}", ex.Message);
                retButton = null;
            }
            lstButtons = KerbalAlarmClock.FindObjectsOfType <ApplicationLauncherButton>();
            LogFormatted("AppLauncher: Creating Button-AFTER", lstButtons.Length);

            return(retButton);
        }
Beispiel #11
0
        void onAppLaunchToggleOff()
        {
            MonoBehaviourExtended.LogFormatted_DebugOnly("TOff");

            WindowVisibleByActiveScene = false;
            settings.Save();
            MonoBehaviourExtended.LogFormatted_DebugOnly("{0}", WindowVisibleByActiveScene);
        }
Beispiel #12
0
 static void DownloadTipsFile(object sender, DoWorkEventArgs e)
 {
     MonoBehaviourExtended.LogFormatted("Downloading tips from: {0}", DOWNLOADURL);
     wwwTips = new WWW(DOWNLOADURL);
     while (!wwwTips.isDone)
     {
     }
 }
 void ARPResourceList_OnAlarmStateChanged(ARPResource sender, ARPResource.AlarmStateEnum oldValue, ARPResource.AlarmStateEnum newValue, ARPResource.MonitorStateEnum MonitorState)
 {
     MonoBehaviourExtended.LogFormatted_DebugOnly("LISTAck-{0}:{1}->{2} ({3})", sender.ResourceDef.name, oldValue, newValue, sender.MonitorState);
     if (OnAlarmStateChanged != null)
     {
         OnAlarmStateChanged(sender, oldValue, newValue, MonitorState);
     }
 }
 /// <summary>
 /// Sets up the App Button - no longer called by the event as that only happens on StartMenu->SpaceCenter now
 /// </summary>
 void OnGUIAppLauncherReady()
 {
     MonoBehaviourExtended.LogFormatted_DebugOnly("AppLauncherReady");
     if (settings.ButtonStyleChosen == Settings.ButtonStyleEnum.Launcher)
     {
         btnAppLauncher = InitAppLauncherButton();
     }
 }
Beispiel #15
0
        internal static void LoadTextures()
        {
            MonoBehaviourExtended.LogFormatted("Loading Textures");

            if (btnChevronUp == null)
            {
                btnChevronUp = new Texture2D(17, 16, TextureFormat.ARGB32, false);
                LoadImageFromFile(ref btnChevronUp, "ChevronUp.png", PathPluginResources);
            }

            if (btnChevronDown == null)
            {
                btnChevronDown = new Texture2D(17, 16, TextureFormat.ARGB32, false);
                LoadImageFromFile(ref btnChevronDown, "ChevronDown.png", PathPluginResources);
            }

            if (texPanel == null)
            {
                texPanel = new Texture2D(16, 16, TextureFormat.ARGB32, false);
                LoadImageFromFile(ref texPanel, "img_PanelBack.png");
            }

            if (texPanelSolarizedDark == null)
            {
                texPanelSolarizedDark = new Texture2D(16, 16, TextureFormat.ARGB32, false);
                LoadImageFromFile(ref texPanelSolarizedDark, "img_PanelSolarizedDark.png");
            }

            if (texPartWindowHead == null)
            {
                texPartWindowHead = new Texture2D(16, 16, TextureFormat.ARGB32, false);
                LoadImageFromFile(ref texPartWindowHead, "img_PartWindowHead.png");
            }

            if (texBox == null)
            {
                texBox = new Texture2D(9, 9, TextureFormat.ARGB32, false);
                LoadImageFromFile(ref texBox, "tex_Box.png");
            }

            if (texBoxUnity == null)
            {
                texBoxUnity = new Texture2D(9, 9, TextureFormat.ARGB32, false);
                LoadImageFromFile(ref texBoxUnity, "tex_BoxUnity.png");
            }

            if (texSeparatorH == null)
            {
                texSeparatorH = new Texture2D(2, 20, TextureFormat.ARGB32, false);
                LoadImageFromFile(ref texSeparatorH, "img_SeparatorHorizontal.png");
            }

            if (texSeparatorV == null)
            {
                texSeparatorV = new Texture2D(6, 2, TextureFormat.ARGB32, false);
                LoadImageFromFile(ref texSeparatorV, "img_SeparatorVertical.png");
            }
        }
Beispiel #16
0
 new internal void Add(KACAlarm item)
 {
     try {
         KerbalAlarmClock.APIInstance.APIInstance_AlarmStateChanged(item, KerbalAlarmClock.AlarmStateEventsEnum.Created);
     } catch (Exception ex) {
         MonoBehaviourExtended.LogFormatted("Error Raising API Event-Created Alarm: {0}\r\n{1}", ex.Message, ex.StackTrace);
     }
     base.Add(item);
 }
Beispiel #17
0
        protected MonoBehaviourExtended Logger; // totally cheating

        public VesselChecker(MonoBehaviourExtended logger)
        {
            this.Logger = logger;
            var dummyPath = Path.Combine(
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                "dummy.protovessel");

            this.DummyVesselConfigNode = ConfigNode.Load(dummyPath);
        }
Beispiel #18
0
        void onAppLaunchToggleOn()
        {
            if (CurrentVessel != null)
            {
                MonoBehaviourExtended.LogFormatted_DebugOnly("TOn");

                ControlWindowVisible = true;
                MonoBehaviourExtended.LogFormatted_DebugOnly("{0}", ControlWindowVisible);
            }
        }
        internal void CleanResources(List <Int32> ExistingIDs)
        {
            List <Int32> IDsToRemove = this.Keys.Except(ExistingIDs).ToList <Int32>();

            foreach (Int32 rID in IDsToRemove)
            {
                MonoBehaviourExtended.LogFormatted_DebugOnly("Removing Resource-{0}", rID);
                this.Remove(rID);
            }
        }
Beispiel #20
0
 static internal void BeginCheck()
 {
     MonoBehaviourExtended.LogFormatted("Checking if we need to download a new tips file (Last={0})...", KSPTips.settings.DateTipsDownloaded);
     if (KSPTips.settings.DateTipsDownloaded != string.Format("{0:yyyy-MM-dd}", DateTime.Now))
     {
         bw.DoWork             += DownloadTipsFile;
         bw.RunWorkerCompleted += DownloadJobDone;
         bw.RunWorkerAsync();
     }
 }
Beispiel #21
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(MonoBehaviour parent, Boolean ForceCheck)
        {
            Boolean blnReturn  = false;
            Boolean blnDoCheck = false;

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

                    if (blnDoCheck)
                    {
                        parent.StartCoroutine(CRVersionCheck());
                    }
                }
                else
                {
                    MonoBehaviourExtended.LogFormatted("Starting Version Check-version check already running");
                }

                blnReturn = true;
            }
            catch (Exception ex)
            {
                MonoBehaviourExtended.LogFormatted("Failed to run the update test");
                MonoBehaviourExtended.LogFormatted(ex.Message);
            }
            return(blnReturn);
        }
Beispiel #22
0
        new internal void Remove(KACAlarm item)
        {
            //Make a copy to pass to the API as we will have deleted the source object before the event subscription gets the event
            //KACAlarm CopyForAPI = (KACAlarm)item.Clone();

            try {
                KerbalAlarmClock.APIInstance.APIInstance_AlarmStateChanged(item, KerbalAlarmClock.AlarmStateEventsEnum.Deleted);
            } catch (Exception ex) {
                MonoBehaviourExtended.LogFormatted("Error Raising API Event-Deleted Alarm: {0}\r\n{1}", ex.Message, ex.StackTrace);
            }
            base.Remove(item);
        }
Beispiel #23
0
 /// <summary>
 /// Copies a skin so you can make a new custom skin from an already defined one
 /// </summary>
 /// <param name="SkinID">The string ID of the custom skin</param>
 /// <returns>The new copy of the skin</returns>
 internal static GUISkin CopySkin(string SkinID)
 {
     if (List.ContainsKey(SkinID))
     {
         return(List[SkinID]);
     }
     else
     {
         MonoBehaviourExtended.LogFormatted("Unable to copy GUISkin to {0}, GUISkin not found", SkinID);
         throw new SystemException(string.Format("Unable to copy GUISkin to {0}, GUISkin not found", SkinID));
     }
 }
Beispiel #24
0
    /// <summary>
    /// Copies a skin so you can make a new custom skin from an already defined one
    /// </summary>
    /// <param name="DefaultSkin">Which predefined skin to use</param>
    /// <returns>The new copy of the skin</returns>
    internal static GUISkin CopySkin(DefSkinType DefaultSkin)
    {
        switch (DefaultSkin)
        {
        case DefSkinType.Unity: return((GUISkin)MonoBehaviourExtended.Instantiate(DefUnitySkin));

        case DefSkinType.KSP: return((GUISkin)MonoBehaviourExtended.Instantiate(DefKSPSkin));

        //case DefSkinType.None: return new GUISkin();
        default: return((GUISkin)MonoBehaviourExtended.Instantiate(DefKSPSkin));
        }
    }
Beispiel #25
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;
                    MonoBehaviourExtended.LogFormatted("Starting Version Check-Forced");
                }
                //else if (this.VersionWeb == "")
                //{
                //    blnDoCheck = true;
                //    MonoBehaviourExtended.LogFormatted("Starting Version Check-No current web version stored");
                //}
                else if (this.VersionCheckDate_Attempt < DateTime.Now.AddYears(-9))
                {
                    blnDoCheck = true;
                    MonoBehaviourExtended.LogFormatted("Starting Version Check-No current date stored");
                }
                else if (this.VersionCheckDate_Attempt.Date != DateTime.Now.Date)
                {
                    blnDoCheck = true;
                    MonoBehaviourExtended.LogFormatted("Starting Version Check-stored date is not today");
                }
                else
                {
                    MonoBehaviourExtended.LogFormatted("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)
            {
                MonoBehaviourExtended.LogFormatted("Failed to run the update test");
                MonoBehaviourExtended.LogFormatted(ex.Message);
            }
            return(blnReturn);
        }
Beispiel #26
0
 /// <summary>
 /// Check whether a custom style exists in one of the custom skins customstyles list
 /// </summary>
 /// <param name="SkinToAction">The GUISkin we are going to adjust</param>
 /// <param name="StyleID">The string ID of the custom style</param>
 /// <returns>whether it exists or not</returns>
 internal static Boolean StyleExists(GUISkin SkinToAction, string StyleID)
 {
     if (SkinToAction.customStyles.Any(x => x.name == StyleID))
     {
         return(true);
     }
     else
     {
         MonoBehaviourExtended.LogFormatted("Unable to find Style: {0} in Skin: {1}", StyleID, SkinToAction.name);
         return(false);
     }
     //return (SkinToAction.customStyles.Any(x => x.name == StyleID));
 }
Beispiel #27
0
        internal static Boolean BackupSaves()
        {
            if (!KerbalAlarmClock.settings.BackupSaves)
            {
                return(true);
            }

            Boolean blnReturn = false;

            MonoBehaviourExtended.LogFormatted("Backing up saves");

            if (!System.IO.Directory.Exists(SavePath))
            {
                MonoBehaviourExtended.LogFormatted("Saves Path not found: {0}");
            }
            else
            {
                if (!System.IO.File.Exists(String.Format("{0}/persistent.sfs", SavePath)))
                {
                    MonoBehaviourExtended.LogFormatted("Persistent.sfs file not found: {0}/persistent.sfs", SavePath);
                }
                else
                {
                    try
                    {
                        System.IO.File.Copy(String.Format("{0}/persistent.sfs", SavePath),
                                            String.Format("{0}/zKACBACKUP{1:yyyyMMddHHmmss}-persistent.sfs", SavePath, DateTime.Now),
                                            true);
                        MonoBehaviourExtended.LogFormatted("Backed Up Persistent.sfs as: {0}/zKACBACKUP{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}/zKACBACKUP{1:yyyyMMddHHmmss}-quicksave.sfs", SavePath, DateTime.Now),
                                                true);
                            MonoBehaviourExtended.LogFormatted("Backed Up quicksave.sfs as: {0}/zKACBACKUP{1:yyyyMMddHHmmss}-quicksave.sfs", SavePath, DateTime.Now);
                        }
                        blnReturn = true;

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

            return(blnReturn);
        }
        /// <summary>
        /// Sets up the App Button - no longer called by the event as that only happens on StartMenu->SpaceCenter now
        /// </summary>
        void OnGUIAppLauncherReady()
        {
            MonoBehaviourExtended.LogFormatted_DebugOnly("AppLauncherReady");
            if (KSPAlternateResourcePanel.settings.ButtonStyleChosen == ARPWindowSettings.ButtonStyleEnum.Launcher ||
                KSPAlternateResourcePanel.settings.ButtonStyleChosen == ARPWindowSettings.ButtonStyleEnum.StockReplace)
            {
                btnAppLauncher = InitAppLauncherButton();

                if (KSPAlternateResourcePanel.settings.ButtonStyleChosen == ARPWindowSettings.ButtonStyleEnum.StockReplace)
                {
                    StartCoroutine(ReplaceStockAppButton());
                }
            }
        }
Beispiel #29
0
        /// <summary>
        /// Checks for and adds a PartWindow to the List if not there already - does NOT update resources
        /// </summary>
        /// <param name="PartToAddorUpdate">Part to Add the Window For</param>
        /// <returns>The PartWindow for this part</returns>
        internal ARPPartWindow AddPartWindow(Part PartToAddorUpdate, KSPAlternateResourcePanel mbARP)
        {
            Int32 PartID = PartToAddorUpdate.GetInstanceID();

            if (!this.ContainsKey(PartID))
            {
                MonoBehaviourExtended.LogFormatted_DebugOnly("Adding Part Window");
                WindowGameObjects.Add(PartID, new GameObject(string.Format("PartWindowObj-{0}", PartID)));
                ARPPartWindow pwNew = WindowGameObjects[PartID].AddComponent <ARPPartWindow>();
                pwNew.Init(PartToAddorUpdate, mbARP);
                this.Add(PartID, pwNew);
            }
            return(this[PartID]);
        }
Beispiel #30
0
    /// <summary>
    /// Sets the current Skin to one of the Pre-Defined types
    /// </summary>
    /// <param name="DefaultSkin">Which predefined skin to use</param>
    internal static void SetCurrent(DefSkinType DefaultSkin)
    {
        MonoBehaviourExtended.LogFormatted_DebugOnly("Setting GUISkin to {0}", DefaultSkin);
        switch (DefaultSkin)
        {
        case DefSkinType.Unity: _CurrentSkin = DefUnitySkin; break;

        case DefSkinType.KSP: _CurrentSkin = DefKSPSkin; break;

        //case DefSkinType.None: _CurrentSkin = new GUISkin(); break;
        default: _CurrentSkin = DefKSPSkin; break;
        }
        //Now set the tooltip style as well
        SetCurrentTooltip();
    }