private static void ActivateMods(CommandLine commandLine) { var mods = new ModCollection(); var modpacks = new ModpackCollection(); 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.Find(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(); }
/// <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); }