getPackageDirectory method

Future<String> getPackageDirectory(
  1. WindowsMetadataPackage package,
  2. String version,
  3. Future<Uint8List> downloadFunction(), {
  4. @Deprecated('No replacement') Logger? logger,
})

Fetches the package directory, downloading and extracting it if necessary.

  • Checks if the package exists locally.
  • If absent, downloads the package via downloadFunction.
  • Extracts the archive contents into a new directory.

Returns the absolute package directory path.

Implementation

Future<String> getPackageDirectory(
  WindowsMetadataPackage package,
  String version,
  Future<Uint8List> Function() downloadFunction, {
  @Deprecated('No replacement') Logger? logger,
}) async {
  final packagePath = _packagePath(package, version);
  final metadataPath = p.join(packagePath, package.assetName);
  if (File(metadataPath).existsSync()) return packagePath;
  Directory(packagePath).createSync(recursive: true);
  final logger = cli_logging.Logger.standard(
    ansi: .new(stdout.supportsAnsiEscapes),
  );
  var progress = logger.progress(
    'Downloading NuGet package "$package" (v$version)',
  );
  final archiveBytes = await _downloadPackage(
    downloadFunction,
    logger: logger,
  );
  progress.finish(showTiming: true);
  progress = logger.progress('Extracting $package.$version.nupkg');
  final archive = ZipDecoder().decodeBytes(archiveBytes);
  await extractArchiveToDisk(archive, packagePath);
  progress.finish(showTiming: true);
  return packagePath;
}