예제 #1
0
        private async Task LoadSavePointsAsync()
        {
            lock (savePoints)
            {
                if (ctsLoader != null && !ctsLoader.IsCancellationRequested)
                {
                    ctsLoader.Cancel();
                    ctsLoader.Dispose();
                }
                ctsLoader = new System.Threading.CancellationTokenSource();
            }

            string warnings = string.Empty;

            string build  = VersionInfo.Build.Contains(" ") ? VersionInfo.Build.Substring(VersionInfo.Build.IndexOf(" ") + 1) : null;
            var    prefix = string.Empty;

            if (SelectedAction == MainForm.UserAction.SinglePlayerTimetableGame)
            {
                prefix = Path.GetFileName(route.Path) + " " + Path.GetFileNameWithoutExtension(timeTable.FileName);
            }
            else if (activity.FilePath != null)
            {
                prefix = Path.GetFileNameWithoutExtension(activity.FilePath);
            }
            else if (activity.Name == "- " + catalog.GetString("Explore Route") + " -")
            {
                prefix = Path.GetFileName(route.Path);
            }
            // Explore in activity mode
            else
            {
                prefix = "ea$" + Path.GetFileName(route.Path) + "$";
            }

            savePoints = (await Task.Run(() => SavePoint.GetSavePoints(UserSettings.UserDataFolder,
                                                                       prefix, build, route.Name, settings.YoungestFailedToRestore, warnings, ctsLoader.Token))).OrderBy(s => s.RealTime).Reverse().ToList();

            saveBindingSource.DataSource = savePoints;
            labelInvalidSaves.Text       = catalog.GetString(
                "To prevent crashes and unexpected behaviour, Open Rails invalidates games saved from older versions if they fail to restore.\n") +
                                           catalog.GetStringFmt("{0} of {1} saves for this route are no longer valid.", savePoints.Count(s => (s.Valid == false)), savePoints.Count);
            GridSaves_SelectionChanged(null, null);
            // Show warning after the list has been updated as this is more useful.
            if (!string.IsNullOrEmpty(warnings))
            {
                MessageBox.Show(warnings, Application.ProductName + " " + VersionInfo.VersionOrBuild);
            }
        }
예제 #2
0
        private async Task LoadSavePointsAsync()
        {
            lock (savePoints)
            {
                if (ctsLoader != null && !ctsLoader.IsCancellationRequested)
                {
                    ctsLoader.Cancel();
                    ctsLoader.Dispose();
                }
                ctsLoader = new CancellationTokenSource();
            }

            StringBuilder warnings = new StringBuilder();
            string        prefix   = string.Empty;

            if (SelectedAction == MainForm.UserAction.SinglePlayerTimetableGame)
            {
                prefix = $"{Path.GetFileName(route.Path)} {Path.GetFileNameWithoutExtension(timeTable.FileName)}";
            }
            else if (activity.FilePath != null)
            {
                prefix = Path.GetFileNameWithoutExtension(activity.FilePath);
            }
            else if (activity.Name == $"- {catalog.GetString("Explore Route")} -")
            {
                prefix = Path.GetFileName(route.Path);
            }
            // Explore in activity mode
            else
            {
                prefix = $"ea${Path.GetFileName(route.Path)}$";
            }

            savePoints = (await SavePoint.GetSavePoints(UserSettings.UserDataFolder,
                                                        prefix, route.Name, warnings, multiplayer, globalRoutes, ctsLoader.Token).ConfigureAwait(true)).
                         OrderByDescending(s => s.Valid).ThenByDescending(s => s.RealTime).ToList();

            saveBindingSource.DataSource = savePoints;
            labelInvalidSaves.Text       = catalog.GetString(
                "To prevent crashes and unexpected behaviour, Open Rails invalidates games saved from older versions if they fail to restore.\n") +
                                           catalog.GetString("{0} of {1} saves for this route are no longer valid.", savePoints.Count(s => (s.Valid == false)), savePoints.Count);
            GridSaves_SelectionChanged(null, null);
            // Show warning after the list has been updated as this is more useful.
            if (warnings.Length > 0)
            {
                MessageBox.Show(warnings.ToString(), $"{RuntimeInfo.ProductName} {VersionInfo.Version}");
            }
        }