Modernize Windows Qt6 wallet build
This commit is contained in:
@@ -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
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user