public Download GetDependenciesOnly(string resourceName) { packageDownloader.LoadMasterAndVersions(false).Wait(); var dep = packageDownloader.GetPackageDependencies(resourceName); if (dep == null) { if (torrentDownloader == null) torrentDownloader = new TorrentDownloader(this); //lazy initialization dep = torrentDownloader.GetFileDependencies(resourceName); } if (dep != null) { Download down = null; foreach (var dept in dep) { if (!string.IsNullOrEmpty(dept)) { var dd = GetResource(DownloadType.UNKNOWN, dept); if (dd != null) { if (down == null) down = dd; else down.AddNeededDownload(dd); } } } return down; } return null; }
public Download GetResource(DownloadType type, string name) { lock (downloads) { downloads.RemoveAll(x => x.IsAborted || x.IsComplete != null); // remove already completed downloads from list} var existing = downloads.FirstOrDefault(x => x.Name == name || x.Alias == name); if (existing != null) return existing; } if (scanner != null && scanner.HasResource(name)) return null; lock (downloads) { if (type == DownloadType.DEMO) { var target = new Uri(name); var targetName = target.Segments.Last(); var filePath = Utils.MakePath(SpringPaths.WritableDirectory, "demos", targetName); if (File.Exists(filePath)) return null; var down = new WebFileDownload(name, filePath, null); downloads.Add(down); DownloadAdded.RaiseAsyncEvent(this, new EventArgs<Download>(down)); //create dowload bar (handled by MainWindow.cs) down.Start(); return down; } if (type == DownloadType.MOD || type == DownloadType.UNKNOWN) { var down = packageDownloader.GetPackageDownload(name); if (down != null) { down.Alias = name; downloads.Add(down); DownloadAdded.RaiseAsyncEvent(this, new EventArgs<Download>(down)); return down; } } if (type == DownloadType.MAP || type == DownloadType.MOD || type == DownloadType.UNKNOWN || type == DownloadType.MISSION) { if (torrentDownloader == null) torrentDownloader = new TorrentDownloader(this); //lazy initialization var down = torrentDownloader.DownloadTorrent(name); if (down != null) { downloads.Add(down); DownloadAdded.RaiseAsyncEvent(this, new EventArgs<Download>(down)); return down; } } if (type == DownloadType.GAME) throw new ApplicationException(string.Format("{0} download not supported in this version", type)); return null; } }
public Download GetResource(DownloadType type, string name) { if (name == "zk:dev" || name == "Zero-K $VERSION") return null; lock (downloads) { downloads.RemoveAll(x => x.IsAborted || x.IsComplete != null); // remove already completed downloads from list} var existing = downloads.FirstOrDefault(x => x.Name == name || x.Alias == name); if (existing != null) return existing; } if (scanner?.HasResource(name) == true) return null; if (SpringPaths.HasEngineVersion(name)) return null; // check rapid to determine type if (type == DownloadType.NOTKNOWN) { if (packageDownloader.GetByInternalName(name) != null || packageDownloader.GetByTag(name) != null) type = DownloadType.RAPID; else { packageDownloader.LoadMasterAndVersions().Wait(); if (packageDownloader.GetByInternalName(name) != null || packageDownloader.GetByTag(name) != null) type = DownloadType.RAPID; else type = DownloadType.MAP; } } lock (downloads) { if (type == DownloadType.DEMO) { var target = new Uri(name); var targetName = target.Segments.Last(); var filePath = Utils.MakePath(SpringPaths.WritableDirectory, "demos", targetName); if (File.Exists(filePath)) return null; var down = new WebFileDownload(name, filePath, null); down.DownloadType = type; downloads.Add(down); DownloadAdded.RaiseAsyncEvent(this, new EventArgs<Download>(down)); //create dowload bar (handled by MainWindow.cs) down.Start(); return down; } if (type == DownloadType.MAP || type == DownloadType.MISSION) { if (torrentDownloader == null) torrentDownloader = new TorrentDownloader(this); //lazy initialization var down = torrentDownloader.DownloadTorrent(name); if (down != null) { down.DownloadType = type; downloads.Add(down); DownloadAdded.RaiseAsyncEvent(this, new EventArgs<Download>(down)); return down; } } if (type == DownloadType.RAPID) { var down = packageDownloader.GetPackageDownload(name); if (down != null) { down.DownloadType = type; down.Alias = name; downloads.Add(down); DownloadAdded.RaiseAsyncEvent(this, new EventArgs<Download>(down)); return down; } } if (type == DownloadType.ENGINE) { var down = new EngineDownload(name, SpringPaths); down.DownloadType = type; downloads.Add(down); DownloadAdded.RaiseAsyncEvent(this, new EventArgs<Download>(down)); down.Start(); return down; } return null; } }