update monero binaries in app directory #655

This commit is contained in:
woodser 2023-08-09 15:35:46 -04:00
parent 3c8c0034d0
commit 586a2478fc
4 changed files with 18 additions and 5 deletions

View File

@ -25,6 +25,7 @@ import org.apache.commons.io.IOUtils;
import javax.annotation.Nullable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@ -175,6 +176,16 @@ public class FileUtil {
}
}
public static boolean resourceEqualToFile(String resourcePath,
File destinationFile) throws ResourceNotFoundException, IOException {
try (InputStream inputStream = ClassLoader.getSystemClassLoader().getResourceAsStream(resourcePath)) {
if (inputStream == null) {
throw new ResourceNotFoundException(resourcePath);
}
return IOUtils.contentEquals(inputStream, new FileInputStream(destinationFile));
}
}
public static void renameFile(File oldFile, File newFile) throws IOException {
if (Utilities.isWindows()) {
// Work around an issue on Windows whereby you can't rename over existing files.

View File

@ -40,7 +40,7 @@ import java.util.List;
@Singleton
public class CoreMoneroNodeService {
public static final String MONEROD_DIR = Config.baseCurrencyNetwork() == BaseCurrencyNetwork.XMR_LOCAL ? System.getProperty("user.dir") + File.separator + ".localnet" : Config.appDataDir().getAbsolutePath();
public static final String MONEROD_DIR = Config.appDataDir().getAbsolutePath();
public static final String MONEROD_NAME = Utilities.isWindows() ? "monerod.exe" : "monerod";
public static final String MONEROD_PATH = MONEROD_DIR + File.separator + MONEROD_NAME;
private static final String MONEROD_DATADIR = Config.baseCurrencyNetwork() == BaseCurrencyNetwork.XMR_LOCAL ? MONEROD_DIR + File.separator + Config.baseCurrencyNetwork().toString().toLowerCase() + File.separator + "node1" : null; // use default directory unless local

View File

@ -340,7 +340,8 @@ public class HavenoSetup {
private void maybeInstallDependencies() {
try {
File monerodFile = new File(CoreMoneroNodeService.MONEROD_PATH);
if (!monerodFile.exists()) {
String monerodResourcePath = "bin/" + CoreMoneroNodeService.MONEROD_NAME;
if (!monerodFile.exists() || !FileUtil.resourceEqualToFile(monerodResourcePath, monerodFile)) {
log.info("Installing monerod");
monerodFile.getParentFile().mkdirs();
FileUtil.resourceToFile("bin/" + CoreMoneroNodeService.MONEROD_NAME, monerodFile);
@ -348,10 +349,11 @@ public class HavenoSetup {
}
File moneroWalletFile = new File(XmrWalletService.MONERO_WALLET_RPC_PATH);
if (!moneroWalletFile.exists()) {
String moneroWalletResourcePath = "bin/" + XmrWalletService.MONERO_WALLET_RPC_NAME;
if (!moneroWalletFile.exists() || !FileUtil.resourceEqualToFile(moneroWalletResourcePath, moneroWalletFile)) {
log.info("Installing monero-wallet-rpc");
moneroWalletFile.getParentFile().mkdirs();
FileUtil.resourceToFile("bin/" + XmrWalletService.MONERO_WALLET_RPC_NAME, moneroWalletFile);
FileUtil.resourceToFile(moneroWalletResourcePath, moneroWalletFile);
moneroWalletFile.setExecutable(true);
}
} catch (Exception e) {

View File

@ -86,7 +86,7 @@ public class XmrWalletService {
public static final int NUM_BLOCKS_UNLOCK = 10;
private static final MoneroNetworkType MONERO_NETWORK_TYPE = getMoneroNetworkType();
private static final MoneroWalletRpcManager MONERO_WALLET_RPC_MANAGER = new MoneroWalletRpcManager();
public static final String MONERO_WALLET_RPC_DIR = Config.baseCurrencyNetwork().isTestnet() ? System.getProperty("user.dir") + File.separator + ".localnet" : Config.appDataDir().getAbsolutePath(); // .localnet contains monero-wallet-rpc and wallet files
public static final String MONERO_WALLET_RPC_DIR = Config.appDataDir().getAbsolutePath();
public static final String MONERO_WALLET_RPC_NAME = Utilities.isWindows() ? "monero-wallet-rpc.exe" : "monero-wallet-rpc";
public static final String MONERO_WALLET_RPC_PATH = MONERO_WALLET_RPC_DIR + File.separator + MONERO_WALLET_RPC_NAME;
private static final String MONERO_WALLET_RPC_USERNAME = "haveno_user";