Search in sources :

Example 1 with Descriptor

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);
}
Also used : ConverterException(ru.playsoftware.j2meloader.util.ConverterException) Descriptor(ru.woesss.j2me.jar.Descriptor) Uri(android.net.Uri)

Example 2 with Descriptor

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));
}
Also used : Descriptor(ru.woesss.j2me.jar.Descriptor) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 3 with Descriptor

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);
    }
}
Also used : ZipInputStream(net.lingala.zip4j.io.inputstream.ZipInputStream) ZipFile(net.lingala.zip4j.ZipFile) Descriptor(ru.woesss.j2me.jar.Descriptor) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileHeader(net.lingala.zip4j.model.FileHeader)

Example 4 with Descriptor

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;
}
Also used : AppItem(ru.playsoftware.j2meloader.applist.AppItem) Descriptor(ru.woesss.j2me.jar.Descriptor) File(java.io.File)

Example 5 with Descriptor

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;
}
Also used : ErrorReporter(org.acra.ErrorReporter) Descriptor(ru.woesss.j2me.jar.Descriptor) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Descriptor (ru.woesss.j2me.jar.Descriptor)5 File (java.io.File)2 Uri (android.net.Uri)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ZipFile (net.lingala.zip4j.ZipFile)1 ZipInputStream (net.lingala.zip4j.io.inputstream.ZipInputStream)1 FileHeader (net.lingala.zip4j.model.FileHeader)1 ErrorReporter (org.acra.ErrorReporter)1 AppItem (ru.playsoftware.j2meloader.applist.AppItem)1 ConverterException (ru.playsoftware.j2meloader.util.ConverterException)1