Exemplo n.º 1
0
        public void BrowseExecuted()
        {
            var openFileDialog = _openFileDialogFactory();

            openFileDialog.CheckFileExists = true;
            openFileDialog.CheckPathExists = true;
            openFileDialog.DefaultExt      = "sbc";
            openFileDialog.FileName        = "Sandbox.sbc";
            openFileDialog.Filter          = AppConstants.SandboxFilter;
            openFileDialog.Multiselect     = false;
            openFileDialog.Title           = Res.DialogLocateSandboxTitle;

            if (_dialogService.ShowOpenFileDialog(this, openFileDialog) == DialogResult.OK)
            {
                IsBusy = true;
                var savePath = Path.GetDirectoryName(openFileDialog.FileName);
                var userName = Environment.UserName;
                var saveType = SaveWorldType.Custom;

                try
                {
                    using (var fs = File.OpenWrite(openFileDialog.FileName))
                    {
                        // test opening the file to verify that we have Write Access.
                    }
                }
                catch
                {
                    saveType = SaveWorldType.CustomAdminRequired;
                }

                // Determine the correct UserDataPath for this custom save game if at all possible for the mods.
                var dp = UserDataPath.FindFromSavePath(savePath);

                var    saveResource = _dataModel.LoadSaveFromPath(savePath, userName, saveType, dp);
                string errorInformation;
                if (saveResource.LoadCheckpoint(out errorInformation))
                {
                    if (saveResource.LoadSector(out errorInformation))
                    {
                        SelectedWorld = saveResource;
                        IsBusy        = false;
                        CloseResult   = true;
                        return;
                    }
                }

                IsBusy = false;
                SystemSounds.Beep.Play();
                _dialogService.ShowErrorDialog(this, Res.ErrorLoadSaveGameFileError, errorInformation, true);
            }
        }
Exemplo n.º 2
0
        internal static WorldResource LoadSession(string savePath)
        {
            if (Directory.Exists(savePath))
            {
                var userPath = Path.GetDirectoryName(savePath);

                var saveResource = new WorldResource
                {
                    Savename = Path.GetFileName(savePath),
                    UserName = Path.GetFileName(userPath),
                    Savepath = savePath,
                    DataPath = UserDataPath.FindFromSavePath(savePath)
                };

                saveResource.LoadCheckpoint();

                return(saveResource);
            }

            return(null);
        }
Exemplo n.º 3
0
        internal static bool LoadSession(string savePath, out WorldResource saveResource, out string errorInformation)
        {
            if (Directory.Exists(savePath))
            {
                var userPath = Path.GetDirectoryName(savePath);

                saveResource = new WorldResource
                {
                    Savename = Path.GetFileName(savePath),
                    UserName = Path.GetFileName(userPath),
                    Savepath = savePath,
                    DataPath = UserDataPath.FindFromSavePath(savePath)
                };

                return(saveResource.LoadCheckpoint(out errorInformation));
            }

            saveResource     = null;
            errorInformation = Res.ErrorDirectoryNotFound;
            return(false);
        }
Exemplo n.º 4
0
        internal static WorldResource FindSaveSession(string baseSavePath, string findSession)
        {
            if (Directory.Exists(baseSavePath))
            {
                var userPaths = Directory.GetDirectories(baseSavePath);

                foreach (var userPath in userPaths)
                {
                    var lastLoadedFile = Path.Combine(userPath, SpaceEngineersConsts.LoadLoadedFilename);

                    // Ignore any other base Save paths without the LastLoaded file.
                    if (File.Exists(lastLoadedFile))
                    {
                        var savePaths = Directory.GetDirectories(userPath);

                        // Still check every potential game world path.
                        foreach (var savePath in savePaths)
                        {
                            var saveResource = new WorldResource
                            {
                                Savename = Path.GetFileName(savePath),
                                UserName = Path.GetFileName(userPath),
                                Savepath = savePath,
                                DataPath = UserDataPath.FindFromSavePath(savePath)
                            };

                            saveResource.LoadCheckpoint();

                            if (saveResource.Savename.ToUpper() == findSession || saveResource.SessionName.ToUpper() == findSession)
                            {
                                return(saveResource);
                            }
                        }
                    }
                }
            }

            return(null);
        }
Exemplo n.º 5
0
        internal static bool FindSaveSession(string baseSavePath, string findSession, out WorldResource saveResource, out string errorInformation)
        {
            if (Directory.Exists(baseSavePath))
            {
                var userPaths = Directory.GetDirectories(baseSavePath);

                foreach (var userPath in userPaths)
                {
                    // Ignore any other base Save paths without the LastLoaded file.
                    if (Directory.Exists(userPath))
                    {
                        var savePaths = Directory.GetDirectories(userPath);

                        // Still check every potential game world path.
                        foreach (var savePath in savePaths)
                        {
                            saveResource = new WorldResource
                            {
                                Savename = Path.GetFileName(savePath),
                                UserName = Path.GetFileName(userPath),
                                Savepath = savePath,
                                DataPath = UserDataPath.FindFromSavePath(savePath)
                            };

                            saveResource.LoadWorldInfo();
                            if (saveResource.IsValid && (saveResource.Savename.ToUpper() == findSession || saveResource.SessionName.ToUpper() == findSession))
                            {
                                return(saveResource.LoadCheckpoint(out errorInformation));
                            }
                        }
                    }
                }
            }

            saveResource     = null;
            errorInformation = Res.ErrorGameNotFound;
            return(false);
        }