private void OnDownItemFinish(DownInfo info) { counter++; if (info == null) { return; } bool isModel = info.Url.EndsWith(".bin") || info.Url.EndsWith(".gltf"); var resName = GetUrlResName(info.Url); if (!info.HasError) { if (isModel) { var modelPath = ProccessModel(info, resName); PTDebug.Log("完成下载模型文件: " + modelPath); } else { var texPath = ProccessTextures(info, resName); PTDebug.Log("完成下载贴图文件: " + texPath); } if (counter >= mUrls.Length) { OnFinish(true); } } else { var path = GetPath(info.Url, isModel, resName); if (File.Exists(path)) { PTDebug.LogError("未下载成功,使用本地缓存,错误:{0}", info.Error); } else { PTDebug.LogError(info.Error); mDownloadPip.StopDownload(); OnFinish(false); } } }
public void Go_DowndLoad(object p) { if (Down_list_Selete == null) { return; } if (DownInfo[Down_list_Selete.ID].State == "下载") { return; } DownLoad d = new DownLoad(); string name = DownInfo[Down_list_Selete.ID].filename; Information inf = d.RSerialization(name); if (inf.filename == null) { MessageBox.Show("文件不存在!"); int i = Down_list_Selete.ID; DownInfo.RemoveAt(Down_list_Selete.ID); for (; i < DownInfo.Count; i++) { DownInfo[i].ID = i; } Serialization(@"./config/ImportDownLoadInfo", DownInfo); return; } d.ContinuousDownLoad(inf); DownInfo[Down_list_Selete.ID].ID = Down_d.Count; DownInfo[Down_list_Selete.ID].State = "下载"; Down_d.Add(d); for (int i = 0; i < Down_d.Count; i++) { Down_d[i].Maxseepd = Limit_DownLoad_Speed; Down_d[i].Sum = Down_d.Count; } Task <int> task = _client.DownloadRequestAsync(Down_list_Selete.Hash, d.Port); task.ContinueWith(T => { }); Serialization(@"./config/ImportDownLoadInfo", DownInfo); }
public void Detelet_DownListViewInfo(object p) { if (Down_list_Selete == null) { return; } GarbageInfo.Add(Down_list_Selete); if (Down_list_Selete.State == "下载") { Down_d[Down_list_Selete.ID].Stop_DownLoad = true; Down_d[Down_list_Selete.ID].AllDone.Set(); Down_d.RemoveAt(Down_list_Selete.ID); } int i = Down_list_Selete.ID; DownInfo.RemoveAt(Down_list_Selete.ID); for (; i < DownInfo.Count; i++) { DownInfo[i].ID = i; } Serialization(@"./config/GarbageInfo", GarbageInfo); Serialization(@"./config/ImportDownLoadInfo", DownInfo); }
public static void BuildDownInfos() { if (DownFactory == null) DownFactory = new DBMyDownloadFactory(); if (MyDownloading == null) MyDownloading = new ObservableCollection<DownInfo>(); if (MyDownloaded == null) MyDownloaded = new ObservableCollection<DownInfo>(); ObservableCollection<DBMyDownloadInfo> downRecords = DownFactory.GetAllRecords(); MyDownloading.Clear(); MyDownloaded.Clear(); foreach (DBMyDownloadInfo record in downRecords) { string progressText = String.Format("正在下载:{0}M/{1}M", ((double)record.Progress / (double)(1024 * 1024)).ToString("f2"), ((double)record.FileLen / (double)(1024 * 1024)).ToString("f2")); double progressNumeric = 0; if (record.FileLen == 0) progressNumeric = 0; else progressNumeric = (double)record.Progress / (double)record.FileLen * 100; string subTitle = string.Empty; string[] id = record.VID.Split('|'); if (!string.IsNullOrEmpty(id[1])) { subTitle = "(第" + (Convert.ToInt32(id[1]) + 1).ToString() + "集)"; } MediaFileDownload downloader = new MediaFileDownload(); downloader.MediaFileUrl = new Uri(record.FileUrl, UriKind.RelativeOrAbsolute); downloader.Tag = record.VID; downloader.PathName = record.LocalPathName; downloader.DownloadProgressChange += OnDownloadProgressChange; downloader.DownloadStatusChange += OnDownloadStatusChange; string statusImage = string.Empty; if (record.Status != (int)DownloadStatus.Completed) { Utils.MediaFileDownload.Add(downloader); switch (Utils.MediaFileDownload.Find(record.VID).Status) { case DownloadStatus.Paused: case DownloadStatus.Error: case DownloadStatus.Timeout: statusImage = "/PPTVForWP7;component/Images/pause.png"; break; case DownloadStatus.Downloading: statusImage = "/PPTVForWP7;component/Images/Download.png"; break; case DownloadStatus.Waiting: statusImage = "/PPTVForWP7;component/Images/waiting.png"; break; } } DownInfo info = new DownInfo(record.VID, record.TitleImgUrl, progressText, progressNumeric, record.Title, subTitle, statusImage, record.Rate,record.LocalPathName); if (record.Status != (int)DownloadStatus.Completed) { MyDownloading.Add(info); } else { MyDownloaded.Add(info); } } if (System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication().DirectoryExists("/PersonalCenter/MyDownload")) { string[] files = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication().GetFileNames("/PersonalCenter/MyDownload/*.*"); foreach (string file in files) { if (!DownFactory.IsExistFile(file)) { System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication().DeleteFile( System.IO.Path.Combine("/PersonalCenter/MyDownload", file)); } } } }
public static bool AddTask(ChannelDetailInfo channelDetailInfo, ProgramInfo programInfo) { MediaFileDownload downloader = new MediaFileDownload(); string index = (programInfo != null) ? programInfo.Index.ToString() : string.Empty; string channelVid = (programInfo != null) ? programInfo.ChannelVID.ToString() : string.Empty; downloader.Tag = channelDetailInfo.VID.ToString() + "|" + index + "|" + channelVid; if (DownFactory.IsExistVid(downloader.Tag as string)) return false; Utils.MediaFileDownload.Add(downloader); int rate = (int)channelDetailInfo.Mark; string subTitle = string.Empty; if (channelDetailInfo.TypeID != 1 && programInfo != null) { subTitle = "(第" + (programInfo.Index + 1).ToString() + "集)"; } DownFactory.InsertRecord(downloader.Tag as string, channelDetailInfo.ImgUrl, channelDetailInfo.Title, "", downloader.PathName, 0, 0, (int)DownloadStatus.Downloading, rate); DownInfo info = new DownInfo(downloader.Tag as string, channelDetailInfo.ImgUrl, "正在下载:0M", 0, channelDetailInfo.Title, subTitle, "/PPTVForWP7;component/Images/Pause.png", rate,String.Empty); MyDownloading.Add(info); foreach (MediaFileDownload down in Utils.MediaFileDownload.DownloadQueue) { down.DownloadStatusChange += OnDownloadStatusChange; down.DownloadProgressChange += OnDownloadProgressChange; } return true; }
protected override DownAndHere AfterPushDependency(Stack <TDependency> currentPath, int expectedPathMatchIndex, AbstractPathMatch <TDependency, TItem> pathMatchOrNull, bool isEnd, DownInfo down) { TDependency tailDependency = currentPath.Peek(); TItem usedItem = tailDependency.UsedItem; if (down.BehindCountMatch != null) { if (!Counts.ContainsKey(usedItem)) { Counts[usedItem] = new HashSet <IMatchableObject>(); } Counts[usedItem].Add(down.BehindCountMatch); } _seenInnerPathStarts.Add(usedItem); IMatchableObject pushDownMatch = null; if (down.BehindCountMatch != null) { pushDownMatch = down.BehindCountMatch; } else if (_countMatch == null) { // default values are ok } else if (_countMatch == pathMatchOrNull) { if (_countMatch is DependencyPathMatch <TDependency, TItem> ) { pushDownMatch = tailDependency; } else { pushDownMatch = usedItem; } } else { // default values are ok } return(new DownAndHere(new DownInfo(pushDownMatch), Ignore.Om)); }
public static void BuildDownInfos() { if (DownFactory == null) { DownFactory = new DBMyDownloadFactory(); } if (MyDownloading == null) { MyDownloading = new ObservableCollection <DownInfo>(); } if (MyDownloaded == null) { MyDownloaded = new ObservableCollection <DownInfo>(); } ObservableCollection <DBMyDownloadInfo> downRecords = DownFactory.GetAllRecords(); MyDownloading.Clear(); MyDownloaded.Clear(); foreach (DBMyDownloadInfo record in downRecords) { string progressText = String.Format("正在下载:{0}M/{1}M", ((double)record.Progress / (double)(1024 * 1024)).ToString("f2"), ((double)record.FileLen / (double)(1024 * 1024)).ToString("f2")); double progressNumeric = 0; if (record.FileLen == 0) { progressNumeric = 0; } else { progressNumeric = (double)record.Progress / (double)record.FileLen * 100; } string subTitle = string.Empty; string[] id = record.VID.Split('|'); if (!string.IsNullOrEmpty(id[1])) { subTitle = "(第" + (Convert.ToInt32(id[1]) + 1).ToString() + "集)"; } MediaFileDownload downloader = new MediaFileDownload(); downloader.MediaFileUrl = new Uri(record.FileUrl, UriKind.RelativeOrAbsolute); downloader.Tag = record.VID; downloader.PathName = record.LocalPathName; downloader.DownloadProgressChange += OnDownloadProgressChange; downloader.DownloadStatusChange += OnDownloadStatusChange; string statusImage = string.Empty; if (record.Status != (int)DownloadStatus.Completed) { Utils.MediaFileDownload.Add(downloader); switch (Utils.MediaFileDownload.Find(record.VID).Status) { case DownloadStatus.Paused: case DownloadStatus.Error: case DownloadStatus.Timeout: statusImage = "/PPTVForWP7;component/Images/pause.png"; break; case DownloadStatus.Downloading: statusImage = "/PPTVForWP7;component/Images/Download.png"; break; case DownloadStatus.Waiting: statusImage = "/PPTVForWP7;component/Images/waiting.png"; break; } } DownInfo info = new DownInfo(record.VID, record.TitleImgUrl, progressText, progressNumeric, record.Title, subTitle, statusImage, record.Rate, record.LocalPathName); if (record.Status != (int)DownloadStatus.Completed) { MyDownloading.Add(info); } else { MyDownloaded.Add(info); } } if (System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication().DirectoryExists("/PersonalCenter/MyDownload")) { string[] files = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication().GetFileNames("/PersonalCenter/MyDownload/*.*"); foreach (string file in files) { if (!DownFactory.IsExistFile(file)) { System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication().DeleteFile( System.IO.Path.Combine("/PersonalCenter/MyDownload", file)); } } } }
private void CreatDowndLoadThread(object p) { FileInfoDataList SeleteInfo1 = (FileInfoDataList)p; if (SeleteInfo1 == null) { return; } #region MyRegion //if (SeleteInfo1.Hash.Length < 36) //{ // MessageBox.Show("根目录不能下载"); // return; //} #endregion if (SeleteInfo1.IsFolder == true) { MessageBox.Show("根目录不能下载"); return; } Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, (ThreadStart) delegate { DownLoad d = new DownLoad(); LoadInfo l = new LoadInfo(); //l.name = @"DriverGenius2012"; //l.type = "文件夹"; d.RootDirectory = CurrentDownloadPath + @"\"; l.name = SeleteInfo1.Name; if (SeleteInfo1.Size == null) { l.size = 0; } else { l.size = (long)SeleteInfo1.Size; } l.type = SeleteInfo1.Type; DownListInfo sm = d.CreatDownLoad(l); if (sm == null) { return; } sm.ID = d.ID = DownInfo.Count; sm.State = "下载"; sm.Hash = SeleteInfo.Hash; DownInfo.Add(sm); Down_d.Add(d); for (int i = 0; i < Down_d.Count; i++) { Down_d[i].Maxseepd = Limit_DownLoad_Speed; Down_d[i].Sum = Down_d.Count; } d.Percentage += Refresh; //if (ShowSharefile == null) { Task <int> task = _client.DownloadRequestAsync(SeleteInfo.Hash, d.Port); task.ContinueWith(T => { }); } //else ShowSharefile.SendDirectoryName(@":\" + Directory + @"\" + l.name); Serialization(@"./config/ImportDownLoadInfo", DownInfo); }); }