public void replace(ResValue value) throws AndrolibException { ResResource res = new ResResource(mConfig, mResSpec, value); mConfig.addResource(res, true); mResSpec.addResource(res, true); }
public Collection<ResValuesFile> listValuesFiles() { Map<Duo<ResTypeSpec, ResType>, ResValuesFile> ret = new HashMap<Duo<ResTypeSpec, ResType>, ResValuesFile>(); for (ResResSpec spec : mResSpecs.values()) { for (ResResource res : spec.listResources()) { if (res.getValue() instanceof ResValuesXmlSerializable) { ResTypeSpec type = res.getResSpec().getType(); ResType config = res.getConfig(); Duo<ResTypeSpec, ResType> key = new Duo<ResTypeSpec, ResType>(type, config); ResValuesFile values = ret.get(key); if (values == null) { values = new ResValuesFile(this, type, config); ret.put(key, values); } values.addResource(res); } } } return ret.values(); }
@Override public String toString() { return getFilePath(); } }
public void decode(ResResource res, Directory inDir, Directory outDir) throws AndrolibException { ResFileValue fileValue = (ResFileValue) res.getValue(); String inFileName = fileValue.getStrippedPath(); String outResName = res.getFilePath(); String typeName = res.getResSpec().getType().getName(); "Could not decode file, replacing by FALSE value: %s", inFileName), ex); res.replace(new ResBoolValue(false, 0, null));
public void removeResource(ResResource res) throws AndrolibException { ResResSpec spec = res.getResSpec(); mResources.remove(spec); }
public Set<ResResource> listFiles() { Set<ResResource> ret = new HashSet<ResResource>(); for (ResResSpec spec : mResSpecs.values()) { for (ResResource res : spec.listResources()) { if (res.getValue() instanceof ResFileValue) { ret.add(res); } } } return ret; }
@Override public void serializeToResValuesXml(XmlSerializer serializer, ResResource res) throws IOException, AndrolibException { String type = res.getResSpec().getType().getName(); boolean item = !"reference".equals(mType) && !type.equals(mType); if (!res.getFilePath().contains("string")) { item = true; serializer.attribute(null, "type", type); serializer.attribute(null, "name", res.getResSpec().getName());
ResResource res) throws IOException, AndrolibException { serializer.startTag(null, "style"); serializer.attribute(null, "name", res.getResSpec().getName()); if (!mParent.isNull() && !mParent.referentIsNull()) { serializer.attribute(null, "parent", mParent.encodeAsResXmlAttr()); } else if (res.getResSpec().getName().indexOf('.') != -1) { serializer.attribute(null, "parent", ""); String value = null; ResValue resource = spec.getDefaultResource().getValue(); if (resource instanceof ResReferenceValue) { continue; ResAttr attr = (ResAttr) resource; value = attr.convertToResXmlFormat(mItems[i].m2); name = spec.getFullName(res.getResSpec().getPackage(), true); } else { name = "@" + spec.getFullName(res.getResSpec().getPackage(), false);
mTypeSpec.addResSpec(spec); ResResource res = new ResResource(mType, spec, value); mType.addResource(res, true); spec.addResource(res, true); LOGGER.warning(String.format("Duplicate Resource Detected. Ignoring duplicate: %s", res.toString())); } else { throw ex;
public void removeResource(ResResource res) throws AndrolibException { ResConfigFlags flags = res.getConfig().getFlags(); mResources.remove(flags); }
public void addResource(ResResource res, boolean overwrite) throws AndrolibException { ResResSpec spec = res.getResSpec(); if (mResources.put(spec, res) != null && !overwrite) { throw new AndrolibException(String.format("Multiple resources: spec=%s, config=%s", spec, this)); } }
public ResValue getValue(String package_, String type, String name) throws AndrolibException { return getPackage(package_).getType(type).getResSpec(name).getDefaultResource().getValue(); }
public void addResource(ResResource res, boolean overwrite) throws AndrolibException { ResConfigFlags flags = res.getConfig().getFlags(); if (mResources.put(flags, res) != null && !overwrite) { throw new AndrolibException(String.format("Multiple resources: spec=%s, config=%s", this, flags)); } }
public boolean isSynthesized(ResResource res) { return mPackage.isSynthesized(res.getResSpec().getId()); }
@Override protected String encodeAsResXml() throws AndrolibException { if (isNull()) { return "@null"; } ResResSpec spec = getReferent(); if (spec == null) { return "@null"; } boolean newId = spec.hasDefaultResource() && spec.getDefaultResource().getValue() instanceof ResIdValue; // generate the beginning to fix @android String mStart = (mTheme ? '?' : '@') + (newId ? "+" : ""); return mStart + spec.getFullName(mPackage, mTheme && spec.getType().getName().equals("attr")); }
private void addMissingResSpecs() throws AndrolibException { int resId = mResId & 0xffff0000; for (int i = 0; i < mMissingResSpecs.length; i++) { if (!mMissingResSpecs[i]) { continue; } ResResSpec spec = new ResResSpec(new ResID(resId | i), "APKTOOL_DUMMY_" + Integer.toHexString(i), mPkg, mTypeSpec); // If we already have this resID dont add it again. if (! mPkg.hasResSpec(new ResID(resId | i))) { mPkg.addResSpec(spec); mTypeSpec.addResSpec(spec); if (mType == null) { mType = mPkg.getOrCreateConfig(new ResConfigFlags()); } ResValue value = new ResBoolValue(false, 0, null); ResResource res = new ResResource(mType, spec, value); mPkg.addResource(res); mType.addResource(res); spec.addResource(res); } } }
@Override public void serializeToResValuesXml(XmlSerializer serializer, ResResource res) throws IOException, AndrolibException { serializer.startTag(null, "item"); serializer .attribute(null, "type", res.getResSpec().getType().getName()); serializer.attribute(null, "name", res.getResSpec().getName()); serializer.endTag(null, "item"); } }
public String decode(int type, int value, String rawValue, int attrResId) throws AndrolibException { ResScalarValue resValue = mCurrentPackage.getValueFactory().factory( type, value, rawValue); String decoded = null; if (attrResId > 0) { try { ResAttr attr = (ResAttr) getCurrentPackage().getResTable() .getResSpec(attrResId).getDefaultResource().getValue(); decoded = attr.convertToResXmlFormat(resValue); } catch (UndefinedResObject | ClassCastException ex) { // ignored } } return decoded != null ? decoded : resValue.encodeAsResXmlAttr(); }
@Override public void serializeToResValuesXml(XmlSerializer serializer, ResResource res) throws IOException, AndrolibException { String type = res.getResSpec().getType().getName(); if ("style".equals(type)) { new ResStyleValue(mParent, new Duo[0], null) .serializeToResValuesXml(serializer, res); return; } if ("array".equals(type)) { new ResArrayValue(mParent, new Duo[0]).serializeToResValuesXml( serializer, res); return; } if ("plurals".equals(type)) { new ResPluralsValue(mParent, new Duo[0]).serializeToResValuesXml( serializer, res); return; } serializer.startTag(null, "item"); serializer.attribute(null, "type", type); serializer.attribute(null, "name", res.getResSpec().getName()); serializer.endTag(null, "item"); }
private void generateValuesFile(ResValuesFile valuesFile, Directory out, ExtXmlSerializer serial) throws AndrolibException { try { OutputStream outStream = out.getFileOutput(valuesFile.getPath()); serial.setOutput((outStream), null); serial.startDocument(null, null); serial.startTag(null, "resources"); for (ResResource res : valuesFile.listResources()) { if (valuesFile.isSynthesized(res)) { continue; } ((ResValuesXmlSerializable) res.getValue()).serializeToResValuesXml(serial, res); } serial.endTag(null, "resources"); serial.newLine(); serial.endDocument(); serial.flush(); outStream.close(); } catch (IOException | DirectoryException ex) { throw new AndrolibException("Could not generate: " + valuesFile.getPath(), ex); } }