static void Main(string[] args) { bool keepRunning = false; try{ foreach (Exception e in Storage.nonCriticalInitExceptions) { el(e); } }catch (Exception e) { el(e); return; } Storage.onMessage += (src, ex) => { if (src != null) { pl(src.ToString()); } if (ex.type == EventMessageType.error) { el(ex.msg); } else { pl(ex.msg); } }; do { if (keepRunning) { p("> "); string par = Console.ReadLine(); if (par == null) { par = ""; } if (par.StartsWith("> ")) { par = par.Substring(2); } args = argSplit(par); } if (args.Length < 1 || args[0].Length < 1) { keepRunning = true; } else { bool errorCmd = true; args[0] = args[0].ToLower(); switch (args[0]) { case "l": case "list": int pad = 10; if (args.Length > 1) { if (args[1].Equals("-s")) { if (args.Length >= 3) { SourceInfo si = SourceInfo.getExistingSource(args[2]); try{ List <ProtoMango> pms = si.listMangos(); if (pms == null) { pl("no data to display or method not implemented for source"); break; } pl("MANGOS \\ URL"); pl("".PadRight(pad * 3, '-')); pms.Sort(); foreach (ProtoMango pm in pms) { pl($"{pm.title}\n\t{pm.idStr})"); } }catch (Exception e) { el(e); } break; } pl("URL"); List <SourceInfo> sis = Storage.sources; sis.Sort(); sis.ForEach(si => pl(si.url)); break; } Mango m = Storage.mango(args[1]); if (m == null) { el("invalid mangoID, all valid mangoIDs can be listed with the list-command"); break; } List <MangoSlice> sls = m.slices; sls.Sort(); pl("CHAPTER".PadRight(pad, ' ') + "\tSOURCE + LOCATION + PAGES"); pl("".PadRight(pad * 3, '-')); foreach (MangoSlice sl in sls) { pl(sl.chapter.ToString().PadRight(pad, ' ') + $"\t{sl.source.url} || {sl.mango.id}/{sl.dir} ({sl.expectedPages})"); } break; } List <Mango> ms = Storage.mangos; ms.Sort(); pl("ID".PadRight(pad, ' ') + "\tTITLE"); pl("".PadRight(pad * 3, '-')); foreach (Mango m in ms) { pl(m.id.PadRight(pad, ' ') + "\t" + m.title); } break; case "a": case "add": if (args.Length == 2) { Mango m = Storage.addMangoByUrl(args[1]); pl($"Mango {m.title} ({m.id}) successfully added"); } else if (args.Length == 3) { Mango m = Storage.mango(args[1]); if (m == null) { el("invalid mangoID, all valid mangoIDs can be listed with the list-command"); break; } Storage.addMangoByUrl(args[2], m); pl($"Mango {m.title} ({m.id}) successfully expanded"); } else { el("invalid usage of 'add', requires one or two parameters:"); el("\tadd [<mangoID>] <source>"); break; } break; case "u": case "update": if (args.Length >= 2) { Mango m = Storage.mango(args[1]); if (m == null) { el("invalid mangoID, all valid mangoIDs can be listed with the list-command"); break; } try{ m.update(); pl($"Mango {m.title} ({m.id}) successfully updated"); }catch (Exception e) { el(e.Message); } } else { try{ Storage.updateAllMangos(ErrorHandling.stack); pl($"All Mango successfully updated"); }catch (ExceptionStack es) { foreach (Exception e in es.stack) { el(e.Message); } } } break; case "ul": case "updateload": if (args.Length >= 2) { Mango m = Storage.mango(args[1]); if (m == null) { el("invalid mangoID, all valid mangoIDs can be listed with the list-command"); break; } try{ m.update(); pl($"Mango {m.title} ({m.id}) successfully updated"); m.loadUnloadedSlices(); pl($"Mango {m.title} ({m.id}) successfully loaded"); }catch (Exception e) { el(e.Message); } } else { try{ Storage.updateAllMangos(ErrorHandling.stack); pl($"All Mango successfully updated"); Storage.loadAllUnloadedSlices(ErrorHandling.stack); pl($"All Mango successfully loaded"); }catch (ExceptionStack es) { foreach (Exception e in es.stack) { el(e.Message); } } } break; case "d": case "load": case "download": if (args.Length >= 2) { Mango m = Storage.mango(args[1]); if (m == null) { el("invalid mangoID, all valid mangoIDs can be listed with the list-command"); break; } try{ m.loadUnloadedSlices(); pl($"Mango {m.title} ({m.id}) successfully loaded"); }catch (Exception e) { el(e.Message); } } else { try{ Storage.loadAllUnloadedSlices(ErrorHandling.stack); pl($"All Mango successfully loaded"); }catch (ExceptionStack es) { foreach (Exception e in es.stack) { el(e.Message); } } } break; case "t": case "test": if (args.Length > 1) { try{ pl("loading data..."); pl(Storage.debugAddMangoByUrl(args[1], 1)); }catch (Exception e) { el(e.Message); } } else { el("invalid usage of 'test', requires one parameter:"); el("\ttest <source>"); break; } break; case "?": case "h": case "help": errorCmd = false; goto default; case "e": case "end": case "exit": keepRunning = false; break; default: if (errorCmd) { el($"unknown command {args[0]}"); } pl("Usage:"); pl("\t<Command> [<param> ...]"); pl("List of Commands:"); pl("\tadd, a"); pl("\t\tadds a new mango with source or a new source to an existing mango"); pl("\t\t\tadd [<mangoID>] <source>"); pl("\t\t\t\tmangoID: optional ID of existing mango"); pl("\t\t\t\tsource: the new source as an url. e.g. http://example.com/a-mango"); pl("\tdownload, load, d"); pl("\t\tloads all mangos or a specific one"); pl("\t\t\tdownload [<mangoID>]"); pl("\t\t\t\tmangoID: optional ID of existing mango"); pl("\texit, end, e"); pl("\t\tends this program"); pl("\thelp, h, ?"); pl("\t\tdisplays this help menu"); pl("\tlist, l"); pl("\t\tdisplays a list of all mangos"); pl("\t\t\tlist [<mangoID>]"); pl("\t\t\t\tmangoID: optional ID of existing mango; displays slices of mango if given"); pl("\t\t\tlist -s [<sourceUrl>]"); pl("\t\t\t\tsourceUrl: if given, attempts to display all mangos in source, otherwise all sources"); pl("\ttest, t"); pl("\t\ttests a plugin by attempting to add a mango"); pl("\t\t\tupdates <source>"); pl("\t\t\t\tsource: the new source as an url. e.g. http://example.com/a-mango"); pl("\tupdate, u"); pl("\t\tupdates all mangos or a specific one"); pl("\t\t\tupdates [<mangoID>]"); pl("\t\t\t\tmangoID: optional ID of existing mango"); pl("\tupdateload, ul"); pl("\t\tupdates and loads all mangos or a specific one"); pl("\t\t\tupdateload [<mangoID>]"); pl("\t\t\t\tmangoID: optional ID of existing mango"); break; } } }while(keepRunning); }