mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2026-07-30 19:46:16 +00:00
remove unnecessary zbar native libraries
This commit is contained in:
+1
-1
Submodule drongo updated: 73acc00ab6...6eb46da87a
@@ -4,7 +4,6 @@ import io.github.doblon8.jzbar.Config;
|
||||
import io.github.doblon8.jzbar.Image;
|
||||
import io.github.doblon8.jzbar.ImageScanner;
|
||||
import io.github.doblon8.jzbar.SymbolType;
|
||||
import com.sparrowwallet.sparrow.net.NativeUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -15,18 +14,8 @@ import java.awt.image.DataBufferByte;
|
||||
public class ZBar {
|
||||
private static final Logger log = LoggerFactory.getLogger(ZBar.class);
|
||||
|
||||
private final static boolean enabled;
|
||||
|
||||
static { // static initializer
|
||||
if(com.sparrowwallet.sparrow.io.Config.get().isUseZbar()) {
|
||||
enabled = loadLibrary();
|
||||
} else {
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return enabled;
|
||||
return com.sparrowwallet.sparrow.io.Config.get().isUseZbar();
|
||||
}
|
||||
|
||||
public static Scan scan(BufferedImage bufferedImage) {
|
||||
@@ -93,31 +82,6 @@ public class ZBar {
|
||||
return outputData;
|
||||
}
|
||||
|
||||
private static boolean loadLibrary() {
|
||||
try {
|
||||
String osName = System.getProperty("os.name");
|
||||
String osArch = System.getProperty("os.arch");
|
||||
if(osName.startsWith("Mac") && osArch.equals("aarch64")) {
|
||||
NativeUtils.loadLibraryFromJar("/native/osx/aarch64/libzbar.dylib");
|
||||
} else if(osName.startsWith("Mac")) {
|
||||
NativeUtils.loadLibraryFromJar("/native/osx/x64/libzbar.dylib");
|
||||
} else if(osName.startsWith("Windows")) {
|
||||
NativeUtils.loadLibraryFromJar("/native/windows/x64/iconv-2.dll");
|
||||
NativeUtils.loadLibraryFromJar("/native/windows/x64/zbar.dll");
|
||||
} else if(osArch.equals("aarch64")) {
|
||||
NativeUtils.loadLibraryFromJar("/native/linux/aarch64/libzbar.so");
|
||||
} else {
|
||||
NativeUtils.loadLibraryFromJar("/native/linux/x64/libzbar.so");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch(Exception e) {
|
||||
log.warn("Could not load ZBar native libraries, disabling. " + e.getMessage());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static byte[] getRawBytes(String str) {
|
||||
char[] chars = str.toCharArray();
|
||||
byte[] bytes = new byte[chars.length];
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package com.sparrowwallet.sparrow.net;
|
||||
|
||||
import com.sparrowwallet.drongo.OsType;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.FileSystemNotFoundException;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.ProviderNotFoundException;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.attribute.PosixFilePermission;
|
||||
import java.nio.file.attribute.PosixFilePermissions;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A simple library class which helps with loading dynamic libraries stored in the
|
||||
@@ -111,9 +117,33 @@ public class NativeUtils {
|
||||
String tempDir = System.getProperty("java.io.tmpdir");
|
||||
File generatedDir = new File(tempDir, prefix + System.nanoTime());
|
||||
|
||||
if (!generatedDir.mkdir())
|
||||
if(!createOwnerOnlyDirectory(generatedDir)) {
|
||||
throw new IOException("Failed to create temp directory " + generatedDir.getName());
|
||||
}
|
||||
|
||||
return generatedDir;
|
||||
}
|
||||
|
||||
public static boolean createOwnerOnlyDirectory(File directory) throws IOException {
|
||||
try {
|
||||
if(OsType.getCurrent() == OsType.WINDOWS) {
|
||||
Files.createDirectories(directory.toPath());
|
||||
return true;
|
||||
}
|
||||
|
||||
Files.createDirectories(directory.toPath(), PosixFilePermissions.asFileAttribute(getDirectoryOwnerOnlyPosixFilePermissions()));
|
||||
return true;
|
||||
} catch(UnsupportedOperationException e) {
|
||||
return directory.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
private static Set<PosixFilePermission> getDirectoryOwnerOnlyPosixFilePermissions() {
|
||||
Set<PosixFilePermission> ownerOnly = EnumSet.noneOf(PosixFilePermission.class);
|
||||
ownerOnly.add(PosixFilePermission.OWNER_READ);
|
||||
ownerOnly.add(PosixFilePermission.OWNER_WRITE);
|
||||
ownerOnly.add(PosixFilePermission.OWNER_EXECUTE);
|
||||
|
||||
return ownerOnly;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user