private async Task SelectSteamVersion() { if (!FactorioSteamVersion.IsPresent()) { MessageBox.Show(Window, App.Instance.GetLocalizedMessage("NoSteam", MessageType.Information), App.Instance.GetLocalizedMessageTitle("NoSteam", MessageType.Information), MessageBoxButton.OK, MessageBoxImage.Information); return; } var progressWindow = new ProgressWindow() { Owner = Window }; var progressViewModel = (ProgressViewModel)progressWindow.ViewModel; progressViewModel.ActionName = App.Instance.GetLocalizedResourceString("AddingSteamVersionAction"); progressViewModel.ProgressDescription = App.Instance.GetLocalizedResourceString("CopyingFilesDescription"); progressViewModel.IsIndeterminate = true; Task closeWindowTask = null; try { Task moveTask = MoveSteamVersionContents(); closeWindowTask = moveTask.ContinueWith(t => progressWindow.Dispatcher.Invoke(progressWindow.Close)); progressWindow.ShowDialog(); await moveTask; } finally { if (closeWindowTask != null) { await closeWindowTask; } } App.Instance.Settings.LoadSteamVersion = true; App.Instance.Settings.Save(); FactorioSteamVersion.TryLoad(out var steamVersion); FactorioVersions.Add(steamVersion); }
/// <summary> /// Starts Factorio if the command line specifies to do so. /// </summary> /// <param name="commandLine">The programs command line.</param> /// <param name="createApp">Specifies whether an app should be created.</param> /// <returns>Returns true if the game was started, otherwise false.</returns> private static bool StartGameIfSpecified(CommandLine commandLine, bool createApp) { string versionString; if (commandLine.TryGetArgument('f', "factorio-version", out versionString)) { // Variable not used but sets 'Application.Current'. App app = null; if (createApp) { app = CreateApp(commandLine); } var versions = FactorioVersion.GetInstalledVersions(); FactorioVersion steamVersion; if (FactorioSteamVersion.TryLoad(out steamVersion)) { versions.Add(steamVersion); } FactorioVersion factorioVersion = null; if (string.Equals(versionString, FactorioVersion.LatestKey, StringComparison.InvariantCultureIgnoreCase)) { factorioVersion = versions.MaxBy(item => item.Version, new VersionComparer()); } else { factorioVersion = versions.Find(item => string.Equals(item.VersionString, versionString, StringComparison.InvariantCultureIgnoreCase)); } if (factorioVersion != null) { var mods = new List <Mod>(); var modpacks = new List <Modpack>(); ModManager.BeginUpdateTemplates(); Mod.LoadMods(mods, modpacks); ModpackTemplateList.Instance.PopulateModpackList(mods, modpacks, null); mods.ForEach(mod => mod.Active = false); string modpackName; if (commandLine.TryGetArgument('p', "modpack", out modpackName)) { Modpack modpack = modpacks.FirstOrDefault(item => item.Name == modpackName); if (modpack != null) { modpack.Active = true; } else { MessageBox.Show( $"No modpack named '{modpackName}' found.\nThe game will be launched without any mods enabled.", "Error loading modpack!", MessageBoxButton.OK, MessageBoxImage.Warning); } } ModManager.EndUpdateTemplates(true); ModManager.SaveTemplates(); Process.Start(factorioVersion.ExecutablePath); } else { MessageBox.Show( $"Factorio version {versionString} is not available.\nCheck your installed Factorio versions.", "Error starting game!", MessageBoxButton.OK, MessageBoxImage.Error); } return(true); } return(false); }