Switched to resources file; Added OptionsUI to Webservices Mod

This commit is contained in:
Yoshi Askharoun
2021-08-04 23:02:07 -05:00
parent f4eee476c2
commit ba28eb7ef7
7 changed files with 325 additions and 80 deletions
+8 -8
View File
@@ -26,7 +26,7 @@ namespace ZuneModCore.Mods
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 +34,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");
byte[] wmvDllAniv = ModResources.WMVCORE;
// Get the original WMVCORE.dll
FileInfo wmvDllInfo = new(WMVCORE_PATH);
@@ -50,7 +50,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);
@@ -59,18 +59,18 @@ namespace ZuneModCore.Mods
// Update the Access Control on the original WMVCORE.dll
wmvDllInfo.SetAccessControl(security);
// Copy the pre-Anniversary Update WMVCORE.dll
File.Copy(sourcePath, WMVCORE_PATH, true);
// Replace with pre-Anniversary Update WMVCORE.dll
await File.WriteAllBytesAsync(wmvDllInfo.FullName, wmvDllAniv);
return Task.FromResult<string?>(null);
return null;
}
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 Task.FromResult(ex.Message)!;
return ex.Message;
}
}
#pragma warning restore CA1416 // Validate platform compatibility