Skip to content

Commit 6c832dc

Browse files
committed
InstallWizard: real extraction progress bar using ZipInputStream
1 parent 045dfef commit 6c832dc

2 files changed

Lines changed: 33 additions & 12 deletions

File tree

mode/CppMode.jar

546 Bytes
Binary file not shown.

src/java/InstallWizard.java

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -308,19 +308,40 @@ private boolean installPortableGcc() {
308308
setProgress(100);
309309
setStep("Extracting gcc...");
310310
appendLog("Extracting to " + gccDir.getAbsolutePath());
311-
setIndeterminate(true);
312-
// Use PowerShell Expand-Archive (available on all modern Windows)
313-
Process extract = new ProcessBuilder(
314-
"powershell", "-NoProfile", "-Command",
315-
"Expand-Archive -Force -Path '" + zipFile.getAbsolutePath() +
316-
"' -DestinationPath '" + gccDir.getAbsolutePath() + "'")
317-
.redirectErrorStream(true).start();
318-
streamToLog(extract);
319-
int code = extract.waitFor();
320-
zipFile.delete(); // clean up zip after extraction
321-
setIndeterminate(false);
311+
// Count entries first for accurate progress
312+
int totalEntries = 0;
313+
try (java.util.zip.ZipInputStream zcount =
314+
new java.util.zip.ZipInputStream(new java.io.FileInputStream(zipFile))) {
315+
while (zcount.getNextEntry() != null) totalEntries++;
316+
}
317+
appendLog("Extracting " + totalEntries + " files...");
318+
int extracted = 0;
319+
try (java.util.zip.ZipInputStream zis =
320+
new java.util.zip.ZipInputStream(new java.io.FileInputStream(zipFile))) {
321+
java.util.zip.ZipEntry entry;
322+
byte[] buf = new byte[64 * 1024];
323+
while ((entry = zis.getNextEntry()) != null) {
324+
if (cancelled.get()) return false;
325+
java.io.File outFile = new java.io.File(gccDir, entry.getName());
326+
if (entry.isDirectory()) {
327+
outFile.mkdirs();
328+
} else {
329+
outFile.getParentFile().mkdirs();
330+
try (java.io.FileOutputStream fos = new java.io.FileOutputStream(outFile)) {
331+
int n;
332+
while ((n = zis.read(buf)) != -1) fos.write(buf, 0, n);
333+
}
334+
}
335+
extracted++;
336+
int pct = totalEntries > 0 ? (extracted * 100 / totalEntries) : 0;
337+
setProgress(pct);
338+
if (extracted % 500 == 0)
339+
appendLog("Extracted " + extracted + " / " + totalEntries + " files...");
340+
}
341+
}
342+
zipFile.delete();
322343
setProgress(100);
323-
if (code != 0) { appendLog("Extraction failed."); return false; }
344+
int code = 0; // Java extraction always succeeds or throws
324345
if (!getPortableGpp().exists()) {
325346
appendLog("g++.exe not found after extraction -- unexpected zip structure.");
326347
return false;

0 commit comments

Comments
 (0)