mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-06-13 05:37:41 +02:00
use static filed json names
This commit is contained in:
@ -44,9 +44,11 @@ public class TableBlockJson {
|
||||
JSONObject jsonObject=new JSONObject();
|
||||
jsonObject.put(PackageBlock.NAME_package_id, packageBlock.getId());
|
||||
jsonObject.put(PackageBlock.NAME_package_name, packageBlock.getName());
|
||||
StagedAlias stagedAlias=StagedAlias.mergeAll(packageBlock.getStagedAliasList().getChildes());
|
||||
StagedAlias stagedAlias=StagedAlias
|
||||
.mergeAll(packageBlock.getStagedAliasList().getChildes());
|
||||
if(stagedAlias!=null){
|
||||
jsonObject.put(PackageBlock.NAME_staged_aliases, stagedAlias.getStagedAliasEntryArray().toJson());
|
||||
jsonObject.put(PackageBlock.NAME_staged_aliases,
|
||||
stagedAlias.getStagedAliasEntryArray().toJson());
|
||||
}
|
||||
jsonObject.write(infoFile);
|
||||
for(SpecTypePair specTypePair: packageBlock.listAllSpecTypePair()){
|
||||
@ -56,8 +58,8 @@ public class TableBlockJson {
|
||||
}
|
||||
}
|
||||
private void writeJsonFiles(File pkgDir, TypeBlock typeBlock) throws IOException {
|
||||
String name= getFileName(typeBlock)+".json";
|
||||
File file=new File(pkgDir, name);
|
||||
File file=new File(pkgDir,
|
||||
getFileName(typeBlock) + ApkUtil.JSON_FILE_EXTENSION);
|
||||
JSONObject jsonObject = typeBlock.toJson();
|
||||
jsonObject.write(file);
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public class TableBlockJsonBuilder {
|
||||
stagedAlias.getStagedAliasEntryArray().fromJson(stagedJson);
|
||||
pkg.getStagedAliasList().add(stagedAlias);
|
||||
}
|
||||
List<File> typeFileList=ApkUtil.listFiles(pkgDir, ".json");
|
||||
List<File> typeFileList = ApkUtil.listFiles(pkgDir, ApkUtil.JSON_FILE_EXTENSION);
|
||||
typeFileList.remove(pkgFile);
|
||||
for(File typeFile:typeFileList){
|
||||
loadType(pkg, typeFile);
|
||||
@ -77,12 +77,13 @@ public class TableBlockJsonBuilder {
|
||||
private void loadType(PackageBlock packageBlock, File typeJsonFile) throws IOException{
|
||||
FileInputStream inputStream=new FileInputStream(typeJsonFile);
|
||||
JSONObject jsonObject=new JSONObject(inputStream);
|
||||
// TODO: change json names to use from static field
|
||||
JSONObject configObj=jsonObject.getJSONObject("config");
|
||||
JSONObject configObj=jsonObject.getJSONObject(TypeBlock.NAME_config);
|
||||
ResConfig resConfig=new ResConfig();
|
||||
resConfig.fromJson(configObj);
|
||||
TypeBlock typeBlock=packageBlock.getSpecTypePairArray()
|
||||
.getOrCreate(((byte)(0xff & jsonObject.getInt("id"))), resConfig);
|
||||
.getOrCreate(
|
||||
((byte)(0xff & jsonObject.getInt(TypeBlock.NAME_id)))
|
||||
, resConfig);
|
||||
typeBlock.fromJson(jsonObject);
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,9 @@ abstract class BaseTypeBlock extends BaseChunk {
|
||||
public int getTypeIdInt(){
|
||||
return (0xff & mTypeId.get());
|
||||
}
|
||||
public void setTypeId(int id){
|
||||
setTypeId((byte) (0xff & id));
|
||||
}
|
||||
public void setTypeId(byte id){
|
||||
mTypeId.set(id);
|
||||
}
|
||||
|
@ -72,12 +72,12 @@ public class SpecBlock extends BaseTypeBlock implements BlockLoad , JSONConvert<
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject jsonObject=new JSONObject();
|
||||
jsonObject.put("id", getTypeIdInt());
|
||||
jsonObject.put(TypeBlock.NAME_id, getTypeIdInt());
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JSONObject json) {
|
||||
setTypeId((byte) json.getInt("id"));
|
||||
setTypeId(json.getInt(TypeBlock.NAME_id));
|
||||
}
|
||||
}
|
||||
|
@ -151,24 +151,23 @@ public class TypeBlock extends BaseTypeBlock
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject jsonObject=new JSONObject();
|
||||
jsonObject.put("id", getTypeIdInt());
|
||||
TypeString typeString=getTypeString();
|
||||
if(typeString!=null){
|
||||
jsonObject.put("name", typeString.get());
|
||||
}
|
||||
jsonObject.put("config", getResConfig().toJson());
|
||||
jsonObject.put("entries", getEntryBlockArray().toJson());
|
||||
jsonObject.put(NAME_id, getTypeIdInt());
|
||||
jsonObject.put(NAME_name, getTypeName());
|
||||
jsonObject.put(NAME_config, getResConfig().toJson());
|
||||
jsonObject.put(NAME_entries, getEntryBlockArray().toJson());
|
||||
return jsonObject;
|
||||
}
|
||||
@Override
|
||||
public void fromJson(JSONObject json) {
|
||||
setTypeId((byte) json.getInt("id"));
|
||||
String name= json.optString("name");
|
||||
setTypeId(json.getInt(NAME_id));
|
||||
String name = json.optString(NAME_name);
|
||||
if(name!=null){
|
||||
setTypeName(name);
|
||||
}
|
||||
getEntryBlockArray().fromJson(json.getJSONArray("entries"));
|
||||
getResConfig().fromJson(json.getJSONObject("config"));
|
||||
getEntryBlockArray()
|
||||
.fromJson(json.getJSONArray(NAME_entries));
|
||||
getResConfig()
|
||||
.fromJson(json.getJSONObject(NAME_config));
|
||||
}
|
||||
public void merge(TypeBlock typeBlock){
|
||||
if(typeBlock==null||typeBlock==this){
|
||||
@ -206,4 +205,9 @@ public class TypeBlock extends BaseTypeBlock
|
||||
builder.append(super.toString());
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static final String NAME_name = "name";
|
||||
public static final String NAME_config = "config";
|
||||
public static final String NAME_id = "id";
|
||||
public static final String NAME_entries = "entries";
|
||||
}
|
||||
|
Reference in New Issue
Block a user