public static Download ScheduleDownload(string name, string url, bool MCRequire) { Download dl = new Download(); dl.Key = name; dl.Url = url; dl.MCRequire = MCRequire; ScheduleDownload(dl); return dl; }
public DownloadControl(Download d) { InitializeComponent(); reference = d; label_name.Content = reference.Key; reference.ProgressUpdated += UpdateProgress; reference.Downloaded += (dl) => { App.InvokeAction(delegate { this.Dispatcher.Invoke((Action)delegate { CloseBtn.IsEnabled = true; }); }); }; ContextMenu cm = new ContextMenu(); MenuItem mi_link = new MenuItem(); mi_link.Header = d.Url; cm.Items.Add(mi_link); MenuItem mi_cp = new MenuItem(); mi_cp.Header = "Copy to clipboard"; mi_cp.Click += delegate { Clipboard.SetText(d.Url); }; cm.Items.Add(mi_cp); this.ContextMenu = cm; }
public void StoreAsset(Download d) { byte[] filedata = d.Data; using (MD5 hasher = MD5.Create()) { byte[] downloadedHash = hasher.ComputeHash(filedata); StringBuilder sb = new StringBuilder(); downloadedHash.ToList().ForEach(b => sb.Append(b.ToString("x2"))); string hashString = sb.ToString(); if (hashString == md5) { Directory.CreateDirectory(new FileInfo(Path).DirectoryName); //MAKE SURE DIRECTORIES EXIST BEFORE WRITING! if (!IsDirectory) { File.WriteAllBytes(Path, filedata); } } else { throw new Exception("MD5 hashes do not match for MinecraftAsset: " + Key + " stored md5: " + md5 + " downloaded md5: " + hashString); } } }
//public static List<Download> getAllDownloads() //{ // List<Download> dlp = new List<Download>(); // foreach (DownloadPackage dlp_ in downloads) // { // foreach (Download dl in dlp_.getDownloads()) // { // dlp.Add(dl); // } // } // return dlp; //} public static void ScheduleDownload(Download dl) { downloads.Add(dl); App.InvokeAction(delegate { DownloadControl dc = new DownloadControl(dl); App.mainWindow.listBox_downloadManager.Items.Add(dc); }); Download(); }
private void ApplyDlStuff(Download dl) { dl.ShouldContinue = true; dl.Downloaded += (d) => { Extract_(d.Data); dl.Continue(); }; }
static void dummyC(Download download) { }
private static void AssetDownloaded(Download dl) { MinecraftAsset asset = assets.Find(a => a.Url == dl.Url); asset.StoreAsset(dl); }
private void DownloadComplete(Download obj) { finishedFile(obj); ProgressUpdated((int)(((totalSize - (files.Count - 1)) / ((float)totalSize)) * 100)); }