Add Utils.isLinux() and Utils.isMac() helpers.

This commit is contained in:
Andreas Schildbach 2018-03-13 12:39:02 +01:00
parent 9e2b0c05c7
commit c35d892fa6
4 changed files with 16 additions and 6 deletions

View file

@ -544,7 +544,15 @@ public class Utils {
return isAndroid == 1; return isAndroid == 1;
} }
public static boolean isLinux() {
return System.getProperty("os.name").toLowerCase().contains("linux");
}
public static boolean isWindows() { public static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().contains("win"); return System.getProperty("os.name").toLowerCase().contains("win");
} }
public static boolean isMac() {
return System.getProperty("os.name").toLowerCase().contains("mac");
}
} }

View file

@ -67,7 +67,7 @@ public class DnsDiscovery extends MultiplexingDiscovery {
protected ExecutorService createExecutor() { protected ExecutorService createExecutor() {
// Attempted workaround for reported bugs on Linux in which gethostbyname does not appear to be properly // Attempted workaround for reported bugs on Linux in which gethostbyname does not appear to be properly
// thread safe and can cause segfaults on some libc versions. // thread safe and can cause segfaults on some libc versions.
if (System.getProperty("os.name").toLowerCase().contains("linux")) if (Utils.isLinux())
return Executors.newSingleThreadExecutor(new ContextPropagatingThreadFactory("DNS seed lookups")); return Executors.newSingleThreadExecutor(new ContextPropagatingThreadFactory("DNS seed lookups"));
else else
return Executors.newFixedThreadPool(seeds.size(), new DaemonThreadFactory("DNS seed lookups")); return Executors.newFixedThreadPool(seeds.size(), new DaemonThreadFactory("DNS seed lookups"));

View file

@ -54,15 +54,16 @@ public class BlockFileLoader implements Iterable<Block>, Iterator<Block> {
*/ */
public static List<File> getReferenceClientBlockFileList() { public static List<File> getReferenceClientBlockFileList() {
String defaultDataDir; String defaultDataDir;
String OS = System.getProperty("os.name").toLowerCase();
if (Utils.isWindows()) { if (Utils.isWindows()) {
defaultDataDir = System.getenv("APPDATA") + "\\.bitcoin\\blocks\\"; defaultDataDir = System.getenv("APPDATA") + "\\.bitcoin\\blocks\\";
} else if (OS.indexOf("mac") >= 0 || (OS.indexOf("darwin") >= 0)) { } else if (Utils.isMac()) {
defaultDataDir = System.getProperty("user.home") + "/Library/Application Support/Bitcoin/blocks/"; defaultDataDir = System.getProperty("user.home") + "/Library/Application Support/Bitcoin/blocks/";
} else { } else if (Utils.isLinux()) {
defaultDataDir = System.getProperty("user.home") + "/.bitcoin/blocks/"; defaultDataDir = System.getProperty("user.home") + "/.bitcoin/blocks/";
} else {
throw new RuntimeException("Unsupported system");
} }
List<File> list = new LinkedList<>(); List<File> list = new LinkedList<>();
for (int i = 0; true; i++) { for (int i = 0; true; i++) {
File file = new File(defaultDataDir + String.format(Locale.US, "blk%05d.dat", i)); File file = new File(defaultDataDir + String.format(Locale.US, "blk%05d.dat", i));

View file

@ -19,6 +19,7 @@ package wallettemplate;
import com.google.common.util.concurrent.*; import com.google.common.util.concurrent.*;
import javafx.scene.input.*; import javafx.scene.input.*;
import org.bitcoinj.core.NetworkParameters; import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Utils;
import org.bitcoinj.kits.WalletAppKit; import org.bitcoinj.kits.WalletAppKit;
import org.bitcoinj.params.*; import org.bitcoinj.params.*;
import org.bitcoinj.utils.BriefLogFormatter; import org.bitcoinj.utils.BriefLogFormatter;
@ -74,7 +75,7 @@ public class Main extends Application {
// Show the crash dialog for any exceptions that we don't handle and that hit the main loop. // Show the crash dialog for any exceptions that we don't handle and that hit the main loop.
GuiUtils.handleCrashesOnThisThread(); GuiUtils.handleCrashesOnThisThread();
if (System.getProperty("os.name").toLowerCase().contains("mac")) { if (Utils.isMac()) {
// We could match the Mac Aqua style here, except that (a) Modena doesn't look that bad, and (b) // We could match the Mac Aqua style here, except that (a) Modena doesn't look that bad, and (b)
// the date picker widget is kinda broken in AquaFx and I can't be bothered fixing it. // the date picker widget is kinda broken in AquaFx and I can't be bothered fixing it.
// AquaFx.style(); // AquaFx.style();