mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-05-16 21:27:04 +02:00
implement chunk StagedAlias
This commit is contained in:
parent
4457492c6e
commit
94b66c9efc
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2022 github.com/REAndroid
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.reandroid.lib.arsc.array;
|
||||
|
||||
import com.reandroid.lib.arsc.base.Block;
|
||||
import com.reandroid.lib.arsc.base.BlockArray;
|
||||
import com.reandroid.lib.arsc.io.BlockLoad;
|
||||
import com.reandroid.lib.arsc.io.BlockReader;
|
||||
import com.reandroid.lib.arsc.item.IntegerItem;
|
||||
import com.reandroid.lib.arsc.value.StagedAliasEntry;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class StagedAliasEntryArray extends BlockArray<StagedAliasEntry> implements BlockLoad {
|
||||
private final IntegerItem count;
|
||||
public StagedAliasEntryArray(IntegerItem count){
|
||||
super();
|
||||
this.count=count;
|
||||
this.count.setBlockLoad(this);
|
||||
}
|
||||
@Override
|
||||
public void addAll(StagedAliasEntry[] aliasEntries){
|
||||
super.addAll(aliasEntries);
|
||||
updateCount();
|
||||
}
|
||||
@Override
|
||||
public StagedAliasEntry[] newInstance(int len) {
|
||||
return new StagedAliasEntry[len];
|
||||
}
|
||||
@Override
|
||||
protected void onRefreshed() {
|
||||
updateCount();
|
||||
}
|
||||
@Override
|
||||
public StagedAliasEntry newInstance() {
|
||||
return new StagedAliasEntry();
|
||||
}
|
||||
@Override
|
||||
public void onBlockLoaded(BlockReader reader, Block sender) throws IOException {
|
||||
if(sender==this.count){
|
||||
setChildesCount(this.count.get());
|
||||
}
|
||||
}
|
||||
private void updateCount(){
|
||||
this.count.set(childesCount());
|
||||
}
|
||||
}
|
61
src/main/java/com/reandroid/lib/arsc/chunk/StagedAlias.java
Normal file
61
src/main/java/com/reandroid/lib/arsc/chunk/StagedAlias.java
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2022 github.com/REAndroid
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.reandroid.lib.arsc.chunk;
|
||||
|
||||
import com.reandroid.lib.arsc.array.StagedAliasEntryArray;
|
||||
import com.reandroid.lib.arsc.item.IntegerItem;
|
||||
import com.reandroid.lib.arsc.value.StagedAliasEntry;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class StagedAlias extends BaseChunk{
|
||||
private final StagedAliasEntryArray stagedAliasEntryArray;
|
||||
public StagedAlias() {
|
||||
super(ChunkType.STAGED_ALIAS, 1);
|
||||
IntegerItem count = new IntegerItem();
|
||||
addToHeader(count);
|
||||
stagedAliasEntryArray = new StagedAliasEntryArray(count);
|
||||
addChild(stagedAliasEntryArray);
|
||||
}
|
||||
public void addStagedAliasEntries(StagedAlias stagedAlias){
|
||||
if(stagedAlias==null||stagedAlias==this){
|
||||
return;
|
||||
}
|
||||
stagedAliasEntryArray.addAll(stagedAlias
|
||||
.getStagedAliasEntryArray().getChildes());
|
||||
}
|
||||
public StagedAliasEntryArray getStagedAliasEntryArray() {
|
||||
return stagedAliasEntryArray;
|
||||
}
|
||||
public Collection<StagedAliasEntry> listStagedAliasEntry(){
|
||||
return getStagedAliasEntryArray().listItems();
|
||||
}
|
||||
public int getStagedAliasEntryCount(){
|
||||
return getStagedAliasEntryArray().childesCount();
|
||||
}
|
||||
@Override
|
||||
public boolean isNull(){
|
||||
return getStagedAliasEntryCount()==0;
|
||||
}
|
||||
@Override
|
||||
protected void onChunkRefreshed() {
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
return getClass().getSimpleName()+
|
||||
": count="+getStagedAliasEntryCount();
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.reandroid.lib.arsc.value;
|
||||
|
||||
import com.reandroid.lib.arsc.item.ByteArray;
|
||||
|
||||
public class StagedAliasEntry extends ByteArray {
|
||||
public StagedAliasEntry(){
|
||||
super(8);
|
||||
}
|
||||
public int getStagedResId(){
|
||||
return getInteger(0);
|
||||
}
|
||||
public void setStagedResId(int id){
|
||||
putInteger(0, id);
|
||||
}
|
||||
public int getFinalizedResId(){
|
||||
return getInteger(4);
|
||||
}
|
||||
public void setFinalizedResId(int id){
|
||||
putInteger(4, id);
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
return "stagedResId="+String.format("0x%08x",getStagedResId())
|
||||
+", finalizedResId="+String.format("0x%08x",getFinalizedResId());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user