public formLoadModpack(Modpack m) : this() { var mega = new MegaApiClient(); mega.LoginAnonymous(); foreach (ModDL d in m.Mods) { ListViewItem lv = new ListViewItem(); lv.Text = d.Name; lv.Tag = d; var node = mega.GetNodeFromLink(d.URL); lv.SubItems.Add(BytesToString(node.Size)); lsvModDLs.Items.Add(lv); } Font temp = rtbDescription.SelectionFont; rtbDescription.SelectionFont = new Font(temp, FontStyle.Bold); rtbDescription.AppendText(m.Name + "\r\n"); rtbDescription.AppendText("by " + m.Authors + "\r\n\r\n"); rtbDescription.SelectionFont = temp; rtbDescription.AppendText(m.Description); }
public override async Task Download(Archive a, string destination) { var client = new MegaApiClient(); Utils.Status("Logging into MEGA (as anonymous)"); client.LoginAnonymous(); var fileLink = new Uri(Url); var node = client.GetNodeFromLink(fileLink); Utils.Status($"Downloading MEGA file: {a.Name}"); client.DownloadFile(fileLink, destination); }
public void DownloadFileFromUrl(string url) { var client = new MegaApiClient(); client.LoginAnonymous(); Uri fileLink = new Uri("https://mega.nz/#!bkwkHC7D!AWJuto8_fhleAI2WG0RvACtKkL_s9tAtvBXXDUp2bQk"); INodeInfo node = client.GetNodeFromLink(fileLink); Console.WriteLine($"Downloading {node.Name}"); client.DownloadFile(fileLink, node.Name); client.Logout(); }
public Profile(string path, string name) { this.mega.Login(); this.uri = new Uri("https://mega.nz/#!AhhDXKzI!kEWFdkaOTTyq2NiStlHtq98OooF4C1Xmr-8_YPq1tVI"); this.url = mega.GetNodeFromLink(uri); this.path = path; this.name = name; item.Name = name; item.Text = name; CultureInfo culture = Thread.CurrentThread.CurrentCulture; this.version = url.ModificationDate.Value.ToString("d", culture); }
private string CheckLink(Comic c) { HtmlWeb oWeb = new HtmlWeb(); oWeb.Load(c.Link); if (oWeb.StatusCode != HttpStatusCode.OK) { return(oWeb.StatusCode.ToString()); } else if (c.Link.Contains("mega.nz")) { try { Mega.GetNodeFromLink(new Uri(c.Link)); } catch { return(HttpStatusCode.InternalServerError.ToString()); } } return(oWeb.StatusCode.ToString()); }
public override async Task <bool> Verify() { var client = new MegaApiClient(); Utils.Status("Logging into MEGA (as anonymous)"); client.LoginAnonymous(); var fileLink = new Uri(Url); try { var node = client.GetNodeFromLink(fileLink); return(true); } catch (Exception) { return(false); } }
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 bool ProcessDownloadMega(Comic comic) { try { Uri uri = new Uri(comic.Link); INodeInfo infoMega = ApiMega.GetNodeFromLink(uri); ApiMega.DownloadFile(uri, Environment.CurrentDirectory + Constantes.Download + infoMega.Name); comic.NameWeb = infoMega.Name; comic.SizeWeb = Functions.FormatSize(infoMega.Size); return(true); } catch (Exception ex) { if (logger != null) { logger.Error(string.Format("Error en el método: '{0}', Mensaje de error: '{1}'", MethodBase.GetCurrentMethod().Name, ex.Message)); } return(false); } }
protected virtual async Task <bool> DownloadBinaryPost(TumblrPost downloadItem) { string url = Url(downloadItem); if (!CheckIfFileExistsInDB(url)) { string blogDownloadLocation = blog.DownloadLocation(); string fileLocationUrlList = FileLocationLocalized(blogDownloadLocation, downloadItem.TextFileLocation); DateTime postDate = PostDate(downloadItem); string fileName = FileName(downloadItem); string fileLocation = FileLocation(blogDownloadLocation, fileName); if (url.Contains("https://mega.nz/#")) { Uri link = new Uri(url); Crawler.MegaLinkType linkType = Crawler.MegaLinkType.Single; //Determines if the MEGA link is a folder or single file based on if the url is mega.nz/#! or mega.nz/#F Regex regType = new Regex("(http[A-Za-z0-9_/:.]*mega.nz/#(.*)([A-Za-z0-9_]*))"); foreach (Match rmatch in regType.Matches(url)) { string subStr = rmatch.Groups[2].Value[0].ToString(); if (subStr == "!") { linkType = Crawler.MegaLinkType.Single; } if (subStr == "F") { linkType = Crawler.MegaLinkType.Folder; } } MegaApiClient client = new MegaApiClient(); client.LoginAnonymous(); switch (linkType) { case Crawler.MegaLinkType.Single: INodeInfo nodeInfo = client.GetNodeFromLink(link); fileName = nodeInfo.Name; fileLocation = FileLocation(blogDownloadLocation, fileName); UpdateProgressQueueInformation(Resources.ProgressDownloadImage, fileName); if (await DownloadBinaryFile(fileLocation, fileLocationUrlList, url)) { updateBlog(fileLocation, postDate, downloadItem, fileName); return(true); } client.Logout(); return(false); case Crawler.MegaLinkType.Folder: //If the link is a folder, download all files from it. IEnumerable <INode> nodes = client.GetNodesFromLink(link); List <INode> allFiles = nodes.Where(n => n.Type == NodeType.File).ToList(); foreach (INode node in allFiles) { fileName = node.Name; fileLocation = FileLocation(blogDownloadLocation, fileName); UpdateProgressQueueInformation(Resources.ProgressDownloadImage, fileName); if (await DownloadBinaryFile(fileLocation, fileLocationUrlList, url, node)) { updateBlog(fileLocation, postDate, downloadItem, fileName); } } client.Logout(); return(false); default: throw new ArgumentOutOfRangeException(); } } if (url.Contains("https://drive.google.com/")) { UserCredential credentials = Authenticate(); DriveService service = OpenService(credentials); RequestInfo(service, url, blogDownloadLocation + "\\"); } UpdateProgressQueueInformation(Resources.ProgressDownloadImage, fileName); if (await DownloadBinaryFile(fileLocation, fileLocationUrlList, url)) { updateBlog(fileLocation, postDate, downloadItem, fileName); return(true); } return(false); } else { string fileName = FileName(downloadItem); UpdateProgressQueueInformation(Resources.ProgressSkipFile, fileName); } return(true); }
public static void DownloadReferenceUrl(Launcher.Game game, bool clearCache = true) { string displayName; if (game.Name.Length > 0) { displayName = game.Name; } else { displayName = game.ID; } string workingDir = ""; if (game.Root == "roms" || game.Root == "data") { workingDir = Path.Combine(Launcher.rootDir, "nulldc-1-0-4-en-win", game.Root); } else { Console.WriteLine("no valid root found in reference entry"); return; } var di = new DirectoryInfo(workingDir); di.Attributes |= FileAttributes.Normal; var zipPath = Path.Combine(workingDir, $"{Path.GetFileNameWithoutExtension(game.ReferenceUrl)}.zip"); if (!File.Exists(zipPath)) { Console.WriteLine($"Downloading {displayName}..."); var referenceUri = new Uri(game.ReferenceUrl); if (referenceUri.Host == "mega.nz") { MegaApiClient client = new MegaApiClient(); client.LoginAnonymous(); INodeInfo node = client.GetNodeFromLink(referenceUri); Console.WriteLine($"Downloading {node.Name}"); client.DownloadFile(referenceUri, zipPath); client.Logout(); } else { using (WebClient client = new WebClient()) { Console.WriteLine($"Downloading {Path.GetFileName(referenceUri.LocalPath)}"); client.DownloadFile(referenceUri, zipPath); } } Console.WriteLine($"Download Complete"); } Console.WriteLine($"Extracting...\n"); string extractPath; if (game.Root == "roms") { extractPath = Path.Combine(workingDir, displayName); Directory.CreateDirectory(extractPath); } else { extractPath = workingDir; } using (ZipArchive archive = ZipFile.OpenRead(zipPath)) { List <Launcher.Asset> files = game.Assets; foreach (ZipArchiveEntry entry in archive.Entries) { try { var fileEntry = files.Where(f => f.Name == entry.Name).First(); if (fileEntry != null) { var destinationFile = Path.Combine(extractPath, fileEntry.LocalName()); entry.ExtractToFile(destinationFile, true); Console.WriteLine(fileEntry.VerifyFile(destinationFile)); } } catch (Exception) { } } } if (clearCache) { File.Delete(zipPath); } Console.WriteLine($"\nPress any key to continue."); Console.ReadKey(); }
private void DownloadFileFromMega(DownloadItemViewModel newDownload, string megaFileId) { bool wasCanceled = false; newDownload.PerformCancel = () => { wasCanceled = true; try { _megaDownloadCancelTokenSource?.Cancel(); } catch (Exception dex) { Logger.Error(dex); } finally { _megaDownloadCancelTokenSource?.Dispose(); _megaDownloadCancelTokenSource = null; } newDownload.OnCancel?.Invoke(); }; var client = new MegaApiClient(); client.LoginAnonymousAsync().ContinueWith((loginResult) => { if (wasCanceled) { return; // don't continue after async login since user already canceled download } if (loginResult.IsFaulted) { newDownload.OnError?.Invoke(loginResult.Exception.GetBaseException()); return; } // get nodes from mega folder Uri fileLink = new Uri($"https://mega.nz/file/{megaFileId}"); INodeInfo node = client.GetNodeFromLink(fileLink); if (wasCanceled) { return; // don't continue after async login since user already canceled download } if (node == null) { newDownload.OnError?.Invoke(new Exception($"could not find node from link {fileLink}")); client.LogoutAsync(); return; } if (File.Exists(newDownload.SaveFilePath)) { File.Delete(newDownload.SaveFilePath); //delete old temp file if it exists (throws exception otherwise) } IProgress <double> progressHandler = new Progress <double>(x => { double estimatedBytesReceived = (double)node.Size * (x / 100); UpdateDownloadProgress(newDownload, (int)x, (long)estimatedBytesReceived); }); _megaDownloadCancelTokenSource = new CancellationTokenSource(); Task downloadTask = client.DownloadFileAsync(fileLink, newDownload.SaveFilePath, progressHandler, _megaDownloadCancelTokenSource.Token); downloadTask.ContinueWith((downloadResult) => { _megaDownloadCancelTokenSource?.Dispose(); _megaDownloadCancelTokenSource = null; client.LogoutAsync(); if (downloadResult.IsCanceled) { return; } if (downloadResult.IsFaulted) { newDownload.OnError?.Invoke(downloadResult.Exception.GetBaseException()); return; } _wc_DownloadFileCompleted(client, new AsyncCompletedEventArgs(null, false, newDownload)); }); }); }