mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-05-06 00:34:27 +02:00
keep sorting with original zip entry
This commit is contained in:
parent
4e9cfd4100
commit
9914722bac
@ -15,10 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.reandroid.archive;
|
package com.reandroid.archive;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
public class InputSourceUtil {
|
public class InputSourceUtil {
|
||||||
|
|
||||||
@ -37,14 +38,11 @@ public class InputSourceUtil {
|
|||||||
while (path.startsWith("/")){
|
while (path.startsWith("/")){
|
||||||
path=path.substring(1);
|
path=path.substring(1);
|
||||||
}
|
}
|
||||||
while (path.startsWith(File.separator)){
|
|
||||||
path=path.substring(1);
|
|
||||||
}
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, InputSource> mapZipFileSources(ZipFile zipFile){
|
public static Map<String, InputSource> mapZipFileSources(ZipFile zipFile){
|
||||||
Map<String, InputSource> results=new HashMap<>();
|
Map<String, InputSource> results=new LinkedHashMap<>();
|
||||||
Enumeration<? extends ZipEntry> entriesEnum = zipFile.entries();
|
Enumeration<? extends ZipEntry> entriesEnum = zipFile.entries();
|
||||||
int i=0;
|
int i=0;
|
||||||
while (entriesEnum.hasMoreElements()){
|
while (entriesEnum.hasMoreElements()){
|
||||||
@ -54,11 +52,42 @@ public class InputSourceUtil {
|
|||||||
}
|
}
|
||||||
ZipEntrySource source=new ZipEntrySource(zipFile, zipEntry);
|
ZipEntrySource source=new ZipEntrySource(zipFile, zipEntry);
|
||||||
source.setSort(i);
|
source.setSort(i);
|
||||||
|
source.setMethod(zipEntry.getMethod());
|
||||||
results.put(source.getName(), source);
|
results.put(source.getName(), source);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
public static Map<String, ByteInputSource> mapInputStreamAsBuffer(InputStream inputStream) throws IOException {
|
||||||
|
Map<String, ByteInputSource> results = new LinkedHashMap<>();
|
||||||
|
ZipInputStream zin = new ZipInputStream(inputStream);
|
||||||
|
ZipEntry zipEntry;
|
||||||
|
int i=0;
|
||||||
|
while ((zipEntry=zin.getNextEntry())!=null){
|
||||||
|
if(zipEntry.isDirectory()){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
byte[] buffer = loadBuffer(zin);
|
||||||
|
String name = sanitize(zipEntry.getName());
|
||||||
|
ByteInputSource source = new ByteInputSource(buffer, name);
|
||||||
|
source.setSort(i);
|
||||||
|
source.setMethod(zipEntry.getMethod());
|
||||||
|
results.put(name, source);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
zin.close();
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
private static byte[] loadBuffer(InputStream in) throws IOException {
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
byte[] buff=new byte[40960];
|
||||||
|
int len;
|
||||||
|
while((len=in.read(buff))>0){
|
||||||
|
outputStream.write(buff, 0, len);
|
||||||
|
}
|
||||||
|
outputStream.close();
|
||||||
|
return outputStream.toByteArray();
|
||||||
|
}
|
||||||
public static List<InputSource> listZipFileSources(ZipFile zipFile){
|
public static List<InputSource> listZipFileSources(ZipFile zipFile){
|
||||||
List<InputSource> results=new ArrayList<>();
|
List<InputSource> results=new ArrayList<>();
|
||||||
Enumeration<? extends ZipEntry> entriesEnum = zipFile.entries();
|
Enumeration<? extends ZipEntry> entriesEnum = zipFile.entries();
|
||||||
|
@ -30,7 +30,7 @@ public class ZipArchive {
|
|||||||
this.mEntriesMap=entriesMap;
|
this.mEntriesMap=entriesMap;
|
||||||
}
|
}
|
||||||
public ZipArchive(){
|
public ZipArchive(){
|
||||||
this(new HashMap<>());
|
this(new LinkedHashMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void extract(File outDir) throws IOException {
|
public void extract(File outDir) throws IOException {
|
||||||
@ -95,19 +95,22 @@ public class ZipArchive {
|
|||||||
List<InputSource> sourceList = InputSourceUtil.listZipFileSources(zipFile);
|
List<InputSource> sourceList = InputSourceUtil.listZipFileSources(zipFile);
|
||||||
this.addAll(sourceList);
|
this.addAll(sourceList);
|
||||||
}
|
}
|
||||||
public void addAll(Collection<InputSource> inputSourceList){
|
public void addAll(Collection<? extends InputSource> inputSourceList){
|
||||||
for(InputSource inputSource:inputSourceList){
|
for(InputSource inputSource:inputSourceList){
|
||||||
add(inputSource);
|
add(inputSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void add(InputSource inputSource){
|
public void add(InputSource inputSource){
|
||||||
|
if(inputSource==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
String name=inputSource.getName();
|
String name=inputSource.getName();
|
||||||
Map<String, InputSource> map=mEntriesMap;
|
Map<String, InputSource> map=mEntriesMap;
|
||||||
map.remove(name);
|
map.remove(name);
|
||||||
map.put(name, inputSource);
|
map.put(name, inputSource);
|
||||||
}
|
}
|
||||||
public List<InputSource> listInputSources(){
|
public List<InputSource> listInputSources(){
|
||||||
return InputSourceUtil.sort(new ArrayList<>(mEntriesMap.values()));
|
return new ArrayList<>(mEntriesMap.values());
|
||||||
}
|
}
|
||||||
public InputSource getInputSource(String name){
|
public InputSource getInputSource(String name){
|
||||||
return mEntriesMap.get(name);
|
return mEntriesMap.get(name);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user