From 536e3ae28cedc9eab12ca616e9ea58ca80daac1d Mon Sep 17 00:00:00 2001 From: Eric Stevens Date: Tue, 3 Mar 2020 09:48:02 +0800 Subject: [PATCH 1/2] Implement early revision of MinecraftUWP support. --- Class/Helper/SystemInfoHelper.cs | 26 +++++++- .../Launch/DefaultMinecraftUWPCore.cs | 63 +++++++++++++++++++ ProjBobcat.csproj | 4 ++ ProjBobcat.nuspec | 5 +- Properties/AssemblyInfo.cs | 4 +- README.md | 1 + README_zh_cn.md | 1 + packages.config | 1 + 8 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 DefaultComponent/Launch/DefaultMinecraftUWPCore.cs diff --git a/Class/Helper/SystemInfoHelper.cs b/Class/Helper/SystemInfoHelper.cs index 5efd7c9e..8732185e 100644 --- a/Class/Helper/SystemInfoHelper.cs +++ b/Class/Helper/SystemInfoHelper.cs @@ -1,6 +1,10 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; +using System.Management.Automation; +using System.Management.Automation.Runspaces; +using System.Text; using Microsoft.Win32; namespace ProjBobcat.Class.Helper @@ -8,9 +12,10 @@ namespace ProjBobcat.Class.Helper public static class SystemInfoHelper { /// + /// Detect javaw.exe via reg. /// 从注册表中查找可能的javaw.exe位置 /// - /// JAVA地址列表 + /// A list, containing all possible path of javaw.exe. JAVA地址列表。 public static IEnumerable FindJava() { try @@ -67,8 +72,25 @@ public static string GetSystemVersion() "6.0" => "2008", "5.2" => "2003", "5.1" => "XP", - _ => "unknow" + _ => "unknown" }; } + + public static bool IsMinecraftUWPInstalled() + { + Runspace rs = RunspaceFactory.CreateRunspace(); + rs.Open(); + Pipeline pl = rs.CreatePipeline(); + pl.Commands.AddScript("Get-AppxPackage -Name \"Microsoft.MinecraftUWP\""); + pl.Commands.Add("Out-String"); + Collection result = pl.Invoke(); + rs.Close(); + rs.Dispose(); + if (result == null || String.IsNullOrEmpty(result[0].ToString())) + { + return false; + } + return true; + } } } \ No newline at end of file diff --git a/DefaultComponent/Launch/DefaultMinecraftUWPCore.cs b/DefaultComponent/Launch/DefaultMinecraftUWPCore.cs new file mode 100644 index 00000000..43e3fac2 --- /dev/null +++ b/DefaultComponent/Launch/DefaultMinecraftUWPCore.cs @@ -0,0 +1,63 @@ +using ProjBobcat.Class.Helper; +using ProjBobcat.Interface; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjBobcat.DefaultComponent.Launch +{ + public class DefaultMinecraftUWPCore + { + public static void LaunchMinecraftUWP() + { + if (SystemInfoHelper.IsMinecraftUWPInstalled() == false) + { + throw new InvalidOperationException(); + } + using (Process process = new Process()) + { + process.StartInfo.UseShellExecute = true; + process.StartInfo.FileName = "minecraft:"; + process.Exited += GameExit; + process.Start(); + } + } + + private static void GameExit(object sender, EventArgs e) + { + throw new NotImplementedException(); + } + + #region IDisposable Support + + // Dispose() calls Dispose(true) + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + // NOTE: Leave out the finalizer altogether if this class doesn't + // own unmanaged resources, but leave the other methods + // exactly as they are. + ~DefaultGameCore() + { + // Finalizer calls Dispose(false) + Dispose(false); + } + + // The bulk of the clean-up code is implemented in Dispose(bool) + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + VersionLocator = null; + } + } + + #endregion + } +} diff --git a/ProjBobcat.csproj b/ProjBobcat.csproj index 62b82b2b..55568048 100644 --- a/ProjBobcat.csproj +++ b/ProjBobcat.csproj @@ -64,6 +64,9 @@ + + ..\packages\Microsoft.PowerShell.5.ReferenceAssemblies.1.1.0\lib\net4\System.Management.Automation.dll + @@ -145,6 +148,7 @@ + diff --git a/ProjBobcat.nuspec b/ProjBobcat.nuspec index 7bbdfe9a..ba53b0bc 100644 --- a/ProjBobcat.nuspec +++ b/ProjBobcat.nuspec @@ -2,7 +2,7 @@ ProjBobcat - 1.0.1.4 + 1.0.1.5 ProjBobcat Corona Studio Corona Studio @@ -13,12 +13,13 @@ Bobcat.png The next-generation Minecraft launcher core written in C# providing the freest, fastest and the most complete experience. The next-generation Minecraft launcher core written in C# providing the freest, fastest and the most complete experience. - Fix critical bugs. + Add MinecraftUWP support. Copyright © 2020 Corona Studio minecraft-launcher minecraft launcher csharp + diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 52655f9c..184e4e29 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //通过使用 "*",如下所示: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.1.4")] -[assembly: AssemblyFileVersion("1.0.1.4")] \ No newline at end of file +[assembly: AssemblyVersion("1.0.1.5")] +[assembly: AssemblyFileVersion("1.0.1.5")] \ No newline at end of file diff --git a/README.md b/README.md index 977fd3b3..fc3cb6c4 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ For Chinese version of README.md, see README_zh_cn.md. | Old Forge Installation Model | ✅ | | New Forge Installation Model | ✅ | | Resource Auto Completion (Multi-thread downloader) | ✅ | +| Minecraft: Windows 10 Edition Support (Detector and launcher) | ✅ | ## Instruction diff --git a/README_zh_cn.md b/README_zh_cn.md index fccb1679..b19c5200 100644 --- a/README_zh_cn.md +++ b/README_zh_cn.md @@ -42,6 +42,7 @@ | 旧版Forge安装模型 | ✅ | | 新版Forge安装模型 | ✅ | | 资源自动补全(多线程下载) | ✅ | +| Windows 10版Minecraft支持(检测和启动) | ✅ | ## 使用说明 diff --git a/packages.config b/packages.config index b0e254ec..5eaa453d 100644 --- a/packages.config +++ b/packages.config @@ -5,6 +5,7 @@ + \ No newline at end of file From 4d6c55125bfb0f0b2a69e6ed0a2c16bd2b26b2f1 Mon Sep 17 00:00:00 2001 From: laolarou Date: Wed, 4 Mar 2020 22:19:17 -0800 Subject: [PATCH 2/2] Add UWP Launcher Core --- DefaultComponent/Launch/DefaultGameCore.cs | 5 ++ .../Launch/DefaultMinecraftUWPCore.cs | 62 ++++++++++++++----- Interface/IGameCore.cs | 1 + ProjBobcat.csproj | 2 +- app.config | 15 +++++ 5 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 app.config diff --git a/DefaultComponent/Launch/DefaultGameCore.cs b/DefaultComponent/Launch/DefaultGameCore.cs index 71360647..86210500 100644 --- a/DefaultComponent/Launch/DefaultGameCore.cs +++ b/DefaultComponent/Launch/DefaultGameCore.cs @@ -38,6 +38,11 @@ public string RootPath public event EventHandler GameLogEventDelegate; public event EventHandler LaunchLogEventDelegate; + public LaunchResult Launch(LaunchSettings settings) + { + throw new NotImplementedException(); + } + /// /// 启动游戏。 /// Launch the game. diff --git a/DefaultComponent/Launch/DefaultMinecraftUWPCore.cs b/DefaultComponent/Launch/DefaultMinecraftUWPCore.cs index 43e3fac2..16b7a9d3 100644 --- a/DefaultComponent/Launch/DefaultMinecraftUWPCore.cs +++ b/DefaultComponent/Launch/DefaultMinecraftUWPCore.cs @@ -1,29 +1,47 @@ using ProjBobcat.Class.Helper; -using ProjBobcat.Interface; using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Linq; -using System.Text; +using ProjBobcat.Interface; +using ProjBobcat.Event; using System.Threading.Tasks; +using ProjBobcat.Class.Model; namespace ProjBobcat.DefaultComponent.Launch { - public class DefaultMinecraftUWPCore + public class DefaultMinecraftUWPCore : IGameCore, IDisposable { - public static void LaunchMinecraftUWP() + [Obsolete("UWP 版本的Minecraft不需要该字段。")] + public string RootPath { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + [Obsolete("UWP 版本的Minecraft不需要该字段。")] + public Guid ClientToken { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + [Obsolete("UWP 版本的Minecraft不需要该字段。")] + public IVersionLocator VersionLocator { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + + [Obsolete("UWP 版本的Minecraft不需要该字段。")] + public event EventHandler GameExitEventDelegate; + [Obsolete("UWP 版本的Minecraft不需要该字段。")] + public event EventHandler GameLogEventDelegate; + [Obsolete("UWP 版本的Minecraft不需要该字段。")] + public event EventHandler LaunchLogEventDelegate; + + public LaunchResult Launch(LaunchSettings launchSettings) { if (SystemInfoHelper.IsMinecraftUWPInstalled() == false) { throw new InvalidOperationException(); } - using (Process process = new Process()) - { - process.StartInfo.UseShellExecute = true; - process.StartInfo.FileName = "minecraft:"; - process.Exited += GameExit; - process.Start(); - } + + using var process = new Process + {StartInfo = new ProcessStartInfo {UseShellExecute = true, FileName = "minecraft:"}}; + process.Start(); + + return default; + } + + [Obsolete("UWP启动核心并不支持异步启动")] + public Task LaunchTaskAsync(LaunchSettings settings) + { + throw new NotImplementedException(); } private static void GameExit(object sender, EventArgs e) @@ -31,6 +49,21 @@ private static void GameExit(object sender, EventArgs e) throw new NotImplementedException(); } + public void LogGameData(object sender, GameLogEventArgs e) + { + throw new NotImplementedException(); + } + + public void LogLaunchData(object sender, LaunchLogEventArgs e) + { + throw new NotImplementedException(); + } + + public void GameExit(object sender, GameExitEventArgs e) + { + throw new NotImplementedException(); + } + #region IDisposable Support // Dispose() calls Dispose(true) @@ -43,7 +76,7 @@ public void Dispose() // NOTE: Leave out the finalizer altogether if this class doesn't // own unmanaged resources, but leave the other methods // exactly as they are. - ~DefaultGameCore() + ~DefaultMinecraftUWPCore() { // Finalizer calls Dispose(false) Dispose(false); @@ -54,7 +87,6 @@ protected virtual void Dispose(bool disposing) { if (disposing) { - VersionLocator = null; } } diff --git a/Interface/IGameCore.cs b/Interface/IGameCore.cs index 973a8cae..18cf2654 100644 --- a/Interface/IGameCore.cs +++ b/Interface/IGameCore.cs @@ -13,6 +13,7 @@ public interface IGameCore string RootPath { get; set; } Guid ClientToken { get; set; } IVersionLocator VersionLocator { get; set; } + LaunchResult Launch(LaunchSettings settings); Task LaunchTaskAsync(LaunchSettings settings); /// diff --git a/ProjBobcat.csproj b/ProjBobcat.csproj index 55568048..cc81f1ad 100644 --- a/ProjBobcat.csproj +++ b/ProjBobcat.csproj @@ -171,6 +171,7 @@ + @@ -185,7 +186,6 @@ - diff --git a/app.config b/app.config new file mode 100644 index 00000000..1f0610e0 --- /dev/null +++ b/app.config @@ -0,0 +1,15 @@ + + + + +
+ + + + + + True + + + + \ No newline at end of file