public static void RegisterMinecraftAppxPackage(string appxPackagePath) {
try {
// Register if it is already extracted
if (Directory.Exists(appxPackagePath)) {
// Remove the current install
DeregisterMinecraftPackage();
// Invoke PowerShell to register the appx package
var powerShellCommand = $"Add-AppxPackage -Path '{Path.Combine(appxPackagePath, "AppxManifest.xml")}' -DisableDevelopmentMode -ForceUpdateFromAnyVersion -Register";
using (var process = new Process {
// set the values needed
StartInfo = new ProcessStartInfo {
FileName = "powershell.exe",
Arguments = powerShellCommand,
RedirectStandardOutput = true, // we want to be able to read the response message
UseShellExecute = false, // dotnet core can handle it for us
CreateNoWindow = true, // execute headlessley
}
}) {
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
Debug.WriteLine(output);
}
} else if (Path.GetExtension(appxPackagePath).ToLower().Equals(".appx")) { // Extract then register
string directoryName = Path.GetFileNameWithoutExtension(appxPackagePath);
string extractPath = Path.Combine(Path.GetDirectoryName(appxPackagePath), directoryName);
Directory.CreateDirectory(extractPath);
ZipFile.ExtractToDirectory(appxPackagePath, extractPath);
RegisterMinecraftAppxPackage(extractPath); // Recursively register the package
}
} catch (Exception e) {
Debug.WriteLine(e.StackTrace);
}
}
public static void RegisterMinecraftAppxPackage(string appxPackagePath) {
try {
// Register if it is already extracted
if (Directory.Exists(appxPackagePath)) {
// Remove the current install
DeregisterMinecraftPackage();
// Invoke PowerShell to register the appx package
var powerShellCommand = $"Add-AppxPackage -Path '{Path.Combine(appxPackagePath, "AppxManifest.xml")}' -DisableDevelopmentMode -ForceUpdateFromAnyVersion -Register";
using (var process = new Process {
// set the values needed
StartInfo = new ProcessStartInfo {
FileName = "powershell.exe",
Arguments = powerShellCommand,
RedirectStandardOutput = true, // we want to be able to read the response message
UseShellExecute = false, // dotnet core can handle it for us
CreateNoWindow = true, // execute headlessley
}
}) {
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
Debug.WriteLine(output);
}
} else if (Path.GetExtension(appxPackagePath).ToLower().Equals(".appx")) { // Extract then register
string directoryName = Path.GetFileNameWithoutExtension(appxPackagePath);
string extractPath = Path.Combine(Path.GetDirectoryName(appxPackagePath), directoryName);
Directory.CreateDirectory(extractPath);
ZipFile.ExtractToDirectory(appxPackagePath, extractPath);
RegisterMinecraftAppxPackage(extractPath); // Recursively register the package
}
} catch (Exception e) {
Debug.WriteLine(e.StackTrace);
}
}