1 module source.applogger; 2 3 import std.stdio; 4 import std.net.curl; 5 import colorize; 6 import std.file: read, exists, mkdir; 7 import std.string; 8 import std.process; 9 import std.zip; 10 import std.json; 11 import std.conv; 12 import std.algorithm; 13 import std.array; 14 15 void logMessage(string msg) { 16 writeln(("-> " ~ msg).color("blue")); 17 } 18 19 void errorMessage(string msg) { 20 writeln(("! " ~ msg).color("red")); 21 } 22 23 void successMessage(string msg) { 24 writeln(("> " ~ msg).color("green")); 25 } 26 27 void postMSG(string msg) { 28 writeln(("* " ~ msg).color("light_white")); 29 } 30 31 void HintMSG(string msg) { 32 writeln(("* " ~ msg).color("yellow")); 33 } 34 35 void DownloadFile(string url, string f) { 36 download(url, f); 37 } 38 39 void Extract(string fname, string outputdir) { 40 logMessage("Extracting " ~ fname ~ "..."); 41 auto zip = new ZipArchive(read(fname)); 42 foreach (ArchiveMember am; zip.directory) 43 { 44 try { 45 // exclude system dirs 46 if (startsWith(am.name, "playlists")) continue; 47 if (startsWith(am.name, "songs")) continue; 48 if (startsWith(am.name, "docs")) continue; 49 if (startsWith(am.name, "Linux")) continue; 50 51 zip.expand(am); 52 logMessage("EXTRACT - " ~ am.name); 53 54 auto data = cast(string)am.expandedData(); 55 File d = File(outputdir ~ "/" ~ am.name, "wb"); 56 d.write(data); 57 d.close(); 58 } catch (Exception e) { 59 errorMessage("Failed to extract " ~ am.name); 60 } 61 } 62 } 63 64 void MakeIfnot(string dir) { 65 if (!exists(dir)) { 66 mkdir(dir); 67 } 68 }