Replace the "Import" action — which copied an out-of-datadir wallet into the datadir and cluttered the list with hard-to-tell-apart duplicates — with an in-place "Open" that links the real file into the datadir under a stable per-target name (wallet-ip-<FNV8>.dat) and switches to it. The daemon only loads a bare filename from its own datadir, so a link is the minimal bridge: hard link first (no privileges, same volume — covers non-admin Windows), symlink fallback (cross-volume), then an error. Never a copy (that would fork the wallet) and never a delete of a real file. Also: - show each external wallet's originating sub-directory (…/Backups/2021) - add a per-row "open folder location" button - widen the modal (780 → 860) for the extra button - guard the daemon against a dangling link (external file moved / USB unplugged) by falling back to wallet.dat rather than creating an empty one Per-target link names (not one shared name) make switching between two external wallets a real -wallet switch, so the rescan/cache index tracks each correctly. Drops the now-dead wallets_import* i18n keys and back-fills the new open/folder strings across all 8 languages + rebuilds the CJK subset. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
144 lines
3.8 KiB
C++
144 lines
3.8 KiB
C++
#include "daemon_controller.h"
|
|
#include "../config/settings.h"
|
|
#include "../util/platform.h"
|
|
|
|
#include <algorithm>
|
|
#include <filesystem>
|
|
#include <system_error>
|
|
|
|
namespace dragonx {
|
|
namespace daemon {
|
|
|
|
DaemonController::DaemonController()
|
|
: daemon_(std::make_unique<EmbeddedDaemon>())
|
|
{
|
|
}
|
|
|
|
DaemonController::~DaemonController() = default;
|
|
|
|
void DaemonController::setStateCallback(StateCallback callback)
|
|
{
|
|
daemon_->setStateCallback(std::move(callback));
|
|
}
|
|
|
|
void DaemonController::syncSettings(const config::Settings* settings)
|
|
{
|
|
if (!settings) return;
|
|
daemon_->setDebugCategories(settings->getDebugCategories());
|
|
daemon_->setMaxConnections(settings->getMaxConnections());
|
|
|
|
std::string walletFile = settings->getActiveWalletFile();
|
|
// The Wallets dialog opens an out-of-datadir wallet by linking it into the datadir under a
|
|
// "wallet-ip-<hash>.dat" name. If that link went dangling (the external file was moved / a USB was
|
|
// unplugged between sessions), don't let the daemon create a fresh EMPTY wallet at that name — fall
|
|
// back to the default this launch. fs::exists follows the link, so it's false for a dangling one.
|
|
if (walletFile.rfind("wallet-ip-", 0) == 0) {
|
|
std::error_code ec;
|
|
if (!std::filesystem::exists(util::Platform::getDragonXDataDir() + "/" + walletFile, ec))
|
|
walletFile = "wallet.dat";
|
|
}
|
|
daemon_->setWalletFile(walletFile);
|
|
}
|
|
|
|
bool DaemonController::start(const config::Settings* settings)
|
|
{
|
|
syncSettings(settings);
|
|
return daemon_->start();
|
|
}
|
|
|
|
void DaemonController::stop(int waitMs)
|
|
{
|
|
daemon_->stop(waitMs);
|
|
}
|
|
|
|
bool DaemonController::isRunning() const
|
|
{
|
|
return daemon_->isRunning();
|
|
}
|
|
|
|
bool DaemonController::externalDaemonDetected() const
|
|
{
|
|
return daemon_->externalDaemonDetected();
|
|
}
|
|
|
|
DaemonController::State DaemonController::state() const
|
|
{
|
|
return daemon_->getState();
|
|
}
|
|
|
|
const std::string& DaemonController::lastError() const
|
|
{
|
|
return daemon_->getLastError();
|
|
}
|
|
|
|
int DaemonController::crashCount() const
|
|
{
|
|
return daemon_->getCrashCount();
|
|
}
|
|
|
|
int DaemonController::lastBlockHeight() const
|
|
{
|
|
return daemon_ ? daemon_->getLastBlockHeight() : 0;
|
|
}
|
|
|
|
double DaemonController::memoryUsageMB() const
|
|
{
|
|
return daemon_ ? daemon_->getMemoryUsageMB() : 0.0;
|
|
}
|
|
|
|
std::vector<std::string> DaemonController::recentLines(std::size_t count) const
|
|
{
|
|
return daemon_ ? daemon_->getRecentLines(count) : std::vector<std::string>{};
|
|
}
|
|
|
|
std::string DaemonController::outputSince(std::size_t& offset) const
|
|
{
|
|
return daemon_ ? daemon_->getOutputSince(offset) : std::string{};
|
|
}
|
|
|
|
void DaemonController::resetCrashCount()
|
|
{
|
|
daemon_->resetCrashCount();
|
|
}
|
|
|
|
void DaemonController::setRescanOnNextStart(bool enabled)
|
|
{
|
|
daemon_->setRescanOnNextStart(enabled);
|
|
}
|
|
|
|
bool DaemonController::rescanOnNextStart() const
|
|
{
|
|
return daemon_->rescanOnNextStart();
|
|
}
|
|
|
|
void DaemonController::setZapOnNextStart(bool enabled)
|
|
{
|
|
daemon_->setZapOnNextStart(enabled);
|
|
}
|
|
|
|
bool DaemonController::zapOnNextStart() const
|
|
{
|
|
return daemon_->zapOnNextStart();
|
|
}
|
|
|
|
void DaemonController::prepareLifecycleOperation(const LifecycleDecision& decision,
|
|
const config::Settings* settings)
|
|
{
|
|
if (settings) syncSettings(settings);
|
|
if (decision.resetCrashCount) resetCrashCount();
|
|
if (decision.setRescanOnNextStart) setRescanOnNextStart(true);
|
|
if (decision.setZapOnNextStart) setZapOnNextStart(true);
|
|
}
|
|
|
|
DaemonController::ShutdownDecision DaemonController::shutdownDecision(
|
|
bool keepDaemonRunning, bool stopExternalDaemon) const
|
|
{
|
|
return evaluateShutdownPolicy(static_cast<bool>(daemon_),
|
|
daemon_ && daemon_->externalDaemonDetected(),
|
|
keepDaemonRunning,
|
|
stopExternalDaemon);
|
|
}
|
|
|
|
} // namespace daemon
|
|
} // namespace dragonx
|