private string GetEnvironmentInfo() { StringBuilder builder = new StringBuilder(); builder.Append("\r\n==========环境信息=========="); builder.Append("\r\nCPU信息:" + SystemTools.GetProcessorInfo()); builder.Append("\r\n内存信息: 总大小:" + SystemTools.GetTotalMemory().ToString() + "MB/可用大小:" + SystemTools.GetRunmemory().ToString() + "MB"); builder.Append("\r\n显卡信息:" + SystemTools.GetVideoCardInfo()); builder.Append("\r\n操作系统:" + Environment.OSVersion.Platform); builder.Append("\r\n版本号:" + Environment.OSVersion.VersionString); builder.Append("\r\n系统位数:" + SystemTools.GetSystemArch()); builder.Append("\r\n程序运行命令行:" + Environment.CommandLine); builder.Append("\r\n程序工作目录:" + Environment.CurrentDirectory); return(builder.ToString()); }
private async void mainWindow_Loaded(object sender, RoutedEventArgs e) { #region 无JAVA提示 if (App.handler.Java == null) { var result = await this.ShowMessageAsync(App.GetResourceString("String.Message.NoJava"), App.GetResourceString("String.Message.NoJava2"), MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = App.GetResourceString("String.Base.Yes"), NegativeButtonText = App.GetResourceString("String.Base.Cancel"), DefaultButtonFocus = MessageDialogResult.Affirmative }); if (result == MessageDialogResult.Affirmative) { var arch = SystemTools.GetSystemArch(); switch (arch) { case ArchEnum.x32: App.downloader.SetDownloadTasks(new DownloadTask("32位JAVA安装包", @"https://bmclapi.bangbang93.com/java/jre_x86.exe", "jre_x86.exe")); App.downloader.StartDownload(); await new DownloadWindow().ShowWhenDownloading(); System.Diagnostics.Process.Start("Explorer.exe", "jre_x86.exe"); break; case ArchEnum.x64: App.downloader.SetDownloadTasks(new DownloadTask("64位JAVA安装包", @"https://bmclapi.bangbang93.com/java/jre_x64.exe", "jre_x64.exe")); App.downloader.StartDownload(); await new DownloadWindow().ShowWhenDownloading(); System.Diagnostics.Process.Start("Explorer.exe", "jre_x64.exe"); break; default: break; } } } #endregion #region 检查更新 if (App.config.MainConfig.Launcher.CheckUpdate) { await CheckUpdate(); } #endregion }
public Modules.MCVersion JsonToVersion(JObject obj) { Modules.MCVersion ver = new Modules.MCVersion(); ver = obj.ToObject <Modules.MCVersion>(); JObject innerVer = null; if (ver.InheritsVersion != null) { SendDebugLog(string.Format("检测到\"{0}\"继承于\"{1}\"", ver.ID, ver.InheritsVersion)); string innerJsonStr = GetVersionJsonText(ver.InheritsVersion); if (innerJsonStr != null) { innerVer = JObject.Parse(innerJsonStr); } } if (obj.ContainsKey("arguments")) { #region 处理新版本引导 SendDebugLog(string.Format("检测到\"{0}\"使用新版本启动参数", ver.ID)); #region 处理版本继承 if (innerVer != null && innerVer.ContainsKey("arguments")) { JObject innerVerArg = (JObject)innerVer["arguments"]; if (innerVerArg.ContainsKey("game")) { ver.MinecraftArguments += string.Format("{0} ", ParseGameArgFromJson(innerVerArg["game"])); } if (innerVerArg.ContainsKey("jvm")) { ver.JvmArguments += string.Format("{0} ", ParseJvmArgFromJson(innerVerArg["jvm"])); } } #endregion JObject verArg = (JObject)obj["arguments"]; #region 游戏参数 if (verArg.ContainsKey("game")) { JToken gameArg = verArg["game"]; ver.MinecraftArguments += ParseGameArgFromJson(gameArg); } #endregion #region JVM参数 if (verArg.ContainsKey("jvm")) { JToken jvmArg = verArg["jvm"]; ver.JvmArguments += ParseJvmArgFromJson(jvmArg); } #endregion } #endregion else { #region 旧版本添加默认JVM参数 SendDebugLog(string.Format("检测到\"{0}\"使用旧版本启动参数", ver.ID)); ver.JvmArguments = "-Djava.library.path=${natives_directory} -cp ${classpath}"; #endregion } #region 处理依赖 ver.Libraries = new List <Library>(); ver.Natives = new List <Native>(); var libToken = obj["libraries"]; foreach (JToken lib in libToken) { var libObj = lib.ToObject <JLibrary>(); if (CheckAllowed(libObj.Rules)) { if (libObj.Natives == null) { //不为native Library library = new Library(libObj.Name); if (!string.IsNullOrWhiteSpace(libObj.Url)) { library.Url = libObj.Url; } if (libObj.Downloads?.Artifact != null) { library.LibDownloadInfo = libObj.Downloads.Artifact; } ver.Libraries.Add(library); } else { ///为native Native native = new Native(libObj.Name, libObj.Natives["windows"].Replace("${arch}", SystemTools.GetSystemArch() == ArchEnum.x64 ? "64" : "32")); if (libObj.Extract != null) { native.Exclude = libObj.Extract.Exculde; } if (libObj.Downloads?.Artifact != null) { native.LibDownloadInfo = libObj.Downloads.Artifact; } if (libObj.Downloads?.Classifiers?.Natives != null) { native.NativeDownloadInfo = libObj.Downloads.Classifiers.Natives; } ver.Natives.Add(native); } } } #endregion #region 处理版本继承 if (innerVer != null) { var iv = JsonToVersion(innerVer); if (iv != null) { ver.Assets = iv.Assets; ver.AssetIndex = iv.AssetIndex; ver.Natives.AddRange(iv.Natives); ver.Libraries.AddRange(iv.Libraries); ver.Jar = iv.ID; } } #endregion return(ver); }
private string ParseJvmArgFromJson(JToken jvmArg) { StringBuilder jvmArgBuilder = new StringBuilder(); foreach (var arg in jvmArg) { if (arg.Type == JTokenType.String) { jvmArgBuilder.AppendFormat("{0} ", arg.ToString()); } else if (arg.Type == JTokenType.Object) { JObject argObj = (JObject)arg; if (argObj.ContainsKey("rules")) { JToken rules = arg["rules"]; #region 规则参数处理 foreach (var rule in rules) { if (rule["action"].ToString() == "allow") { #region 判断是否合法 JObject OS = (JObject)rule["os"]; if (OS.ContainsKey("arch")) { string arch = OS["arch"].ToString(); switch (SystemTools.GetSystemArch()) { case ArchEnum.x32: if (arch != "x86") { continue; } break; case ArchEnum.x64: if (arch != "x64") { continue; } break; default: continue; } } if (OS.ContainsKey("name")) { if (OS["name"].ToString() == "windows") { if (OS.ContainsKey("version")) { if (!Regex.Match(Environment.OSVersion.Version.ToString(), OS["version"].ToString()).Success) { continue; } } } else { continue; } } #endregion if (arg["value"].Type == JTokenType.String) { string value = arg["value"].ToString(); if (value.Contains(" ")) { jvmArgBuilder.AppendFormat("\"{0}\" ", value); } else { jvmArgBuilder.AppendFormat("{0} ", value); } } else if (arg["value"].Type == JTokenType.Array) { foreach (var str in arg["value"]) { string value = str.ToString(); if (value.Contains(" ")) { jvmArgBuilder.AppendFormat("\"{0}\" ", value); } else { jvmArgBuilder.AppendFormat("{0} ", value); } } } } } #endregion } else { JToken valueJtoken = argObj["value"]; if (valueJtoken.Type == JTokenType.String) { jvmArgBuilder.AppendFormat("{0} ", valueJtoken.ToString()); } else if (valueJtoken.Type == JTokenType.Array) { foreach (var item in valueJtoken) { jvmArgBuilder.AppendFormat("{0} ", item.ToString()); } } } } } return(jvmArgBuilder.ToString().Trim()); }