Skip to content

Commit 79bc547

Browse files
committed
Initialize empty resource table for encoding #66
1 parent 3400536 commit 79bc547

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/main/java/com/reandroid/apk/xmlencoder/XMLTableBlockEncoder.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,17 @@ public void scanMainDirectory(File mainDirectory) throws IOException {
8282
public void scanResourcesDirectory(File resourcesDirectory) throws IOException {
8383
try {
8484
scanResourceFiles(resourcesDirectory);
85+
ensureEmptyTable();
8586
} catch (XmlPullParserException ex) {
8687
throw new IOException(ex);
8788
}
8889
}
90+
private void ensureEmptyTable() {
91+
TableBlock tableBlock = this.getTableBlock();
92+
if(tableBlock.initializeAsEmpty()) {
93+
logMessage("Using <NULL> resource table");
94+
}
95+
}
8996
private void scanResourceFiles(File resourcesDirectory) throws IOException, XmlPullParserException {
9097
List<File> pubXmlFileList = ApkUtil.listPublicXmlFiles(resourcesDirectory);
9198
if(pubXmlFileList.size() == 0){

src/main/java/com/reandroid/arsc/chunk/TableBlock.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,14 @@ public boolean isEmpty(){
530530
}
531531
return true;
532532
}
533+
public boolean initializeAsEmpty() {
534+
if(isEmpty()) {
535+
setNull(true);
536+
setCurrentPackage(pickOrEmptyPackage());
537+
return true;
538+
}
539+
return false;
540+
}
533541
public boolean isMultiPackage() {
534542
return size() > 1;
535543
}
@@ -845,8 +853,7 @@ public static TableBlock load(InputStream inputStream) throws IOException{
845853
}
846854
public static TableBlock createEmpty() {
847855
TableBlock tableBlock = new TableBlock();
848-
tableBlock.pickOrEmptyPackage();
849-
tableBlock.setNull(true);
856+
tableBlock.initializeAsEmpty();
850857
return tableBlock;
851858
}
852859

0 commit comments

Comments
 (0)