Skip to content

Commit

Permalink
MobilePlatform: When loading a jar, check for accompanying jad file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AShiningRay committed Nov 20, 2024
1 parent e82a27a commit 6531ec8
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/org/recompile/mobile/MobilePlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +33,7 @@
import java.io.IOException;
import java.io.InputStream;


import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
Expand Down Expand Up @@ -230,6 +233,24 @@ private void updateKeyState(int key, int val)
public boolean load(String fileName)
{
Map<String, String> 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)
Expand Down

0 comments on commit 6531ec8

Please sign in to comment.