mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2025-11-05 11:56:37 +00:00
remove unnecessary zbar native libraries
This commit is contained in:
parent
7802510e58
commit
84566b92e6
9 changed files with 33 additions and 39 deletions
2
drongo
2
drongo
|
|
@ -1 +1 @@
|
|||
Subproject commit 73acc00ab60b9e337934b564271dc253e8131b7c
|
||||
Subproject commit 6eb46da87a0e1fd37daf8108b6e44b753fd982db
|
||||
|
|
@ -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.
Loading…
Reference in a new issue