public override ValueSet OnRequest(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args) { string versionID = args.Request.Message["version"].ToString(); KMCCC.Launcher.Version ver = Program.Launcher.Core.GetVersion(versionID); if (ver == null) { return(null); } ValueSet ret = new ValueSet(); ret["client"] = ver.Downloads.Client.Url; ret["client-sha1"] = ver.Downloads.Client.SHA1; ret["server"] = ver.Downloads.Server.Url; ret["server-sha1"] = ver.Downloads.Server.SHA1; return(ret); }
public override ValueSet OnRequest(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args) { ValueSet valueSet = new ValueSet(); string versionId = args.Request.Message["version"].ToString(); if (string.IsNullOrEmpty(versionId)) { return(null); } Logger.Info("Checking asset index for # " + versionId); KMCCC.Launcher.Version ver = Program.Launcher.Core.GetVersion(versionId); if (ver == null) { Logger.ErrorFormat("Version {0} dose not exist", versionId); return(null); } Logger.Info("AssetIndex: " + ver.Assets); var assetsResult = Program.Launcher.CheckAssets(ver); if (!assetsResult.hasValidIndex) { Logger.Warn("Asset index dose not exist or invalid"); valueSet["index_url"] = ver.AssetsIndex.Url; valueSet["index_path"] = string.Format(@"assets\indexes\{0}.json", ver.Assets); return(valueSet); } Logger.Info(string.Format("Found {0} missing assets", assetsResult.missingAssets.Count)); string json = JsonConvert.SerializeObject(assetsResult.missingAssets); valueSet["missing_assets"] = json; return(valueSet); }
private async void Button_Click(object sender, RoutedEventArgs e) { MinecraftVersion version = _verList.SelectedItem as MinecraftVersion; if (version == null) { return; } ViewModel.isWorking = true; try { string jsonPath = CoreManager.CoreMCL.Core.GameRootPath + "\\" + version.GetJsonPath(); using (HttpClient client = new HttpClient()) { FileInfo file = new FileInfo(jsonPath); if (!file.Directory.Exists) { file.Directory.Create(); } File.Create(jsonPath).Dispose(); File.WriteAllText(jsonPath, await client.GetStringAsync(version.url)); string jarPath; KMCCC.Launcher.Version kver = CoreManager.CoreMCL.Core.GetVersion(version.id); jarPath = CoreManager.CoreMCL.Core.GameRootPath + "\\" + version.GetJarPath(); file = new FileInfo(jarPath); if (!file.Directory.Exists) { file.Directory.Create(); } File.Create(jarPath); HttpDownloader downloader = new HttpDownloader(kver.Downloads.Client.Url, jarPath); var progressController = await MainWindow.Current.ShowProgressAsync("正在下载: " + kver.Id, "", true, DefaultDialogSettings); downloader.DownloadProgressChanged += async delegate { if (downloader.ProgressInPercent == 100) { await progressController.CloseAsync(); } else { progressController.SetProgress(downloader.ProgressInPercent / 100); progressController.SetMessage("下载速度: " + GetDownloadSpeedFriendlyText(downloader)); } }; progressController.Canceled += delegate { if (downloader.State != DownloadState.Completed) { downloader.Cancel(); } }; downloader.Start(); } } catch (IOException ex) { await MainWindow.Current.ShowMessageAsync("下载失败", ex.Message + ex.StackTrace); } catch (HttpRequestException ex) { await MainWindow.Current.ShowMessageAsync("下载失败", ex.Message + ex.StackTrace); } ViewModel.isWorking = false; }