Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BedrockLauncher.Core.slnx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<Solution>
<Project Path="BedrockLauncher.Core/BedrockLauncher.Core.csproj" />
<Project Path="CoreTest/CoreTest.csproj" Id="6db1b9d0-2f09-4dcd-96ad-7844c4792ed5" />
<Project Path="TestProject/TestProject.csproj" Id="3eb9c45c-7961-4af0-aeec-b14a7faba7d5" />
</Solution>
19 changes: 5 additions & 14 deletions BedrockLauncher.Core/BedrockCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
{
if (!GetWindowsDevelopmentState())
{
OpenWindowsDevelopment();
throw new BedrockCoreException("Windows Developer Mode is required for non-admin UWP loose package registration. Please enable Developer Mode in Windows settings.");
}
}

Expand Down Expand Up @@ -100,18 +100,9 @@
}

/// <summary>
/// Enables Windows Developer Mode by modifying the system registry to allow development without a developer license.
/// Opens Windows Settings so the current user can enable Developer Mode without requiring this process to run elevated.
/// </summary>
/// <remarks>
/// Administrator privileges are required to modify the system registry. Enabling Developer Mode
/// allows the installation and testing of apps without a developer license. Use with caution, as modifying the
/// registry can affect system stability and security.
/// </remarks>
/// <returns>true if Developer Mode is successfully enabled; otherwise, false.</returns>
/// <exception cref="Exception">
/// Thrown if the operation fails to enable Developer Mode, such as due to insufficient permissions or registry access
/// errors.
/// </exception>
/// <returns>true if the settings page was opened; otherwise, false.</returns>
public bool OpenWindowsDevelopment()
{
try
Expand Down Expand Up @@ -162,7 +153,7 @@
};
isHasVCwin32 = CheckVersion(registryPaths);
var packageManager = new PackageManager();
var packages = packageManager.FindPackages();
var packages = packageManager.FindPackagesForUser(string.Empty);

var vcRuntimePackages = packages.Where(p =>
p.Id.Name.Contains("Microsoft.VCLibs.140")
Expand Down Expand Up @@ -253,7 +244,7 @@

if (processes.Length > 0)
{
return processes

Check warning on line 247 in BedrockLauncher.Core/BedrockCore.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Possible null reference return.

Check warning on line 247 in BedrockLauncher.Core/BedrockCore.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Possible null reference return.
.Where(p => p.StartTime > startTime)
.OrderBy(p => (p.StartTime - startTime).TotalMilliseconds)
.FirstOrDefault();
Expand All @@ -263,7 +254,7 @@
await Task.Delay(200);
}

return null;

Check warning on line 257 in BedrockLauncher.Core/BedrockCore.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Possible null reference return.

Check warning on line 257 in BedrockLauncher.Core/BedrockCore.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Possible null reference return.
}
private static DateTime GetStartTimeSafe(Process proc)
{
Expand Down Expand Up @@ -304,7 +295,7 @@
UseShellExecute = true
});

Process minecraftProcess = null;

Check warning on line 298 in BedrockLauncher.Core/BedrockCore.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Converting null literal or possible null value to non-nullable type.

Check warning on line 298 in BedrockLauncher.Core/BedrockCore.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Converting null literal or possible null value to non-nullable type.


for (int i = 0; i < 10; i++)
Expand Down Expand Up @@ -360,7 +351,7 @@
}
PackageManager packageManager = new PackageManager();
bool twice_launch = false;
foreach (var package in packageManager.FindPackages())
foreach (var package in packageManager.FindPackagesForUser(string.Empty))
{
if (package.Id.Name.Equals(packageName, StringComparison.OrdinalIgnoreCase))
{
Expand Down Expand Up @@ -418,7 +409,7 @@
processes = processes.Concat(process_oldVersion).ToArray();
process = processes.OrderBy(p => p.StartTime).Last();
}
return process;

Check warning on line 412 in BedrockLauncher.Core/BedrockCore.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Possible null reference return.

Check warning on line 412 in BedrockLauncher.Core/BedrockCore.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Possible null reference return.
}
/// <summary>
/// Remove Uwp Minecraft Game
Expand Down
4 changes: 2 additions & 2 deletions BedrockLauncher.Core/BedrockLauncher.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<Version>2.0.4.2-dev</Version>
<Version>2.0.4.3-dev</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<Version>2.0.4.2</Version>
<Version>2.0.4.3</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
70 changes: 43 additions & 27 deletions BedrockLauncher.Core/UwpRegister/UwpRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,25 @@ public class DeploymentOptionsConfig
public class UwpRegister
{
/// <summary>
/// Registers an appx package with flexible configuration (no admin required)
/// Registers an unpacked appx package for the current user in developer mode (no admin required).
/// </summary>
/// <param name="config">Deployment configuration options</param>
/// <returns>Deployment result containing operation status</returns>
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(PackageManager))]
public static async Task<DeploymentResult> RegisterAppxAsync(DeploymentOptionsConfig config)
{
ValidateConfig(config);

// 处理包路径,确保是文件夹路径
string packageFolderPath = config.PackagePath;
if (packageFolderPath.StartsWith("file://"))
{
packageFolderPath = new Uri(packageFolderPath).LocalPath;
}

// 移除签名文件(如果存在)

var packageUri = GetPackageUri(config.PackagePath);
var packageFolderPath = GetPackageFolderPath(packageUri);

RemoveSignatureFile(packageFolderPath);

var manager = new PackageManager();
var asyncOperation = manager.RegisterPackageAsync(
new Uri(config.PackagePath),
packageUri,
null,
config.DeploymentOptions | DeploymentOptions.DevelopmentMode);
ToCurrentUserDevelopmentOptions(config.DeploymentOptions));

return await ExecuteWithTimeout(asyncOperation, config);
}
Expand All @@ -80,26 +75,44 @@ public static async Task<DeploymentResult> RegisterAppxAsync(DeploymentOptionsCo
public static async Task<DeploymentResult> AddAppxAsync(DeploymentOptionsConfig config)
{
ValidateConfig(config);

// 处理包路径,确保是文件夹路径
string packageFolderPath = config.PackagePath;
if (packageFolderPath.StartsWith("file://"))
{
packageFolderPath = new Uri(packageFolderPath).LocalPath;
}

// 移除签名文件(如果存在)

var packageUri = GetPackageUri(config.PackagePath);
var packageFolderPath = GetPackageFolderPath(packageUri);

RemoveSignatureFile(packageFolderPath);

var packageManager = new PackageManager();
var asyncOperation = packageManager.AddPackageAsync(
new Uri(config.PackagePath),
packageUri,
null,
config.DeploymentOptions | DeploymentOptions.DevelopmentMode);
ToCurrentUserDevelopmentOptions(config.DeploymentOptions));

return await ExecuteWithTimeout(asyncOperation, config);
}

private static Uri GetPackageUri(string packagePath)
{
if (Uri.TryCreate(packagePath, UriKind.Absolute, out var uri) && uri.IsFile)
{
return uri;
}

return new Uri(Path.GetFullPath(packagePath));
}

private static string GetPackageFolderPath(Uri packageUri)
{
var localPath = packageUri.LocalPath;
return File.Exists(localPath)
? Path.GetDirectoryName(localPath) ?? localPath
: localPath;
}

private static DeploymentOptions ToCurrentUserDevelopmentOptions(DeploymentOptions options)
{
return options | DeploymentOptions.DevelopmentMode;
}

/// <summary>
/// Removes the signature file from the package folder
/// </summary>
Expand Down Expand Up @@ -141,7 +154,7 @@ public static bool CheckForPackageVersion(string packageName, string version)
{
PackageManager packageManager = new PackageManager();

foreach (var package in packageManager.FindPackages())
foreach (var package in packageManager.FindPackagesForUser(string.Empty))
{
if (package.Id.Name == packageName)
{
Expand All @@ -164,7 +177,7 @@ public static bool IsPackageInstalled(string packageName)

PackageManager packageManager = new PackageManager();

foreach (var package in packageManager.FindPackages())
foreach (var package in packageManager.FindPackagesForUser(string.Empty))
{
if (package.Id.Name.Equals(packageName, StringComparison.OrdinalIgnoreCase))
{
Expand All @@ -180,8 +193,11 @@ private static void ValidateConfig(DeploymentOptionsConfig config)
if (string.IsNullOrWhiteSpace(config.PackagePath))
throw new ArgumentException("Package path cannot be null or empty", nameof(config));

if (!Uri.TryCreate(config.PackagePath, UriKind.Absolute, out _))
throw new ArgumentException("Package path must be a valid absolute URI", nameof(config));
if (Uri.TryCreate(config.PackagePath, UriKind.Absolute, out var uri) && uri.IsFile)
return;

if (!Path.IsPathFullyQualified(config.PackagePath))
throw new ArgumentException("Package path must be an absolute file path or file URI", nameof(config));
}
}
}
6 changes: 3 additions & 3 deletions CoreTest/LaunchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public void Test()
bedrockCore.InitAsync().Wait();
var launchOptions = new LaunchOptions()
{
GameFolder = Path.GetFullPath(@"E:\test2\plugins\Glacie\bedrock_versions\1.26.2"),
MinecraftBuildType = MinecraftBuildTypeVersion.GDK,
GameType = MinecraftGameTypeVersion.Release,
GameFolder = Path.GetFullPath(@"D:\BedrockBoot\bedrock_versions\1.21.12020"),
MinecraftBuildType = MinecraftBuildTypeVersion.UWP,
GameType = MinecraftGameTypeVersion.Preview,
LaunchArgs = null
};
var process = bedrockCore.LaunchGameAsync(launchOptions).Result;
Expand Down
24 changes: 24 additions & 0 deletions TestProject/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using BedrockLauncher.Core;
using BedrockLauncher.Core.CoreOption;
using System.Diagnostics;

namespace TestProject
{
internal class Program
{
static void Main(string[] args)
{
var bedrockCore = new BedrockCore();
bedrockCore.InitAsync().Wait();
var launchOptions = new LaunchOptions()
{
GameFolder = Path.GetFullPath(@"E:\Bedrock\bedrock_versions\1.21.11401"),
MinecraftBuildType = MinecraftBuildTypeVersion.UWP,
GameType = MinecraftGameTypeVersion.Release,
LaunchArgs = null
};
var process = bedrockCore.LaunchGameAsync(launchOptions).Result;
Console.WriteLine(process.Id);
}
}
}
15 changes: 15 additions & 0 deletions TestProject/TestProject.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<SupportedOSPlatformVersion>10.0.19041.0</SupportedOSPlatformVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\BedrockLauncher.Core\BedrockLauncher.Core.csproj" />
</ItemGroup>

</Project>
Loading