public List <MinecraftAssembly> CheckLibraries(KMCCC.Launcher.Version version) { List <MinecraftAssembly> missing = new List <MinecraftAssembly>(); List <Library> missingLib = Core.CheckLibraries(version); foreach (Library lib in missingLib) { string dName = lib.Url.Substring(lib.Url.LastIndexOf('/') + 1); missing.Add(new MinecraftAssembly { Name = dName, Path = Core.GetLibPath(lib), Url = lib.Url }); } return(missing); }
private async void Btn_启动_Click(object sender, RoutedEventArgs e) { if (设置框.IsVisible) { Nosave(); return; } Btn_启动.IsEnabled = false; runts.Text = "正在启动中"; runts.Visibility = Visibility.Visible; if (ListVersions.Items.Count == 0) { await this.ShowMessageAsync("无法启动游戏", "没有读取到游戏版本", MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "确定" }); Btn_启动.IsEnabled = true; runts.Text = null; load.Visibility = Visibility.Hidden; return; } if (DownWindow.bgWorker.IsBusy) { //bgWorker.IsBusy await this.ShowMessageAsync("正在下载", "正在下载资源文件", MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "确定" }); // new downWindow { Owner = this }.ShowDialog(); //downWindow.Showdown(); downw.ShowDialog(); //this.Hide(); //down.Show(); } else { runts.Text = "检查支持库"; lostFlie.Clear();//清空列表,防止重新启动后,列表重复 ver = (Version)ListVersions.SelectedItem; core = LauncherCore.Create(); var version = ver;//设置读取的版本配置为当前选择的项 var jarid = ver.JarId; // MessageBox.Show(core.GetVersionJsonPath(jarid)); if (!File.Exists(core.GetVersionJsonPath(jarid))) { Ts("无法启动游戏", "游戏核心不存在,请确认已选择正确的核心版本!"); runts.Visibility = Visibility.Hidden; Btn_启动.Content = "启动游戏"; load.Visibility = Visibility.Hidden; return; } try { var libs = version.Libraries.Select(lib => core.GetLibPath(lib)); var natives = version.Natives.Select(native => core.GetNativePath(native)); foreach (string libflie in libs) { if (!File.Exists(libflie)) { lostFlie.Add(libflie); // MessageBox.Show("当前缺少的Libraries文件有:" + file); } } foreach (string libflie in natives) { if (!File.Exists(libflie)) { lostFlie.Add(libflie); //MessageBox.Show("当前缺少的Libraries-natives文件有:" + file); } } if (lostFlie.Count != 0) { //返回一个值,中止继续执行后面的代码 new DownWindow { Owner = this }.ShowDialog(); } } catch { Ts("无法启动游戏", "版本信息获取失败,无法读取所需的支持库,请确认已选择正确的核心版本!"); runts.Visibility = Visibility.Hidden; Btn_启动.Content = "启动游戏"; load.Visibility = Visibility.Hidden; return; } lostFlie.Clear(); lostasset.Clear(); lostlegacyasset.Clear(); runts.Text = "检查资源文件"; if (!Directory.Exists(rundir + ".minecraft/assets/indexes")) { Directory.CreateDirectory(rundir + ".minecraft/assets/indexes");//创建文件夹 } if (!Directory.Exists(rundir + ".minecraft/assets/objects")) { Directory.CreateDirectory(rundir + ".minecraft/assets/objects");//创建文件夹 } var jsondir = core.GetVersionJsonPath(jarid); string json = File.ReadAllText(jsondir); // MessageBox.Show(core.VersionLocator); JsonData data = JsonMapper.ToObject(json); string type; string url; try { type = data["assetIndex"]["id"].ToString(); url = data["assetIndex"]["url"].ToString().Replace("https://launchermeta.mojang.com", "http://download.mcbbs.net"); if (type != "legacy") { string jsonindex; if (File.Exists(rundir + @".minecraft\assets\indexes\" + type + ".json")) { jsonindex = File.ReadAllText(rundir + @".minecraft\assets\indexes\" + type + ".json"); } else { jsonindex = Beelogin.GetGeneralContent(url); File.WriteAllText(rundir + @".minecraft\assets\indexes\" + type + ".json", jsonindex, Encoding.Default); } JsonData jdata = JsonMapper.ToObject(jsonindex); jdata = jdata["objects"]; string hash; string two; string lj; for (int i = 0; i < jdata.Count; i++) { hash = jdata[i]["hash"].ToString(); two = hash.Substring(0, 2); lj = two + "\\" + hash; if (!File.Exists(rundir + @".minecraft\assets\objects\" + lj)) { lostasset.Add(hash); } } } else if (type == "legacy") { string jsonindex; if (File.Exists(rundir + @".minecraft\assets\indexes\legacy.json")) { jsonindex = File.ReadAllText(rundir + ".minecraft/assets/indexes/legacy.json"); } else { jsonindex = Beelogin.GetGeneralContent(url); } File.WriteAllText(rundir + @".minecraft\assets\indexes\legacy.json", jsonindex, Encoding.Default); JObject jdata = (JObject)JsonConvert.DeserializeObject(jsonindex); jdata = (JObject)jdata["objects"]; // jdata = jdata["objects"]; foreach (var name in jdata) { //MessageBox.Show(rundir + @".minecraft\assets\" + name.Key); if (!File.Exists(rundir + @".minecraft\assets\" + name.Key)) { lostlegacyasset.Add(name.Key.Replace("/", "\\")); } } } } catch { type = data["assets"].ToString(); url = "null"; if (type != "legacy") { string jsonindex; if (File.Exists(rundir + @".minecraft\assets\indexes\" + type + ".json")) { jsonindex = File.ReadAllText(rundir + @".minecraft\assets\indexes\" + type + ".json"); JsonData jdata = JsonMapper.ToObject(jsonindex); jdata = jdata["objects"]; string hash; string two; string lj; for (int i = 0; i < jdata.Count; i++) { hash = jdata[i]["hash"].ToString(); two = hash.Substring(0, 2); lj = two + "\\" + hash; if (!File.Exists(rundir + @".minecraft\assets\objects\" + lj)) { lostasset.Add(hash); } } lostassets = false; } else { lostassets = true; } } else if (type == "legacy") { string jsonindex; if (File.Exists(rundir + @".minecraft\assets\indexes\legacy.json")) { jsonindex = File.ReadAllText(rundir + ".minecraft/assets/indexes/legacy.json"); File.WriteAllText(rundir + @".minecraft\assets\indexes\legacy.json", jsonindex, Encoding.Default); JObject jdata = (JObject)JsonConvert.DeserializeObject(jsonindex); jdata = (JObject)jdata["objects"]; // jdata = jdata["objects"]; foreach (var name in jdata) { //MessageBox.Show(rundir + @".minecraft\assets\" + name.Key); if (!File.Exists(rundir + @".minecraft\assets\" + name.Key)) { lostlegacyasset.Add(name.Key.Replace("/", "\\")); } } lostassets = false; } else { lostassets = true; } } } try { if (lostasset.Count != 0 || lostlegacyasset.Count != 0) { if (url == "null") { await this.ShowMessageAsync("资源文件缺失", "发现缺少了" + (lostasset.Count != 0 ? lostasset.Count.ToString() : lostlegacyasset.Count != 0 ? lostlegacyasset.Count.ToString() : null) + "个资源文件,这可能导致游戏声音丢失\n但您的游戏核心版本较旧,不能自动补全.\n建议前往下载游戏窗口下载新版本客户端!", MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "确定" }); // Ts("资源文件缺失", "发现缺少了" + (lostasset.Count != 0 ? lostasset.Count.ToString() : lostlegacyasset.Count != 0 ? lostlegacyasset.Count.ToString() : null) + "个资源文件,但您的游戏核心版本较旧,不能自动补全.\n建议前往下载游戏窗口下载新版本客户端!"); } else { // new downWindow { Owner = this }.ShowDialog(); downw.Owner = this; downw.ShowDialog(); } } } catch { //ts("错误", "尝试检查资源文件时失败,建议前往下载游戏窗口下载新版本客户端!"); lostassets = true; // await this.ShowMessageAsync("错误", "尝试检查资源文件时失败,建议前往下载游戏窗口下载新版本客户端!", MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "确定" }); } } if (!bgWorker.IsBusy) { //MessageBox.Show("1"); // bgWorker.CancelAsync(); //bgWorker.Dispose(); if (islaunch) { bgWorker.RunWorkerAsync(); } else { bgWorker.WorkerReportsProgress = true; bgWorker.ProgressChanged += new ProgressChangedEventHandler(Bw_ProgressChanged); bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Bw_RunWorkerCompleted); bgWorker.DoWork += new DoWorkEventHandler(Bw_DoWork1); bgWorker.RunWorkerAsync(); islaunch = true; } } }