This repository has been archived by the owner on Mar 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make BASS not be constantly reloaded
- Loading branch information
Showing
3 changed files
with
79 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import java.lang.reflect.Field; | ||
|
||
import jouvieje.bass.BassInit; | ||
import jouvieje.bass.exceptions.BassException; | ||
|
||
public class BASSLoader { | ||
|
||
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 = "."; | ||
|
||
static void initializeBASS() { | ||
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(); | ||
} | ||
|
||
//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 ); | ||
} | ||
|
||
|
||
private static void init() { | ||
/* | ||
* NativeBass Init | ||
*/ | ||
try { | ||
BassInit.DEBUG = true; | ||
BassInit.loadLibraries(); | ||
} catch (final BassException e) { | ||
printfExit("NativeBass error! %s\n", e.getMessage()); | ||
return; | ||
} | ||
|
||
/* | ||
* Checking NativeBass version | ||
*/ | ||
if (BassInit.NATIVEBASS_LIBRARY_VERSION() != BassInit.NATIVEBASS_JAR_VERSION()) { | ||
printfExit("Error! NativeBass library version (%08x) is different to jar version (%08x)\n", BassInit.NATIVEBASS_LIBRARY_VERSION(), BassInit.NATIVEBASS_JAR_VERSION()); | ||
return; | ||
} | ||
|
||
/*==================================================*/ | ||
|
||
RadicalBASS.init = true; | ||
} | ||
|
||
private static final void printfExit(final String format, final Object... args) { | ||
String s = String.format(format, args); | ||
System.out.println(s); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters