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.string;
11 import std.json;
12 import std.conv;
13 import std.algorithm;
14 import std.array;
15 
16 void logMessage(string msg) {
17 	writeln(("-> " ~ msg).color("blue"));
18 }
19 
20 void errorMessage(string msg) {
21 	writeln(("! " ~ msg).color("red"));
22 }
23 
24 void successMessage(string msg) {
25 	writeln(("> " ~ msg).color("green"));
26 }
27 
28 void postMSG(string msg) {
29 	writeln(("* " ~ msg).color("light_white"));
30 }
31 
32 void HintMSG(string msg) {
33 	writeln(("* " ~ msg).color("yellow"));
34 }
35 
36 void DownloadFile(string url, string f) {
37 	download(url, f);
38 }
39 
40 void Extract(string fname, string outputdir) {
41 	logMessage("Extracting " ~ fname ~ "...");
42 	auto zip = new ZipArchive(read(fname));
43 	foreach (ArchiveMember am; zip.directory)
44 		{
45 			try {
46 				if (!am.name.endsWith("/")) {
47 					zip.expand(am);
48 					logMessage("EXTRACT - " ~ am.name);
49 					
50 					auto data = cast(string)am.expandedData();
51 					File d = File(outputdir ~ "/" ~ am.name, "wb");
52 					d.write(data);
53 					d.close();
54 				} else {
55 					MakeIfnot(outputdir ~ "/" ~ am.name);
56 
57 				}
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 }