use of ru.woesss.j2me.jar.Descriptor in project J2ME-Loader by nikita36078.
the class AppInstaller method loadInfo.
/**
* Load and check app info from source
*/
void loadInfo(SingleEmitter<Integer> emitter) throws IOException, ConverterException {
boolean isLocal;
boolean isContentUri = uri.getScheme().equals("content");
if ("http".equals(uri.getScheme()) || "https".equals(uri.getScheme())) {
downloadJad();
isLocal = false;
} else {
srcFile = FileUtils.getFileForUri(context, uri);
isLocal = true;
}
String name = srcFile.getName();
if (name.toLowerCase().endsWith(".jad")) {
newDesc = new Descriptor(srcFile, true);
String url = newDesc.getJarUrl();
if (url == null) {
throw new ConverterException("Jad not have " + Descriptor.MIDLET_JAR_URL);
}
Uri uri = Uri.parse(url);
String scheme = uri.getScheme();
String host = uri.getHost();
if (isLocal && scheme == null && host == null) {
if (isContentUri) {
emitter.onSuccess(STATUS_NEED_JAD);
return;
} else if (!checkJarFile(srcFile)) {
emitter.onSuccess(STATUS_UNMATCHED);
return;
}
}
} else if (name.toLowerCase().endsWith(".kjx")) {
/* Load kjx file */
parseKjx();
newDesc = new Descriptor(srcFile, true);
} else {
srcJar = srcFile;
newDesc = loadManifest(srcFile);
}
int result = checkDescriptor();
emitter.onSuccess(result);
}
use of ru.woesss.j2me.jar.Descriptor in project J2ME-Loader by nikita36078.
the class InstallerDialog method convert.
private void convert(AppInstaller installer) {
Descriptor nd = installer.getNewDescriptor();
SpannableStringBuilder info = nd.getInfo(requireActivity());
tvMessage.setText(info);
tvStatus.setText(R.string.converting_wait);
showProgress();
hideButtons();
Single.create(installer::install).subscribeOn(Schedulers.computation()).observeOn(AndroidSchedulers.mainThread()).subscribe(new CompleteObserver(installer));
}
use of ru.woesss.j2me.jar.Descriptor in project J2ME-Loader by nikita36078.
the class AppInstaller method loadManifest.
private Descriptor loadManifest(File jar) throws IOException {
ZipFile zip = new ZipFile(jar);
FileHeader manifest = zip.getFileHeader(JarFile.MANIFEST_NAME);
if (manifest == null)
throw new IOException("JAR not have " + JarFile.MANIFEST_NAME);
try (ZipInputStream is = zip.getInputStream(manifest)) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(20480);
byte[] buf = new byte[4096];
int read;
while ((read = is.read(buf)) != -1) {
baos.write(buf, 0, read);
}
return new Descriptor(baos.toString(), false);
}
}
use of ru.woesss.j2me.jar.Descriptor in project J2ME-Loader by nikita36078.
the class AppUtils method getApp.
private static AppItem getApp(File appDir) throws IOException {
File mf = new File(appDir, Config.MIDLET_MANIFEST_FILE);
Descriptor params = new Descriptor(mf, false);
AppItem item = new AppItem(appDir.getName(), params.getName(), params.getVendor(), params.getVersion());
File icon = new File(appDir, Config.MIDLET_ICON_FILE);
if (icon.exists()) {
item.setImagePathExt(Config.MIDLET_ICON_FILE);
} else {
String iconPath = Config.MIDLET_RES_DIR + '/' + params.getIcon();
icon = new File(appDir, iconPath);
if (icon.exists()) {
item.setImagePathExt(iconPath);
}
}
return item;
}
use of ru.woesss.j2me.jar.Descriptor in project J2ME-Loader by nikita36078.
the class MicroLoader method loadMIDletList.
LinkedHashMap<String, String> loadMIDletList() throws IOException {
LinkedHashMap<String, String> midlets = new LinkedHashMap<>();
Descriptor descriptor = new Descriptor(new File(appDir, Config.MIDLET_MANIFEST_FILE), false);
Map<String, String> attr = descriptor.getAttrs();
ErrorReporter errorReporter = ACRA.getErrorReporter();
String report = errorReporter.getCustomData(Constants.KEY_APPCENTER_ATTACHMENT);
StringBuilder sb = new StringBuilder();
if (report != null) {
sb.append(report).append("\n");
}
sb.append(Descriptor.MIDLET_NAME).append(": ").append(descriptor.getName()).append("\n");
sb.append(Descriptor.MIDLET_VENDOR).append(": ").append(descriptor.getVendor()).append("\n");
sb.append(Descriptor.MIDLET_VERSION).append(": ").append(descriptor.getVersion());
errorReporter.putCustomData(Constants.KEY_APPCENTER_ATTACHMENT, sb.toString());
MIDlet.initProps(attr);
for (Map.Entry<String, String> entry : attr.entrySet()) {
if (entry.getKey().matches("MIDlet-[0-9]+")) {
String tmp = entry.getValue();
String clazz = tmp.substring(tmp.lastIndexOf(',') + 1).trim();
String title = tmp.substring(0, tmp.indexOf(',')).trim();
midlets.put(clazz, title);
}
}
return midlets;
}
Aggregations