private bool DownloadMegaArchive(MEGAArchive m, bool download) { var client = new MegaApiClient(); Status("Logging into MEGA (as anonymous)"); client.LoginAnonymous(); var file_link = new Uri(m.URL); var node = client.GetNodeFromLink(file_link); if (!download) { return(true); } Status("Downloading MEGA file: {0}", m.Name); var output_path = Path.Combine(DownloadFolder, m.Name); client.DownloadFile(file_link, output_path); return(true); }
private Archive ResolveArchive(string sha, IDictionary <string, IndexedArchive> archives) { if (archives.TryGetValue(sha, out var found)) { if (found.IniData == null) { Error("No download metadata found for {0}, please use MO2 to query info or add a .meta file and try again.", found.Name); } var general = found.IniData.General; if (general == null) { Error("No General section in mod metadata found for {0}, please use MO2 to query info or add the info and try again.", found.Name); } Archive result; if (general.directURL != null && general.directURL.StartsWith("https://drive.google.com")) { var regex = new Regex("((?<=id=)[a-zA-Z0-9_-]*)|(?<=\\/file\\/d\\/)[a-zA-Z0-9_-]*"); var match = regex.Match(general.directURL); result = new GoogleDriveMod() { Id = match.ToString() }; } else if (general.directURL != null && general.directURL.StartsWith(Consts.MegaPrefix)) { result = new MEGAArchive() { URL = general.directURL }; } else if (general.directURL != null && general.directURL.StartsWith("https://www.dropbox.com/")) { var uri = new UriBuilder((string)general.directURL); var query = HttpUtility.ParseQueryString(uri.Query); if (query.GetValues("dl").Count() > 0) { query.Remove("dl"); } query.Set("dl", "1"); uri.Query = query.ToString(); result = new DirectURLArchive() { URL = uri.ToString() }; } else if (general.directURL != null && general.directURL.StartsWith("https://www.moddb.com/downloads/start")) { result = new MODDBArchive() { URL = general.directURL }; } else if (general.directURL != null && general.directURL.StartsWith("http://www.mediafire.com/file/")) { Error("Mediafire links are not currently supported"); return(null); /*result = new MediaFireArchive() * { * URL = general.directURL * };*/ } else if (general.directURL != null) { var tmp = new DirectURLArchive() { URL = general.directURL }; if (general.directURLHeaders != null) { tmp.Headers = new List <string>(); tmp.Headers.AddRange(general.directURLHeaders.Split('|')); } result = tmp; } else if (general.manualURL != null) { result = new ManualURLArchive() { URL = general.manualURL.ToString() }; } else if (general.modID != null && general.fileID != null && general.gameName != null) { var nm = new NexusMod() { GameName = general.gameName, FileID = general.fileID, ModID = general.modID, Version = general.version ?? "0.0.0.0" }; var info = NexusAPI.GetModInfo(nm, NexusKey); nm.Author = info.author; nm.UploadedBy = info.uploaded_by; nm.UploaderProfile = info.uploaded_users_profile_url; result = nm; } else { Error("No way to handle archive {0} but it's required by the modpack", found.Name); return(null); } result.Name = found.Name; result.Hash = found.File.Hash; result.Meta = found.Meta; Info($"Checking link for {found.Name}"); var installer = new Installer(null, "", s => Utils.Log(s)); installer.NexusAPIKey = NexusKey; if (!installer.DownloadArchive(result, false)) { Error($"Unable to resolve link for {found.Name}. If this is hosted on the nexus the file may have been removed."); } return(result); } Error("No match found for Archive sha: {0} this shouldn't happen", sha); return(null); }