From 6531ec86b1d7fb25f984aa1d8802122795ec6874 Mon Sep 17 00:00:00 2001 From: AShiningRay Date: Wed, 20 Nov 2024 18:13:52 -0300 Subject: [PATCH] MobilePlatform: When loading a jar, check for accompanying jad file This is mostly a workaround for libretro's database. Since it will match only against jar files, .jad files won't be added to the J2ME playlist. So what we can do here is check if, when a jar is loaded, there is an accompanying jad with the same name on the same directory. If there is, we load it up, since often games benefit from having its jad properties present, and others even refuse to get ingame without them (certain versions of DOOM RPG). This still maintains single jar loading, and direct jad loading as they were before. --- src/org/recompile/mobile/MobilePlatform.java | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/org/recompile/mobile/MobilePlatform.java b/src/org/recompile/mobile/MobilePlatform.java index d66fc7c6..4e764314 100644 --- a/src/org/recompile/mobile/MobilePlatform.java +++ b/src/org/recompile/mobile/MobilePlatform.java @@ -16,6 +16,8 @@ */ package org.recompile.mobile; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; @@ -31,6 +33,7 @@ import java.io.IOException; import java.io.InputStream; + import java.awt.Color; import java.awt.Graphics2D; import java.awt.RenderingHints; @@ -230,6 +233,24 @@ private void updateKeyState(int key, int val) public boolean load(String fileName) { Map descriptorProperties = new HashMap<>(); + + /* + * If loading a jar directly, check if an accompanying jad with the same name + * is present in the directory, to load any platform properties from there. + */ + if(fileName.toLowerCase().contains(".jar")) + { + try + { + File checkJad = new File(new URI(fileName.replace(".jar", ".jad"))); + if(checkJad.exists() && !checkJad.isDirectory()) + { + Mobile.log(Mobile.LOG_INFO, MobilePlatform.class.getPackage().getName() + "." + MobilePlatform.class.getSimpleName() + ": " + "Accompanying JAD found! Parsing additional MIDlet properties."); + fileName = fileName.replace(".jar", ".jad"); + } + } catch (Exception e) { Mobile.log(Mobile.LOG_INFO, MobilePlatform.class.getPackage().getName() + "." + MobilePlatform.class.getSimpleName() + ": " + "Couldn't check for accompanying JAD:" + e.getMessage()); } + } + boolean isJad = fileName.toLowerCase().endsWith(".jad"); if (isJad)