Skip to content

Commit

Permalink
include native driver dlls; W64 works fine, Linux so is likely 32bit …
Browse files Browse the repository at this point in the history
…and should be replaced by a 64bit variant (also with proper filename)
  • Loading branch information
peterhalicky committed Mar 22, 2019
1 parent 1611c00 commit 1c03e24
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions gui/src/main/java/usbscope50software/LoadDataArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import java.awt.event.ActionListener;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import javax.swing.Timer;
Expand Down Expand Up @@ -857,16 +861,33 @@ private void Update() {
}
}

static {
if (USBFamily_Main.OS.equalsIgnoreCase("Linux")) {
System.load("/usr/lib/" + USBscope50_Main.productID + "Drvr.so");
} else if (USBFamily_Main.OS.equalsIgnoreCase("Windows")) {
try {
System.load(System.getenv("ProgramFiles") + "/" + USBscope50_Main.companyID + "/" + USBscope50_Main.productID + " Java Software/" + USBscope50_Main.productID + "Drvr_W" + System.getProperty("sun.arch.data.model") + ".dll");
} catch (UnsatisfiedLinkError err) {
USBscope50_Main.abort = 10;
err.getMessage();
public static void loadJarLibrary(String name) throws IOException {
try (InputStream in = ClassLoader.getSystemResourceAsStream(name)) {
if (in==null)
throw new IOException("Can't find "+name+" resource");
File temp = File.createTempFile(name, "");

try (FileOutputStream fos = new FileOutputStream(temp)) {
byte[] buffer = new byte[10240];
int read;
while ((read = in.read(buffer)) != -1) {
fos.write(buffer, 0, read);
}
}
System.load(temp.getAbsolutePath());
}
}

static {
try {
if (USBFamily_Main.OS.equalsIgnoreCase("Linux")) {
loadJarLibrary(USBscope50_Main.productID + "Drvr.so");
} else if (USBFamily_Main.OS.equalsIgnoreCase("Windows")) {
loadJarLibrary(USBscope50_Main.productID + "Drvr_W" + System.getProperty("sun.arch.data.model") + ".dll");
}
} catch (UnsatisfiedLinkError | IOException err) {
USBscope50_Main.abort = 10;
err.getMessage();
}
}

Expand Down
Binary file added gui/src/main/resources/USBscope50Drvr.so
Binary file not shown.
Binary file added gui/src/main/resources/USBscope50Drvr_W32.dll
Binary file not shown.
Binary file added gui/src/main/resources/USBscope50Drvr_W64.dll
Binary file not shown.

0 comments on commit 1c03e24

Please sign in to comment.