From 6fbe64d8e271dd1c4d69c2b2c43cef503ba07a74 Mon Sep 17 00:00:00 2001 From: idk Date: Sun, 23 Oct 2022 15:41:59 -0400 Subject: [PATCH] monitor execution of update installer for errors --- java/net/i2p/router/ZipUpdateProcess.java | 43 +++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/java/net/i2p/router/ZipUpdateProcess.java b/java/net/i2p/router/ZipUpdateProcess.java index 35c62fe..6ed01a7 100644 --- a/java/net/i2p/router/ZipUpdateProcess.java +++ b/java/net/i2p/router/ZipUpdateProcess.java @@ -1,8 +1,14 @@ package net.i2p.router; import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.Map; import java.util.function.*; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; import net.i2p.I2PAppContext; import net.i2p.router.*; import net.i2p.util.Log; @@ -79,4 +85,41 @@ public class ZipUpdateProcess implements Runnable { _log.error("Error running updater, update may fail." + ioe); } } + + private static void unzip(String zipFilePath, String destDir) { + File dir = new File(destDir); + // create output directory if it doesn't exist + if (!dir.exists()) + dir.mkdirs(); + FileInputStream fis; + // buffer for read and write data to file + byte[] buffer = new byte[1024]; + try { + fis = new FileInputStream(zipFilePath); + ZipInputStream zis = new ZipInputStream(fis); + ZipEntry ze = zis.getNextEntry(); + while (ze != null) { + String fileName = ze.getName(); + File newFile = new File(destDir + File.separator + fileName); + System.out.println("Unzipping to " + newFile.getAbsolutePath()); + // create directories for sub directories in zip + new File(newFile.getParent()).mkdirs(); + FileOutputStream fos = new FileOutputStream(newFile); + int len; + while ((len = zis.read(buffer)) > 0) { + fos.write(buffer, 0, len); + } + fos.close(); + // close this ZipEntry + zis.closeEntry(); + ze = zis.getNextEntry(); + } + // close last ZipEntry + zis.closeEntry(); + zis.close(); + fis.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } }