avoid adding testnet symlink in windows as admin privileges are required

This commit is contained in:
Craig Raw 2024-05-08 16:15:31 +02:00
parent d420c71673
commit f6ff92865b

View file

@ -534,7 +534,7 @@ public class Storage {
File networkNameDir = new File(getSparrowHome(), network.getName()); File networkNameDir = new File(getSparrowHome(), network.getName());
if(networkNameDir.exists() && networkNameDir.isDirectory() && !Files.isSymbolicLink(networkNameDir.toPath())) { if(networkNameDir.exists() && networkNameDir.isDirectory() && !Files.isSymbolicLink(networkNameDir.toPath())) {
try { try {
if(networkNameDir.renameTo(sparrowDir)) { if(networkNameDir.renameTo(sparrowDir) && !isWindows()) {
Files.createSymbolicLink(networkNameDir.toPath(), Path.of(sparrowDir.getName())); Files.createSymbolicLink(networkNameDir.toPath(), Path.of(sparrowDir.getName()));
} }
} catch(Exception e) { } catch(Exception e) {
@ -550,7 +550,7 @@ public class Storage {
createOwnerOnlyDirectory(sparrowDir); createOwnerOnlyDirectory(sparrowDir);
} }
if(!network.getName().equals(network.getHome())) { if(!network.getName().equals(network.getHome()) && !isWindows()) {
try { try {
Path networkNamePath = getSparrowHome().toPath().resolve(network.getName()); Path networkNamePath = getSparrowHome().toPath().resolve(network.getName());
if(Files.isSymbolicLink(networkNamePath)) { if(Files.isSymbolicLink(networkNamePath)) {
@ -579,7 +579,7 @@ public class Storage {
return new File(System.getProperty(SparrowWallet.APP_HOME_PROPERTY)); return new File(System.getProperty(SparrowWallet.APP_HOME_PROPERTY));
} }
if(Platform.getCurrent() == Platform.WINDOWS) { if(isWindows()) {
return new File(getHomeDir(), WINDOWS_SPARROW_DIR); return new File(getHomeDir(), WINDOWS_SPARROW_DIR);
} }
@ -587,7 +587,7 @@ public class Storage {
} }
static File getHomeDir() { static File getHomeDir() {
if(Platform.getCurrent() == Platform.WINDOWS) { if(isWindows()) {
return new File(System.getenv("APPDATA")); return new File(System.getenv("APPDATA"));
} }
@ -596,7 +596,7 @@ public class Storage {
public static boolean createOwnerOnlyDirectory(File directory) { public static boolean createOwnerOnlyDirectory(File directory) {
try { try {
if(Platform.getCurrent() == Platform.WINDOWS) { if(isWindows()) {
Files.createDirectories(directory.toPath()); Files.createDirectories(directory.toPath());
return true; return true;
} }
@ -614,7 +614,7 @@ public class Storage {
public static boolean createOwnerOnlyFile(File file) { public static boolean createOwnerOnlyFile(File file) {
try { try {
if(Platform.getCurrent() == Platform.WINDOWS) { if(isWindows()) {
Files.createFile(file.toPath()); Files.createFile(file.toPath());
return true; return true;
} }
@ -645,6 +645,10 @@ public class Storage {
return ownerOnly; return ownerOnly;
} }
private static boolean isWindows() {
return Platform.getCurrent() == Platform.WINDOWS;
}
public static class LoadWalletService extends Service<WalletAndKey> { public static class LoadWalletService extends Service<WalletAndKey> {
private final Storage storage; private final Storage storage;
private final SecureString password; private final SecureString password;