getNatives method

Future<void> getNatives ()

Implementation

Future<void> getNatives() async {
  String nativeDirectory = path.join(root, 'natives', this.version["id"]);

  if(!await File(nativeDirectory).exists()) {
    await createDirIfNotExists(nativeDirectory);
    List<Future Function()> funcs = [];

    this.version["libraries"].forEach((lib) {
      funcs.add(() async {

        if (lib["downloads"] == null || lib["downloads"]["classifiers"] == null ||this.parseRule(lib)) { return; }
        Map native = this.getOS() == 'osx'
            ? lib["downloads"]["classifiers"]['natives-osx'] || lib["downloads"]["classifiers"]['natives-macos']
            : lib["downloads"]["classifiers"]['natives-${this.getOS()}'];

        if (native != null) {
          String name = native["path"].substring(native["path"].lastIndexOf("/") + 1);
          await createDirIfNotExists(nativeDirectory);
          await downloadFile(native["url"], path.join(nativeDirectory,name));

          try {
            List<int> bytes = File(path.join(nativeDirectory, name)).readAsBytesSync();

            Archive archive = ZipDecoder().decodeBytes(bytes);

            for (ArchiveFile file in archive) {
              String filename = file.name;
              if (file.isFile) {
                List<int> data = file.content;
                File('$nativeDirectory/' + filename)
                  ..createSync(recursive: true)
                  ..writeAsBytesSync(data);
              } else {
                Directory('$nativeDirectory/' + filename)
                  ..create(recursive: true);
              }
            }
          } catch(e) {
          }
         await File(path.join(nativeDirectory, name)).delete();
        }
      });
    });
    for(Function f in funcs) {
      await f();
    }
  }
}