public static Card[] DownloadAll(DLMode mode, Dictionary <int, int> ids) { Directory.CreateDirectory(folderPath); Directory.CreateDirectory(imagePath); Card[] cards = null; try { var JSON = DownloadJSON(ids); Console.WriteLine("Done! "); cards = ParseJSON(JSON); } catch { Console.WriteLine($"Exception while downloading cards data"); Environment.Exit(1); } if (mode != DLMode.JSON) { foreach (var card in cards) { try { DownloadImage(card); Thread.Sleep(200); } catch { Console.WriteLine($"Exception while downloading the image of the card with id {card.id}"); Environment.Exit(1); } } Console.WriteLine("Done! "); } return(cards); }
static void Main(string[] args) { Console.Clear(); Console.WriteLine("*********************************************************************************"); Console.WriteLine("* Yu-Gi-Oh Deck Downloader - By billy4479 *"); Console.WriteLine("* *"); Console.WriteLine("* You can find the code on Github: https://github.com/billy4479/deck-downloader *"); Console.WriteLine("* Powered by the awesome YGOPRODeck API: https://ygoprodeck.com *"); Console.WriteLine("* PDF Framework: iText7 https://itextpdf.com *"); Console.WriteLine("*********************************************************************************\n"); //Args parsing bool cleanMode = false; foreach (var arg in args) { switch (arg) { case "-y": useDefault = true; break; case "-c": cleanMode = true; break; case "--help": Console.WriteLine("\n\t-y\tRun in batch mode, no input from user is required.\n\t--help\tShow this screen"); return; default: Console.WriteLine($"Invalid argumant: {arg}. Use --help for more informations"); return; } } DLMode dlMode = default; bool pdfOnly = false; bool noPdf = false; if (!useDefault) { Console.Write("Mode: \n\t0. Everything (default)\n\t1. PDF Only (no internet required)\n\t2. No PDF\n\t3. No images and no PDF\nEnter mode: "); var choise = Console.ReadKey().KeyChar; switch (choise) { case '0': dlMode = DLMode.All; break; case '\r': dlMode = DLMode.All; break; case '\n': dlMode = DLMode.All; break; case '1': pdfOnly = true; break; case '2': dlMode = DLMode.All; noPdf = true; break; case '3': noPdf = true; dlMode = DLMode.JSON; break; default: Console.WriteLine("\nInvalid mode."); Environment.Exit(1); break; } } Console.WriteLine(); if (cleanMode && Directory.Exists(DownloadHelper.folderPath)) { Directory.Delete(DownloadHelper.folderPath, true); } Card[] cards = null; if (!pdfOnly) { var ids = LoadFile(); cards = DownloadHelper.DownloadAll(dlMode, ids); } else { string json; using (var sr = new StreamReader(File.OpenRead(DownloadHelper.jsonPath))) { json = sr.ReadToEnd(); } cards = JsonSerializer.Deserialize <Card[]>(json, DownloadHelper.serializerOptions); } if (!noPdf) { PDFCreator.CreatePDF(cards); } }