private void LoadSaveGame(SaveGameInfo save)
        {
            Log.Info("Loading save: {0}", save.SaveFile.Name);
            var name = Path.GetFileNameWithoutExtension(save.SaveFile.Name);
            var game = GamePersistence.LoadGame(name, HighLogic.SaveFolder, true, false);

            // For some reason, loading games that start at the space center
            // just loads the latest persistent save instead. Copying the save
            // files over the persistent save seems to fix the problem.
            // Interestingly from my testing, this is similar to what the stock
            // load game dialog does as well, which updates the persistent save
            // when loading a game that starts in the space center, but not one
            // that starts in flight. I'm sure there's a better way to solve this
            // but this will do until I find it.
            if (name != "persistent" && game != null && game.startScene == GameScenes.SPACECENTER)
            {
                _saveWatcher.Enable(false);

                CopySaveFile(name + ".sfs", "persistent.sfs");
                CopySaveFile(name + ".loadmeta", "persistent.loadmeta");
                CopySaveFile(name + "-thumb.png", "persistent-thumb.png");

                _saveWatcher.Enable(true);
            }

            if (game != null)
            {
                game.Start();
            }
        }
Ejemplo n.º 2
0
        internal static void MoveSaveToArchive(SaveGameInfo sgi)
        {
            var    name   = Path.GetFileNameWithoutExtension(sgi.SaveFile.Name);
            string path   = sgi.SaveFile.DirectoryName + ARCHIVEDIR;
            string suffix = "";

            if (File.Exists(path + "/" + name + suffix + ".sfs"))
            {
                int cnt = 0;
                while (File.Exists(path + "/" + name + suffix + ".sfs"))
                {
                    cnt++;
                    suffix = "-" + cnt;
                }
                Log.Error("Archive path exists as a file, renaming: " + path + "/" + name + suffix + ".sfs");
            }
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            if (!Directory.Exists(path))
            {
                Log.Error("Archive directory doesn't exist, and unable to create it: " + path);
                return;
            }

            MoveFile(sgi.SaveFile.DirectoryName, name, ".sfs", suffix, path);
            MoveFile(sgi.SaveFile.DirectoryName, name, ".loadmeta", suffix, path);
            MoveFile(sgi.SaveFile.DirectoryName, name, "-thumb.png", suffix, path);
        }
Ejemplo n.º 3
0
        private void OnSave(object sender, System.IO.FileSystemEventArgs e)
        {
            if (SystemInfo.operatingSystemFamily != OperatingSystemFamily.Windows)
            {
                //
                // The following is because of behaviour on OSX
                // That sends multiple OnSave messages for a single save
                //

                if (Time.realtimeSinceStartup - lastTimeSaved < 2)
                {
                    return;
                }
                lastTimeSaved = Time.realtimeSinceStartup;
            }
            if (e.FullPath.EndsWith(".sfs"))
            {
                var newSave      = new SaveGameInfo(e.FullPath);
                var existingSave = _saves.Find(r => r.SaveFile.Name == newSave.SaveFile.Name);
                if (existingSave != null)
                {
                    _saves.Remove(existingSave);
                }
                _saves.Add(newSave);
                UpdateSort();
            }
        }
Ejemplo n.º 4
0
        internal static void DeleteSaveGame(string dir, SaveGameInfo sgi)
        {
            var name = Path.GetFileNameWithoutExtension(sgi.SaveFile.Name);
            var game = GamePersistence.LoadGame(name, HighLogic.SaveFolder + dir, true, false);

            DeleteFile(HighLogic.SaveFolder + dir + "/" + name + ".sfs");
            DeleteFile(HighLogic.SaveFolder + dir + "/" + name + ".loadmeta");
            DeleteFile(HighLogic.SaveFolder + dir + "/" + name + "-thumb.png");
            Main.fetch.RefreshSaves();
        }
Ejemplo n.º 5
0
 private void OnSave(object sender, System.IO.FileSystemEventArgs e)
 {
     if (e.FullPath.EndsWith(".sfs"))
     {
         var newSave      = new SaveGameInfo(e.FullPath);
         var existingSave = _saves.Find(r => r.SaveFile.Name == newSave.SaveFile.Name);
         if (existingSave != null)
         {
             _saves.Remove(existingSave);
         }
         _saves.Add(newSave);
         UpdateSort();
     }
 }
Ejemplo n.º 6
0
        public Texture2D GetScreenshot(SaveGameInfo save)
        {
            Texture2D screenshot = null;

            var imageFile = save.SaveFile.FullName.Replace(".sfs", "-thumb.png");

            if (!_loadedScreenshots.TryGetValue(imageFile, out screenshot) && File.Exists(imageFile))
            {
                var data = File.ReadAllBytes(imageFile);
                screenshot = new Texture2D(2, 2);
                screenshot.LoadImage(data);
                _loadedScreenshots.Add(imageFile, screenshot);
            }

            if (screenshot != null)
            {
                return(screenshot);
            }
            else
            {
                return(_placeholder);
            }
        }
        private void RenderGameList()
        {
            GUILayout.BeginHorizontal();
            _scrollPos = GUILayout.BeginScrollView(_scrollPos, GUI.skin.scrollView);
            for (int saveIndex = 0; saveIndex < _saveGameCollection._saves.Count; saveIndex++)
            {
                SaveGameInfo save = _saveGameCollection._saves[saveIndex];
                // Determine if the button is visible.
                // This is not very accurate...
                bool isVisible = (saveIndex * 100 - _scrollPos.y) < HEIGHT;

                var name = Path.GetFileNameWithoutExtension(save.SaveFile.Name);

                if (_filterText == "" || name.Contains(_filterText) || (save.ButtonText != null && save.ButtonText.Contains(_filterText)))
                {
                    if (save.buttonContent == null)
                    {
                        save.buttonContent      = new GUIContent();
                        save.buttonContent.text = save.ButtonText;

                        //if (isVisible)
                        {
                            save.buttonContent.image = _screenshotManager.GetScreenshot(save);
                        }
                    }

                    bool value = false;
                    if (lastButtonclicked == name && clicked)
                    {
                        value = true;
                    }

                    var rc = GUILayout.Toggle(value, save.buttonContent, gameButtonStyle);
                    if (rc != value)
                    {
                        if (Event.current.clickCount >= 2)
                        {
                            Log.Info("Clicked save: {0}", save.SaveFile.Name);
                            EnqueueAction(() =>
                            {
                                Visible = false;
                                LoadSaveGame(save);
                            });
                        }
                        else
                        {
                            if (lastButtonclicked == name)
                            {
                                lastButtonclicked = "";
                            }
                            else
                            {
                                lastButtonclicked = name;
                                clicked           = true;
                                selectedSave      = save;
                            }
                        }
                    }
                }
            }
            GUILayout.EndScrollView();
            GUILayout.EndHorizontal();
        }