Example #1
0
        private void buttonChangeBeatSaberLocation_Click(object sender, EventArgs e)
        {
            string[]      searchLocationPaths = Properties.Resources.locations.Split('\n');
            List <string> searchLocations     = new List <string>();

            foreach (DriveInfo d in DriveInfo.GetDrives())
            {
                foreach (string s in searchLocationPaths)
                {
                    searchLocations.Add(d.Name + s.Trim());
                }
            }

            FormFindFile fff = new FormFindFile(@"Beat Saber.exe", searchLocations, "Please select the location of " +
                                                "Beat Saber you would like to mod. If the right Beat Saber installation is not listed, please use " +
                                                "the 'Browse' button to locate it yourself.");

            if (fff.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            config.beatSaberLocation = fff.SelectedDirectory;
            SaveConfig();

            RestartAndSelfDestruct();
        }
Example #2
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            linkLabelAbout.LinkArea = new LinkArea(0, 0);
            linkLabelAbout.Links.Add(16, 8, @"https://github.com/CodeStix");
            linkLabelAbout.Links.Add(39, 13, @"https://beatmods.com");

            labelVersion.Text = $"Version: { StringUtil.GetCurrentVersion(3) }";

            checkBoxAllowNonApproved.Enabled = Properties.Settings.Default.AllowUnApproved;

            ProgressChange("Loading files...", 0.1f);

            LoadConfig();
            config.allowNonApproved &= Properties.Settings.Default.AllowUnApproved;

            checkBoxConsole.Checked          = config.showConsole;
            checkBoxAllowNonApproved.Checked = config.allowNonApproved;
            checkBoxAutoUpdate.Checked       = config.autoUpdate;
            checkBoxKeepModDownloads.Checked = config.keepModArchives;

            if (!config.firstTime)
            {
                Size = config.windowSize;
            }

            if (string.IsNullOrEmpty(config.beatSaberLocation) ||
                !File.Exists(Path.Combine(config.beatSaberLocation, "Beat Saber.exe")))
            {
                string[]      searchLocationPaths = Properties.Resources.locations.Split('\n');
                List <string> searchLocations     = new List <string>();

                foreach (DriveInfo d in DriveInfo.GetDrives())
                {
                    foreach (string s in searchLocationPaths)
                    {
                        searchLocations.Add(d.Name + s.Trim());
                    }
                }

                FormFindFile fff = new FormFindFile(@"Beat Saber.exe", searchLocations, "Please select the location of " +
                                                    "Beat Saber you would like to mod. If the right Beat Saber installation is not listed, please use " +
                                                    "the 'Browse' button to locate it yourself.");

                if (fff.ShowDialog() != DialogResult.OK)
                {
                    SelfDestruct();
                }

                config.beatSaberLocation = fff.SelectedDirectory;
                SaveConfig();
            }

            Task.Run(async() =>
            {
                bool updateAvailable = await updateCheck.CheckForUpdate(StringUtil.GetCurrentVersion(3));
                if (updateAvailable)
                {
                    if (MessageBox.Show("There is an update available for Beat Modder, please download the newest version " +
                                        "to ensure that everything can work correctly. Go to the download page right now?", "An update!", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                    {
                        Process.Start(@"https://github.com/CodeStix/Beat-Modder/releases");

                        SelfDestruct();
                    }
                }
            });

            Task.Run(new Action(async() =>
            {
                ProgressChange("Checking for Beat Saber process...", 0.15f);

                if (BeatSaberInstallation.IsBeatSaberRunning)
                {
                    if (MessageBox.Show("It looks like Beat Saber is still running, to install or uninstall " +
                                        "mods, Beat Saber must be closed.\nDo you want to close Beat Saber right now?\n" +
                                        "You can press the play button in the bottom right corner to restart Beat Saber.",
                                        "Beat Saber is running", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
                    {
                        SelfDestruct();
                    }

                    BeatSaberInstallation.KillBeatSaberProcess();
                }

                ProgressChange("Communicating with beatmods...", 0.2f);
                beatMods = await BeatMods.CreateSession(true);

                ProgressChange("Gathering game information...", 0.3f);
                beatSaber = new BeatSaberInstallation(config.beatSaberLocation, beatMods)
                {
                    RemoveModArchivesAfterInstall = !config.keepModArchives
                };

                ProgressChange("Checking for manual installs/uninstalls...", 0.35f);

                beatSaber.DetectManualModInstallOrUninstall(out List <Mod> wasManuallyInstalled, out List <InstalledMod> wasManuallyUninstalled);
                await beatSaber.InstallMultipleMods(wasManuallyInstalled, ProgressReport.Partial(progress, 0.35f, 0.1f));
                await beatSaber.UninstallMultipleMods(wasManuallyUninstalled, true, ProgressReport.Partial(progress, 0.45f, 0.1f));

                currentListVersion = beatSaber.BeatSaberVersion;
                UpdateModList();

                ProgressChange("List of mods has been refreshed.", 0.55f);

                if (beatSaber.DidBeatSaberUpdate)
                {
                    MessageBox.Show($"Good news!" +
                                    $"\nThere was a Beat Saber update: { beatSaber.BeatSaberVersionString }\n" +
                                    $"This means that some of the mods have to get updated too.\n" +
                                    $"If the update was released recently, be aware that some mods could be broken.\n\n" +
                                    $"At any moment you can open this program to automatically repatch, check for and install mod updates!", "Oh snap!", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    ProgressChange("Patching Beat Saber...", 0.55f);

                    await beatSaber.RunIPA(revert: false, wait: config.showConsole, shown: config.showConsole);

                    // API moves old plugins to a folder, we don't do that here.
                    string movedDirectory = Path.Combine(beatSaber.BeatSaberDirectory, $"Old { beatSaber.PreviousBeatSaberVersionString } Plugins");
                    if (Directory.Exists(movedDirectory))
                    {
                        MessageBox.Show("Files where moved by API");
                    }

                    ProgressChange("Patched Beat Saber!", 0.6f);
                }

                if (config.autoUpdate)
                {
                    await CheckForAndInstallModUpdates(ProgressReport.Partial(progress, 0.6f, 0.4f));
                }
                else
                {
                    ProgressChange($"Mod updates on startup are disabled in settings.", 1f);
                }

                UpdateModList();

                BeginInvoke(new Action(() =>
                {
                    labelBeatSaberType.Text         = "Beat Saber type: " + beatSaber.BeatSaberType;
                    textBoxBeatSaberLocation.Text   = config.beatSaberLocation;
                    labelBeatSaberVersion.ForeColor = Color.Green;
                    labelBeatSaberVersion.Text      = $"Beat Saber version: { beatSaber.BeatSaberVersionString }";
                    foreach (string version in beatMods.AllGameVersions)
                    {
                        var tti    = buttonSwitchListVersion.DropDownItems.Add(version);
                        tti.Click += (sender2, e2) =>
                        {
                            currentListVersion = SemVersion.Parse(tti.Text.FixOddVersion());
                            UpdateModList();
                        };
                    }
                }));

                config.firstTime = false;
                SaveConfig();

                /*while (beatMods.IsOffline)
                 * {
                 *  await Task.Delay(3000);
                 *
                 *  Console.WriteLine("Checking if BeatMods is reachable...");
                 *  if (BeatModsUrlBuilder.IsReachable)
                 *  {
                 *      Console.WriteLine("BeatMods is available, creating new session...");
                 *
                 *      await Task.Delay(1000);
                 *
                 *      beatMods.Dispose();
                 *      beatMods = await BeatMods.CreateSession(true);
                 *
                 *      UpdateModList();
                 *      ProgressChange("BeatMods went available, list was refreshed.", 1f);
                 *  }
                 * }*/
            }
                                ));
        }