VRCMelonAssistant/ModAssistant/Pages/Options.xaml.cs

322 lines
12 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
2020-02-05 17:58:35 +13:00
using System.IO;
using System.Net.Http;
2019-04-22 18:41:43 +12:00
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Path = System.IO.Path;
2019-04-22 18:41:43 +12:00
namespace ModAssistant.Pages
{
/// <summary>
/// Interaction logic for Options.xaml
/// </summary>
public partial class Options : Page
{
public static Options Instance = new Options();
public string InstallDirectory { get; set; }
public string InstallType { get; set; }
public bool SaveSelection { get; set; }
public bool CheckInstalledMods { get; set; }
public bool SelectInstalledMods { get; set; }
2020-05-10 09:40:45 +12:00
public bool ReinstallInstalledMods { get; set; }
public bool ModelSaberProtocolHandlerEnabled { get; set; }
public bool BeatSaverProtocolHandlerEnabled { get; set; }
2019-12-20 18:25:34 +13:00
public string LogURL { get; private set; }
2019-04-22 18:41:43 +12:00
public Options()
{
InitializeComponent();
InstallDirectory = App.BeatSaberInstallDirectory;
InstallType = App.BeatSaberInstallType;
SaveSelection = App.SaveModSelection;
CheckInstalledMods = App.CheckInstalledMods;
SelectInstalledMods = App.SelectInstalledMods;
2020-05-10 09:40:45 +12:00
ReinstallInstalledMods = App.ReinstallInstalledMods;
if (!CheckInstalledMods)
2020-05-10 09:40:45 +12:00
{
SelectInstalled.IsEnabled = false;
2020-05-10 09:40:45 +12:00
ReinstallInstalled.IsEnabled = false;
}
2019-04-22 18:41:43 +12:00
UpdateHandlerStatus();
2019-05-05 04:08:54 +12:00
2019-04-22 18:41:43 +12:00
this.DataContext = this;
}
public void UpdateHandlerStatus()
{
ModelSaberProtocolHandlerEnabled = OneClickInstaller.IsRegistered("modelsaber");
BeatSaverProtocolHandlerEnabled = OneClickInstaller.IsRegistered("beatsaver");
}
private void SelectDirButton_Click(object sender, RoutedEventArgs e)
2019-04-22 18:41:43 +12:00
{
Utils.GetManualDir();
2019-05-25 08:32:34 +12:00
DirectoryTextBlock.Text = InstallDirectory;
GameTypeTextBlock.Text = InstallType;
2019-04-22 18:41:43 +12:00
}
2019-12-19 17:13:44 +13:00
private void OpenDirButton_Click(object sender, RoutedEventArgs e)
{
2020-02-28 03:43:03 +13:00
Utils.OpenFolder(InstallDirectory);
2019-12-19 17:13:44 +13:00
}
2019-04-22 18:41:43 +12:00
private void Test_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(Utils.GetSteamDir());
}
private void SaveSelected_Checked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.SaveSelected = true;
App.SaveModSelection = true;
Properties.Settings.Default.Save();
}
private void SaveSelected_Unchecked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.SaveSelected = false;
App.SaveModSelection = false;
Properties.Settings.Default.Save();
}
private void CheckInstalled_Checked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.CheckInstalled = true;
App.CheckInstalledMods = true;
CheckInstalledMods = true;
Properties.Settings.Default.Save();
SelectInstalled.IsEnabled = true;
2020-05-10 09:40:45 +12:00
ReinstallInstalled.IsEnabled = true;
2020-02-03 15:41:09 +13:00
2019-05-19 03:32:14 +12:00
if (MainWindow.ModsOpened)
2020-02-03 15:41:09 +13:00
{
2019-05-19 03:32:14 +12:00
Mods.Instance.PendingChanges = true;
2020-02-03 15:41:09 +13:00
}
2019-04-22 18:41:43 +12:00
}
private void CheckInstalled_Unchecked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.CheckInstalled = false;
App.CheckInstalledMods = false;
CheckInstalledMods = false;
Properties.Settings.Default.Save();
SelectInstalled.IsEnabled = false;
2020-05-10 09:40:45 +12:00
ReinstallInstalled.IsEnabled = false;
2020-02-03 15:41:09 +13:00
2019-05-19 03:32:14 +12:00
if (MainWindow.ModsOpened)
2020-02-03 15:41:09 +13:00
{
2019-05-19 03:32:14 +12:00
Mods.Instance.PendingChanges = true;
2020-02-03 15:41:09 +13:00
}
2019-04-22 18:41:43 +12:00
}
public void ModelSaberProtocolHandler_Checked(object sender, RoutedEventArgs e)
2019-04-22 18:41:43 +12:00
{
OneClickInstaller.Register("modelsaber");
}
2019-04-22 18:41:43 +12:00
public void ModelSaberProtocolHandler_Unchecked(object sender, RoutedEventArgs e)
{
OneClickInstaller.Unregister("modelsaber");
2019-04-22 18:41:43 +12:00
}
public void BeatSaverProtocolHandler_Checked(object sender, RoutedEventArgs e)
2019-04-22 18:41:43 +12:00
{
OneClickInstaller.Register("beatsaver");
}
2019-04-22 18:41:43 +12:00
public void BeatSaverProtocolHandler_Unchecked(object sender, RoutedEventArgs e)
{
OneClickInstaller.Unregister("beatsaver");
}
private void SelectInstalled_Checked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.SelectInstalled = true;
App.SelectInstalledMods = true;
SelectInstalledMods = true;
Properties.Settings.Default.Save();
}
private void SelectInstalled_Unchecked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.SelectInstalled = false;
App.SelectInstalledMods = false;
SelectInstalledMods = false;
Properties.Settings.Default.Save();
}
2020-05-10 09:40:45 +12:00
private void ReinstallInstalled_Checked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.ReinstallInstalled = true;
App.ReinstallInstalledMods = true;
ReinstallInstalledMods = true;
Properties.Settings.Default.Save();
}
private void ReinstallInstalled_Unchecked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.ReinstallInstalled = false;
App.ReinstallInstalledMods = false;
ReinstallInstalledMods = false;
Properties.Settings.Default.Save();
}
2019-12-20 18:25:34 +13:00
private async void OpenLogsDirButton_Click(object sender, RoutedEventArgs e)
{
try
{
2020-02-02 20:46:00 +13:00
MainWindow.Instance.MainText = $"{Application.Current.FindResource("Options:UploadingLog")}...";
await Task.Run(async () => await UploadLog());
2019-12-20 18:25:34 +13:00
System.Diagnostics.Process.Start(LogURL);
Clipboard.SetText(LogURL);
2020-02-02 20:46:00 +13:00
MainWindow.Instance.MainText = (string)Application.Current.FindResource("Options:LogUrlCopied");
2019-12-20 18:25:34 +13:00
}
catch (Exception exception)
{
2020-02-02 20:46:00 +13:00
MainWindow.Instance.MainText = $"{Application.Current.FindResource("Options:LogUploadFailed")}.";
string title = (string)Application.Current.FindResource("Options:LogUploadFailed:Title");
string body = (string)Application.Current.FindResource("Options:LogUploadFailed:Body");
MessageBox.Show($"{body}\n ================= \n" + exception, title);
2020-02-28 03:43:03 +13:00
Utils.OpenFolder(Path.Combine(InstallDirectory, "Logs"));
2019-12-20 18:25:34 +13:00
}
}
private async Task UploadLog()
2019-12-20 18:25:34 +13:00
{
const string DateFormat = "yyyy-mm-dd HH:mm:ss";
DateTime now = DateTime.Now;
var nvc = new List<KeyValuePair<string, string>>()
2019-12-20 18:25:34 +13:00
{
new KeyValuePair<string, string>("title", $"_latest.log ({now.ToString(DateFormat)})"),
new KeyValuePair<string, string>("expireUnit", "hour"),
new KeyValuePair<string, string>("expireLength", "5"),
new KeyValuePair<string, string>("code", File.ReadAllText(Path.Combine(InstallDirectory, "Logs", "_latest.log"))),
};
var req = new HttpRequestMessage(HttpMethod.Post, Utils.Constants.TeknikAPIUrl + "Paste")
{
Content = new FormUrlEncodedContent(nvc),
};
var resp = await Http.HttpClient.SendAsync(req);
var body = await resp.Content.ReadAsStringAsync();
var TeknikResponse = Http.JsonSerializer.Deserialize<Utils.TeknikPasteResponse>(body);
2019-12-20 18:25:34 +13:00
LogURL = TeknikResponse.result.url;
}
2020-02-20 17:53:14 +13:00
private void OpenAppDataButton_Click(object sender, RoutedEventArgs e)
{
string location = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
"AppData", "LocalLow", "Hyperbolic Magnetism");
2020-05-05 04:11:54 +12:00
if (Directory.Exists(location))
{
Utils.OpenFolder(location);
}
else
{
MessageBox.Show((string)Application.Current.FindResource("Options:AppDataNotFound"));
}
2020-02-20 17:53:14 +13:00
}
private async void YeetBSIPAButton_Click(object sender, RoutedEventArgs e)
{
if (Mods.Instance.AllModsList == null)
{
2020-02-02 20:46:00 +13:00
MainWindow.Instance.MainText = $"{Application.Current.FindResource("Options:GettingModList")}...";
await Task.Run(async () => await Mods.Instance.GetAllMods());
2020-02-02 20:46:00 +13:00
MainWindow.Instance.MainText = $"{Application.Current.FindResource("Options:FindingBSIPAVersion")}...";
await Task.Run(() => Mods.Instance.GetBSIPAVersion());
}
2020-02-03 00:04:30 +13:00
foreach (Mod mod in Mods.InstalledMods)
{
if (mod.name.ToLower() == "bsipa")
{
Mods.Instance.UninstallMod(mod);
break;
}
}
2020-02-02 20:46:00 +13:00
MainWindow.Instance.MainText = $"{Application.Current.FindResource("Options:BSIPAUninstalled")}...";
}
private async void YeetModsButton_Click(object sender, RoutedEventArgs e)
{
2020-02-02 20:46:00 +13:00
string title = (string)Application.Current.FindResource("Options:YeetModsBox:Title");
string line1 = (string)Application.Current.FindResource("Options:YeetModsBox:RemoveAllMods");
string line2 = (string)Application.Current.FindResource("Options:YeetModsBox:CannotBeUndone");
var resp = System.Windows.Forms.MessageBox.Show($"{line1}\n{line2}", title, System.Windows.Forms.MessageBoxButtons.YesNo);
if (resp == System.Windows.Forms.DialogResult.Yes)
{
if (Mods.Instance.AllModsList == null)
{
2020-03-28 05:57:30 +13:00
MainWindow.Instance.MainText = $"{Application.Current.FindResource("Options:GettingModList")}...";
await Task.Run(async () => await Mods.Instance.CheckInstalledMods());
}
foreach (Mod mod in Mods.InstalledMods)
{
Mods.Instance.UninstallMod(mod);
}
if (Directory.Exists(Path.Combine(App.BeatSaberInstallDirectory, "Plugins")))
Directory.Delete(Path.Combine(App.BeatSaberInstallDirectory, "Plugins"), true);
if (Directory.Exists(Path.Combine(App.BeatSaberInstallDirectory, "Libs")))
Directory.Delete(Path.Combine(App.BeatSaberInstallDirectory, "Libs"), true);
if (Directory.Exists(Path.Combine(App.BeatSaberInstallDirectory, "IPA")))
Directory.Delete(Path.Combine(App.BeatSaberInstallDirectory, "IPA"), true);
2020-02-02 20:46:00 +13:00
MainWindow.Instance.MainText = $"{Application.Current.FindResource("Options:AllModsUninstalled")}...";
}
}
2020-02-03 19:53:12 +13:00
private void ApplicationThemeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if ((sender as ComboBox).SelectedItem == null)
{
2020-02-17 13:39:52 +13:00
Themes.ApplyWindowsTheme();
2020-02-17 15:16:22 +13:00
MainWindow.Instance.MainText = (string)Application.Current.FindResource("Options:CurrentThemeRemoved");
2020-02-17 13:39:52 +13:00
}
else
{
Themes.ApplyTheme((sender as ComboBox).SelectedItem.ToString());
}
2020-02-03 19:53:12 +13:00
}
private void ApplicationThemeExportTemplate_Click(object sender, RoutedEventArgs e)
{
2020-02-17 13:52:10 +13:00
Themes.WriteThemeToDisk("Ugly Kulu-Ya-Ku");
Themes.LoadThemes();
}
2020-02-08 12:49:03 +13:00
private void ApplicationThemeOpenThemesFolder_Click(object sender, RoutedEventArgs e)
{
2020-02-08 12:55:01 +13:00
if (Directory.Exists(Themes.ThemeDirectory))
{
2020-02-28 03:43:03 +13:00
Utils.OpenFolder(Themes.ThemeDirectory);
2020-02-17 13:39:52 +13:00
}
else
{
2020-02-17 15:16:22 +13:00
MessageBox.Show((string)Application.Current.FindResource("Options:ThemeFolderNotFound"));
2020-02-17 13:39:52 +13:00
}
2020-02-08 12:49:03 +13:00
}
2020-05-18 22:56:16 +12:00
private void InstallPlaylistButton_Click(object sender, RoutedEventArgs e)
{
string playlistFile = Utils.GetManualFile();
2020-05-19 03:05:42 +12:00
if (File.Exists(playlistFile))
{
Task.Run(() => { API.Playlists.DownloadFrom(playlistFile, true).Wait(); });
}
2020-05-18 22:56:16 +12:00
}
2019-04-22 18:41:43 +12:00
}
}