mirror of
https://github.com/ZuneDev/ZuneModdingHelper.git
synced 2026-07-27 13:12:21 -07:00
Update to net8.0-windows and C# 12
This commit is contained in:
+4
-7
@@ -6,10 +6,10 @@ using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using ZuneModCore.Mods;
|
||||
|
||||
namespace ZuneModCore
|
||||
namespace ZuneModCore;
|
||||
|
||||
public abstract class Mod
|
||||
{
|
||||
public abstract class Mod
|
||||
{
|
||||
/// <summary>
|
||||
/// A list of all available mods
|
||||
/// </summary>
|
||||
@@ -67,9 +67,7 @@ namespace ZuneModCore
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_OptionsUI == null)
|
||||
_OptionsUI = GetDefaultOptionsUI();
|
||||
return _OptionsUI;
|
||||
return _OptionsUI ??= GetDefaultOptionsUI();
|
||||
}
|
||||
set => _OptionsUI = value;
|
||||
}
|
||||
@@ -86,5 +84,4 @@ namespace ZuneModCore
|
||||
}
|
||||
|
||||
public abstract IReadOnlyList<Type>? DependentMods { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ using System.Threading.Tasks;
|
||||
using Vestris.ResourceLib;
|
||||
using ZuneModCore.Win32;
|
||||
|
||||
namespace ZuneModCore.Mods
|
||||
namespace ZuneModCore.Mods;
|
||||
|
||||
public class BackgroundImageMod : Mod
|
||||
{
|
||||
public class BackgroundImageMod : Mod
|
||||
{
|
||||
public override string Id => nameof(BackgroundImageMod);
|
||||
|
||||
public override string Title => "Background Image";
|
||||
@@ -128,5 +128,4 @@ namespace ZuneModCore.Mods
|
||||
return Task.FromResult(ex.Message)!;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using ZuneModCore.Win32;
|
||||
|
||||
namespace ZuneModCore.Mods
|
||||
namespace ZuneModCore.Mods;
|
||||
|
||||
public class FeaturesOverrideMod : Mod
|
||||
{
|
||||
public class FeaturesOverrideMod : Mod
|
||||
{
|
||||
private const string ZUNE_FEATURESOVERRIDE_REGKEY = RegEdit.ZUNE_REG_PATH + "FeaturesOverride";
|
||||
|
||||
public override string Id => nameof(FeaturesOverrideMod);
|
||||
@@ -115,5 +115,4 @@ namespace ZuneModCore.Mods
|
||||
|
||||
public static void ResetFeatureOverride(string feature) =>
|
||||
RegEdit.CurrentUserDeleteValue(ZUNE_FEATURESOVERRIDE_REGKEY, feature);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,19 +5,16 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZuneModCore.Mods
|
||||
namespace ZuneModCore.Mods;
|
||||
|
||||
public class MbidLocatorMod : Mod
|
||||
{
|
||||
public class MbidLocatorMod : Mod
|
||||
{
|
||||
public const string ZUNE_ALBUM_ARTIST_MEDIA_ID_NAME = "ZuneAlbumArtistMediaID";
|
||||
public const string ZUNE_ALBUM_MEDIA_ID_NAME = "ZuneAlbumMediaID";
|
||||
public const string ZUNE_MEDIA_ID_NAME = "ZuneMediaID";
|
||||
public const string ZUNE_COLLECTION_ID_NAME = "ZuneCollectionID";
|
||||
|
||||
private static readonly string[] KNOWN_EXTS = new[]
|
||||
{
|
||||
".mp3", ".mp4", ".m4a", ".wav"
|
||||
};
|
||||
private static readonly string[] KNOWN_EXTS = [".mp3", ".mp4", ".m4a", ".wav"];
|
||||
|
||||
public override string Id => nameof(MbidLocatorMod);
|
||||
|
||||
@@ -167,5 +164,4 @@ namespace ZuneModCore.Mods
|
||||
|
||||
tfile.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZuneModCore.Mods
|
||||
namespace ZuneModCore.Mods;
|
||||
|
||||
public class VideoSyncMod : Mod
|
||||
{
|
||||
public class VideoSyncMod : Mod
|
||||
{
|
||||
private const int ZUNEENCENG_WMVCORA_OFFSET = 0x161E;
|
||||
|
||||
public override string Title => "Fix Video Sync";
|
||||
@@ -91,5 +91,4 @@ namespace ZuneModCore.Mods
|
||||
}
|
||||
|
||||
public override IReadOnlyList<Type>? DependentMods => null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using static ZuneModCore.Mods.FeaturesOverrideMod;
|
||||
|
||||
namespace ZuneModCore.Mods
|
||||
namespace ZuneModCore.Mods;
|
||||
|
||||
public class WebservicesMod : Mod
|
||||
{
|
||||
public class WebservicesMod : Mod
|
||||
{
|
||||
private const int ZUNESERVICES_ENDPOINTS_BLOCK_OFFSET = 0x14D60;
|
||||
private const int ZUNESERVICES_ENDPOINTS_BLOCK_LENGTH = 0x884;
|
||||
private const string WEBSERVICE_ICON_TESTING = "\uE72C";
|
||||
@@ -21,6 +21,15 @@ namespace ZuneModCore.Mods
|
||||
private const string WEBSERVICE_SUBTITLE_SUCCESS = "OK";
|
||||
private const string WEBSERVICE_SUBTITLE_UNREACHABLE = "Unreachable";
|
||||
|
||||
private static readonly string[] _affectedFeatures =
|
||||
[
|
||||
"Apps", "Channels", "Games", "Marketplace",
|
||||
"MBRPreview", "MBRPurchase", "MBRRental",
|
||||
"Music", "MusicVideos", "Picks", "Podcasts",
|
||||
"Sign In Available", "Social", "Videos",
|
||||
"SocialMarketplace", "SubscriptionFreeTracks",
|
||||
];
|
||||
|
||||
private HttpClient _client;
|
||||
private CancellationTokenSource _cts = new();
|
||||
|
||||
@@ -151,26 +160,11 @@ namespace ZuneModCore.Mods
|
||||
|
||||
// Enable all feature overrides affected by new servers
|
||||
bool setOverrideSuccess = true;
|
||||
setOverrideSuccess &= SetFeatureOverride("Apps", true);
|
||||
setOverrideSuccess &= SetFeatureOverride("Channels", true);
|
||||
setOverrideSuccess &= SetFeatureOverride("Games", true);
|
||||
setOverrideSuccess &= SetFeatureOverride("Marketplace", true);
|
||||
setOverrideSuccess &= SetFeatureOverride("MBRPreview", true);
|
||||
setOverrideSuccess &= SetFeatureOverride("MBRPurchase", true);
|
||||
setOverrideSuccess &= SetFeatureOverride("MBRRental", true);
|
||||
setOverrideSuccess &= SetFeatureOverride("Music", true);
|
||||
setOverrideSuccess &= SetFeatureOverride("MusicVideos", true);
|
||||
setOverrideSuccess &= SetFeatureOverride("Picks", true);
|
||||
setOverrideSuccess &= SetFeatureOverride("Podcasts", true);
|
||||
setOverrideSuccess &= SetFeatureOverride("Sign In Available", true);
|
||||
setOverrideSuccess &= SetFeatureOverride("Social", true);
|
||||
setOverrideSuccess &= SetFeatureOverride("SocialMarketplace", true);
|
||||
setOverrideSuccess &= SetFeatureOverride("SubscriptionFreeTracks", true);
|
||||
setOverrideSuccess &= SetFeatureOverride("Videos", true);
|
||||
foreach (var feature in _affectedFeatures)
|
||||
setOverrideSuccess &= SetFeatureOverride(feature, true);
|
||||
|
||||
if (setOverrideSuccess != true)
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -194,26 +188,11 @@ namespace ZuneModCore.Mods
|
||||
|
||||
// Disable all feature overrides affected by new servers
|
||||
bool setOverrideSuccess = true;
|
||||
setOverrideSuccess &= SetFeatureOverride("Apps", false);
|
||||
setOverrideSuccess &= SetFeatureOverride("Channels", false);
|
||||
setOverrideSuccess &= SetFeatureOverride("Games", false);
|
||||
setOverrideSuccess &= SetFeatureOverride("Marketplace", false);
|
||||
setOverrideSuccess &= SetFeatureOverride("MBRPreview", false);
|
||||
setOverrideSuccess &= SetFeatureOverride("MBRPurchase", false);
|
||||
setOverrideSuccess &= SetFeatureOverride("MBRRental", false);
|
||||
setOverrideSuccess &= SetFeatureOverride("Music", false);
|
||||
setOverrideSuccess &= SetFeatureOverride("MusicVideos", false);
|
||||
setOverrideSuccess &= SetFeatureOverride("Picks", false);
|
||||
setOverrideSuccess &= SetFeatureOverride("Podcasts", false);
|
||||
setOverrideSuccess &= SetFeatureOverride("Sign In Available", false);
|
||||
setOverrideSuccess &= SetFeatureOverride("Social", false);
|
||||
setOverrideSuccess &= SetFeatureOverride("SocialMarketplace", false);
|
||||
setOverrideSuccess &= SetFeatureOverride("SubscriptionFreeTracks", false);
|
||||
setOverrideSuccess &= SetFeatureOverride("Videos", false);
|
||||
foreach (var feature in _affectedFeatures)
|
||||
setOverrideSuccess &= SetFeatureOverride(feature, false);
|
||||
|
||||
if (setOverrideSuccess != true)
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -290,5 +269,4 @@ namespace ZuneModCore.Mods
|
||||
metadata.Subtitle = WEBSERVICE_SUBTITLE_UNREACHABLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
namespace ZuneModCore.Services
|
||||
namespace ZuneModCore.Services;
|
||||
|
||||
public interface IModCoreConfig
|
||||
{
|
||||
public interface IModCoreConfig
|
||||
{
|
||||
string ZuneInstallDir { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
using System;
|
||||
namespace ZuneModCore.Win32;
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZuneModCore.Win32
|
||||
public static partial class FileUtil
|
||||
{
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
static public class FileUtil
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct RM_UNIQUE_PROCESS
|
||||
{
|
||||
@@ -55,18 +49,18 @@ namespace ZuneModCore.Win32
|
||||
|
||||
[DllImport("rstrtmgr.dll", CharSet = CharSet.Unicode)]
|
||||
static extern int RmRegisterResources(uint pSessionHandle,
|
||||
UInt32 nFiles,
|
||||
uint nFiles,
|
||||
string[] rgsFilenames,
|
||||
UInt32 nApplications,
|
||||
uint nApplications,
|
||||
[In] RM_UNIQUE_PROCESS[] rgApplications,
|
||||
UInt32 nServices,
|
||||
uint nServices,
|
||||
string[] rgsServiceNames);
|
||||
|
||||
[DllImport("rstrtmgr.dll", CharSet = CharSet.Auto)]
|
||||
static extern int RmStartSession(out uint pSessionHandle, int dwSessionFlags, string strSessionKey);
|
||||
|
||||
[DllImport("rstrtmgr.dll")]
|
||||
static extern int RmEndSession(uint pSessionHandle);
|
||||
[LibraryImport("rstrtmgr.dll")]
|
||||
private static partial int RmEndSession(uint pSessionHandle);
|
||||
|
||||
[DllImport("rstrtmgr.dll")]
|
||||
static extern int RmGetList(uint dwSessionHandle,
|
||||
@@ -87,21 +81,20 @@ namespace ZuneModCore.Win32
|
||||
/// </remarks>
|
||||
static public List<Process> WhoIsLocking(string path)
|
||||
{
|
||||
uint handle;
|
||||
string key = Guid.NewGuid().ToString();
|
||||
List<Process> processes = new List<Process>();
|
||||
List<Process> processes = [];
|
||||
|
||||
int res = RmStartSession(out handle, 0, key);
|
||||
if (res != 0) throw new Exception("Could not begin restart session. Unable to determine file locker.");
|
||||
int res = RmStartSession(out uint handle, 0, key);
|
||||
if (res != 0)
|
||||
throw new Exception("Could not begin restart session. Unable to determine file locker.");
|
||||
|
||||
try
|
||||
{
|
||||
const int ERROR_MORE_DATA = 234;
|
||||
uint pnProcInfoNeeded = 0,
|
||||
pnProcInfo = 0,
|
||||
uint pnProcInfo = 0,
|
||||
lpdwRebootReasons = RmRebootReasonNone;
|
||||
|
||||
string[] resources = new string[] { path }; // Just checking on one resource.
|
||||
string[] resources = [path]; // Just checking on one resource.
|
||||
|
||||
res = RmRegisterResources(handle, (uint)resources.Length, resources, 0, null, 0, null);
|
||||
|
||||
@@ -110,7 +103,7 @@ namespace ZuneModCore.Win32
|
||||
//Note: there's a race condition here -- the first call to RmGetList() returns
|
||||
// the total number of process. However, when we call RmGetList() again to get
|
||||
// the actual processes this number may have increased.
|
||||
res = RmGetList(handle, out pnProcInfoNeeded, ref pnProcInfo, null, ref lpdwRebootReasons);
|
||||
res = RmGetList(handle, out uint pnProcInfoNeeded, ref pnProcInfo, null, ref lpdwRebootReasons);
|
||||
|
||||
if (res == ERROR_MORE_DATA)
|
||||
{
|
||||
@@ -147,5 +140,4 @@ namespace ZuneModCore.Win32
|
||||
|
||||
return processes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace ZuneModCore.Win32
|
||||
namespace ZuneModCore.Win32;
|
||||
|
||||
public class RegEdit
|
||||
{
|
||||
|
||||
#pragma warning disable CA1416 // Validate platform compatibility
|
||||
|
||||
public class RegEdit
|
||||
{
|
||||
public const string ZUNE_REG_PATH = @"SOFTWARE\Microsoft\Zune\";
|
||||
|
||||
public static bool CurrentUserSetBoolValue(string key, string name, bool value)
|
||||
{
|
||||
RegistryKey? regKey = Registry.CurrentUser.OpenSubKey(key, true);
|
||||
if (regKey == null)
|
||||
regKey = Registry.CurrentUser.CreateSubKey(key, true);
|
||||
regKey ??= Registry.CurrentUser.CreateSubKey(key, true);
|
||||
|
||||
regKey.SetValue(name, value, RegistryValueKind.DWord);
|
||||
regKey.Close();
|
||||
@@ -66,8 +62,4 @@ namespace ZuneModCore.Win32
|
||||
|
||||
regKey.DeleteValue(name, false);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning restore CA1416 // Validate platform compatibility
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Principal;
|
||||
using Vanara.PInvoke;
|
||||
|
||||
namespace ZuneModCore.Win32
|
||||
namespace ZuneModCore.Win32;
|
||||
|
||||
public class TokenManipulator
|
||||
{
|
||||
public class TokenManipulator
|
||||
{
|
||||
public static bool AddPrivilege(string privilege)
|
||||
{
|
||||
try
|
||||
@@ -54,7 +53,6 @@ namespace ZuneModCore.Win32
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable CA1416 // Validate platform compatibility
|
||||
public static void TakeOwnership(FileInfo file)
|
||||
{
|
||||
EscalateToAdmin();
|
||||
@@ -94,7 +92,6 @@ namespace ZuneModCore.Win32
|
||||
else if (info is DirectoryInfo dir)
|
||||
TakeOwnership(dir);
|
||||
}
|
||||
#pragma warning restore CA1416 // Validate platform compatibility
|
||||
|
||||
public static bool TryTakeOwnership(FileInfo file, out Exception? exception)
|
||||
{
|
||||
@@ -119,5 +116,4 @@ namespace ZuneModCore.Win32
|
||||
AddPrivilege("SeBackupPrivilege"); // Necessary to bypass Traverse Checking
|
||||
AddPrivilege("SeTakeOwnershipPrivilege"); // Necessary to override FilePermissions
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<LangVersion>9</LangVersion>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<LangVersion>12</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<Platforms>AnyCPU;x64;x86</Platforms>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
|
||||
Reference in New Issue
Block a user