From 85fad174aabb64e40f7e4e1dc337b2f772cca52f Mon Sep 17 00:00:00 2001 From: chrishansen69 Date: Mon, 1 Feb 2016 20:37:16 -0200 Subject: [PATCH] add cross-platform support --- .classpath | 6 +----- RadicalBASS.java | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.classpath b/.classpath index 9749cc1..0f0e2cd 100644 --- a/.classpath +++ b/.classpath @@ -1,10 +1,6 @@ - - - - - + diff --git a/RadicalBASS.java b/RadicalBASS.java index b552a40..a3991cf 100644 --- a/RadicalBASS.java +++ b/RadicalBASS.java @@ -30,6 +30,7 @@ import java.awt.image.BufferedImage; import java.io.File; +import java.lang.reflect.Field; import jouvieje.bass.BassInit; import jouvieje.bass.callbacks.SYNCPROC; @@ -85,6 +86,7 @@ public void init() { * NativeBass Init */ try { + BassInit.DEBUG = true; BassInit.loadLibraries(); } catch (final BassException e) { printfExit("NativeBass error! %s\n", e.getMessage()); @@ -251,10 +253,42 @@ private int getIndexColor(final int index) { public RadicalBASS(final File songFile) { file = songFile; + System.out.println(System.getProperty("java.library.path")); + + try { + if (isUnix) { + System.out.println("running on a unix system"); + appendToPath(workingDirectory + "/libraries/dlls/linux" + x64 + "/"); + } else if (isMac) { + System.out.println("running on a mac system"); + appendToPath(workingDirectory + "/libraries/dlls/mac/"); + } else if (isWindows) { + System.out.println("running on a windows system"); + appendToPath(workingDirectory + "\\libraries\\dlls\\win" + x64 + "\\"); + } + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + } + init(); //run(); } + private static final String os = System.getProperty("os.name").toLowerCase(); + private static final String x64 = System.getProperty("sun.arch.data.model").equals("64") ? "64" : "32"; + private static final boolean isUnix = os.indexOf("nix") == 0 || os.indexOf("nux") == 0; + private static final boolean isWindows = os.indexOf("win") == 0; + private static final boolean isMac = os.indexOf("mac") == 0; + private static final String workingDirectory = "."; + //private static final String workingDirectory = System.getProperty("user.dir"); + + private static void appendToPath(final String s) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + System.setProperty( "java.library.path", System.getProperty("java.library.path") + (isWindows ? ";" : ":") + s ); + + Field fieldSysPath = ClassLoader.class.getDeclaredField( "sys_paths" ); + fieldSysPath.setAccessible( true ); + fieldSysPath.set( null, null ); + } + @Override public int getType() { // TODO Auto-generated method stub