/*
         * BackupWork
         */
        public void BackupWork(AS asRef)
        {
            SaveFilesHandlers sfh  = new SaveFilesHandlers ();

            // SaveMode is:  OVERWRITE    APPEND   ABORT
            SaveMode s = SaveMode.OVERWRITE;

            saveFileCnt = FileSaveCnt(KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder) + 1;
            string saveFileName = AS.AddInfo (AS.configuration.savePrefix, saveFileCnt,	asRef.isSceneReady(), asRef.isSpecialScene(), asRef.isPreCrash());

            string str = GamePersistence.SaveGame (saveFileName, HighLogic.SaveFolder, s);
            Log.Info ("String: " + str);

            sfh.deleteOldestSaveFile (KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder, AS.configuration.numToRotate, saveFileCnt, saveFileName);

            Log.Info ("backup thread terminated");
        }
Esempio n. 2
0
        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");
        }
Esempio n. 3
0
        /*
         * BackupWork
         */
        private void BackupWork(AS asRef)
        {
            SaveFilesHandlers sfh = new SaveFilesHandlers();

            // SaveMode is:  OVERWRITE    APPEND   ABORT
            SaveMode s = SaveMode.OVERWRITE;

            saveFileCnt = FileSaveCnt() + 1;
            string saveFileName = AS.AddInfo(AS.configuration.savePrefix, saveFileCnt, asRef.isSceneReady(), asRef.isSpecialScene(), asRef.isPreCrash());

            string str = GamePersistence.SaveGame(saveFileName, HighLogic.SaveFolder, s);

            Log.dbg("String: {0}", str);

            sfh.deleteOldestSaveFile(SAVEDIR, AS.configuration.numToRotate, saveFileCnt, saveFileName);

            Log.trace("backup thread terminated");
        }
Esempio n. 4
0
        public void FixedUpdate()
//		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 || snapshotInProgress)
            {
                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       = "";
                        snapshotInProgress = false;
                    }
                }
                else
                {
                    snapshotInProgress = false;
                    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.newScene) || this.precrash || dualScreenshots == 1 ||
                        (                     /*AS.configuration.screenshotAtIntervals && */
                            ((this.newScene && (this.sceneReady && Time.realtimeSinceStartup - sceneReadyAt > 0.1) && Time.realtimeSinceStartup - lastSceneUpdate > 1) ||
                             ((Time.realtimeSinceStartup - lastUpdate) > configuration.screenshotInterval && !this.newScene)
                            )
                        ))
                    {
                        Log.Info("this.specialScene: " + this.specialScene.ToString());
                        Log.Info("this.precrash: " + this.precrash.ToString());
                        Log.Info("dualScreenshots: " + dualScreenshots.ToString());
                        Log.Info("this.newScene: " + this.newScene.ToString());
                        Log.Info("this.sceneReady: " + this.sceneReady.ToString());
                        Log.Info("Time.realtimeSinceStartup - sceneReadyAt: " + (Time.realtimeSinceStartup - sceneReadyAt).ToString());
                        Log.Info("Time.realtimeSinceStartup - lastSceneUpdate: " + (Time.realtimeSinceStartup - lastSceneUpdate).ToString());
                        Log.Info("Time.realtimeSinceStartup - lastUpdate: " + (Time.realtimeSinceStartup - lastUpdate).ToString());


                        Log.Info("Taking screenshot");
                        Log.Info("CurrentDirectory: " + System.IO.Directory.GetCurrentDirectory());
                        Log.Info("FileOperations.ScreenshotFolder: " + FileOperations.ScreenshotFolder());
                        snapshotInProgress = true;
                        newScene           = false;
                        this.specialScene  = false;

                        lastUpdate = Time.realtimeSinceStartup;
                        //check if directory doesn't exist
                        if (!System.IO.Directory.Exists(FileOperations.ScreenshotFolder()))
                        {
                            Log.Info("Directory does not exist");
                            //if it doesn't, try to create it
                            try {
                                Log.Info("Trying to create directory");
                                System.IO.Directory.CreateDirectory(FileOperations.ScreenshotFolder());
                            } catch (Exception e) {
                                Log.Error("Exception trying to create directory: " + e);
                                return;
                            }
                            Log.Info("Directory created");
                        }
                        do
                        {
                            cnt++;
                            string s = AddInfo(configuration.filename, cnt, sceneReady, specialScene, precrash);

                            pngName = System.IO.Path.GetFullPath(FileOperations.ScreenshotFolder()) + s + ".png";
                            jpgName = System.IO.Path.GetFullPath(FileOperations.ScreenshotFolder()) + 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();
                        // Change second number for supersize.  If non-zero,
                        // then multiplies the resolution by that number
                        // Must be an integer
                        Application.CaptureScreenshot(pngName, configuration.supersize);

                        if (configuration.convertToJPG)
                        {
                            pngToConvert = pngName;
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        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.dbg("In LateUpdate, doSnapshots");

                if (screenshotTaken && configuration.noGUIOnScreenshot && wasUIVisible && (null != this.lastScreenshot && IO.File.Exists(this.lastScreenshot)))                 // FIXME hitting the filesyste on Updates are bad. Try to work around this.
                {
                    GameEvents.onShowUI.Fire();
                }

                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.dbg("vessel.verticalSpeed: {0}", vessel.verticalSpeed);
                                Log.dbg("FlightGlobals.ship_altitude: {0}", FlightGlobals.ship_altitude);
                                Log.dbg("FlightGlobals.ship_altitude  / -vessel.verticalSpeed: {0}", (FlightGlobals.ship_altitude / -vessel.verticalSpeed));
                            }
                        }
                    }
                }

                if ((this.specialScene && !this.newScene) || this.precrash || dualScreenshots ||
                    (                     /*AS.configuration.screenshotAtIntervals && */
                        ((this.newScene && (this.sceneReady && Time.realtimeSinceStartup - sceneReadyAt > 0.1) && Time.realtimeSinceStartup - lastSceneUpdate > 1) ||
                         ((Time.realtimeSinceStartup - lastUpdate) > configuration.screenshotInterval && !this.newScene)
                        )
                    ))
                {
                    Log.dbg("this.specialScene: {0}", this.specialScene);
                    Log.dbg("this.precrash: {0}", this.precrash);
                    Log.dbg("dualScreenshots: {0}", this.dualScreenshots);
                    Log.dbg("this.newScene: {0}", this.newScene);
                    Log.dbg("this.sceneReady: {0}", this.sceneReady);
                    Log.dbg("Time.realtimeSinceStartup - sceneReadyAt: {0}", (Time.realtimeSinceStartup - sceneReadyAt));
                    Log.dbg("Time.realtimeSinceStartup - lastSceneUpdate: {0}", (Time.realtimeSinceStartup - lastSceneUpdate));
                    Log.dbg("Time.realtimeSinceStartup - lastUpdate: {0}", (Time.realtimeSinceStartup - lastUpdate));

                    Log.dbg("Taking screenshot");
                    Log.dbg("FileOperations.ScreenshotFolder: {0}", Configuration.Instance.screenshotPath);
                    newScene          = false;
                    this.specialScene = false;

                    do
                    {
                        string s = AddInfo(configuration.filename, cnt++, sceneReady, specialScene, precrash);

                        pngName = IO.Path.GetFullPath(Configuration.Instance.screenshotPath) + s + ".png";
                        jpgName = IO.Path.GetFullPath(Configuration.Instance.screenshotPath) + s + ".jpg";
                    } while (IO.File.Exists(pngName) || IO.File.Exists(jpgName));

                    this.precrash = false;

                    if (configuration.noGUIOnScreenshot)
                    {
                        GameEvents.onHideUI.Fire();
                    }
                    if (configuration.noGUIOnScreenshot && configuration.guiOnScreenshot)
                    {
                        if (!dualScreenshots)
                        {
                            dualScreenshots = true;
                        }
                        else if (dualScreenshots)
                        {
                            dualScreenshots = false;
                            GameEvents.onShowUI.Fire();
                        }
                    }

                    if (!dualScreenshots)
                    {
                        lastUpdate      = Time.realtimeSinceStartup;
                        screenshotTaken = true;
                    }

                    // If Historian is available, then tell it to activate
                    HistorianSupport.Instance.set_m_Active();

                    // Change second number for supersize.  If non-zero,
                    // then multiplies the resolution by that number
                    // Must be an integer
                    KSPe.Util.Image.Screenshot.Capture(pngName, configuration.supersize);
                    this.lastScreenshot = pngName;

                    if (configuration.convertToJPG)
                    {
                        this.imageConverter.AddJob(pngName, configuration.keepOrginalPNG, jpgName, configuration.JPGQuality);
                    }
                }
            }
        }
        //        public void LateUpdate ()
        public void FixedUpdate()
        {
            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 || snapshotInProgress) {
                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 = "";
                        snapshotInProgress = false;
                    }
                } else {
                    snapshotInProgress = false;
                    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.newScene) || this.precrash || dualScreenshots == 1 ||
                        ( /*AS.configuration.screenshotAtIntervals && */
                            ((this.newScene && (this.sceneReady && Time.realtimeSinceStartup - sceneReadyAt > 0.1)  && Time.realtimeSinceStartup - lastSceneUpdate > 1) ||
                                ((Time.realtimeSinceStartup - lastUpdate) > configuration.screenshotInterval && !this.newScene)
                            )
                        )) {

                        Log.Info ("this.specialScene: " + this.specialScene.ToString ());
                        Log.Info ("this.precrash: " + this.precrash.ToString ());
                        Log.Info ("dualScreenshots: " + dualScreenshots.ToString ());
                        Log.Info ("this.newScene: " + this.newScene.ToString ());
                        Log.Info ("this.sceneReady: " + this.sceneReady.ToString ());
                        Log.Info ("Time.realtimeSinceStartup - sceneReadyAt: " + (Time.realtimeSinceStartup - sceneReadyAt).ToString ());
                        Log.Info ("Time.realtimeSinceStartup - lastSceneUpdate: " + (Time.realtimeSinceStartup - lastSceneUpdate).ToString ());
                        Log.Info ("Time.realtimeSinceStartup - lastUpdate: " + (Time.realtimeSinceStartup - lastUpdate).ToString ());

                        Log.Info ("Taking screenshot");
                        Log.Info ("CurrentDirectory: " + System.IO.Directory.GetCurrentDirectory ());
                        Log.Info ("FileOperations.ScreenshotFolder: " + FileOperations.ScreenshotFolder ());
                        snapshotInProgress = true;
                        newScene = false;
                        this.specialScene = false;

                        lastUpdate = Time.realtimeSinceStartup;
                        //check if directory doesn't exist
                        if (!System.IO.Directory.Exists (FileOperations.ScreenshotFolder ())) {
                            Log.Info ("Directory does not exist");
                            //if it doesn't, try to create it
                            try {
                                Log.Info ("Trying to create directory");
                                System.IO.Directory.CreateDirectory (FileOperations.ScreenshotFolder ());
                            } catch (Exception e) {
                                Log.Error ("Exception trying to create directory: " + e);
                                return;
                            }
                            Log.Info ("Directory created");
                        }
                        do {
                            cnt++;
                            string s = AddInfo (configuration.filename, cnt, sceneReady, specialScene, precrash);

                            pngName = System.IO.Path.GetFullPath (FileOperations.ScreenshotFolder ()) + s + ".png";
                            jpgName = System.IO.Path.GetFullPath (FileOperations.ScreenshotFolder ()) + 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 ();
                        // Change second number for supersize.  If non-zero,
                        // then multiplies the resolution by that number
                        // Must be an integer
                        Application.CaptureScreenshot (pngName, configuration.supersize);

                        if (configuration.convertToJPG) {
                            pngToConvert = pngName;
                        }

                    }
                }
            }
        }