Remove MainWindow

This commit is contained in:
Yoshi Askharoun
2024-05-16 21:10:26 -05:00
parent 15beff6c31
commit ecb6fb30a7
2 changed files with 0 additions and 443 deletions
-166
View File
@@ -1,166 +0,0 @@
<mah:MetroWindow x:Class="ZuneModdingHelper.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ZuneModdingHelper"
xmlns:core="clr-namespace:ZuneModCore;assembly=ZuneModCore"
xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:b="clr-namespace:ZuneModdingHelper.Behaviors"
mc:Ignorable="d"
Title="{x:Static local:App.Title}" Height="450" Width="800" WindowStartupLocation="CenterScreen"
Loaded="Window_Loaded">
<mah:MetroWindow.IconTemplate>
<DataTemplate>
<mah:FontIcon Glyph="&#xE000;" FontFamily="{StaticResource ZMHIcons}"
Margin="0,0,-6,0"/>
</DataTemplate>
</mah:MetroWindow.IconTemplate>
<mah:MetroWindow.RightWindowCommands>
<mah:WindowCommands>
<Button Style="{StaticResource MahApps.Styles.Button.WindowCommands}" ToolTip="Check for updates" Click="UpdatesButton_Click">
<mah:FontIcon Glyph="&#xE003;" FontFamily="{StaticResource ZMHIcons}"/>
</Button>
<Button Style="{StaticResource MahApps.Styles.Button.WindowCommands}" ToolTip="About" Click="AboutButton_Click">
<mah:FontIcon Glyph="&#xE004;" FontFamily="{StaticResource ZMHIcons}"/>
</Button>
</mah:WindowCommands>
</mah:MetroWindow.RightWindowCommands>
<mah:MetroWindow.Flyouts>
<mah:FlyoutsControl>
<mah:Flyout x:Name="AboutFlyout" Position="Right" IsModal="True" Theme="Adapt">
<mah:Flyout.Header>
<Grid>
<TextBlock Text="About" FontSize="26" FontWeight="Bold"/>
<Button Click="DonateButton_Click" ToolTip="Support development of this and other projects"
HorizontalAlignment="Right" Margin="4"
Style="{StaticResource MahApps.Styles.Button.MetroSquare.Accent}">
<mah:FontIcon Glyph="&#xE006;" FontFamily="{StaticResource ZMHIcons}"/>
</Button>
</Grid>
</mah:Flyout.Header>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock FontSize="14" Padding="16" TextWrapping="Wrap">
<Run Text="{x:Static local:App.Title}" FontWeight="Bold" FontSize="16"/><LineBreak/>
<Run Text="{x:Static local:App.VersionStr}"/><LineBreak/>
<Hyperlink NavigateUri="https://github.com/ZuneDev/ZuneModdingHelper" RequestNavigate="Link_RequestNavigate">
<Run Text="&#xE005;" FontFamily="{StaticResource ZMHIcons}"/>
<Run Text="View source"/>
</Hyperlink><LineBreak/>
<Hyperlink NavigateUri="https://github.com/ZuneDev/ZuneModdingHelper/releases" RequestNavigate="Link_RequestNavigate">
<Run Text="&#xE003;" FontFamily="{StaticResource ZMHIcons}"/>
<Run Text="View releases"/>
</Hyperlink><LineBreak/>
<Hyperlink NavigateUri="https://reddit.com/r/Zune" RequestNavigate="Link_RequestNavigate">
<Run Text="&#xE001;" FontFamily="{StaticResource ZMHIcons}"/>
<Run Text="Join r/Zune subreddit"/>
</Hyperlink><LineBreak/>
<Hyperlink NavigateUri="https://discord.zunes.me/" RequestNavigate="Link_RequestNavigate">
<Run Text="&#xE002;" FontFamily="{StaticResource ZMHIcons}"/>
<Run Text="Join r/Zune Discord server"/>
</Hyperlink><LineBreak/><LineBreak/>
<Run Text="Developed by Joshua &quot;Yoshi&quot; Askharoun." FontWeight="SemiBold"/>
<Run Text="Mods included with authors' permission."/><LineBreak/><LineBreak/>
<Run Text="I am not liable for any damages caused directly or indirectly by this tool or any of the mods it contains."/>
</TextBlock>
</Grid>
</mah:Flyout>
</mah:FlyoutsControl>
</mah:MetroWindow.Flyouts>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ListView x:Name="ModList" HorizontalContentAlignment="Stretch"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.Resources>
<Style x:Key="MetroButton" TargetType="Button" BasedOn="{StaticResource MahApps.Styles.Button.Square}">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Margin" Value="8,0,0,0"/>
<Setter Property="Grid.RowSpan" Value="3"/>
</Style>
<Style x:Key="MetroAccentButton" TargetType="Button" BasedOn="{StaticResource MahApps.Styles.Button.Square.Accent}">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Margin" Value="8,0,0,0"/>
<Setter Property="Grid.RowSpan" Value="3"/>
</Style>
</ListView.Resources>
<ListView.ItemTemplate>
<DataTemplate DataType="{x:Type core:Mod}">
<Border BorderThickness="0,0,0,0" BorderBrush="{StaticResource MahApps.Brushes.Separator}"
Padding="8">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock TextTrimming="CharacterEllipsis">
<Run Text="{Binding Title, Mode=OneWay}" FontWeight="SemiBold" FontSize="16"/>
<Run Text=" By "/><Run Text="{Binding Author, Mode=OneWay}"/>
</TextBlock>
<TextBlock Text="{Binding Description}" Grid.Row="1" FontSize="14" TextWrapping="Wrap"/>
<Button x:Name="ModResetButton" Grid.Column="1" Click="ModResetButton_Click" ToolTip="Reset"
Style="{StaticResource MetroButton}">
<mah:FontIcon Glyph="&#xE10E;" FontFamily="Segoe MDL2 Assets" Margin="4" />
</Button>
<Button x:Name="ModInstallButton" Grid.Column="2" Click="ModInstallButton_Click" ToolTip="Install"
Style="{StaticResource MetroAccentButton}">
<mah:FontIcon Glyph="&#xE73E;" FontFamily="Segoe MDL2 Assets" Margin="4" />
</Button>
</Grid>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
<i:Interaction.Behaviors>
<b:FadeAnimateItemsBehavior Tick="0:0:0.05">
<b:FadeAnimateItemsBehavior.Animation>
<DoubleAnimation From="0" To="1" Duration="0:0:0.3"/>
</b:FadeAnimateItemsBehavior.Animation>
</b:FadeAnimateItemsBehavior>
</i:Interaction.Behaviors>
</ListView>
<Border Grid.Row="1" BorderThickness="0,1,0,0" BorderBrush="{StaticResource MahApps.Brushes.Control.Border}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="Zune software install directory:" FontSize="14" Margin="4,4,0,2" />
<TextBox x:Name="ZuneInstallDirBox" Grid.Row="1" Margin="4,0,0,4"/>
<Button x:Name="LocateZuneButton" Content="..." ToolTip="Locate Zune software..." Click="LocateZuneButton_Click"
Grid.Row="1" Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Right" Margin="4,0,4,4"
Style="{StaticResource MahApps.Styles.Button.MetroSquare}"/>
</Grid>
</Border>
</Grid>
</mah:MetroWindow>
-277
View File
@@ -1,277 +0,0 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using ControlzEx.Theming;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using Microsoft.WindowsAPICodePack.Dialogs;
using Octokit;
using OwlCore.AbstractUI.Models;
using Syroot.Windows.IO;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Navigation;
using ZuneModCore;
namespace ZuneModdingHelper
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : MetroWindow
{
private readonly MetroDialogSettings defaultMetroDialogSettings = new()
{
ColorScheme = MetroDialogColorScheme.Accented,
AnimateShow = true,
AnimateHide = true,
AffirmativeButtonText = "OK"
};
private readonly IGitHubClient? _gitHub = Ioc.Default.GetService<IGitHubClient>();
public MainWindow()
{
InitializeComponent();
// https://github.com/Arlodotexe/OwlCore/issues/1
OwlCore.Threading.SetPrimarySynchronizationContext(System.Threading.SynchronizationContext.Current!);
OwlCore.Threading.SetPrimaryThreadInvokeHandler(RunOnUI);
ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.SyncWithAppMode;
ThemeManager.Current.SyncTheme();
ModList.ItemsSource = Mod.AvailableMods;
ZuneInstallDirBox.Text = Mod.ZuneInstallDir;
}
private async System.Threading.Tasks.Task RunOnUI(Action action) => await Dispatcher.BeginInvoke(action);
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
// Show a warning if Zune is running
Process[] procs = Process.GetProcessesByName("Zune");
string zuneExePath = Path.Combine(Mod.ZuneInstallDir, "Zune.exe");
if (procs.Length > 0 && procs.Any(p => p.MainModule.FileName == zuneExePath))
{
await this.ShowMessageAsync(
"Warning",
"The Zune software is currently running. You may run into issues applying or resetting mods.",
settings: defaultMetroDialogSettings);
}
}
private async void ModInstallButton_Click(object sender, RoutedEventArgs e)
{
var progDialog = await this.ShowProgressAsync("Getting ready...", "Preparing to apply mod", settings: defaultMetroDialogSettings);
Mod mod = (Mod)((FrameworkElement)sender).DataContext;
Mod.ZuneInstallDir = ZuneInstallDirBox.Text;
progDialog.Maximum = 3;
int numCompleted = 0;
// Stage 0: Initialize mod
progDialog.SetTitle($"Installing '{mod.Title}'");
progDialog.SetMessage("Preparing to install...");
await mod.Init();
progDialog.SetProgress(++numCompleted);
// Stage 1: Display AbstractUI for options
progDialog.SetMessage("Awaiting options...");
if (mod.OptionsUI != null)
{
var optionsDialog = new AbstractUIGroupDialog(mod.OptionsUI);
optionsDialog.Title = optionsDialog.Title + " | " + mod.Title;
bool? optionsResult = optionsDialog.ShowDialog();
if (!(optionsResult.HasValue && optionsResult.Value))
{
await progDialog.CloseAsync();
return;
}
mod.OptionsUI = (AbstractUICollection)optionsDialog.ViewModel.Model;
}
progDialog.SetProgress(++numCompleted);
// Stage 2: Apply mod
progDialog.SetMessage("Applying mod...");
string applyResult = await mod.Apply();
if (applyResult != null)
{
await progDialog.CloseAsync();
await this.ShowMessageAsync($"Failed to apply '{mod.Title}'", applyResult, settings: defaultMetroDialogSettings);
return;
}
progDialog.SetProgress(++numCompleted);
await progDialog.CloseAsync();
await this.ShowMessageAsync("Completed", $"Installed '{mod.Title}'", settings: defaultMetroDialogSettings);
}
private async void ModResetButton_Click(object sender, RoutedEventArgs e)
{
if (sender is FrameworkElement elem && elem.DataContext is Mod mod)
{
var progDialog = await this.ShowProgressAsync("Getting ready...", "Preparing to reset mod", settings: defaultMetroDialogSettings);
Mod.ZuneInstallDir = ZuneInstallDirBox.Text;
progDialog.Maximum = 2;
int numCompleted = 0;
progDialog.SetTitle("Resetting mod...");
progDialog.SetMessage($"Setting up '{mod.Title}'");
await mod.Init();
progDialog.SetProgress(++numCompleted);
// TODO: Implement AbstractUI display for options
//if (mod.OptionsUI != null)
//{
// var optionsDialog = new AbstractUIGroupDialog();
// optionsDialog.OptionsUIPresenter.ViewModel = new AbstractUICollectionViewModel(mod.OptionsUI);
// optionsDialog.ShowDialog();
//}
progDialog.SetMessage($"Resetting '{mod.Title}'");
string resetResult = await mod.Reset();
if (resetResult != null)
{
await progDialog.CloseAsync();
await this.ShowMessageAsync("Completed", $"Failed to reset '{mod.Title}':\r\n{resetResult}", settings: defaultMetroDialogSettings);
return;
}
progDialog.SetProgress(++numCompleted);
await progDialog.CloseAsync();
await this.ShowMessageAsync("Completed", $"Successfully reset '{mod.Title}'", settings: defaultMetroDialogSettings);
}
}
private void AboutButton_Click(object sender, RoutedEventArgs e)
{
AboutFlyout.Width = Math.Max(Math.Min(500, ActualWidth), ActualWidth / 3);
AboutFlyout.IsOpen = true;
}
private void Link_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
App.OpenInBrowser(e.Uri.AbsoluteUri);
e.Handled = true;
}
private async void UpdatesButton_Click(object sender, RoutedEventArgs e)
{
if (_gitHub is null)
return;
var checkDialog = await this.ShowProgressAsync("Checking for updates...", "Please wait.", settings: defaultMetroDialogSettings);
checkDialog.SetIndeterminate();
try
{
// Get releases list from GitHub
// Why not use the `releases/latest` endpoint? Good question: https://github.com/octokit/octokit.net/issues/2916
var releases = await _gitHub.Repository.Release.GetAll("ZuneDev", "ZuneModdingHelper");
var latest = releases
.Select(r => new { Release = r, Version = ReleaseVersion.Parse(r.TagName) })
.OrderByDescending(t => t.Version)
.ThenBy(t => t.Release.Prerelease)
.First();
if (!ReleaseVersion.TryParse(latest.Release.TagName, out var latestVer) || App.Version >= latestVer)
{
await checkDialog.CloseAsync();
await this.ShowMessageAsync("No updates available", "You're already using the latest version.", settings: defaultMetroDialogSettings);
return;
}
// Newer version available, prompt user to download
MetroDialogSettings promptSettings = new()
{
ColorScheme = MetroDialogColorScheme.Accented,
AnimateShow = true,
AnimateHide = true,
AffirmativeButtonText = "Download",
NegativeButtonText = "Later"
};
await checkDialog.CloseAsync();
var promptResult = await this.ShowMessageAsync("Update available", $"Release {latest.Release.Name} is available. Would you like to download it now?",
MessageDialogStyle.AffirmativeAndNegative, promptSettings);
bool acceptedUpdate = promptResult == MessageDialogResult.Affirmative;
if (acceptedUpdate)
{
var progDialog = await this.ShowProgressAsync("Downloading update...", "This may take a few minutes.", settings: defaultMetroDialogSettings);
progDialog.Maximum = 100;
progDialog.SetIndeterminate();
// Download new version to AppData
var asset = latest.Release.Assets[0];
string downloadedFile = Path.Combine(Path.GetTempPath(), asset.Name);
if (File.Exists(downloadedFile)) File.Delete(downloadedFile);
using (var client = new System.Net.WebClient())
{
client.DownloadProgressChanged += (object sender, System.Net.DownloadProgressChangedEventArgs e) => {
// Update UI with download progress
progDialog.SetProgress(e.ProgressPercentage);
};
progDialog.SetProgress(0);
await client.DownloadFileTaskAsync(new Uri(asset.BrowserDownloadUrl), downloadedFile);
}
// Ask user to save file
Microsoft.Win32.SaveFileDialog saveFileDialog = new()
{
FileName = asset.Name,
InitialDirectory = new KnownFolder(KnownFolderType.Downloads).Path
};
bool dialogResult = saveFileDialog.ShowDialog() ?? false;
await progDialog.CloseAsync();
if (dialogResult)
{
File.Copy(downloadedFile, saveFileDialog.FileName, true);
await this.ShowMessageAsync("Update complete", "You may now exit this program and open the new version.", settings: defaultMetroDialogSettings);
}
File.Delete(downloadedFile);
}
}
catch
{
App.OpenInBrowser("https://github.com/ZuneDev/ZuneModdingHelper/releases");
}
finally
{
if (checkDialog.IsOpen)
await checkDialog.CloseAsync();
}
}
private void DonateButton_Click(object sender, RoutedEventArgs e) => App.OpenInBrowser(App.DonateLink);
private void LocateZuneButton_Click(object sender, RoutedEventArgs e)
{
if (CommonFileDialog.IsPlatformSupported)
{
CommonOpenFileDialog dialog = new()
{
IsFolderPicker = true,
DefaultDirectory = Mod.ZuneInstallDir
};
CommonFileDialogResult result = dialog.ShowDialog();
if (result == CommonFileDialogResult.Ok)
{
ZuneInstallDirBox.Text = dialog.FileName;
}
}
else
{
// TODO: Fallback to pre-Vista dialog
this.ShowMessageAsync("Error",
"Please use File Explorer to locate and copy the path.",
settings: defaultMetroDialogSettings);
}
}
}
}