|
25 | 25 | import java.awt.event.ActionListener;
|
26 | 26 | import java.awt.geom.Point2D;
|
27 | 27 | 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; |
28 | 32 | import java.text.DecimalFormat;
|
29 | 33 | import java.text.NumberFormat;
|
30 | 34 | import javax.swing.Timer;
|
@@ -857,16 +861,33 @@ private void Update() {
|
857 | 861 | }
|
858 | 862 | }
|
859 | 863 |
|
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 | + } |
869 | 876 | }
|
| 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(); |
870 | 891 | }
|
871 | 892 | }
|
872 | 893 |
|
|
0 commit comments