Пример #1
0
        private static void ActivateMods(CommandLine commandLine)
        {
            var mods     = new ModCollection();
            var modpacks = new ModpackCollection();

            ModManager.BeginUpdateTemplates();
            ModSettingsManager.LoadSettings();
            ModSettingsManager.BeginUpdate();

            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();
            ModSettingsManager.EndUpdate(true);
            ModSettingsManager.SaveBinarySettings(mods);
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
 private void OnModManagerCreated(ModManager modManager)
 => ModManagerCreated?.Invoke(this, new ModManagerCreatedEventArgs(modManager));
Пример #4
0
 internal ModManagerCreatedEventArgs(ModManager modManager)
 => ModManager = modManager;
Пример #5
0
 /// <summary>
 /// Tries to gets the mod manager associated with a specific version of Factorio<br/>
 /// Fails if no mod manager has been created for the specified version yet
 /// </summary>
 public bool TryGetModManager(AccurateVersion factorioVersion, out ModManager result)
 {
     factorioVersion = factorioVersion.ToFactorioMajor();
     return(_modManagers.TryGetValue(factorioVersion, out result));
 }