Skip to content
7 changes: 7 additions & 0 deletions extensions/ql-vscode/src/codeql-cli/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
showAndLogWarningMessage,
} from "../common/logging";
import { unzipToDirectoryConcurrently } from "../common/unzip-concurrently";
import { reportUnzipProgress } from "../common/vscode/unzip-progress";

/**
* distribution.ts
Expand Down Expand Up @@ -423,6 +424,12 @@ class ExtensionSpecificDistributionManager {
await unzipToDirectoryConcurrently(
archivePath,
this.getDistributionStoragePath(),
progressCallback
? reportUnzipProgress(
`Extracting CodeQL CLI ${release.name}…`,
progressCallback,
)
: undefined,
);
} finally {
await remove(tmpDirectory);
Expand Down
10 changes: 6 additions & 4 deletions extensions/ql-vscode/src/common/vscode/progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ export function withInheritedProgress<R>(
}
}

export function readableBytesMb(numBytes: number): string {
Comment thread
koesie10 marked this conversation as resolved.
Outdated
return `${(numBytes / (1024 * 1024)).toFixed(1)} MB`;
}

/**
* Displays a progress monitor that indicates how much progess has been made
* reading from a stream.
Expand All @@ -125,15 +129,13 @@ export function reportStreamProgress(
) {
if (progress && totalNumBytes) {
let numBytesDownloaded = 0;
const bytesToDisplayMB = (numBytes: number): string =>
`${(numBytes / (1024 * 1024)).toFixed(1)} MB`;
const updateProgress = () => {
progress({
step: numBytesDownloaded,
maxStep: totalNumBytes,
message: `${messagePrefix} [${bytesToDisplayMB(
message: `${messagePrefix} [${readableBytesMb(
numBytesDownloaded,
)} of ${bytesToDisplayMB(totalNumBytes)}]`,
)} of ${readableBytesMb(totalNumBytes)}]`,
});
};

Expand Down
17 changes: 17 additions & 0 deletions extensions/ql-vscode/src/common/vscode/unzip-progress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { UnzipProgressCallback } from "../unzip";
import { ProgressCallback, readableBytesMb } from "./progress";

export function reportUnzipProgress(
messagePrefix: string,
progress: ProgressCallback,
): UnzipProgressCallback {
return ({ bytesExtracted, totalBytes }) => {
progress({
step: bytesExtracted,
maxStep: totalBytes,
message: `${messagePrefix} [${readableBytesMb(
bytesExtracted,
)} of ${readableBytesMb(totalBytes)}]`,
});
};
}