public void LateUpdate () { string pngName; if (doSave || (AS.configuration.autoSave && ((Time.realtimeSinceStartup - lastBackup) > AS.configuration.minBetweenSaves * 60))) { lastBackup = Time.realtimeSinceStartup; SaveFilesHandlers sfh = new SaveFilesHandlers (); sfh.startBackup (this); doSave = false; } if (doSnapshots) { Log.Info ("In LateUpdate, doSnapshots"); if (screenshotTaken && configuration.noGUIOnScreenshot == true && System.IO.File.Exists (screenshotFile) && wasUIVisible) GameEvents.onShowUI.Fire (); // If there is a png file waiting to be converted, then don't do another screenshot if (pngToConvert != "") { //Log.Info ("pngToConvert: " + pngToConvert); if (System.IO.File.Exists (pngToConvert)) { Log.Info ("Converting screenshot to JPG. New name: " + jpgName); ConvertToJPG (pngToConvert, jpgName, configuration.JPGQuality); System.IO.FileInfo file = new System.IO.FileInfo (pngToConvert); if (!configuration.keepOrginalPNG) { Log.Info ("AutomatedScreenshots: Delete PNG file"); file.Delete (); } pngToConvert = ""; } } else { if (AS.configuration.precrashSnapshots) { if (FlightGlobals.ActiveVessel != null) { Vessel vessel = FlightGlobals.ActiveVessel; if ((-vessel.verticalSpeed > AS.configuration.hsMinVerticalSpeed) && ((FlightGlobals.ship_altitude / -vessel.verticalSpeed < AS.configuration.secondsUntilImpact) || (FlightGlobals.ship_altitude < AS.configuration.hsAltitudeLimit) )) { if (Time.realtimeSinceStartup - lastPrecrashUpdate > configuration.hsScreenshotInterval) { this.precrash = true; lastPrecrashUpdate = Time.realtimeSinceStartup; Log.Info ("vessel.verticalSpeed: " + vessel.verticalSpeed.ToString ()); Log.Info ("FlightGlobals.ship_altitude: " + FlightGlobals.ship_altitude.ToString ()); Log.Info ("FlightGlobals.ship_altitude / -vessel.verticalSpeed: " + (FlightGlobals.ship_altitude / -vessel.verticalSpeed).ToString ()); } } } } if (this.specialScene || this.precrash || dualScreenshots == 1 || ( /*AS.configuration.screenshotAtIntervals && */ ((this.newScene && this.sceneReady && Time.realtimeSinceStartup - lastSceneUpdate > 1) || ((Time.realtimeSinceStartup - lastUpdate) > configuration.screenshotInterval) ) )) { Log.Info ("Taking screenshot"); newScene = false; this.specialScene = false; lastUpdate = Time.realtimeSinceStartup; //check if directory doesn't exist if (!System.IO.Directory.Exists (FileOperations.ScreenshotFolder ())) { //if it doesn't, try to create it try { System.IO.Directory.CreateDirectory (FileOperations.ScreenshotFolder ()); } catch (Exception e) { Log.Error ("Exception trying to create directory: " + e); return; } } do { cnt++; string s = AddInfo (configuration.filename, cnt, sceneReady, specialScene, precrash); pngName = configuration.screenshotPath + s + ".png"; jpgName = configuration.screenshotPath + s + ".jpg"; } while (System.IO.File.Exists (pngName) || System.IO.File.Exists (jpgName)); this.precrash = false; // // I make the assumption that if the player wants the gui during the screenshot, then // it will be left visible. // wasUIVisible = uiVisiblity.isVisible () | configuration.guiOnScreenshot; //Log.Info ("Update: Screenshotfolder:" + pngName); if (configuration.noGUIOnScreenshot == true) GameEvents.onHideUI.Fire (); if (configuration.noGUIOnScreenshot && configuration.guiOnScreenshot) { if (dualScreenshots == 0) dualScreenshots = 1; else if (dualScreenshots == 1) { dualScreenshots = 0; GameEvents.onShowUI.Fire (); } } screenshotTaken = true; screenshotFile = pngName; // // If Historian is available, then tell it to activate // Version.set_m_Active (); Application.CaptureScreenshot (pngName); if (configuration.convertToJPG) { pngToConvert = pngName; } } } } }
public void BackupWork () { SaveFilesHandlers sfh = new SaveFilesHandlers (); // SaveMode is: OVERWRITE APPEND ABORT SaveMode s = SaveMode.OVERWRITE; saveFileCnt = sfh.FileSaveCnt(KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder) + 1; string saveFileName = AddInfo (configuration.savePrefix, saveFileCnt, sceneReady, specialScene, precrash); string str = GamePersistence.SaveGame (saveFileName, HighLogic.SaveFolder, s); Log.Info ("String: " + str); sfh.deleteOldestSaveFile (KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder, configuration.numToRotate, saveFileCnt, saveFileName); Log.Info ("backup thread terminated"); }