1 /** 2 * download dxlib lib 3 * 4 * Author: dokutoku 5 * License: CC0 Universal 6 */ 7 module hello; 8 9 10 private static import std.algorithm; 11 private static import std.ascii; 12 private static import std.digest; 13 private static import std.digest.sha; 14 private static import std.file; 15 private static import std.getopt; 16 private static import std.net.curl; 17 private static import std.path; 18 private static import std.zip; 19 20 struct download_info 21 { 22 string uri; 23 string sha512_hash; 24 25 private bool verify(string file_path) const 26 27 do 28 { 29 return std.file.exists(file_path) && std.file.isFile(file_path) && std.digest.secureEqual(this.sha512_hash, std.digest.toHexString!(std.ascii.LetterCase.lower)(std.digest.sha.sha512Of(std.file.read(file_path))).idup); 30 } 31 32 private void download(string dir_path) const 33 34 in 35 { 36 assert(dir_path.length != 0); 37 assert(std.path.isValidPath(dir_path)); 38 } 39 40 do 41 { 42 string file_path = std.path.buildNormalizedPath(dir_path, std.path.baseName(this.uri)); 43 44 if (this.verify(file_path)) { 45 return; 46 } 47 48 std.net.curl.download(this.uri, file_path); 49 50 if (!this.verify(file_path)) { 51 throw new Exception(`The hash value of the downloaded file is invalid.`); 52 } 53 } 54 55 void extract_lib(string dir_path, string base_dir) const 56 57 in 58 { 59 assert(std.path.extension(this.uri) == `.zip`); 60 } 61 62 do 63 { 64 this.download(dir_path); 65 string zip_file = std.path.baseName(this.uri); 66 //string base_dir = std.path.buildNormalizedPath(output_dir, `lib`); 67 std.file.mkdirRecurse(base_dir); 68 auto zip = new std.zip.ZipArchive(std.file.read(std.path.buildNormalizedPath(dir_path, zip_file))); 69 70 foreach (name, am; zip.directory) { 71 if (!std.algorithm.endsWith(name, `.a`, `.lib`)) { 72 continue; 73 } 74 75 string out_filename = std.path.buildPath(base_dir, std.path.baseName(name)); 76 std.file.write(out_filename, zip.expand(am)); 77 } 78 } 79 } 80 81 static immutable download_info windows_vc_info = 82 { 83 uri: `https://dxlib.xsrv.jp/DxLib/DxLib_VC3_22c.zip`, 84 sha512_hash: `1af5ee1c96221db199b4a376df846ede048698488317db7508aec2b4da66356295f8432b4abd6db0b4e29d1524ee15a656e8870fe032d073d85537b6b82b6e67`, 85 }; 86 87 static immutable download_info windows_bcc_info = 88 { 89 uri: `https://dxlib.xsrv.jp/DxLib/DxLib_BCC3_22c.zip`, 90 sha512_hash: `00211f9ac32c4ac3646b72fbfd53a4ebff02f27ca72531e6248c600a18f52b2e414b9a98b382420a6274d97753ad29f112af9d0fe35282086a5c1040f898e366`, 91 }; 92 93 static immutable download_info windows_bcc2_info = 94 { 95 uri: `https://dxlib.xsrv.jp/DxLib/DxLib_BCC23_22c.zip`, 96 sha512_hash: `0f7232d51ef720b9e3d32821d81cc27808d9417cf38845982a75e05adf7c67dc5dcb1eec2646e5aa394f1914d193ee77852f9e41417c4ee0f93fcfd96ddb29da`, 97 }; 98 99 static immutable download_info windows_gcc_info = 100 { 101 uri: `https://dxlib.xsrv.jp/DxLib/DxLib_GCC3_22c.zip`, 102 sha512_hash: `479632f1602a09fd122be54c650310855e07cd998d4d90b174e9b41293dbc9eec4aacd8243a22f7b1c68e26a2f04d5ee54fdb027009fdf3bc41a9fb24a74f22d`, 103 }; 104 105 static immutable download_info android_info = 106 { 107 uri: `https://dxlib.xsrv.jp/DxLib_Android3_22c.zip`, 108 sha512_hash: `a6a757d9f7df859f7fd181db4263d6903f2daea05edd2bc8b27df1492ca45f855d9d0de7f0548791a7198e8f06ea33c9b5ce6b5efa42ae168ab51c6d9aa4d8e6`, 109 }; 110 111 static immutable download_info ios_info = 112 { 113 uri: `https://dxlib.xsrv.jp/DxLib/DxLib_iOS3_22c.zip`, 114 sha512_hash: `e18eb3138ec89f79f3835d17f269e4f74a9fd4f2654afe3df6c98e6f29544dc33d0043c14ba5de26a0b617290b7f3b25817198100af631f06e6070e4da6f76ff`, 115 }; 116 117 void main(string[] argv) 118 119 do 120 { 121 string download_path = null; 122 string output_path = null; 123 bool is_windows = false; 124 bool is_windows_vc = false; 125 bool is_windows_bcc = false; 126 bool is_windows_bcc2 = false; 127 bool is_windows_gcc = false; 128 bool is_android = false; 129 bool is_ios = false; 130 bool is_all = false; 131 132 auto helpInformation = std.getopt.getopt 133 ( 134 argv, 135 `download-path`, `download zip path.`, &download_path, 136 `out-path`, `Output lib path.`, &output_path, 137 `Windows`, `Download Visual Studio lib.`, &is_windows, 138 `Windows-vc`, `Download Visual Studio lib.`, &is_windows_vc, 139 `Windows-bcc`, `Download C++ Builder lib.`, &is_windows_bcc, 140 `Windows-bcc2`, `Download Borland C++ Compiler lib.`, &is_windows_bcc2, 141 `Windows-gcc`, `Download Gnu C++ lib.`, &is_windows_gcc, 142 `Android`, `Download Android lib.`, &is_android, 143 `iOS`, `Download iOS lib.`, &is_ios, 144 `All`, `All download lib.`, &is_all, 145 ); 146 147 if (helpInformation.helpWanted) { 148 std.getopt.defaultGetoptPrinter(`Some information about the program.`, helpInformation.options); 149 150 return; 151 } 152 153 if ((!std.path.isValidPath(download_path)) || (!std.file.isDir(download_path))) { 154 download_path = `./`; 155 } 156 157 if ((!std.path.isValidPath(output_path)) || (!std.file.isDir(output_path))) { 158 output_path = `./`; 159 } 160 161 if ((is_all) || (is_windows) || (is_windows_vc)) { 162 windows_vc_info.extract_lib(download_path, std.path.buildNormalizedPath(output_path, `lib`, `windows-vc`)); 163 } 164 165 if ((is_all) || (is_windows_bcc)) { 166 windows_bcc_info.extract_lib(download_path, std.path.buildNormalizedPath(output_path, `lib`, `windows-bcc`)); 167 } 168 169 if ((is_all) || (is_windows_bcc2)) { 170 windows_bcc2_info.extract_lib(download_path, std.path.buildNormalizedPath(output_path, `lib`, `windows-bcc2`)); 171 } 172 173 if ((is_all) || (is_windows_gcc)) { 174 windows_gcc_info.extract_lib(download_path, std.path.buildNormalizedPath(output_path, `lib`, `windows-gcc`)); 175 } 176 177 if ((is_all) || (is_android)) { 178 android_info.extract_lib(download_path, std.path.buildNormalizedPath(output_path, `lib`, `android`)); 179 } 180 181 if ((is_all) || (is_ios)) { 182 ios_info.extract_lib(download_path, std.path.buildNormalizedPath(output_path, `lib`, `ios`)); 183 } 184 }