diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index 7f62d3619b5ffbde797ec59d484e0916d6a525de..05f4ff881dda9828c295f5e45034375322efc97a 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -328,25 +328,14 @@ public class Compressor { pathToFile(utility, utility.getSignaturePath(), NULL_DIR_NAME, false); } - String[] outPath = utility.getOutPath().replace("\\", "/").split("/"); - if (outPath.length < 2) { - LOG.error("Compressor::compressAppMode the outPath is invalid, length: " + outPath.length); - return; - } - String[] path = utility.getOutPath().split(outPath[outPath.length - 2].toString()); + File appOutputFile = new File(utility.getOutPath().trim()); List fileList = new ArrayList<>(); for (String hapPathItem : utility.getFormattedHapPathList()) { - String fName = hapPathItem.trim(); - String[] temp = fName.replace("\\", "/").split("/"); - if (temp.length < 1) { - LOG.error("Compressor::compressAppMode the hap file path is invalid, length: " + temp.length); - continue; - } - String[] str = temp[temp.length - 1].split("\\."); - String outPathString = path[0] + str[0]; - fileList.add(outPathString); + File hapFile = new File(hapPathItem.trim()); + String hapTempPath = appOutputFile.getParentFile().getParent() + File.separator + hapFile.getName(); + fileList.add(hapTempPath); try { - compressPackinfoIntoHap(hapPathItem, outPathString, utility.getPackInfoPath()); + compressPackinfoIntoHap(hapPathItem, hapTempPath, utility.getPackInfoPath()); } catch ( IOException e) { LOG.error("Compressor::compressAppMode compress pack.info into hap failed"); throw new BundleException("Compressor::compressAppMode compress pack.info into hap failed"); @@ -354,11 +343,11 @@ public class Compressor { } for (String hapPath : fileList) { - pathToFile(utility, hapPath + HAP_SUFFIX, NULL_DIR_NAME, false); + pathToFile(utility, hapPath, NULL_DIR_NAME, false); } for (String hapPath : fileList) { - deleteFile(hapPath + HAP_SUFFIX); + deleteFile(hapPath); } if (!utility.getEntryCardPath().isEmpty()) { @@ -388,7 +377,7 @@ public class Compressor { private void compressPackinfoIntoHap(String hapPathItem, String outPathString, String packInfo) throws FileNotFoundException, IOException, BundleException { ZipFile sourceHapFile = new ZipFile(hapPathItem); - ZipOutputStream append = new ZipOutputStream(new FileOutputStream(outPathString + ".hap")); + ZipOutputStream append = new ZipOutputStream(new FileOutputStream(outPathString)); try { Enumeration entries = sourceHapFile.entries(); while (entries.hasMoreElements()) { diff --git a/adapter/ohos/ResourcesParser.java b/adapter/ohos/ResourcesParser.java index 899dc9cb171c0ff57a940d4e3be1b9caee9e3eed..f8ffbcdcb657fcdc744764f6b642a0701e7b3006 100644 --- a/adapter/ohos/ResourcesParser.java +++ b/adapter/ohos/ResourcesParser.java @@ -36,7 +36,6 @@ public class ResourcesParser { private static final int VERSION_BYTE_LENGTH = 128; private static final int TAG_BYTE_LENGTH = 4; - private static final int BUF_MOVE_LENGTH = 8; private static final Log LOG = new Log(ResourcesParser.class.toString()); /**