Making Remotemaster's library loading more flexible
Posted: Wed Nov 16, 2011 1:51 pm
Remotemaster depends heavily on the external loadable libraries DecodeIR, jp12serial, jp1parallell, jp1usb (.dll on windows, called .so on Linux and others). It loads these libraries from a subdirectory of the installation directory, called e.g. Windows or Linux-amd64. There is presently no possibility to load libraries located elsewhere, for example in a shared system directory like ...Program Files\Common Files\jp1\libs or /usr/local/lib. In contrast, most Java programs respects the system property java.libraries.path, pointing to a system directory where to load dynamic libraries. This can be given with the -Djava.libraries.path=... option when invoking the JVM.
I propose the fix included at the end of this posting. It will make RM(IR) first search the "old" local location, then the system location.
Nothing will change for the user who has installed in the "old" way. No internet connection is needed.
If someone requests a RemoteMaster.jar to test with, just say so.
No answer is taken as approval.
I propose the fix included at the end of this posting. It will make RM(IR) first search the "old" local location, then the system location.
Nothing will change for the user who has installed in the "old" way. No internet connection is needed.
If someone requests a RemoteMaster.jar to test with, just say so.
No answer is taken as approval.
Code: Select all
Index: com/hifiremote/jp1/RemoteMaster.java
===================================================================
--- com/hifiremote/jp1/RemoteMaster.java (revision 1081)
+++ com/hifiremote/jp1/RemoteMaster.java (working copy)
@@ -2533,7 +2533,7 @@
sb.append( "</ul>" );
sb.append( "<p>Libraries loaded from " );
- sb.append( LibraryLoader.getLibraryFolder() );
+ sb.append( LibraryLoader.getLibraryFolder() != null ? LibraryLoader.getLibraryFolder() : "system path." );
sb.append( "</p></html>" );
JEditorPane pane = new JEditorPane( "text/html", sb.toString() );
Index: com/hifiremote/LibraryLoader.java
===================================================================
--- com/hifiremote/LibraryLoader.java (revision 1081)
+++ com/hifiremote/LibraryLoader.java (working copy)
@@ -33,27 +33,44 @@
{
String mappedName = System.mapLibraryName( libraryName );
File libraryFile = new File( libraryFolder, mappedName );
- System.err.println( "Loading " + libraryFile.getAbsolutePath() );
- System.load( libraryFile.getAbsolutePath() );
- System.err.println( "Loaded " + libraryFile.getAbsolutePath() );
- libraries.put( libraryName, mappedName );
+ System.err.println( "Trying to load " + libraryFile.getAbsolutePath() );
+ try
+ {
+ System.load(libraryFile.getAbsolutePath());
+ System.err.println("Loaded " + libraryFile.getAbsolutePath());
+ libraries.put(libraryName, mappedName);
+ }
+ catch (UnsatisfiedLinkError ex)
+ {
+ System.err.println("Loading of " + libraryFile.getAbsolutePath() + " failed, trying system path.");
+ loadLibrary(libraryName);
+ }
}
}
public static void loadLibrary( String libraryName ) throws UnsatisfiedLinkError
{
- if ( libraries.get( libraryName ) == null )
+ if (libraries.get(libraryName) == null)
{
- System.err.println( "Loading " + libraryName );
- System.loadLibrary( libraryName );
- System.err.println( "Loaded " + libraryName );
- libraries.put( libraryName, libraryName );
+ System.err.println("Trying to load " + libraryName + " from system path" );
+ try
+ {
+ System.loadLibrary(libraryName);
+ System.err.println("Loaded " + libraryName);
+ libraries.put(libraryName, libraryName);
+ libraryFolder = null;
+ }
+ catch (UnsatisfiedLinkError ex)
+ {
+ System.err.println("Loading of " + libraryName + " from system path failed.");
+ throw (ex);
+ }
}
}
public static String getLibraryFolder()
{
- return libraryFolder.getAbsolutePath();
+ return libraryFolder != null ? libraryFolder.getAbsolutePath() : null;
}
protected static HashMap< String, String > libraries = new HashMap< String, String >();