mirror of
https://github.com/ZuneDev/ZuneModdingHelper.git
synced 2026-07-27 13:12:21 -07:00
Various changes for .NET Framework 3.5
This commit is contained in:
+5
-4
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using ZuneModCore.Mods;
|
||||
|
||||
namespace ZuneModCore
|
||||
@@ -29,11 +30,11 @@ namespace ZuneModCore
|
||||
|
||||
public abstract string Author { get; }
|
||||
|
||||
public virtual void Init() { }
|
||||
public virtual Task Init() => TaskEx.CompletedTask;
|
||||
|
||||
public abstract string? Apply();
|
||||
public abstract Task<string?> Apply();
|
||||
|
||||
public abstract string? Reset();
|
||||
public abstract Task<string?> Reset();
|
||||
|
||||
public string StorageDirectory
|
||||
{
|
||||
@@ -48,4 +49,4 @@ namespace ZuneModCore
|
||||
|
||||
public abstract ReadOnlyCollection<Type>? DependentMods { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ZuneModCore.Win32;
|
||||
|
||||
@@ -49,48 +51,29 @@ namespace ZuneModCore.Mods
|
||||
|
||||
public override ReadOnlyCollection<Type>? DependentMods => null;
|
||||
|
||||
public override void Init()
|
||||
public override Task Init()
|
||||
{
|
||||
foreach (AbstractUIElement uiElem in OptionsUI.Items)
|
||||
for (int i = 0; i < AvailableOverrides.Count; i++)
|
||||
{
|
||||
if (uiElem is AbstractBooleanUIElement boolElem)
|
||||
{
|
||||
bool? featureOverride = GetFeatureOverride(boolElem.Id);
|
||||
boolElem.ChangeState(featureOverride ?? false);
|
||||
}
|
||||
string key = AvailableOverrides.Keys.ElementAt(i);
|
||||
AvailableOverrides[key] = GetFeatureOverride(key) ?? false;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
return TaskEx.CompletedTask;
|
||||
}
|
||||
|
||||
public override async Task<string?> Apply()
|
||||
{
|
||||
// TODO: Use user choices from AbstractUI
|
||||
foreach (AbstractUIElement uiElem in OptionsUI.Items)
|
||||
for (int i = 0; i < AvailableOverrides.Count; i++)
|
||||
{
|
||||
if (uiElem is AbstractBooleanUIElement boolElem)// && boolElem.State)
|
||||
{
|
||||
bool isSuccess = SetFeatureOverride(boolElem.Id, true);
|
||||
if (!isSuccess)
|
||||
{
|
||||
string? resetStatus = await Reset();
|
||||
if (resetStatus != null)
|
||||
{
|
||||
// The reset failed as well, return both errors
|
||||
return "Failed to set registry keys. Unable to clean up partial overrides:\r\n" + resetStatus;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Failed to set registry keys. Automatically cleaned up partial changes.";
|
||||
}
|
||||
}
|
||||
}
|
||||
string key = AvailableOverrides.Keys.ElementAt(i);
|
||||
SetFeatureOverride(key, true);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override string? Reset()
|
||||
public override async Task<string?> Reset()
|
||||
{
|
||||
for (int i = 0; i < AvailableOverrides.Count; i++)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using OwlCore.AbstractUI.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZuneModCore.Mods
|
||||
@@ -24,29 +22,15 @@ namespace ZuneModCore.Mods
|
||||
|
||||
public override string Author => "Joshua \"Yoshi\" Askharoun";
|
||||
|
||||
public override AbstractUIElementGroup OptionsUI => new(nameof(MbidLocatorMod))
|
||||
{
|
||||
Title = "Select music folder:",
|
||||
Items =
|
||||
{
|
||||
new AbstractTextBox("folderBox"),
|
||||
new AbstractBooleanUIElement("recursiveBox", "Search recursively")
|
||||
}
|
||||
};
|
||||
|
||||
public override IReadOnlyList<Type>? DependentMods => null;
|
||||
public override ReadOnlyCollection<Type>? DependentMods => null;
|
||||
|
||||
public override async Task<string?> Apply()
|
||||
{
|
||||
// TODO: Use user choices from AbstractUI
|
||||
string folderPath = ((AbstractTextBox)OptionsUI.Items[0]).Value;
|
||||
bool recursive = ((AbstractBooleanUIElement)OptionsUI.Items[1]).State;
|
||||
string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
|
||||
bool recursive = false;
|
||||
string errorString = string.Empty;
|
||||
|
||||
// If the user didn't enter a folder, default to the "My Music" user folder
|
||||
if (string.IsNullOrEmpty(folderPath))
|
||||
folderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
|
||||
|
||||
// Verify that the folder exists
|
||||
DirectoryInfo folder = new(folderPath);
|
||||
if (!folder.Exists)
|
||||
@@ -75,12 +59,14 @@ namespace ZuneModCore.Mods
|
||||
|
||||
public override Task<string?> Reset()
|
||||
{
|
||||
return Task.FromResult<string?>(null);
|
||||
return TaskEx.FromResult<string?>(null);
|
||||
}
|
||||
|
||||
public static void UpdateMbidInFile(FileInfo file)
|
||||
{
|
||||
var tfile = TagLib.File.Create(file.FullName);
|
||||
throw new NotImplementedException("Music tag library is not supported.");
|
||||
|
||||
/*var tfile = TagLib.File.Create(file.FullName);
|
||||
|
||||
if (tfile.Tag is TagLib.Asf.Tag asfTag)
|
||||
{
|
||||
@@ -144,7 +130,7 @@ namespace ZuneModCore.Mods
|
||||
}
|
||||
}
|
||||
|
||||
tfile.Save();
|
||||
tfile.Save();*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using OwlCore.AbstractUI.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Security.AccessControl;
|
||||
@@ -23,10 +22,8 @@ namespace ZuneModCore.Mods
|
||||
|
||||
public override string Id => nameof(VideoSyncMod);
|
||||
|
||||
public override AbstractUIElementGroup? OptionsUI => null;
|
||||
|
||||
#pragma warning disable CA1416 // Validate platform compatibility
|
||||
public override Task<string?> Apply()
|
||||
public override async Task<string?> Apply()
|
||||
{
|
||||
// Make a backup of the original file
|
||||
FileVersionInfo wmvDllVersionInfo = FileVersionInfo.GetVersionInfo(WMVCORE_PATH);
|
||||
@@ -34,7 +31,7 @@ namespace ZuneModCore.Mods
|
||||
File.Copy(WMVCORE_PATH, Path.Combine(StorageDirectory, "WMVCORE.original.dll"), true);
|
||||
|
||||
// Get the working WMVCORE.dll
|
||||
string sourcePath = Path.Combine(AppContext.BaseDirectory, "Resources\\WMVCORE.dll");
|
||||
string sourcePath = Path.Combine(Directory.GetCurrentDirectory(), "Resources\\WMVCORE.dll");
|
||||
|
||||
// Get the original WMVCORE.dll
|
||||
FileInfo wmvDllInfo = new(WMVCORE_PATH);
|
||||
@@ -50,7 +47,7 @@ namespace ZuneModCore.Mods
|
||||
FileSecurity security = wmvDllInfo.GetAccessControl();
|
||||
SecurityIdentifier? cu = WindowsIdentity.GetCurrent().User;
|
||||
if (cu == null)
|
||||
return Task.FromResult<string?>("Failed to set permissions on WMVCORE.dll, current user was null");
|
||||
return "Failed to set permissions on WMVCORE.dll, current user was null";
|
||||
|
||||
// Set owner to current user
|
||||
security.SetOwner(cu);
|
||||
@@ -66,16 +63,16 @@ namespace ZuneModCore.Mods
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
return Task.FromResult<string?>($"Unable to replace '{wmvDllInfo.FullName}'. Verify that Zune and Windows Media Player are not running and try again.");
|
||||
return $"Unable to replace '{wmvDllInfo.FullName}'. Verify that Zune and Windows Media Player are not running and try again.";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message!;
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
#pragma warning restore CA1416 // Validate platform compatibility
|
||||
|
||||
public override string? Reset()
|
||||
public override async Task<string?> Reset()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace ZuneModCore.Mods
|
||||
|
||||
public override ReadOnlyCollection<Type>? DependentMods => null;
|
||||
|
||||
public override string? Apply()
|
||||
public override async Task<string?> Apply()
|
||||
{
|
||||
// Verify that ZuneServices.dll exists
|
||||
FileInfo zsDllInfo = new(Path.Combine(ZuneInstallDir, "ZuneService.dll"));
|
||||
@@ -79,7 +79,7 @@ namespace ZuneModCore.Mods
|
||||
setOverrideSuccess &= SetFeatureOverride("Videos", true);
|
||||
if (setOverrideSuccess != true)
|
||||
{
|
||||
return Task.FromResult<string?>("Unable to set feature overrides. The mod was successful, but you may not be able to see it in the Zune Software.");
|
||||
return "Unable to set feature overrides. The mod was successful, but you may not be able to see it in the Zune Software.";
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -94,7 +94,7 @@ namespace ZuneModCore.Mods
|
||||
}
|
||||
}
|
||||
|
||||
public override string? Reset()
|
||||
public override async Task<string?> Reset()
|
||||
{
|
||||
string zsDllPath = Path.Combine(ZuneInstallDir, "ZuneService.dll");
|
||||
try
|
||||
@@ -115,7 +115,7 @@ namespace ZuneModCore.Mods
|
||||
setOverrideSuccess &= SetFeatureOverride("Videos", false);
|
||||
if (setOverrideSuccess != true)
|
||||
{
|
||||
return Task.FromResult<string?>("Unable to reset feature overrides. The mod was successfully removed, but you may still be able to see it in the Zune Software.");
|
||||
return "Unable to reset feature overrides. The mod was successfully removed, but you may still be able to see it in the Zune Software.";
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZuneModCore
|
||||
{
|
||||
public static class TaskEx
|
||||
{
|
||||
public static Task<T> FromResult<T>(T result)
|
||||
{
|
||||
return Task.Factory.StartNew(() => result);
|
||||
}
|
||||
|
||||
public static Task CompletedTask => Task.Factory.StartNew(() => { });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net40</TargetFramework>
|
||||
<LangVersion>9</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<Platforms>AnyCPU;x64;x86</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
|
||||
<PackageReference Include="OwlCore" Version="0.0.6" />
|
||||
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="5.0.0" />
|
||||
<PackageReference Include="TagLibSharp" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
>>>>>>> master
|
||||
<None Update="Resources\WMVCORE.DLL">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -6,6 +6,10 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Bcl.Async" Version="1.0.168" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Resources\WMVCORE.DLL">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using Microsoft.AppCenter;
|
||||
using Microsoft.AppCenter.Analytics;
|
||||
using Microsoft.AppCenter.Crashes;
|
||||
//using Microsoft.AppCenter;
|
||||
//using Microsoft.AppCenter.Analytics;
|
||||
//using Microsoft.AppCenter.Crashes;
|
||||
|
||||
namespace ZuneModdingHelper
|
||||
{
|
||||
@@ -24,12 +24,12 @@ namespace ZuneModdingHelper
|
||||
base.OnStartup(e);
|
||||
|
||||
// Set up App Center analytics
|
||||
AppCenter.SetCountryCode(System.Globalization.RegionInfo.CurrentRegion.TwoLetterISORegionName);
|
||||
AppCenter.Start("24903c19-b3d9-4ab5-b445-b981ca647125", typeof(Analytics), typeof(Crashes));
|
||||
//AppCenter.SetCountryCode(System.Globalization.RegionInfo.CurrentRegion.TwoLetterISORegionName);
|
||||
//AppCenter.Start("24903c19-b3d9-4ab5-b445-b981ca647125", typeof(Analytics), typeof(Crashes));
|
||||
|
||||
#if DEBUG
|
||||
// Disable crash and event analytics when in debug
|
||||
AppCenter.SetEnabledAsync(false);
|
||||
//AppCenter.SetEnabledAsync(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace ZuneModdingHelper
|
||||
ZuneInstallDirBox.Text = Mod.ZuneInstallDir;
|
||||
}
|
||||
|
||||
private 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", settings: defaultMetroDialogSettings);
|
||||
Mod.ZuneInstallDir = ZuneInstallDirBox.Text;
|
||||
@@ -54,7 +54,7 @@ namespace ZuneModdingHelper
|
||||
//}
|
||||
|
||||
//progDialog.SetMessage($"Applying '{mod.Title}'");
|
||||
string applyResult = mod.Apply();
|
||||
string applyResult = await mod.Apply();
|
||||
if (applyResult != null)
|
||||
{
|
||||
//progDialog.SetMessage($"Failed to apply '{mod.Title}':\r\n{applyResult}");
|
||||
@@ -67,7 +67,7 @@ namespace ZuneModdingHelper
|
||||
//await this.ShowMessageAsync("Completed", "Finished installing selected mods", settings: defaultMetroDialogSettings);
|
||||
}
|
||||
|
||||
private void ModResetButton_Click(object sender, RoutedEventArgs e)
|
||||
private async void ModResetButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is FrameworkElement elem && elem.DataContext is Mod mod)
|
||||
{
|
||||
@@ -79,7 +79,7 @@ namespace ZuneModdingHelper
|
||||
|
||||
//progDialog.SetTitle("Resetting mod...");
|
||||
//progDialog.SetMessage($"Setting up '{mod.Title}'");
|
||||
mod.Init();
|
||||
await mod.Init();
|
||||
++numCompleted;
|
||||
//progDialog.SetProgress(numCompleted);
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace ZuneModdingHelper
|
||||
//}
|
||||
|
||||
//progDialog.SetMessage($"Resetting '{mod.Title}'");
|
||||
string applyResult = mod.Reset();
|
||||
string applyResult = await mod.Reset();
|
||||
if (applyResult != null)
|
||||
{
|
||||
//await progDialog.CloseAsync();
|
||||
@@ -149,34 +149,18 @@ namespace ZuneModdingHelper
|
||||
if (File.Exists(downloadedFile)) File.Delete(downloadedFile);
|
||||
client.DownloadFile(new Uri(asset["browser_download_url"].Value<string>()), downloadedFile);
|
||||
|
||||
// Newer version available, prompt user to download
|
||||
MetroDialogSettings promptSettings = new()
|
||||
// Ask user to save file
|
||||
Microsoft.Win32.SaveFileDialog saveFileDialog = new()
|
||||
{
|
||||
ColorScheme = MetroDialogColorScheme.Accented,
|
||||
AnimateShow = true,
|
||||
AnimateHide = true,
|
||||
AffirmativeButtonText = "Download",
|
||||
NegativeButtonText = "Later"
|
||||
FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads", assetName)
|
||||
};
|
||||
await checkDialog.CloseAsync();
|
||||
var promptResult = await this.ShowMessageAsync("Update available", $"Relase {latest["name"]} is available. Would you like to download it now?",
|
||||
MessageDialogStyle.AffirmativeAndNegative, promptSettings);
|
||||
bool acceptedUpdate = promptResult == MessageDialogResult.Affirmative;
|
||||
if (saveFileDialog.ShowDialog() == true)
|
||||
{
|
||||
File.Copy(downloadedFile, saveFileDialog.FileName, true);
|
||||
|
||||
//await progDialog.CloseAsync();
|
||||
//await this.ShowMessageAsync("Update complete", "You may now exit this program and open the new version.", settings: defaultMetroDialogSettings);
|
||||
}
|
||||
|
||||
Analytics.TrackEvent("Checked for updates", new Dictionary<string, string> {
|
||||
{ "UpdatesFound", bool.TrueString },
|
||||
{ "Accepted", acceptedUpdate.ToString() },
|
||||
});
|
||||
}
|
||||
catch
|
||||
{
|
||||
App.OpenInBrowser("https://github.com/ZuneDev/ZuneModdingHelper/releases");
|
||||
if (checkDialog.IsOpen)
|
||||
await checkDialog.CloseAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<<<<<<< HEAD
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net40</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<LangVersion>9</LangVersion>
|
||||
</PropertyGroup>
|
||||
=======
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net5.0-windows</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<Version>2021.5.30.0</Version>
|
||||
<Authors>Joshua "Yoshi" Askharoun</Authors>
|
||||
<RepositoryUrl>https://github.com/yoshiask/ZuneModdingHelper</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<Platforms>AnyCPU;x64;x86</Platforms>
|
||||
</PropertyGroup>
|
||||
>>>>>>> master
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ZuneModCore\ZuneModCore.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<<<<<<< HEAD
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MahApps.Metro" Version="1.6.5" />
|
||||
<PackageReference Include="Microsoft.Bcl.Async" Version="1.0.168" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="System.Threading.Tasks" Version="3.1.1" />
|
||||
</ItemGroup>
|
||||
=======
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Flurl.Http" Version="3.2.0" />
|
||||
<PackageReference Include="MahApps.Metro" Version="2.4.5" />
|
||||
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="4.2.0" />
|
||||
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="4.2.0" />
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.31" />
|
||||
<PackageReference Include="OwlCore" Version="0.0.6" />
|
||||
</ItemGroup>
|
||||
>>>>>>> master
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user