Search in sources :

Example 6 with AppItem

use of ru.playsoftware.j2meloader.applist.AppItem in project J2ME-Loader by nikita36078.

the class AppInstaller method install.

/**
 * Install app
 */
void install(SingleEmitter<AppItem> emitter) throws ConverterException, IOException {
    if (!cacheDir.exists() && !cacheDir.mkdirs()) {
        throw new ConverterException("Can't create cache dir");
    }
    tmpDir = new File(targetDir.getParent(), ".tmp");
    if (!tmpDir.isDirectory() && !tmpDir.mkdirs())
        throw new ConverterException("Can't create directory: '" + targetDir + "'");
    if (srcJar == null) {
        srcJar = new File(cacheDir, "tmp.jar");
        downloadJar();
        manifest = loadManifest(srcJar);
        if (!manifest.equals(newDesc)) {
            throw new ConverterException("*Jad not matches with Jar");
        }
    }
    File patchedJar = new File(cacheDir, "patched.jar");
    AndroidProducer.processJar(srcJar, patchedJar);
    try {
        Main.main(new String[] { "--no-optimize", "--output=" + tmpDir + Config.MIDLET_DEX_FILE, patchedJar.getAbsolutePath() });
    } catch (Throwable e) {
        throw new ConverterException("Dexing error", e);
    }
    if (manifest != null) {
        manifest.merge(newDesc);
        newDesc = manifest;
    }
    File resJar = new File(tmpDir, Config.MIDLET_RES_FILE);
    FileUtils.copyFileUsingChannel(srcJar, resJar);
    String icon = newDesc.getIcon();
    File iconFile = new File(tmpDir, Config.MIDLET_ICON_FILE);
    if (icon != null) {
        try {
            ZipUtils.unzipEntry(resJar, icon, iconFile);
        } catch (IOException e) {
            Log.w(TAG, "Can't unzip icon: " + icon, e);
            icon = null;
            // noinspection ResultOfMethodCallIgnored
            iconFile.delete();
        }
    }
    newDesc.writeTo(new File(tmpDir, Config.MIDLET_MANIFEST_FILE));
    FileUtils.deleteDirectory(targetDir);
    if (!tmpDir.renameTo(targetDir)) {
        throw new ConverterException("Can't rename '" + tmpDir + "' to '" + targetDir + "'");
    }
    String name = newDesc.getName();
    String vendor = newDesc.getVendor();
    AppItem app = new AppItem(appDirName, name, vendor, newDesc.getVersion());
    if (icon != null) {
        app.setImagePathExt(Config.MIDLET_ICON_FILE);
    }
    if (currentApp != null) {
        app.setId(currentApp.getId());
        String path = currentApp.getPath();
        if (!path.equals(appDirName)) {
            File rms = new File(Config.getDataDir(), path);
            if (rms.exists()) {
                File newRms = new File(Config.getDataDir(), appDirName);
                FileUtils.deleteDirectory(newRms);
                rms.renameTo(newRms);
            }
            File config = new File(Config.getConfigsDir(), path);
            if (config.exists()) {
                File newConfig = new File(Config.getConfigsDir(), appDirName);
                FileUtils.deleteDirectory(newConfig);
                config.renameTo(newConfig);
            }
            File appDir = new File(Config.getAppDir(), path);
            FileUtils.deleteDirectory(appDir);
        }
    }
    emitter.onSuccess(app);
}
Also used : ConverterException(ru.playsoftware.j2meloader.util.ConverterException) AppItem(ru.playsoftware.j2meloader.applist.AppItem) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) File(java.io.File) ZipFile(net.lingala.zip4j.ZipFile)

Example 7 with AppItem

use of ru.playsoftware.j2meloader.applist.AppItem in project J2ME-Loader by nikita36078.

the class AppUtils method getAppsList.

private static ArrayList<AppItem> getAppsList(@NonNull List<String> appFolders) {
    ArrayList<AppItem> apps = new ArrayList<>();
    File appsDir = new File(Config.getAppDir());
    for (String appFolderName : appFolders) {
        File appFolder = new File(appsDir, appFolderName);
        if (!appFolder.isDirectory()) {
            if (!appFolder.delete()) {
                Log.e(TAG, "getAppsList() failed delete file: " + appFolder);
            }
            continue;
        }
        File dex = new File(appFolder, Config.MIDLET_DEX_FILE);
        if (!dex.isFile()) {
            FileUtils.deleteDirectory(appFolder);
            continue;
        }
        try {
            AppItem item = getApp(appFolder);
            apps.add(item);
        } catch (Exception e) {
            Log.w(TAG, "getAppsList: ", e);
            FileUtils.deleteDirectory(appFolder);
        }
    }
    return apps;
}
Also used : AppItem(ru.playsoftware.j2meloader.applist.AppItem) ArrayList(java.util.ArrayList) File(java.io.File) IOException(java.io.IOException)

Example 8 with AppItem

use of ru.playsoftware.j2meloader.applist.AppItem 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)

Aggregations

AppItem (ru.playsoftware.j2meloader.applist.AppItem)8 File (java.io.File)6 ArrayList (java.util.ArrayList)4 IOException (java.io.IOException)2 AppsListAdapter (ru.playsoftware.j2meloader.applist.AppsListAdapter)2 FragmentManager (android.support.v4.app.FragmentManager)1 JarFile (java.util.jar.JarFile)1 ZipFile (net.lingala.zip4j.ZipFile)1 AppsListFragment (ru.playsoftware.j2meloader.applist.AppsListFragment)1 ConverterException (ru.playsoftware.j2meloader.util.ConverterException)1 Descriptor (ru.woesss.j2me.jar.Descriptor)1