Skip to content

Commit

Permalink
fixed dll and dylib finding
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysonh committed May 4, 2022
1 parent cf6ec9a commit 3f57972
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/com/jaysonh/dmx4artists/DMXControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ public void close()
*/
private void setupDevice( int numChannels )
{
System.out.println("DMXForArtists version: " + VERSION_NUM);

if ( numChannels <= MAX_CHANNELS ) // make sure we don't have too many channels
{
this.numChannels = numChannels;
Expand Down Expand Up @@ -280,6 +282,8 @@ public void setFixtureFadeRate( float fadeVal )
************************************************************************************/
private final int SLEEP_TIME = 50; // number of ms for the update thread to sleep for

public final String VERSION_NUM = "1.4";

private FTDIDmx ftdiDmx; // dmx control object
private ArrayList <DMXFixture> fixtureList; // list of all the DMX fixtures

Expand Down
6 changes: 5 additions & 1 deletion src/com/jaysonh/dmx4artists/FTDI_D2XX.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ public interface FTDI_D2XX extends Library
final static byte FT_PURGE_RX = 1; // Purge rx and tx buffers
final static byte FT_PURGE_TX = 2;

FTDI_D2XX INSTANCE = (FTDI_D2XX) Native.loadLibrary("ftd2xx", FTDI_D2XX.class);
//FTDI_D2XX INSTANCE = (FTDI_D2XX) Native.loadLibrary("ftd2xx", FTDI_D2XX.class);
// Load the dylib or dll from the Processing DMXForArtist library folder
// This is hopefully more reliable than before
FTDI_D2XX INSTANCE = (FTDI_D2XX) Native.loadLibrary( new PathFinder().getLibraryPath(), FTDI_D2XX.class);

int FT_Open(short intDeviceNumber, PointerByReference handle);
int FT_Close(Pointer handle);
int FT_ResetDevice (Pointer handle);
Expand Down
8 changes: 4 additions & 4 deletions src/com/jaysonh/dmx4artists/OSXValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public boolean isValid()

String[] res = commandDylib.getOutput();

boolean dylibOK = false;
boolean permsOK = false;
boolean dylibOK = true;
boolean permsOK = true;

if(res.length > 0)
/*if(res.length > 0)
{
String []cols = res[0].split(" ");
Expand All @@ -46,7 +46,7 @@ public boolean isValid()
permsOK = true;
}
}
}
}*/

OSXCommand kextstatCmd = new OSXCommand("kextstat");

Expand Down
49 changes: 49 additions & 0 deletions src/com/jaysonh/dmx4artists/PathFinder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.jaysonh.dmx4artists;

public class PathFinder
{
String getLibraryPath()
{
String res = System.getProperty("java.class.path");

String [] comps;

int os = new SystemValidator().checkOS();

// if osx then need to split by :
// if win then need to split by ;
if(os == SystemValidator.OS_OSX)
{
comps = res.split(":");
}else if(os == SystemValidator.OS_WIN)
{
comps = res.split(";");
}else
{
comps = null; //empty
}

boolean foundLibPath = false;
String dmxLibPath = "";

for(int i = 0; i < comps.length && !foundLibPath;i++)
{
if( comps[i].contains("Dmx4Artists"))
{
String [] paths =comps[i].split("Dmx4Artists");

if(os == SystemValidator.OS_OSX)
{
dmxLibPath = paths[0] + "Dmx4Artists/dependencies/osx/libftd2xx.1.2.2.dylib";
}else if(os == SystemValidator.OS_WIN)
{
dmxLibPath = paths[0] + "Dmx4Artists/dependencies/win/ftd2xx.dll";
}
System.out.println("found path: " + dmxLibPath);
foundLibPath = true;
}
}

return dmxLibPath;
}
}
18 changes: 18 additions & 0 deletions src/com/jaysonh/dmx4artists/SystemValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ else if(osName.startsWith("mac os x"))
}
}

/*
* Get the operating string as a 3 letter string
*/
String getOS()
{
if( checkOS() == OS_OSX )
{
return "osx";
}else if(checkOS() == OS_WIN )
{
return "win";
}else
{
System.err.println("Unsupported operating system");
return "";
}
}

static final int OS_UNK = 0;
static final int OS_OSX = 1;
static final int OS_WIN = 2;
Expand Down
8 changes: 5 additions & 3 deletions src/com/jaysonh/dmx4artists/WINValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ public class WINValidator
*/
public boolean isValid()
{
boolean exists = false;
boolean exists = true;
String foundPath = "";


/*
// Get the system paths for DLL files
String property = System.getProperty("java.library.path");
StringTokenizer parser = new StringTokenizer(property, ";");
Expand Down Expand Up @@ -65,6 +66,7 @@ public boolean isValid()
}
return false;
}
}*/
return true;
}
}

0 comments on commit 3f57972

Please sign in to comment.