Пример #1
0
        public ModHandler(Form1 baseForm)
        {
            BaseForm      = baseForm;
            OurIntegrator = new ModIntegrator();
            OurIntegrator.RefuseMismatchedConnections = true;

            string automaticSteamPath = null;
            string automaticWin10Path = null;

            if (!Program.CommandLineOptions.ServerMode)
            {
                try
                {
                    automaticSteamPath = AMLUtils.FixGamePath(CheckRegistryForSteamPath(361420)); // Astroneer: 361420
                }
                catch { }

                try
                {
                    automaticWin10Path = AMLUtils.FixGamePath(CheckRegistryForMicrosoftStorePath());
                }
                catch { }
            }

            //automaticSteamPath = null;
            //automaticWin10Path = null;

            ValidPlatformTypesToPaths = new Dictionary <PlatformType, string>();
            if (automaticSteamPath != null)
            {
                ValidPlatformTypesToPaths[PlatformType.Steam] = automaticSteamPath;
            }
            if (automaticWin10Path != null)
            {
                ValidPlatformTypesToPaths[PlatformType.Win10] = automaticWin10Path;
            }

            SyncIndependentConfigFromDisk();
            if (!string.IsNullOrEmpty(CustomBasePath))
            {
                string customGamePath = GetGamePathFromBasePath(CustomBasePath);
                if (!string.IsNullOrEmpty(customGamePath))
                {
                    ValidPlatformTypesToPaths[PlatformType.Custom] = customGamePath;
                }
            }

            RefreshAllPlatformsList();
            if (!ValidPlatformTypesToPaths.ContainsKey(Platform) && AllPlatforms.Count > 0)
            {
                Platform = AllPlatforms[0];
            }
            if (Program.CommandLineOptions.ServerMode)
            {
                Platform = PlatformType.Server;
            }

            DeterminePaths();
            SyncModsFromDisk();
            SyncDependentConfigFromDisk();
            VerifyGamePath();

            if (Program.CommandLineOptions.ServerMode && Directory.Exists(Path.Combine(BasePath, "Saved")))
            {
                GamePath = Path.GetFullPath(Path.Combine(BasePath, ".."));
            }

            if (GamePath == null || !Directory.Exists(GamePath))
            {
                GamePath = null;
                if (ValidPlatformTypesToPaths.ContainsKey(Platform))
                {
                    GamePath = ValidPlatformTypesToPaths[Platform];
                }
                else
                {
                    TextPrompt initialPathPrompt = new TextPrompt
                    {
                        StartPosition = FormStartPosition.CenterScreen,
                        DisplayText   = "Select your game installation directory",
                        VerifyMode    = VerifyPathMode.Game
                    };

                    if (initialPathPrompt.ShowDialog(BaseForm) == DialogResult.OK)
                    {
                        GamePath = initialPathPrompt.OutputText;
                        Platform = PlatformType.Custom;
                        ValidPlatformTypesToPaths[PlatformType.Custom] = GamePath;
                        RefreshAllPlatformsList();
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }
            }

            ApplyGamePathDerivatives();
            VerifyIntegrity();

            foreach (Mod mod in Mods)
            {
                mod.Dirty = true;
            }
            FullUpdateSynchronous();
            SortMods();
            RefreshAllPriorites();
            SyncConfigToDisk();
        }
Пример #2
0
        public void DeterminePaths()
        {
            string normalSteamBasePath          = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Astro");
            string normalMicrosoftStoreBasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Packages", "SystemEraSoftworks.29415440E1269_ftk5pbg2rayv2", "LocalState", "Astro");

            BasePath = null;
            if (!string.IsNullOrEmpty(Program.CommandLineOptions.LocalDataPath))
            {
                BasePath = AMLUtils.FixBasePath(Path.GetFullPath(Path.Combine(Program.CommandLineOptions.LocalDataPath, "Astro")));
            }
            else
            {
                if (Program.CommandLineOptions.ServerMode)
                {
                    BasePath = Path.Combine(GamePath != null ? GamePath : Directory.GetCurrentDirectory(), "Astro");
                }
                else if (Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) != null)
                {
                    switch (Platform)
                    {
                    case PlatformType.Steam:
                        BasePath = normalSteamBasePath;
                        break;

                    case PlatformType.Win10:
                        BasePath = normalMicrosoftStoreBasePath;
                        break;
                    }
                }
            }

            if (BasePath == null || !Directory.Exists(BasePath))
            {
                if (Platform == PlatformType.Custom || Platform == PlatformType.Unknown)
                {
                    if (!string.IsNullOrEmpty(CustomBasePath))
                    {
                        BasePath = CustomBasePath;
                    }
                    else
                    {
                        // If the regular Steam or Microsoft Store base paths do exist, they're probably what the user actually wants, but we still want to give them the option to change it here so we just put it in as prefilled text

                        TextPrompt initialPathPrompt = new TextPrompt
                        {
                            StartPosition = FormStartPosition.CenterScreen,
                            DisplayText   = "Select your local application data directory",
                            PrefilledText = Directory.Exists(normalSteamBasePath) ? normalSteamBasePath : (Directory.Exists(normalMicrosoftStoreBasePath) ? normalMicrosoftStoreBasePath : null),
                            VerifyMode    = VerifyPathMode.Base
                        };

                        if (initialPathPrompt.ShowDialog(BaseForm) == DialogResult.OK)
                        {
                            CustomBasePath = initialPathPrompt.OutputText;
                            BasePath       = CustomBasePath;
                        }
                        else
                        {
                            Environment.Exit(0);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Unable to find the local application data directory. If you have never created an Astroneer save file within the game on this computer before, please do so and then re-open AstroModLoader. Otherwise, please specify a local application data directory with the --data parameter.", "Uh oh!");
                    Environment.Exit(0);
                }
            }

            DetermineBasePathDerivatives();
        }
Пример #3
0
        private async void playButton_Click(object sender, EventArgs e)
        {
            ModManager.IsUpdatingAvailableVersionsFromIndexFilesWaitHandler.WaitOne(3000);

            await ModManager.FullUpdate();

            if (!Program.CommandLineOptions.ServerMode)
            {
                if (ModManager.Platform == PlatformType.Steam)
                {
                    Process.Start(@"steam://run/361420");
                    return;
                }
                else if (ModManager.Platform == PlatformType.Win10)
                {
                    if (!string.IsNullOrEmpty(ModManager.MicrosoftRuntimeID))
                    {
                        Process.Start(@"shell:appsFolder\" + ModManager.MicrosoftRuntimeID + "!ASTRONEER");
                    }
                    return;
                }
            }

            if ((Program.CommandLineOptions.ServerMode || AMLUtils.IsLinux || string.IsNullOrEmpty(ModManager.BinaryFilePath)) && string.IsNullOrEmpty(ModManager.LaunchCommand))
            {
                TextPrompt initialPathPrompt = new TextPrompt
                {
                    StartPosition = FormStartPosition.CenterScreen,
                    DisplayText   = "Select a file to run:",
                    AllowBrowse   = true,
                    BrowseMode    = BrowseMode.File
                };

                if (initialPathPrompt.ShowDialog(this) == DialogResult.OK)
                {
                    ModManager.LaunchCommand = initialPathPrompt.OutputText;
                    ModManager.SyncConfigToDisk();
                }
            }

            if (string.IsNullOrEmpty(ModManager.LaunchCommand) && !string.IsNullOrEmpty(ModManager.BinaryFilePath))
            {
                Process.Start(ModManager.BinaryFilePath, Program.CommandLineOptions.ServerMode ? "-log" : "");
            }
            else
            {
                if (string.IsNullOrEmpty(ModManager.LaunchCommand))
                {
                    return;
                }
                try
                {
                    Process.Start(new ProcessStartInfo()
                    {
                        WorkingDirectory = Path.GetDirectoryName(ModManager.LaunchCommand),
                        FileName         = ModManager.LaunchCommand
                    });
                }
                catch
                {
                    this.ShowBasicButton("Invalid path to file: \"" + ModManager.LaunchCommand + "\"", "OK", null, null);
                    ModManager.LaunchCommand = null;
                    ModManager.SyncConfigToDisk();
                }
            }
        }