From 3e1a1b2bb4480cdf2750f6c3fe46c2c8a567c3ca Mon Sep 17 00:00:00 2001 From: wangdengjia Date: Fri, 20 Aug 2021 17:45:28 +0800 Subject: [PATCH] IssueNo:#I46KJV Description:add packtools code to master Sig:appexecfwk Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangdengjia Change-Id: Ib27dc71181316419d911d3016165b4db6ac60df5 --- adapter/ohos/Distro.java | 5 +++++ adapter/ohos/JsonUtil.java | 5 +++++ adapter/ohos/Uncompress.java | 41 +++++++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/adapter/ohos/Distro.java b/adapter/ohos/Distro.java index 67c08baa..6f3b4849 100644 --- a/adapter/ohos/Distro.java +++ b/adapter/ohos/Distro.java @@ -39,4 +39,9 @@ public class Distro { * Indicates the installationFree of Distro. */ public int installationFree = 2; + + /** + * Indicates the virtualMachine of Distro. + */ + public String virtualMachine = "default"; } \ No newline at end of file diff --git a/adapter/ohos/JsonUtil.java b/adapter/ohos/JsonUtil.java index 4824b159..34841750 100644 --- a/adapter/ohos/JsonUtil.java +++ b/adapter/ohos/JsonUtil.java @@ -428,6 +428,11 @@ public class JsonUtil { } else { distro.installationFree = 2; } + if (distroObj.containsKey("virtualMachine")) { + distro.virtualMachine = getJsonString(distroObj, "virtualMachine"); + } else { + distro.virtualMachine = "default"; + } hapInfo.distro = distro; } diff --git a/adapter/ohos/Uncompress.java b/adapter/ohos/Uncompress.java index 4224d66a..ffbef2d1 100644 --- a/adapter/ohos/Uncompress.java +++ b/adapter/ohos/Uncompress.java @@ -103,7 +103,7 @@ public class Uncompress { } else if (Utility.MODE_HAR.equals(utility.getMode())) { dataTransferAllFiles(utility.getHarPath(), utility.getOutPath()); } else { - dataTransferAllFiles(utility.getAppPath(), utility.getOutPath()); + dataTransferFilesByApp(utility, utility.getAppPath(), utility.getOutPath()); } } catch (BundleException ignored) { unpackageResult = false; @@ -518,6 +518,45 @@ public class Uncompress { } } + private static void dataTransferFilesByApp(Utility utility, String srcPath, String destDirPath) + throws BundleException { + ZipFile zipFile = null; + try { + zipFile = new ZipFile(new File(srcPath)); + int entriesNum = 0; + for (Enumeration entries = zipFile.entries(); entries.hasMoreElements(); ) { + entriesNum++; + ZipEntry entry = entries.nextElement(); + if (entry == null) { + continue; + } + String filePath = destDirPath + LINUX_FILE_SEPARATOR + entry.getName(); + File destFile = new File(filePath); + if (destFile != null && destFile.getParentFile() != null && !destFile.getParentFile().exists()) { + destFile.getParentFile().mkdirs(); + } + boolean isUnpackApk = "true".equals(utility.getUnpackApk()); + if (isUnpackApk && filePath.toLowerCase().endsWith(HAP_SUFFIX)) { + dataTransfer(zipFile, entry, destFile); + unzip(utility, filePath, destDirPath, APK_SUFFIX); + String[] temp = filePath.replace("\\", "/").split("/"); + String hapName = temp[temp.length - 1]; + repackHap(filePath, destDirPath, hapName, utility.getUnpackApk()); + } else { + dataTransfer(zipFile, entry, destFile); + } + } + } catch (FileNotFoundException ignored) { + LOG.error("Uncompress::unzipApk file not found exception"); + throw new BundleException("Unzip Apk failed"); + } catch (IOException exception) { + LOG.error("Uncompress::unzipApk io exception: " + exception.getMessage()); + throw new BundleException("Unzip Apk failed"); + } finally { + Utility.closeStream(zipFile); + } + } + private static byte[] getResourceDataFromHap(ZipFile zipFile) throws BundleException, IOException { int entriesNum = 0; InputStream indexInputStream = null; -- Gitee