Added reset button for each mod; Minor UI tweaks

This commit is contained in:
Joshua Askharoun
2021-04-26 17:02:21 -05:00
parent 8ffe681b4b
commit 7f2db257d1
5 changed files with 98 additions and 25 deletions
+10 -3
View File
@@ -46,10 +46,17 @@ namespace ZuneModCore.Mods
public override Task<string?> Reset() public override Task<string?> Reset()
{ {
// Copy backup to application folder try
File.Copy(Path.Combine(StorageDirectory, "WMVCORE.original.dll"), WMVCORE_PATH, true); {
// Copy backup to application folder
File.Copy(Path.Combine(StorageDirectory, "WMVCORE.original.dll"), WMVCORE_PATH, true);
return Task.FromResult<string?>(null); return Task.FromResult<string?>(null);
}
catch (Exception ex)
{
return Task.FromResult(ex.Message)!;
}
} }
public override IReadOnlyList<Type>? DependentMods => null; public override IReadOnlyList<Type>? DependentMods => null;
+27 -15
View File
@@ -80,9 +80,9 @@ namespace ZuneModCore.Mods
return Task.FromResult<string?>(null); return Task.FromResult<string?>(null);
} }
catch (UnauthorizedAccessException) catch (IOException)
{ {
return Task.FromResult<string?>($"Failed to open '{zsDllInfo.FullName}'. Verify that the Zune software is not running and try again."); return Task.FromResult<string?>($"Unable to replace '{zsDllInfo.FullName}'. Verify that the Zune software is not running and try again.");
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -92,21 +92,33 @@ namespace ZuneModCore.Mods
public override Task<string?> Reset() public override Task<string?> Reset()
{ {
// Copy backup to application folder string zsDllPath = Path.Combine(ZuneInstallDir, "ZuneService.dll");
File.Copy(Path.Combine(StorageDirectory, "ZuneService.original.dll"), Path.Combine(ZuneInstallDir, "ZuneService.dll"), true); try
{
// Copy backup to application folder
File.Copy(Path.Combine(StorageDirectory, "ZuneService.original.dll"), zsDllPath, true);
// Disable all feature overrides affected by new servers // Disable all feature overrides affected by new servers
SetFeatureOverride("Apps", false); SetFeatureOverride("Apps", false);
SetFeatureOverride("Channels", false); SetFeatureOverride("Channels", false);
SetFeatureOverride("Games", false); SetFeatureOverride("Games", false);
SetFeatureOverride("Marketplace", false); SetFeatureOverride("Marketplace", false);
SetFeatureOverride("Music", false); SetFeatureOverride("Music", false);
SetFeatureOverride("MusicVideos", false); SetFeatureOverride("MusicVideos", false);
SetFeatureOverride("Podcasts", false); SetFeatureOverride("Podcasts", false);
SetFeatureOverride("Social", false); SetFeatureOverride("Social", false);
SetFeatureOverride("Videos", false); SetFeatureOverride("Videos", false);
return Task.FromResult<string?>(null); return Task.FromResult<string?>(null);
}
catch (IOException)
{
return Task.FromResult<string?>($"Unable to replace '{zsDllPath}'. Verify that the Zune software is not running and try again.");
}
catch (Exception ex)
{
return Task.FromResult<string?>(ex.Message);
}
} }
} }
} }
+1 -1
View File
@@ -55,7 +55,7 @@ namespace ZuneModCore
if (regKey == null) if (regKey == null)
return; return;
regKey.DeleteValue(name); regKey.DeleteValue(name, false);
} }
} }
+12 -3
View File
@@ -24,9 +24,18 @@
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Title}" FontWeight="SemiBold" FontSize="16" TextTrimming="CharacterEllipsis"/> <TextBlock Text="{Binding Title}" FontWeight="SemiBold" FontSize="16" TextTrimming="CharacterEllipsis"/>
<TextBlock Text="{Binding Description}" Grid.Row="1" FontSize="12" TextWrapping="Wrap"/> <TextBlock Text="{Binding Description}" Grid.Row="1" FontSize="14" TextWrapping="Wrap"/>
<Button x:Name="ModResetButton" Grid.Column="1" Grid.RowSpan="2" VerticalAlignment="Center"
Click="ModResetButton_Click">
<mah:FontIcon Glyph="&#xE10E;" FontFamily="Segoe MDL2 Assets" />
</Button>
</Grid> </Grid>
<!--<Border Padding="8" Margin="8" Background="White"> <!--<Border Padding="8" Margin="8" Background="White">
@@ -49,11 +58,11 @@
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Text="Zune Software install directory:" Margin="4,4,0,0"/> <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"/> <TextBox x:Name="ZuneInstallDirBox" Grid.Row="1" Margin="4,0,0,4"/>
<Button x:Name="InstallModsButton" Content="Install" ToolTip="Install selected mods" Click="InstallModsButton_Click" <Button x:Name="InstallModsButton" Content="Install" ToolTip="Install selected mods" Click="InstallModsButton_Click"
Grid.RowSpan="2" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="4"/> Grid.Row="1" Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Right" Margin="4,0,4,4"/>
</Grid> </Grid>
</Grid> </Grid>
</mah:MetroWindow> </mah:MetroWindow>
+48 -3
View File
@@ -25,6 +25,14 @@ namespace ZuneModdingHelper
/// </summary> /// </summary>
public partial class MainWindow : MetroWindow public partial class MainWindow : MetroWindow
{ {
private readonly MetroDialogSettings defaultMetroDialogSettings = new()
{
ColorScheme = MetroDialogColorScheme.Accented,
AnimateShow = true,
AnimateHide = true,
AffirmativeButtonText = "Close"
};
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
@@ -41,7 +49,7 @@ namespace ZuneModdingHelper
private async void InstallModsButton_Click(object sender, RoutedEventArgs e) private async void InstallModsButton_Click(object sender, RoutedEventArgs e)
{ {
var progDialog = await this.ShowProgressAsync("Getting ready...", "Preparing to apply mods"); var progDialog = await this.ShowProgressAsync("Getting ready...", "Preparing to apply mods", settings: defaultMetroDialogSettings);
Mod.ZuneInstallDir = ZuneInstallDirBox.Text; Mod.ZuneInstallDir = ZuneInstallDirBox.Text;
var selectedMods = ModList.SelectedItems.Cast<Mod>(); var selectedMods = ModList.SelectedItems.Cast<Mod>();
@@ -75,8 +83,45 @@ namespace ZuneModdingHelper
} }
await progDialog.CloseAsync(); await progDialog.CloseAsync();
await this.ShowMessageAsync("Completed", "Finished installing selected mods", await this.ShowMessageAsync("Completed", "Finished installing selected mods", settings: defaultMetroDialogSettings);
settings: new MetroDialogSettings() { AffirmativeButtonText = "Close" }); }
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 AbstractUIElementGroupViewModel(mod.OptionsUI);
// optionsDialog.ShowDialog();
//}
progDialog.SetMessage($"Resetting '{mod.Title}'");
string applyResult = await mod.Reset();
if (applyResult != null)
{
await progDialog.CloseAsync();
await this.ShowMessageAsync("Completed", $"Failed to reset '{mod.Title}':\r\n{applyResult}", settings: defaultMetroDialogSettings);
return;
}
progDialog.SetProgress(++numCompleted);
await progDialog.CloseAsync();
await this.ShowMessageAsync("Completed", $"Successfully reset '{mod.Title}'", settings: defaultMetroDialogSettings);
}
} }
} }
} }