(tool: Tool)
| 17 | * @returns filePath for the tool if download was successful or null. |
| 18 | */ |
| 19 | export async function downloadTool(tool: Tool): Promise<string | null> { |
| 20 | try { |
| 21 | outputChannel.show(); |
| 22 | outputChannel.appendLine("-".repeat(50)); |
| 23 | outputChannel.appendLine(`Downloading file: ${tool.fileName}`); |
| 24 | outputChannel.appendLine("-".repeat(50)); |
| 25 | const buffer = await downloadFile(tool.downloadUrl); |
| 26 | const filePath = path.join(apklabDataDir, tool.fileName); |
| 27 | fs.writeFileSync(filePath, buffer); |
| 28 | let configPath = filePath; |
| 29 | if (tool.zipped && tool.unzipDir) { |
| 30 | configPath = path.join(apklabDataDir, tool.unzipDir); |
| 31 | try { |
| 32 | await extract(filePath, { dir: configPath }); |
| 33 | outputChannel.appendLine( |
| 34 | `Extracted ${filePath} into ${configPath}`, |
| 35 | ); |
| 36 | } catch (err) { |
| 37 | const errorMessage = |
| 38 | err instanceof Error ? err.message : String(err); |
| 39 | outputChannel.appendLine( |
| 40 | `Error: Extracting file ${filePath}: ${errorMessage}`, |
| 41 | ); |
| 42 | } |
| 43 | } |
| 44 | await vscode.workspace |
| 45 | .getConfiguration(extensionConfigName) |
| 46 | .update( |
| 47 | tool.configName, |
| 48 | configPath, |
| 49 | vscode.ConfigurationTarget.Global, |
| 50 | ); |
| 51 | return filePath; |
| 52 | } catch (error) { |
| 53 | outputChannel.appendLine(`Error: ${error}`); |
| 54 | return null; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Maximum number of redirects to follow |
no test coverage detected