Exemplo n.º 1
0
 private void LoadGame(string name)
 {
     if (name.EndsWith(".sfs"))
     {
         name = name.Substring(0, name.Length - 4);
     }
     if (HighLogic.CurrentGame.Parameters.Flight.CanQuickLoad)
     {
         string filename = name + ".sfs";
         string path     = KSPUtil.GetOrCreatePath("saves/" + HighLogic.SaveFolder);
         if (!File.Exists(Path.Combine(path, filename)))
         {
             throw new KOSException("Error loading the quicksave file, the save file does not exist.");
         }
         shared.Cpu.GetCurrentOpcode().AbortProgram = true;
         try
         {
             SaveGame("kos-backup-quicksave");
             var game = GamePersistence.LoadGame(name, HighLogic.SaveFolder, true, false);
             if (game.flightState != null)
             {
                 if (game.compatible)
                 {
                     GamePersistence.UpdateScenarioModules(game);
                     if (game.startScene != GameScenes.FLIGHT)
                     {
                         if (KSPUtil.CheckVersion(game.file_version_major, game.file_version_minor, game.file_version_revision, 0, 24, 0) != VersionCompareResult.INCOMPATIBLE_TOO_EARLY)
                         {
                             GamePersistence.SaveGame(game, name, HighLogic.SaveFolder, SaveMode.OVERWRITE);
                             HighLogic.LoadScene(GameScenes.SPACECENTER);
                             return;
                         }
                     }
                     FlightDriver.StartAndFocusVessel(game, game.flightState.activeVesselIdx);
                 }
             }
         }
         catch (Exception ex)
         {
             SafeHouse.Logger.Log(ex.Message);
             throw new KOSException("Error loading the quicksave file");
         }
     }
     else
     {
         throw new KOSException("KSP prevents using quickload currently.");
     }
 }
Exemplo n.º 2
0
        private ListValue GetQuicksaveList()
        {
            var    ret   = new ListValue();
            string path  = KSPUtil.GetOrCreatePath("saves/" + HighLogic.SaveFolder);
            var    files = Directory.GetFiles(path, "*.sfs");

            foreach (var file in files)
            {
                string name = Path.GetFileNameWithoutExtension(file);
                if (!name.Equals("persistent"))
                {
                    ret.Add(new StringValue(name));
                }
            }
            return(ret);
        }
Exemplo n.º 3
0
        private static List <string> GetAllPathStrings()
        {
            var    ret   = new List <string>();
            string path1 = KSPUtil.GetOrCreatePath("Ships/VAB");
            string path2 = KSPUtil.GetOrCreatePath("Ships/SPH");
            string path3 = KSPUtil.GetOrCreatePath("saves/" + HighLogic.SaveFolder + "/Ships/VAB");
            string path4 = KSPUtil.GetOrCreatePath("saves/" + HighLogic.SaveFolder + "/Ships/SPH");

            if (HighLogic.CurrentGame.Parameters.Difficulty.AllowStockVessels)
            {
                ret.AddRange(Directory.GetFiles(path1));
                ret.AddRange(Directory.GetFiles(path2));
            }
            ret.AddRange(Directory.GetFiles(path3));
            ret.AddRange(Directory.GetFiles(path4));
            return(ret);
        }
Exemplo n.º 4
0
        private bool SaveCopyOfTexture([NotNull] string textureUrl, [NotNull] Texture target)
        {
            if (textureUrl == null)
            {
                throw new ArgumentNullException("textureUrl");
            }
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            bool successful = false;

            try
            {
                KSPUtil.GetOrCreatePath("GameData/" + _skinDirectory.url);

                target
                .With(tar => ((Texture2D)tar).CreateReadable())
                .Do(readable =>
                {
                    successful = readable.SaveToDisk(textureUrl);
                }).Do(Object.Destroy);
            }
            catch (UnauthorizedAccessException e)
            {
                Debug.LogError("[NavBallChanger] - Could not create copy of stock NavBall texture inside directory '" + _skinDirectory.url +
                               "' due to insufficient permissions.");
                Debug.LogException(e);
            }
            catch (Exception e)
            {
                Debug.LogError("[NavBallChanger] - Error while creating copy of stock NavBall texture.");
                Debug.LogException(e);
            }

            return(successful);
        }