Skip to content

Commit 1c03e24

Browse files
committed
include native driver dlls; W64 works fine, Linux so is likely 32bit and should be replaced by a 64bit variant (also with proper filename)
1 parent 1611c00 commit 1c03e24

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

gui/src/main/java/usbscope50software/LoadDataArray.java

+30-9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
import java.awt.event.ActionListener;
2626
import java.awt.geom.Point2D;
2727
import java.awt.geom.Rectangle2D;
28+
import java.io.File;
29+
import java.io.FileOutputStream;
30+
import java.io.IOException;
31+
import java.io.InputStream;
2832
import java.text.DecimalFormat;
2933
import java.text.NumberFormat;
3034
import javax.swing.Timer;
@@ -857,16 +861,33 @@ private void Update() {
857861
}
858862
}
859863

860-
static {
861-
if (USBFamily_Main.OS.equalsIgnoreCase("Linux")) {
862-
System.load("/usr/lib/" + USBscope50_Main.productID + "Drvr.so");
863-
} else if (USBFamily_Main.OS.equalsIgnoreCase("Windows")) {
864-
try {
865-
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");
866-
} catch (UnsatisfiedLinkError err) {
867-
USBscope50_Main.abort = 10;
868-
err.getMessage();
864+
public static void loadJarLibrary(String name) throws IOException {
865+
try (InputStream in = ClassLoader.getSystemResourceAsStream(name)) {
866+
if (in==null)
867+
throw new IOException("Can't find "+name+" resource");
868+
File temp = File.createTempFile(name, "");
869+
870+
try (FileOutputStream fos = new FileOutputStream(temp)) {
871+
byte[] buffer = new byte[10240];
872+
int read;
873+
while ((read = in.read(buffer)) != -1) {
874+
fos.write(buffer, 0, read);
875+
}
869876
}
877+
System.load(temp.getAbsolutePath());
878+
}
879+
}
880+
881+
static {
882+
try {
883+
if (USBFamily_Main.OS.equalsIgnoreCase("Linux")) {
884+
loadJarLibrary(USBscope50_Main.productID + "Drvr.so");
885+
} else if (USBFamily_Main.OS.equalsIgnoreCase("Windows")) {
886+
loadJarLibrary(USBscope50_Main.productID + "Drvr_W" + System.getProperty("sun.arch.data.model") + ".dll");
887+
}
888+
} catch (UnsatisfiedLinkError | IOException err) {
889+
USBscope50_Main.abort = 10;
890+
err.getMessage();
870891
}
871892
}
872893

77.4 KB
Binary file not shown.
47 KB
Binary file not shown.
47 KB
Binary file not shown.

0 commit comments

Comments
 (0)