Skip to content

Commit

Permalink
Add Utils.isLinux() and Utils.isMac() helpers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Schildbach committed Mar 13, 2018
1 parent 9e2b0c0 commit c35d892
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
8 changes: 8 additions & 0 deletions core/src/main/java/org/bitcoinj/core/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,15 @@ public static boolean isAndroidRuntime() {
return isAndroid == 1;
}

public static boolean isLinux() {
return System.getProperty("os.name").toLowerCase().contains("linux");
}

public static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().contains("win");
}

public static boolean isMac() {
return System.getProperty("os.name").toLowerCase().contains("mac");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static List<PeerDiscovery> buildDiscoveries(NetworkParameters params, St
protected ExecutorService createExecutor() {
// 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.
if (System.getProperty("os.name").toLowerCase().contains("linux"))
if (Utils.isLinux())
return Executors.newSingleThreadExecutor(new ContextPropagatingThreadFactory("DNS seed lookups"));
else
return Executors.newFixedThreadPool(seeds.size(), new DaemonThreadFactory("DNS seed lookups"));
Expand Down
9 changes: 5 additions & 4 deletions core/src/main/java/org/bitcoinj/utils/BlockFileLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ public class BlockFileLoader implements Iterable<Block>, Iterator<Block> {
*/
public static List<File> getReferenceClientBlockFileList() {
String defaultDataDir;
String OS = System.getProperty("os.name").toLowerCase();
if (Utils.isWindows()) {
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/";
} else {
} else if (Utils.isLinux()) {
defaultDataDir = System.getProperty("user.home") + "/.bitcoin/blocks/";
} else {
throw new RuntimeException("Unsupported system");
}

List<File> list = new LinkedList<>();
for (int i = 0; true; i++) {
File file = new File(defaultDataDir + String.format(Locale.US, "blk%05d.dat", i));
Expand Down
3 changes: 2 additions & 1 deletion wallettemplate/src/main/java/wallettemplate/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.common.util.concurrent.*;
import javafx.scene.input.*;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Utils;
import org.bitcoinj.kits.WalletAppKit;
import org.bitcoinj.params.*;
import org.bitcoinj.utils.BriefLogFormatter;
Expand Down Expand Up @@ -74,7 +75,7 @@ private void realStart(Stage mainWindow) throws IOException {
// Show the crash dialog for any exceptions that we don't handle and that hit the main loop.
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)
// the date picker widget is kinda broken in AquaFx and I can't be bothered fixing it.
// AquaFx.style();
Expand Down

0 comments on commit c35d892

Please sign in to comment.