Ejemplo n.º 1
0
        private async void GetDowned()
        {
            loading.Visibility = Visibility.Visible;
            Dictionary <string, string> valuePairs = new Dictionary <string, string>();
            var folder = await DownloadHelper2.GetDownloadFolder();

            List <VideoDiaplayModel> list = new List <VideoDiaplayModel>();

            try
            {
                foreach (var item in await folder.GetFoldersAsync())
                {
                    if (await DownloadHelper2.ExistsFile(item.Path + @"\info.json"))
                    {
                        var file = await item.GetFileAsync("info.json");

                        var data = await FileIO.ReadTextAsync(file);

                        DownloadVideonInfoModel downloadVideonInfoModel = Newtonsoft.Json.JsonConvert.DeserializeObject <DownloadVideonInfoModel>(data);
                        var video = new VideoDiaplayModel()
                        {
                            id        = downloadVideonInfoModel.id,
                            mode      = downloadVideonInfoModel.type,
                            title     = downloadVideonInfoModel.title,
                            videolist = new List <PartDiaplayModel>()
                        };
                        if (await DownloadHelper2.ExistsFile(item.Path + @"\thumb.jpg"))
                        {
                            video.thumb = item.Path + "/thumb.jpg";
                        }
                        else
                        {
                            video.thumb = downloadVideonInfoModel.thumb;
                        }
                        foreach (var item1 in await item.GetFoldersAsync())
                        {
                            if (await DownloadHelper2.ExistsFile(item1.Path + @"\info.json"))
                            {
                                var flag  = false;
                                var files = (await item1.GetFilesAsync()).Where(x => x.FileType == ".mp4" || x.FileType == ".flv");
                                if (files.Count() != 0)
                                {
                                    //DownloadHelper2.GetFileSize(x.Path).Result
                                    foreach (var subfile in files)
                                    {
                                        if (await DownloadHelper2.GetFileSize(subfile.Path) == 0)
                                        {
                                            flag = true;
                                            break;
                                        }
                                    }
                                    if (flag)
                                    {
                                        break;
                                    }
                                    var file1 = await item1.GetFileAsync("info.json");

                                    var data1 = await FileIO.ReadTextAsync(file1);

                                    DownloadPartnInfoModel downloadPartnInfoModel = Newtonsoft.Json.JsonConvert.DeserializeObject <DownloadPartnInfoModel>(data1);
                                    var part = new PartDiaplayModel()
                                    {
                                        cid     = downloadPartnInfoModel.cid,
                                        eptitle = downloadPartnInfoModel.title,
                                        path    = item1.Path,
                                        index   = downloadPartnInfoModel.index,
                                        id      = video.id,
                                        mode    = video.mode,
                                        title   = video.title
                                    };
                                    if (!valuePairs.ContainsKey(downloadPartnInfoModel.cid))
                                    {
                                        valuePairs.Add(downloadPartnInfoModel.cid, item1.Path);
                                    }
                                    video.videolist.Add(part);
                                }
                                //foreach (var item2 in files)
                                //{
                                //    if (item2.FileType == ".mp4" || item2.FileType == ".flv")

                                //        check.Add(await DownloadHelper2.GetFileSize(item2.Path) == 0);

                                //    }
                                //}
                                //if (!check.Contains(false))
                                //{

                                // }
                            }
                        }

                        if (video.videolist.Count != 0)
                        {
                            video.videolist = video.videolist.OrderBy(x => x.index).ToList();
                            list.Add(video);
                        }
                    }
                }
                DownloadHelper2.downloadeds = valuePairs;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                await new MessageDialog("无法读取已经下载完成的视频").ShowAsync();
            }
            list_Downed.ItemsSource = list;
            loading.Visibility      = Visibility.Collapsed;
        }
Ejemplo n.º 2
0
        private async void GetDowned()
        {
            loading.Visibility = Visibility.Visible;
            var folder = await DownloadHelper2.GetDownloadFolder();

            List <VideoDiaplayModel> list = new List <VideoDiaplayModel>();

            try
            {
                foreach (var item in await folder.GetFoldersAsync())
                {
                    if (await DownloadHelper2.ExistsFile(item.Path + @"\info.json"))
                    {
                        var file = await item.GetFileAsync("info.json");

                        var data = await FileIO.ReadTextAsync(file);

                        DownloadVideonInfoModel downloadVideonInfoModel = Newtonsoft.Json.JsonConvert.DeserializeObject <DownloadVideonInfoModel>(data);
                        var video = new VideoDiaplayModel()
                        {
                            id        = downloadVideonInfoModel.id,
                            mode      = downloadVideonInfoModel.type,
                            title     = downloadVideonInfoModel.title,
                            videolist = new List <PartDiaplayModel>()
                        };
                        if (await DownloadHelper2.ExistsFile(item.Path + @"\thumb.jpg"))
                        {
                            video.thumb = item.Path + "/thumb.jpg";
                        }
                        else
                        {
                            video.thumb = downloadVideonInfoModel.thumb;
                        }
                        foreach (var item1 in await item.GetFoldersAsync())
                        {
                            if (await DownloadHelper2.ExistsFile(item1.Path + @"\info.json"))
                            {
                                List <bool> check = new List <bool>();
                                var         files = await item1.GetFilesAsync();

                                foreach (var item2 in files)
                                {
                                    if (item2.FileType == ".mp4" || item2.FileType == ".flv")
                                    {
                                        if (await DownloadHelper2.GetFileSize(item2.Path) == 0)
                                        {
                                            check.Add(false);
                                        }
                                        else
                                        {
                                            check.Add(true);
                                        }
                                    }
                                }
                                if (!check.Contains(false))
                                {
                                    var file1 = await item1.GetFileAsync("info.json");

                                    var data1 = await FileIO.ReadTextAsync(file1);

                                    DownloadPartnInfoModel downloadPartnInfoModel = Newtonsoft.Json.JsonConvert.DeserializeObject <DownloadPartnInfoModel>(data1);
                                    var part = new PartDiaplayModel()
                                    {
                                        cid     = downloadPartnInfoModel.cid,
                                        eptitle = downloadPartnInfoModel.title,
                                        path    = item1.Path,
                                        index   = downloadPartnInfoModel.index,
                                        id      = video.id,
                                        mode    = video.mode,
                                        title   = video.title
                                    };
                                    if (!DownloadHelper2.downloadeds.ContainsKey(downloadPartnInfoModel.cid))
                                    {
                                        DownloadHelper2.downloadeds.Add(downloadPartnInfoModel.cid, item1.Path);
                                    }
                                    video.videolist.Add(part);
                                }
                            }
                        }

                        if (video.videolist.Count != 0)
                        {
                            video.videolist = video.videolist.OrderBy(x => x.eptitle).ToList();
                            list.Add(video);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                await new MessageDialog("无法读取已经下载完成的视频").ShowAsync();
            }
            list_Downed.ItemsSource = list;
            loading.Visibility      = Visibility.Collapsed;
        }