internal void libraries(ForgeJson.Root json) { int num = 0; List <Minecraft.MCDownload> download = new List <Minecraft.MCDownload>(); foreach (ForgeJson.LibrariesItem item in json.libraries) { if (!(item.downloads.artifact.url == "") && (this.SLC.FileExist(System.Directory.GetCurrentDirectory() + @"\.minecraft\libraries\" + item.downloads.artifact.path.Replace('/', '\\')) != null)) { num++; Minecraft.MCDownload download1 = new Minecraft.MCDownload(); download1.path = System.Directory.GetCurrentDirectory() + @"\.minecraft\libraries\" + item.downloads.artifact.path.Replace('/', '\\'); download1.Url = item.downloads.artifact.url.Replace("https://files.minecraftforge.net/maven/", "https://bmclapi2.bangbang93.com/maven/"); download.Add(download1); } } ForgeDownload forgedownload = new ForgeDownload(5, download.ToArray()); forgedownload.StartDownload(); bool flag = true; while (flag) { if (forgedownload.error > 0) { throw new SquareMinecraftLauncherException("安装失败"); } else if (forgedownload.GetEndDownload()) { flag = false; } Thread.Sleep(1000); } }
private async void DownloadProgress() { List <FileDownloader> files = new List <FileDownloader>(); for (int i = 0; i < 3; i++) { Minecraft.MCDownload download = AssignedDownload(); //分配下载任务 try { if (download != null) { FileDownloader fileDownloader = new FileDownloader(download.Url, download.path.Replace(System.IO.Path.GetFileName(download.path), ""), System.IO.Path.GetFileName(download.path) + ".Square"); //增加下载 fileDownloader.download(null); files.Add(fileDownloader); } } catch (Exception ex) //当出现下载失败时,忽略该文件 { error++; Console.WriteLine(ex.Message); } } if (files.Count == 0) { return; } await Task.Factory.StartNew(() => { while (true) //循环检测当前线程files.Count个下载任务是否下载完毕 { int end = 0; for (int i = 0; i < files.Count; i++) { if (files[i].download(null) == files[i].getFileSize()) { end++; } Console.WriteLine(files[i].download(null) + " from " + files[i].getFileSize()); } Console.WriteLine(EndDownload); if (end == files.Count) //完成则递归当前函数 { EndDownload += files.Count; DownloadProgress(); //递归 return; } Thread.Sleep(1000); } }); }