private async void ExecuteOpenLinkCommand() { _info = new LinkInfo(); DownloadDialog dialog = new DownloadDialog(); var res = await dialog.ShowAsync(); switch (res) { case ContentDialogResult.None: break; case ContentDialogResult.Primary: _info.Path = dialog.Link; _info.Type = LinkType.Online; ReadLinkInfo(_info); if (RecentList.All(p => p.Path != _info.Path)) { _dataAccess.AddRecent(_info); RecentList.Add(_info); } break; case ContentDialogResult.Secondary: break; } }
private async void btnDownload_Click(object sender, RoutedEventArgs e) { if (seasonDetailVM.Detail == null || seasonDetailVM.Detail.episodes == null || seasonDetailVM.Detail.episodes.Count == 0) { return; } var downloadItem = new DownloadItem() { Cover = seasonDetailVM.Detail.cover, SeasonID = seasonDetailVM.Detail.season_id, SeasonType = seasonDetailVM.Detail.type, Episodes = new List <DownloadEpisodeItem>(), Subtitle = seasonDetailVM.Detail.subtitle, Title = seasonDetailVM.Detail.title, Type = DownloadType.Season }; int i = 0; foreach (var item in seasonDetailVM.Detail.episodes) { // 检查正在下载及下载完成是否存在此视频 int state = 0; if (DownloadVM.Instance.Downloadings.FirstOrDefault(x => x.EpisodeID == item.id.ToString()) != null) { state = 2; } if (DownloadVM.Instance.Downloadeds.FirstOrDefault(x => x.Epsidoes.FirstOrDefault(y => y.EpisodeID == item.id.ToString()) != null) != null) { state = 3; } //如果正在下载state=2,下载完成state=3 downloadItem.Episodes.Add(new DownloadEpisodeItem() { CID = item.cid, EpisodeID = item.id.ToString(), Index = i, Title = item.title + " " + item.long_title, State = state, AVID = item.aid, BVID = item.bvid, ShowBadge = item.show_badge, Badge = item.badge, IsPreview = item.IsPreview }); i++; } DownloadDialog downloadDialog = new DownloadDialog(downloadItem); await downloadDialog.ShowAsync(); }
private async void btnDownload_Click(object sender, RoutedEventArgs e) { if (videoDetailVM.VideoInfo == null || videoDetailVM.VideoInfo.pages == null || videoDetailVM.VideoInfo.pages.Count == 0) { return; } var downloadItem = new DownloadItem() { Cover = videoDetailVM.VideoInfo.pic, ID = videoDetailVM.VideoInfo.aid, Episodes = new List <DownloadEpisodeItem>(), Subtitle = videoDetailVM.VideoInfo.bvid, Title = videoDetailVM.VideoInfo.title, Type = DownloadType.Video }; int i = 0; foreach (var item in videoDetailVM.VideoInfo.pages) { //检查正在下载及下载完成是否存在此视频 int state = 0; if (DownloadVM.Instance.Downloadings.FirstOrDefault(x => x.EpisodeID == item.cid) != null) { state = 2; } if (DownloadVM.Instance.Downloadeds.FirstOrDefault(x => x.Epsidoes.FirstOrDefault(y => y.CID == item.cid) != null) != null) { state = 3; } //如果正在下载state=2,下载完成state=3 downloadItem.Episodes.Add(new DownloadEpisodeItem() { AVID = videoDetailVM.VideoInfo.aid, BVID = videoDetailVM.VideoInfo.bvid, CID = item.cid, EpisodeID = "", Index = i, Title = "P" + item.page + " " + item.part, State = state }); i++; } DownloadDialog downloadDialog = new DownloadDialog(downloadItem); await downloadDialog.ShowAsync(); }
private async Task Launch(LaunchOption option) { //Check connection to launch agent if (AppServiceManager.appServiceConnection == null) { return; } List <MinecraftAssembly> missingLibs = null; //include missing natives List <MinecraftAsset> missingAssets = new List <MinecraftAsset>(); #region Libraries and natives check ValueSet valueSet = new ValueSet(); valueSet["type"] = "librariesCheck"; valueSet["version"] = option.versionId; AppServiceResponse response = await AppServiceManager.appServiceConnection.SendMessageAsync(valueSet); string responseJson = response.Message["value"].ToString(); try { missingLibs = JsonConvert.DeserializeObject <List <MinecraftAssembly> >(responseJson); } catch (JsonException) { } #endregion #region Assets check valueSet = new ValueSet(); valueSet["type"] = "assetsCheck"; valueSet["version"] = option.versionId; response = await AppServiceManager.appServiceConnection.SendMessageAsync(valueSet); object obj = null; response.Message.TryGetValue("index_path", out obj); // Asset index dose not exist or invalid if (obj != null) { string path = obj.ToString(); string url = response.Message["index_url"].ToString(); try { using (HttpClient client = new HttpClient()) { string json = await client.GetStringAsync(url); StorageFile file = await CoreManager.WorkDir.CreateFileAsync(path, CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(file, json); } } catch (Exception e) { await _msgDialog.Show( CoreManager.GetStringFromResource("/StartPage/LaunchFailed"), "Cannot fetch asset index \r\n " + e.Message + "\r\n" + e.StackTrace ); return; } //Check again after asset index downloaded response = await AppServiceManager.appServiceConnection.SendMessageAsync(valueSet); obj = null; response.Message.TryGetValue("index_path", out obj); if (obj != null) { await _msgDialog.Show( CoreManager.GetStringFromResource("/StartPage/LaunchFailed"), "Asset index validation failed"); return; } } responseJson = response.Message["missing_assets"].ToString(); try { missingAssets = JsonConvert.DeserializeObject <List <MinecraftAsset> >(responseJson); } catch (JsonException) { } #endregion //Found missing libs, go to download. if ((missingLibs != null && missingLibs.Count > 0) || (missingAssets != null && missingAssets.Count > 0)) { missingLibs.ForEach(lib => { DownloadItem item = new DownloadItem(lib.Name, lib.Path, lib.Url); DownloadManager.DownloadQuene.Add(item); }); missingAssets.ForEach(ass => { DownloadItem item = new DownloadItem( string.Format("{0}: {1}", CoreManager.GetStringFromResource("/Resources/Asset"), ass.Hash), ass.GetPath(), ass.GetDownloadUrl() ); DownloadManager.DownloadQuene.Add(item); }); DownloadManager.StartDownload(); await DownloadDialog.ShowAsync(); return; } DebugWriteLine("Serializing launch message to json"); string messageJson; try { LaunchOptionBase tmp = option as LaunchOptionBase; if (string.IsNullOrWhiteSpace(option.javaExt)) { tmp.javaExt = CoreManager.GlobalJVMPath; } messageJson = JsonConvert.SerializeObject(tmp); } catch (JsonSerializationException exp) { DebugWriteLine("ERROR: " + exp.Message); return; } DebugWriteLine(messageJson); //Check if the launch message was successfully generated if (!string.IsNullOrWhiteSpace(messageJson)) { valueSet = new ValueSet(); valueSet.Add("type", "launch"); valueSet.Add("launch_option", messageJson); valueSet.Add("auth_type", CoreManager.AccountTypeTag); valueSet.Add("auth_username", CoreManager.Username); response = await AppServiceManager.appServiceConnection.SendMessageAsync(valueSet); //Display error obj = response.Message["result"]; if (obj is bool && !((bool)obj)) { await _msgDialog.Show( CoreManager.GetStringFromResource("/StartPage/LaunchFailed"), response.Message["errorMessage"].ToString() + "\r\n" + response.Message["errorStack"] ); } } }