temporary fix for "file name too long errors" REAndroid/APKEditor#15

This commit is contained in:
REAndroid 2023-03-21 13:11:32 -04:00
parent 128346351a
commit c650910b2b
3 changed files with 71 additions and 5 deletions

View File

@ -77,9 +77,17 @@ public class ApkJsonDecoder {
jsonObject.write(file); jsonObject.write(file);
addDecoded(path); addDecoded(path);
} }
// TODO: temporary fix
private void writeRootFiles(File dir) throws IOException { private void writeRootFiles(File dir) throws IOException {
for(InputSource inputSource:apkModule.getApkArchive().listInputSources()){ for(InputSource inputSource:apkModule.getApkArchive().listInputSources()){
try{
writeRootFile(dir, inputSource); 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 { private void writeRootFile(File dir, InputSource inputSource) throws IOException {

View File

@ -279,7 +279,11 @@ import java.util.*;
return element; return element;
} }
private String getPackageDirName(PackageBlock packageBlock){ 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 { private void extractRootFiles(File outDir) throws IOException {
logMessage("Extracting root files"); logMessage("Extracting root files");
@ -300,9 +304,14 @@ import java.util.*;
if(!dir.exists()){ if(!dir.exists()){
dir.mkdirs(); dir.mkdirs();
} }
// TODO:Temporary fix
try{
FileOutputStream outputStream=new FileOutputStream(file); FileOutputStream outputStream=new FileOutputStream(file);
inputSource.write(outputStream); inputSource.write(outputStream);
outputStream.close(); outputStream.close();
}catch (IOException ex){
logMessage("ERROR: "+ex.getMessage());
}
} }
private boolean containsDecodedPath(String path){ private boolean containsDecodedPath(String path){
return mDecodedPaths.contains(path); return mDecodedPaths.contains(path);

View File

@ -21,6 +21,53 @@ import java.io.File;
import java.util.*; import java.util.*;
public class ApkUtil { 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){ public static int parseHex(String hex){
long l=Long.decode(hex); long l=Long.decode(hex);
return (int) l; return (int) l;
@ -144,4 +191,6 @@ public class ApkUtil {
public static final String TAG_STRING_ARRAY = "string-array"; public static final String TAG_STRING_ARRAY = "string-array";
public static final String TAG_INTEGER_ARRAY = "integer-array"; public static final String TAG_INTEGER_ARRAY = "integer-array";
private static final int MAX_FILE_NAME_LENGTH = 50;
} }