Modernize Windows Qt6 wallet build

This commit is contained in:
root
2026-04-30 14:46:44 +00:00
parent 099316b662
commit c90370640c
17 changed files with 137 additions and 95 deletions
+3 -3
View File
@@ -56,7 +56,7 @@ static void convertSeed6(std::vector<CAddress>& vSeedsOut, const SeedSpec6* data
static Checkpoints::MapCheckpoints mapCheckpoints =
boost::assign::map_list_of
(0, uint256("000003452250d81f8b07d42e127c92729802e3c48f3c7b9834256fd0fb9a0c2e"));
static const Checkpoints::CCheckpointData data = {
static const Checkpoints::CCheckpointData mainCheckpointData = {
&mapCheckpoints,
1643790201, // * UNIX timestamp of last checkpoint block
0, // * total number of transactions between genesis and last checkpoint
@@ -255,7 +255,7 @@ public:
const Checkpoints::CCheckpointData& Checkpoints() const
{
return data;
return mainCheckpointData;
}
};
static CMainParams mainParams;
@@ -462,7 +462,7 @@ public:
const Checkpoints::CCheckpointData& Checkpoints() const
{
// UnitTest share the same checkpoints as MAIN
return data;
return mainCheckpointData;
}
//! Published setters to allow changing values in unit test cases
+24 -24
View File
@@ -684,12 +684,12 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
}
// hardcoded $DATADIR/bootstrap.dat
filesystem::path pathBootstrap = GetDataDir() / "bootstrap.dat";
if (filesystem::exists(pathBootstrap)) {
boost::filesystem::path pathBootstrap = GetDataDir() / "bootstrap.dat";
if (boost::filesystem::exists(pathBootstrap)) {
FILE* file = fopen(pathBootstrap.string().c_str(), "rb");
if (file) {
CImportingNow imp;
filesystem::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old";
boost::filesystem::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old";
LogPrintf("Importing bootstrap.dat...\n");
LoadExternalBlockFile(file);
RenameOver(pathBootstrap, pathBootstrapOld);
@@ -1105,15 +1105,15 @@ bool AppInit2()
// ********************************************************* Step 5: Backup wallet and verify wallet database integrity
#ifdef ENABLE_WALLET
if (!fDisableWallet) {
filesystem::path backupDir = GetDataDir() / "backups";
if (!filesystem::exists(backupDir)) {
boost::filesystem::path backupDir = GetDataDir() / "backups";
if (!boost::filesystem::exists(backupDir)) {
// Always create backup folder to not confuse the operating system's file browser
filesystem::create_directories(backupDir);
boost::filesystem::create_directories(backupDir);
}
nWalletBackups = GetArg("-createwalletbackups", 10);
nWalletBackups = std::max(0, std::min(10, nWalletBackups));
if (nWalletBackups > 0) {
if (filesystem::exists(backupDir)) {
if (boost::filesystem::exists(backupDir)) {
// Create backup of the wallet
std::string dateTimeStr = DateTimeStrFormat(".%Y-%m-%d-%H-%M", GetTime());
std::string backupPathStr = backupDir.string();
@@ -1176,30 +1176,30 @@ bool AppInit2()
if (GetBoolArg("-resync", false)) {
uiInterface.InitMessage(_("Preparing for resync..."));
// Delete the local blockchain folders to force a resync from scratch to get a consitent blockchain-state
filesystem::path blocksDir = GetDataDir() / "blocks";
filesystem::path chainstateDir = GetDataDir() / "chainstate";
filesystem::path sporksDir = GetDataDir() / "sporks";
filesystem::path zerocoinDir = GetDataDir() / "zerocoin";
boost::filesystem::path blocksDir = GetDataDir() / "blocks";
boost::filesystem::path chainstateDir = GetDataDir() / "chainstate";
boost::filesystem::path sporksDir = GetDataDir() / "sporks";
boost::filesystem::path zerocoinDir = GetDataDir() / "zerocoin";
LogPrintf("Deleting blockchain folders blocks, chainstate, sporks and zerocoin\n");
// We delete in 4 individual steps in case one of the folder is missing already
try {
if (filesystem::exists(blocksDir)){
if (boost::filesystem::exists(blocksDir)){
boost::filesystem::remove_all(blocksDir);
LogPrintf("-resync: folder deleted: %s\n", blocksDir.string().c_str());
}
if (filesystem::exists(chainstateDir)){
if (boost::filesystem::exists(chainstateDir)){
boost::filesystem::remove_all(chainstateDir);
LogPrintf("-resync: folder deleted: %s\n", chainstateDir.string().c_str());
}
if (filesystem::exists(sporksDir)){
if (boost::filesystem::exists(sporksDir)){
boost::filesystem::remove_all(sporksDir);
LogPrintf("-resync: folder deleted: %s\n", sporksDir.string().c_str());
}
if (filesystem::exists(zerocoinDir)){
if (boost::filesystem::exists(zerocoinDir)){
boost::filesystem::remove_all(zerocoinDir);
LogPrintf("-resync: folder deleted: %s\n", zerocoinDir.string().c_str());
}
@@ -1236,7 +1236,7 @@ bool AppInit2()
return false;
}
if (filesystem::exists(GetDataDir() / strWalletFile)) {
if (boost::filesystem::exists(GetDataDir() / strWalletFile)) {
CDBEnv::VerifyResult r = bitdb.Verify(strWalletFile, CWalletDB::Recover);
if (r == CDBEnv::RECOVER_OK) {
string msg = strprintf(_("Warning: wallet.dat corrupt, data salvaged!"
@@ -1400,19 +1400,19 @@ bool AppInit2()
fReindex = GetBoolArg("-reindex", false);
// Upgrading to 0.8; hard-link the old blknnnn.dat files into /blocks/
filesystem::path blocksDir = GetDataDir() / "blocks";
if (!filesystem::exists(blocksDir)) {
filesystem::create_directories(blocksDir);
boost::filesystem::path blocksDir = GetDataDir() / "blocks";
if (!boost::filesystem::exists(blocksDir)) {
boost::filesystem::create_directories(blocksDir);
bool linked = false;
for (unsigned int i = 1; i < 10000; i++) {
filesystem::path source = GetDataDir() / strprintf("blk%04u.dat", i);
if (!filesystem::exists(source)) break;
filesystem::path dest = blocksDir / strprintf("blk%05u.dat", i - 1);
boost::filesystem::path source = GetDataDir() / strprintf("blk%04u.dat", i);
if (!boost::filesystem::exists(source)) break;
boost::filesystem::path dest = blocksDir / strprintf("blk%05u.dat", i - 1);
try {
filesystem::create_hard_link(source, dest);
boost::filesystem::create_hard_link(source, dest);
LogPrintf("Hardlinked %s -> %s\n", source.string(), dest.string());
linked = true;
} catch (filesystem::filesystem_error& e) {
} catch (boost::filesystem::filesystem_error& e) {
// Note: hardlink creation failing is not a disaster, it just means
// blocks will get re-downloaded from peers.
LogPrintf("Error hardlinking blk%04u.dat : %s\n", i, e.what());
+1 -1
View File
@@ -4966,7 +4966,7 @@ bool AbortNode(const std::string& strMessage, const std::string& userMessage)
bool CheckDiskSpace(uint64_t nAdditionalBytes)
{
uint64_t nFreeBytesAvailable = filesystem::space(GetDataDir()).available;
uint64_t nFreeBytesAvailable = boost::filesystem::space(GetDataDir()).available;
// Check for nMinDiskSpace bytes (currently 50MB)
if (nFreeBytesAvailable < nMinDiskSpace + nAdditionalBytes)
+19 -18
View File
@@ -4,6 +4,25 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifdef WIN32
#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
#define _WIN32_WINNT 0x0501
#ifdef _WIN32_IE
#undef _WIN32_IE
#endif
#define _WIN32_IE 0x0501
#define WIN32_LEAN_AND_MEAN 1
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#include <shellapi.h>
#include <shlobj.h>
#include <shlwapi.h>
#endif
#include "guiutil.h"
#include "bitcoinaddressvalidator.h"
@@ -19,24 +38,6 @@
#include "script/standard.h"
#include "util.h"
#ifdef WIN32
#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
#define _WIN32_WINNT 0x0501
#ifdef _WIN32_IE
#undef _WIN32_IE
#endif
#define _WIN32_IE 0x0501
#define WIN32_LEAN_AND_MEAN 1
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include "shellapi.h"
#include "shlobj.h"
#include "shlwapi.h"
#endif
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#if BOOST_FILESYSTEM_VERSION >= 3
+1 -1
View File
@@ -17,7 +17,7 @@
// If we don't want a message to be processed by Qt, return true and set result to
// the value that the window procedure should return. Otherwise return false.
bool WinShutdownMonitor::nativeEventFilter(const QByteArray& eventType, void* pMessage, long* pnResult)
bool WinShutdownMonitor::nativeEventFilter(const QByteArray& eventType, void* pMessage, WinShutdownMonitorResult* pnResult)
{
Q_UNUSED(eventType);
+8 -1
View File
@@ -12,12 +12,19 @@
#include <windef.h> // for HWND
#include <QAbstractNativeEventFilter>
#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
typedef qintptr WinShutdownMonitorResult;
#else
typedef long WinShutdownMonitorResult;
#endif
class WinShutdownMonitor : public QAbstractNativeEventFilter
{
public:
/** Implements QAbstractNativeEventFilter interface for processing Windows messages */
bool nativeEventFilter(const QByteArray& eventType, void* pMessage, long* pnResult);
bool nativeEventFilter(const QByteArray& eventType, void* pMessage, WinShutdownMonitorResult* pnResult);
/** Register the reason for blocking shutdown on Windows to allow clean client exit */
static void registerShutdownBlockReason(const QString& strReason, const HWND& mainWinId);
+9 -9
View File
@@ -4505,22 +4505,22 @@ string CWallet::GetUniqueWalletBackupName(bool fzagrAuto) const
void CWallet::ZPivBackupWallet()
{
filesystem::path backupDir = GetDataDir() / "backups";
filesystem::path backupPath;
boost::filesystem::path backupDir = GetDataDir() / "backups";
boost::filesystem::path backupPath;
string strNewBackupName;
for (int i = 0; i < 10; i++) {
strNewBackupName = strprintf("wallet-autozagrbackup-%d.dat", i);
backupPath = backupDir / strNewBackupName;
if (filesystem::exists(backupPath)) {
if (boost::filesystem::exists(backupPath)) {
//Keep up to 10 backups
if (i <= 8) {
//If the next file backup exists and is newer, then iterate
filesystem::path nextBackupPath = backupDir / strprintf("wallet-autozagrbackup-%d.dat", i + 1);
if (filesystem::exists(nextBackupPath)) {
time_t timeThis = filesystem::last_write_time(backupPath);
time_t timeNext = filesystem::last_write_time(nextBackupPath);
boost::filesystem::path nextBackupPath = backupDir / strprintf("wallet-autozagrbackup-%d.dat", i + 1);
if (boost::filesystem::exists(nextBackupPath)) {
time_t timeThis = boost::filesystem::last_write_time(backupPath);
time_t timeNext = boost::filesystem::last_write_time(nextBackupPath);
if (timeThis > timeNext) {
//The next backup is created before this backup was
//The next backup is the correct path to use
@@ -4543,8 +4543,8 @@ void CWallet::ZPivBackupWallet()
BackupWallet(*this, backupPath.string());
if(!GetArg("-zagrbackuppath", "").empty()) {
filesystem::path customPath(GetArg("-zagrbackuppath", ""));
filesystem::create_directories(customPath);
boost::filesystem::path customPath(GetArg("-zagrbackuppath", ""));
boost::filesystem::create_directories(customPath);
if(!customPath.has_extension()) {
customPath /= GetUniqueWalletBackupName(true);
+19 -19
View File
@@ -962,10 +962,10 @@ void NotifyBacked(const CWallet& wallet, bool fSuccess, string strMessage)
wallet.NotifyWalletBacked(fSuccess, strMessage);
}
bool BackupWallet(const CWallet& wallet, const filesystem::path& strDest, bool fEnableCustom)
bool BackupWallet(const CWallet& wallet, const boost::filesystem::path& strDest, bool fEnableCustom)
{
filesystem::path pathCustom;
filesystem::path pathWithFile;
boost::filesystem::path pathCustom;
boost::filesystem::path pathWithFile;
if (!wallet.fFileBacked) {
return false;
} else if(fEnableCustom) {
@@ -978,8 +978,8 @@ bool BackupWallet(const CWallet& wallet, const filesystem::path& strDest, bool f
pathCustom = pathWithFile.parent_path();
}
try {
filesystem::create_directories(pathCustom);
} catch(const filesystem::filesystem_error& e) {
boost::filesystem::create_directories(pathCustom);
} catch(const boost::filesystem::filesystem_error& e) {
NotifyBacked(wallet, false, strprintf("%s\n", e.what()));
pathCustom = "";
}
@@ -996,8 +996,8 @@ bool BackupWallet(const CWallet& wallet, const filesystem::path& strDest, bool f
bitdb.mapFileUseCount.erase(wallet.strWalletFile);
// Copy wallet.dat
filesystem::path pathDest(strDest);
filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile;
boost::filesystem::path pathDest(strDest);
boost::filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile;
if (is_directory(pathDest)) {
if(!exists(pathDest)) create_directory(pathDest);
pathDest /= wallet.strWalletFile;
@@ -1008,21 +1008,21 @@ bool BackupWallet(const CWallet& wallet, const filesystem::path& strDest, bool f
int nThreshold = GetArg("-custombackupthreshold", DEFAULT_CUSTOMBACKUPTHRESHOLD);
if (nThreshold > 0) {
typedef std::multimap<std::time_t, filesystem::path> folder_set_t;
typedef std::multimap<std::time_t, boost::filesystem::path> folder_set_t;
folder_set_t folderSet;
filesystem::directory_iterator end_iter;
boost::filesystem::directory_iterator end_iter;
pathCustom.make_preferred();
// Build map of backup files for current(!) wallet sorted by last write time
filesystem::path currentFile;
for (filesystem::directory_iterator dir_iter(pathCustom); dir_iter != end_iter; ++dir_iter) {
boost::filesystem::path currentFile;
for (boost::filesystem::directory_iterator dir_iter(pathCustom); dir_iter != end_iter; ++dir_iter) {
// Only check regular files
if (filesystem::is_regular_file(dir_iter->status())) {
if (boost::filesystem::is_regular_file(dir_iter->status())) {
currentFile = dir_iter->path().filename();
// Only add the backups for the current wallet, e.g. wallet.dat.*
if (dir_iter->path().stem().string() == wallet.strWalletFile) {
folderSet.insert(folder_set_t::value_type(filesystem::last_write_time(dir_iter->path()), *dir_iter));
folderSet.insert(folder_set_t::value_type(boost::filesystem::last_write_time(dir_iter->path()), *dir_iter));
}
}
}
@@ -1046,10 +1046,10 @@ bool BackupWallet(const CWallet& wallet, const filesystem::path& strDest, bool f
try {
auto entry = folderSet.find(oldestBackup);
if (entry != folderSet.end()) {
filesystem::remove(entry->second);
boost::filesystem::remove(entry->second);
LogPrintf("Old backup deleted: %s\n", (*entry).second);
}
} catch (filesystem::filesystem_error& error) {
} catch (boost::filesystem::filesystem_error& error) {
string strMessage = strprintf("Failed to delete backup %s\n", error.what());
LogPrint(nullptr, strMessage.data());
NotifyBacked(wallet, false, strMessage);
@@ -1067,7 +1067,7 @@ bool BackupWallet(const CWallet& wallet, const filesystem::path& strDest, bool f
return false;
}
bool AttemptBackupWallet(const CWallet& wallet, const filesystem::path& pathSrc, const filesystem::path& pathDest)
bool AttemptBackupWallet(const CWallet& wallet, const boost::filesystem::path& pathSrc, const boost::filesystem::path& pathDest)
{
bool retStatus;
string strMessage;
@@ -1077,9 +1077,9 @@ bool AttemptBackupWallet(const CWallet& wallet, const filesystem::path& pathSrc,
return false;
}
#if BOOST_VERSION >= 107400 /* BOOST_LIB_VERSION 1_74 */
filesystem::copy_file(pathSrc.c_str(), pathDest, filesystem::copy_options::overwrite_existing);
boost::filesystem::copy_file(pathSrc.c_str(), pathDest, boost::filesystem::copy_options::overwrite_existing);
#elif BOOST_VERSION >= 105800 /* BOOST_LIB_VERSION 1_58 */
filesystem::copy_file(pathSrc.c_str(), pathDest, filesystem::copy_option::overwrite_if_exists);
boost::filesystem::copy_file(pathSrc.c_str(), pathDest, boost::filesystem::copy_option::overwrite_if_exists);
#else
std::ifstream src(pathSrc.c_str(), std::ios::binary | std::ios::in);
std::ofstream dst(pathDest.c_str(), std::ios::binary | std::ios::out | std::ios::trunc);
@@ -1091,7 +1091,7 @@ bool AttemptBackupWallet(const CWallet& wallet, const filesystem::path& pathSrc,
strMessage = strprintf("copied wallet.dat to %s\n", pathDest.string());
LogPrint(nullptr, strMessage.data());
retStatus = true;
} catch (const filesystem::filesystem_error& e) {
} catch (const boost::filesystem::filesystem_error& e) {
retStatus = false;
strMessage = strprintf("%s\n", e.what());
LogPrint(nullptr, strMessage.data());