Exemplo n.º 1
0
        /// <summary>
        /// Tries to load the Steam version of Factorio specified in the settings.
        /// </summary>
        /// <param name="steamVersion">Out. The Steam version.</param>
        /// <returns>Returns true if the Steam version has been loaded sucessfully, otherwise false.</returns>
        public static bool TryLoad(out FactorioVersion steamVersion)
        {
            if (string.IsNullOrEmpty(App.Instance.Settings.SteamVersionPath))
            {
                steamVersion = null;
                return(false);
            }

            var     steamVersionDirectory = new DirectoryInfo(App.Instance.Settings.SteamVersionPath);
            Version version;
            bool    is64Bit;

            if (steamVersionDirectory.Exists && FactorioVersion.LocalInstallationValid(steamVersionDirectory, out version, out is64Bit))
            {
                if (is64Bit != Environment.Is64BitOperatingSystem)
                {
                    // This should be impossible.
                    steamVersion = null;
                    return(false);
                }

                steamVersion = new FactorioSteamVersion(steamVersionDirectory, version);
                return(true);
            }
            else
            {
                App.Instance.Settings.SteamVersionPath = string.Empty;
                App.Instance.Settings.Save();

                steamVersion = null;
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tries to load the Steam version of Factorio.
        /// </summary>
        /// <param name="steamVersion">Out. The Steam version.</param>
        /// <returns>Returns true if the Steam version has been loaded sucessfully, otherwise false.</returns>
        public static bool TryLoad(out FactorioVersion steamVersion)
        {
            steamVersion = null;

            var steamLibraries = SteamHelper.ListSteamLibraries(true);

            if ((steamLibraries == null) || (steamLibraries.Count == 0))
            {
                return(false);
            }

            foreach (var library in steamLibraries)
            {
                var factorioDir = library.EnumerateDirectories("Factorio").FirstOrDefault();
                if (factorioDir != null)
                {
                    if (FactorioFolder.TryLoad(factorioDir, out var folder))
                    {
                        if (folder.Is64Bit == Environment.Is64BitOperatingSystem)
                        {
                            steamVersion = new FactorioSteamVersion(folder);
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }