예제 #1
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);
        }
예제 #2
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;
        }
예제 #3
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
        //    {
        //        //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;
        }
예제 #4
0
        internal static void LoadSounds()
        {
            MonoBehaviourExtended.LogFormatted("Loading Sounds");

            clipAlarms = new Dictionary <string, AudioClip>();
            clipAlarms.Add("None", null);
            if (Directory.Exists(PathPluginSounds))
            {
                //get all the png and tga's
                FileInfo[] fileClips = new System.IO.DirectoryInfo(PathPluginSounds).GetFiles("*.wav");

                foreach (FileInfo fileClip in fileClips)
                {
                    try
                    {
                        //load the file from the GameDB
                        AudioClip clipLoading = null;
                        if (LoadAudioClipFromGameDB(ref clipLoading, fileClip.Name))
                        {
                            String ClipKey = fileClip.Name;
                            if (ClipKey.ToLower().EndsWith(".wav"))
                            {
                                ClipKey = ClipKey.Substring(0, ClipKey.Length - 4);
                            }
                            clipAlarms.Add(ClipKey, clipLoading);
                        }
                    }
                    catch (Exception)
                    {
                        //MonoBehaviourExtended.LogFormatted("Unable to load AudioClip from GameDB:{0}/{1}", PathPluginSounds,fileClip.Name);
                    }
                }
            }
        }
예제 #5
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))
        {
            GUIStyle styleTemp = lstTemp.First(x => x.name == NewStyle.name);
            styleTemp = NewStyle;
        }
        else
        {
            lstTemp.Add(NewStyle);
        }
        //Write the list back to the array
        SkinToAction.customStyles = lstTemp.ToArray <GUIStyle>();
    }
        /// <summary>
        /// This calculates the details of the Ejection Angles for the Eject burn
        /// </summary>
        public void CalcEjectionValues()
        {
            Double mu = Origin.gravParameter;
            Double rsoi = Origin.sphereOfInfluence;
            Double vsoi = EjectionVector.magnitude;
            Double v1 = Math.Sqrt(vsoi * vsoi + 2 * OriginVesselOrbitalSpeed * OriginVesselOrbitalSpeed - 2 * mu / rsoi);
            EjectionDVNormal = v1 * Math.Sin(EjectionInclination);
            EjectionDVPrograde = v1 * Math.Cos(EjectionInclination) - OriginVesselOrbitalSpeed;
            EjectionHeading = Math.Atan2(EjectionDVPrograde, EjectionDVNormal);

            Double initialOrbitRadius = mu / (OriginVesselOrbitalSpeed * OriginVesselOrbitalSpeed);
            Double e = initialOrbitRadius * v1 * v1 / mu - 1;
            Double a = initialOrbitRadius / (1 - e);
            Double theta = Math.Acos((a * (1 - e * e) - rsoi) / (e * rsoi));
            theta += Math.Asin(v1 * initialOrbitRadius / (vsoi * rsoi));
            EjectionAngle = EjectionAngleCalc(EjectionDeltaVector, theta, OriginVelocity.normalized);

            MonoBehaviourExtended.LogFormatted("{0}",EjectionAngle);

            if (Destination.orbit.semiMajorAxis < Origin.orbit.semiMajorAxis)
            {
                EjectionAngleIsRetrograde = true;
                EjectionAngle -= Math.PI;
                if (EjectionAngle < 0)
                    EjectionAngle += 2 * Math.PI;
            }
            else
            {
                EjectionAngleIsRetrograde = false;
            }

        }
예제 #7
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;
        }
        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);
            //}
        }
        internal ApplicationLauncherButton InitAppLauncherButton()
        {
            ApplicationLauncherButton retButton = null;

            ApplicationLauncherButton[] lstButtons = KSPAlternateResourcePanel.FindObjectsOfType <ApplicationLauncherButton>();
            LogFormatted("AppLauncher: Creating Button-BEFORE", lstButtons.Length);
            try
            {
                retButton = ApplicationLauncher.Instance.AddModApplication(
                    onAppLaunchToggleOn, onAppLaunchToggleOff,
                    onAppLaunchHoverOn, onAppLaunchHoverOff,
                    null, null,
                    ApplicationLauncher.AppScenes.FLIGHT | ApplicationLauncher.AppScenes.MAPVIEW,
                    (Texture)Resources.texAppLaunchIcon);

                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 = KSPAlternateResourcePanel.FindObjectsOfType <ApplicationLauncherButton>();
            LogFormatted("AppLauncher: Creating Button-AFTER", lstButtons.Length);

            return(retButton);
        }
예제 #10
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();
            }
        }
예제 #11
0
        //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);
        }
예제 #12
0
 static void DownloadTipsFile(object sender, DoWorkEventArgs e)
 {
     MonoBehaviourExtended.LogFormatted("Downloading tips from: {0}", DOWNLOADURL);
     wwwTips = new WWW(DOWNLOADURL);
     while (!wwwTips.isDone)
     {
     }
 }
예제 #13
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");
            }
        }
예제 #14
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);
 }
예제 #15
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();
     }
 }
예제 #16
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));
     }
 }
예제 #17
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);
        }
예제 #18
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);
        }
예제 #19
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);
        }
예제 #20
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));
 }
예제 #21
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);
        }
예제 #22
0
        private static List <ManeuverNode> ManNodeDeserializeList(String strInput)
        {
            List <ManeuverNode> lstReturn = new List <ManeuverNode>();

            String[] strInputParts = strInput.Split(",".ToCharArray());
            MonoBehaviourExtended.LogFormatted("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);
        }
 internal void AppLauncherButtonMutuallyExclusive(Boolean Enable)
 {
     if (btnAppLauncher == null)
     {
         return;
     }
     if (Enable)
     {
         MonoBehaviourExtended.LogFormatted("AppLauncher: Setting Mutually Exclusive");
         ApplicationLauncher.Instance.EnableMutuallyExclusive(btnAppLauncher);
     }
     else
     {
         MonoBehaviourExtended.LogFormatted("AppLauncher: Clearing Mutually Exclusive");
         ApplicationLauncher.Instance.DisableMutuallyExclusive(btnAppLauncher);
     }
 }
예제 #24
0
        internal static void loadGUIAssets()
        {
            MonoBehaviourExtended.LogFormatted("Loading Textures");

            try
            {
                LoadingUtilities.LoadImageFromFile(ref iconAirshipControlWindow, "AirshipIcon.png", LoadingUtilities.PathToolbarIcons);
                LoadingUtilities.LoadImageFromFile(ref iconAirshipControlWindowActive, "AirshipIconOn.png", LoadingUtilities.PathToolbarIcons);


                MonoBehaviourExtended.LogFormatted("Loaded Textures");
            }
            catch (Exception)
            {
                MonoBehaviourExtended.LogFormatted("Failed to Load Textures - are you missing a file?");
            }
        }
예제 #25
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
            MonoBehaviourExtended.LogFormatted("Reading version from Web");
            wwwVersionCheck = new WWW(VersionCheckURL);
            while (!wwwVersionCheck.isDone)
            {
            }
            MonoBehaviourExtended.LogFormatted("Download complete:{0}", wwwVersionCheck.text.Length);
            VersionCheckRunning = false;
        }
예제 #26
0
    /// <summary>
    /// Sets the current skin to one of the custom skins
    /// </summary>
    /// <param name="SkinID">The string ID of the custom skin</param>
    internal static void SetCurrent(string SkinID)
    {
        MonoBehaviourExtended.LogFormatted_DebugOnly("Setting GUISkin to {0}", SkinID);

        //check the skin exists, and throw a log line if it doesnt
        if (List.ContainsKey(SkinID))
        {
            _CurrentSkin = List[SkinID];
        }
        else
        {
            MonoBehaviourExtended.LogFormatted("Unable to change GUISkin to {0}, GUISkin not found", SkinID);
        }

        //Now set the tooltip style as well
        SetCurrentTooltip();
    }
예제 #27
0
        internal static void LoadTextures()
        {
            MonoBehaviourExtended.LogFormatted("Loading Textures");

            LoadImageFromFile(ref btnChevronUp, "ChevronUp.png", PathPluginResources);
            LoadImageFromFile(ref btnChevronDown, "ChevronDown.png", PathPluginResources);

            LoadImageFromFile(ref texPanel, "img_PanelBack.png");
            LoadImageFromFile(ref texPanelSolarizedDark, "img_PanelSolarizedDark.png");

            LoadImageFromFile(ref texPartWindowHead, "img_PartWindowHead.png");

            LoadImageFromFile(ref texBox, "tex_Box.png");
            LoadImageFromFile(ref texBoxUnity, "tex_BoxUnity.png");

            LoadImageFromFile(ref texSeparatorH, "img_SeparatorHorizontal.png");
            LoadImageFromFile(ref texSeparatorV, "img_SeparatorVertical.png");
        }
예제 #28
0
        /// <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 (ApplicationLauncher.Ready)
            {
                if (KSPAlternateResourcePanel.settings.ButtonStyleChosen == ARPWindowSettings.ButtonStyleEnum.Launcher ||
                    KSPAlternateResourcePanel.settings.ButtonStyleChosen == ARPWindowSettings.ButtonStyleEnum.StockReplace)
                {
                    btnAppLauncher = InitAppLauncherButton();

                    if (KSPAlternateResourcePanel.settings.ButtonStyleChosen == ARPWindowSettings.ButtonStyleEnum.StockReplace)
                    {
                        ReplaceStockAppButton();
                    }
                }
            }
            else
            {
                MonoBehaviourExtended.LogFormatted("App Launcher-Not Actually Ready");
            }
        }
예제 #29
0
        public override void OnLoad(ConfigNode gameNode)
        {
            //reset the list here
            //KerbalAlarmClock.alarms = new KACAlarmList();
            KerbalAlarmClock.alarms.RemoveRange(0, KerbalAlarmClock.alarms.Count);

            base.OnLoad(gameNode);
            MonoBehaviourExtended.LogFormatted("BaseLoadDone. Alarms Count (Should be 0):{0}", KerbalAlarmClock.alarms.Count);

            MonoBehaviourExtended.LogFormatted_DebugOnly("OnLoad: ");
            MonoBehaviourExtended.LogFormatted_DebugOnly("{0}", gameNode);

            if (gameNode.HasNode("KerbalAlarmClockScenario"))
            {
                MonoBehaviourExtended.LogFormatted_DebugOnly("Found {0}", "KerbalAlarmClockScenario");
            }
            if (gameNode.HasNode("KACAlarmListStorage"))
            {
                MonoBehaviourExtended.LogFormatted_DebugOnly("Found {0}", "KACAlarmListStorage");
            }
            if (gameNode.HasNode("KACAlarmListStorage"))
            {
                KerbalAlarmClock.alarms.DecodeFromCN(gameNode.GetNode("KACAlarmListStorage"));

                foreach (KACAlarm a in KerbalAlarmClock.alarms)
                {
                    if (!a.AlarmActionConverted)
                    {
                        a.AlarmActionConvert   = a.AlarmAction;
                        a.AlarmAction          = KACAlarm.AlarmActionEnum.Converted;
                        a.AlarmActionConverted = true;
                    }
                }
            }

            MonoBehaviourExtended.LogFormatted("ScenarioLoadDone. Alarms Count:{0}", KerbalAlarmClock.alarms.Count);
            //{MonoBehaviourExtended.LogFormatted_DebugOnly("A");} else {MonoBehaviourExtended.LogFormatted_DebugOnly("B");}
            //KerbalAlarmClock.alarms.DecodeFromCN(gameNode.GetNode(this.GetType().Name));
        }
예제 #30
0
        /// <summary>
        /// This one gets all the icons named in the resource definitions
        /// </summary>
        /// <returns></returns>
        private static Dictionary <String, Texture2D> LoadIconDictionary_Defs()
        {
            Dictionary <String, Texture2D> dictReturn = new Dictionary <string, Texture2D>();
            Texture2D texLoading;

            //Find All the RESOURCE_DEFINITION Nodes
            ConfigNode[] cns = GameDatabase.Instance.GetConfigNodes("RESOURCE_DEFINITION");
            foreach (ConfigNode cn in cns)
            {
                if (cn.HasValue("name"))
                {
                    if (cn.HasValue("ksparpicon"))
                    {
                        //If it has a name and a ksparpicon
                        try
                        {
                            //lead the Texture from the GameDB
                            texLoading = GameDatabase.Instance.GetTexture(cn.GetValue("ksparpicon"), false);
                            if ((texLoading.width > 32) || (texLoading.height > 16))
                            {
                                MonoBehaviourExtended.LogFormatted("Texture Too Big (32x16 is limit) - w:{0} h:{1}", texLoading.width, texLoading.height);
                            }
                            else
                            {
                                dictReturn.Add(cn.GetValue("name").ToLower(), texLoading);
                            }
                        }
                        catch (Exception)
                        {
                            MonoBehaviourExtended.LogFormatted("Unable to load texture {0}-{1}", cn.GetValue("name"), cn.GetValue("ksparpicon"));
                        }
                    }
                }
            }

            return(dictReturn);
        }