checkTools static method

Future<bool> checkTools()

Checks if the required compression tools are available on the current platform.

Returns true if the compression tools are available, false otherwise.

Platform-specific tools checked:

  • Windows: PowerShell's Compress-Archive cmdlet
  • macOS/Linux: zip command-line utility

Throws UnsupportedError for unsupported platforms.

Example usage:

if (await CompressFiles.checkTools()) {
  print('Compression tools are available');
} else {
  print('Compression tools not found');
}

Implementation

static Future<bool> checkTools() async {
  if (Platform.isWindows) {
    // Check if PowerShell Compress-Archive cmdlet is available
    return await Process.run(
            "powershell",
            [
              "Get-Command",
              "Compress-Archive",
            ],
            runInShell: true)
        .then((value) => value.exitCode == 0);
  } else if (Platform.isMacOS || Platform.isLinux) {
    // Check if zip command is available in PATH
    return await Process.run("which", [
      "zip",
    ]).then((value) => value.exitCode == 0);
  } else {
    throw UnsupportedError(
      "Unsupported platform for compression tools check",
    );
  }
}