public static void DownloadMissing(string tmdPath, bool autoClose = false) { if (!File.Exists(tmdPath)) { return; } FileInfo info = new FileInfo(tmdPath); TMD tmd = new TMD(File.ReadAllBytes(tmdPath)); var onlineTMDTask = NUS.DownloadTMD(tmd.TitleID); onlineTMDTask.Wait(); TMD onlineTMD = onlineTMDTask.Result; if (!tmd.rawBytes.SequenceEqual(onlineTMD.rawBytes)) { MessageBox.Show(Localization.Strings.RepairFailed, Localization.Strings.Error); return; } List <DownloadItem> queue = new List <DownloadItem> { }; var URLTask = NUS.GetTitleContentURLs(tmd, true); URLTask.Wait(); NUS.UrlFilenamePair[] URLs = URLTask.Result; AppDomain.CurrentDomain.DoCallBack(() => { frmDownload frm = new frmDownload(); frm.DownloadQueue.Add(new DownloadItem(tmd.TitleID, tmd, URLs, new byte[] { }, info.DirectoryName)); frm.AutoClose = autoClose; frm.DownloadPath = info.DirectoryName; frm.lblDownloadingMetadata.Dispose(); Program.FormContext.AddForm(frm); }); }
public void getSizes() { var titlesCopy = titles.titles.Where(o => !titleSizes.Keys.Contains(o.titleID)).ToList(); var titlesCopy2 = titles.titles.Where(o => titleSizes.Keys.Contains(o.titleID)).ToList(); List <Task> workers = new List <Task> { }; for (var i = 0; i < 8; i++) { Task.Run(async() => { while (true) { TitleInfo item; lock (titlesCopy) { if (titlesCopy.Count == 0) { break; } item = titlesCopy[0]; titlesCopy.RemoveAt(0); } String contentSize; titleSizes.TryGetValue(item.titleID, out contentSize); if (contentSize == null || contentSize.Length == 0) { try { contentSize = HelperFunctions.SizeSuffix((await NUS.DownloadTMD(item.titleID)).TitleContentSize); } catch (Exception ex) { Debug.WriteLine(ex?.Message); Debug.WriteLine(ex?.InnerException?.Message); contentSize = ""; } if (titleSizes.ContainsKey(item.titleID) == false && contentSize != "") { titleSizes.Add(item.titleID, contentSize); } } if (contentSize != "") { this.Invoke((MethodInvoker) delegate { item.size = contentSize; frmList_SizeChanged(null, null); }); } } }); } Task.Run(() => { this.Invoke((MethodInvoker) delegate { lstMain.BeginUpdate(); foreach (TitleInfo item in titlesCopy2) { string size = ""; titleSizes.TryGetValue(item.titleID, out size); if (size != null) { item.size = size; } } frmList_SizeChanged(null, null); lstMain.EndUpdate(); }); while (workers.Count > 0) { ; } Common.Settings.cachedSizes = titleSizes; }); }
private Nullable <DownloadItem> getDownloadItem(TitleInfo item, DownloadType type) { TitleInfo info; lock (item) { info = item; } switch (type) { case DownloadType.Game: if (!info.isUpdate) { try { bool madeTicket = false; TMD titleTMD = AsyncHelpers.RunSync <TMD>(() => NUS.DownloadTMD(info.titleID)); if (info.ticket.Length == 0 && info.hasTicket) { info.ticket = AsyncHelpers.RunSync <byte[]>(() => HelperFunctions.DownloadTitleKeyWebsiteTicket(info.titleID)); } if (!info.hasTicket && info.titleKey.Length > 0) { madeTicket = true; info.ticket = info.getGeneratedTitleTicket(titleTMD.TitleVersion); } return(new DownloadItem( info.displayName + (madeTicket ? " (FakeSign)" : ""), titleTMD, AsyncHelpers.RunSync <NUS.UrlFilenamePair[]>(() => NUS.GetTitleContentURLs(titleTMD, true)), info.ticket, null, null, madeTicket )); } catch { } } break; case DownloadType.DLC: try { if (info.dlcKey.Length > 0) { TMD dlcTMD = AsyncHelpers.RunSync <TMD>(() => NUS.DownloadTMD(info.dlcID)); return(new DownloadItem( info.DisplayNameWithVersion(dlcTMD.TitleVersion, "DLC") + " (FakeSign)", dlcTMD, AsyncHelpers.RunSync <NUS.UrlFilenamePair[]>(() => NUS.GetTitleContentURLs(dlcTMD, true)), info.getDLCTicket(dlcTMD.TitleVersion), null, null, true )); } } catch { } break; case DownloadType.Update: try { TMD updateTMD = AsyncHelpers.RunSync <TMD>(() => NUS.DownloadTMD(info.updateID)); return(new DownloadItem( info.DisplayNameWithVersion(updateTMD.TitleVersion, "Update"), updateTMD, AsyncHelpers.RunSync <NUS.UrlFilenamePair[]>(() => NUS.GetTitleContentURLs(updateTMD, true)), AsyncHelpers.RunSync <byte[]>(() => NUS.DownloadTicket(info.updateID)) )); } catch { } break; } return(null); }