mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-05-09 02:04:26 +02:00
temporary fix for "file name too long errors" REAndroid/APKEditor#15
This commit is contained in:
parent
128346351a
commit
c650910b2b
@ -77,9 +77,17 @@ public class ApkJsonDecoder {
|
||||
jsonObject.write(file);
|
||||
addDecoded(path);
|
||||
}
|
||||
// TODO: temporary fix
|
||||
private void writeRootFiles(File dir) throws IOException {
|
||||
for(InputSource inputSource:apkModule.getApkArchive().listInputSources()){
|
||||
writeRootFile(dir, inputSource);
|
||||
try{
|
||||
writeRootFile(dir, inputSource);
|
||||
}catch (IOException ex){
|
||||
APKLogger logger = apkModule.getApkLogger();
|
||||
if(logger!=null){
|
||||
logger.logMessage("ERROR: "+ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void writeRootFile(File dir, InputSource inputSource) throws IOException {
|
||||
|
@ -279,7 +279,11 @@ import java.util.*;
|
||||
return element;
|
||||
}
|
||||
private String getPackageDirName(PackageBlock packageBlock){
|
||||
return packageBlock.getIndex()+"-"+packageBlock.getName();
|
||||
String name = ApkUtil.sanitizeForFileName(packageBlock.getName());
|
||||
if(name==null){
|
||||
name="package";
|
||||
}
|
||||
return packageBlock.getIndex()+"-"+name;
|
||||
}
|
||||
private void extractRootFiles(File outDir) throws IOException {
|
||||
logMessage("Extracting root files");
|
||||
@ -300,9 +304,14 @@ import java.util.*;
|
||||
if(!dir.exists()){
|
||||
dir.mkdirs();
|
||||
}
|
||||
FileOutputStream outputStream=new FileOutputStream(file);
|
||||
inputSource.write(outputStream);
|
||||
outputStream.close();
|
||||
// TODO:Temporary fix
|
||||
try{
|
||||
FileOutputStream outputStream=new FileOutputStream(file);
|
||||
inputSource.write(outputStream);
|
||||
outputStream.close();
|
||||
}catch (IOException ex){
|
||||
logMessage("ERROR: "+ex.getMessage());
|
||||
}
|
||||
}
|
||||
private boolean containsDecodedPath(String path){
|
||||
return mDecodedPaths.contains(path);
|
||||
|
@ -21,6 +21,53 @@ import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class ApkUtil {
|
||||
public static String sanitizeForFileName(String name){
|
||||
if(name==null){
|
||||
return null;
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
char[] chars = name.toCharArray();
|
||||
boolean skipNext = true;
|
||||
int length = 0;
|
||||
int lengthMax = MAX_FILE_NAME_LENGTH;
|
||||
for(int i=0;i<chars.length;i++){
|
||||
if(length>=lengthMax){
|
||||
break;
|
||||
}
|
||||
char ch = chars[i];
|
||||
if(isGoodFileNameSymbol(ch)){
|
||||
if(!skipNext){
|
||||
builder.append(ch);
|
||||
length++;
|
||||
}
|
||||
skipNext=true;
|
||||
continue;
|
||||
}
|
||||
if(!isGoodFileNameChar(ch)){
|
||||
skipNext = true;
|
||||
continue;
|
||||
}
|
||||
builder.append(ch);
|
||||
length++;
|
||||
skipNext=false;
|
||||
}
|
||||
if(length==0){
|
||||
return null;
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
private static boolean isGoodFileNameSymbol(char ch){
|
||||
return ch == '.'
|
||||
|| ch == '+'
|
||||
|| ch == '-'
|
||||
|| ch == '_'
|
||||
|| ch == '#';
|
||||
}
|
||||
private static boolean isGoodFileNameChar(char ch){
|
||||
return (ch >= '0' && ch <= '9')
|
||||
|| (ch >= 'A' && ch <= 'Z')
|
||||
|| (ch >= 'a' && ch <= 'z');
|
||||
}
|
||||
public static int parseHex(String hex){
|
||||
long l=Long.decode(hex);
|
||||
return (int) l;
|
||||
@ -144,4 +191,6 @@ public class ApkUtil {
|
||||
|
||||
public static final String TAG_STRING_ARRAY = "string-array";
|
||||
public static final String TAG_INTEGER_ARRAY = "integer-array";
|
||||
|
||||
private static final int MAX_FILE_NAME_LENGTH = 50;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user