From c5a532a1385c898c9e7facb0d45d2a19ebe2f69b Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Tue, 21 May 2024 13:23:56 +0200 Subject: [PATCH] fix NTFS issues --- cw_monero/lib/monero_wallet.dart | 19 ++++++++++++++++++- cw_monero/lib/monero_wallet_service.dart | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/cw_monero/lib/monero_wallet.dart b/cw_monero/lib/monero_wallet.dart index 64c9f6512..f5f786d27 100644 --- a/cw_monero/lib/monero_wallet.dart +++ b/cw_monero/lib/monero_wallet.dart @@ -1,5 +1,7 @@ import 'dart:async'; +import 'dart:ffi'; import 'dart:io'; +import 'dart:isolate'; import 'package:cw_core/account.dart'; import 'package:cw_core/crypto_currency.dart'; @@ -22,6 +24,7 @@ import 'package:cw_monero/api/monero_output.dart'; import 'package:cw_monero/api/structs/pending_transaction.dart'; import 'package:cw_monero/api/transaction_history.dart' as transaction_history; import 'package:cw_monero/api/wallet.dart' as monero_wallet; +import 'package:cw_monero/api/wallet_manager.dart'; import 'package:cw_monero/exceptions/monero_transaction_creation_exception.dart'; import 'package:cw_monero/exceptions/monero_transaction_no_inputs_exception.dart'; import 'package:cw_monero/monero_transaction_creation_credentials.dart'; @@ -332,7 +335,21 @@ abstract class MoneroWalletBase @override Future renameWalletFiles(String newWalletName) async { final currentWalletDirPath = await pathForWalletDir(name: name, type: type); - + if (openedWalletsByPath[currentWalletDirPath] != null) { + // NOTE: this is realistically only required on windows. + print("closing wallet"); + final wmaddr = wmPtr!.address; + final waddr = openedWalletsByPath[currentWalletDirPath]!.address; + await Isolate.run(() { + monero.WalletManager_closeWallet( + Pointer.fromAddress(wmaddr), + Pointer.fromAddress(waddr), + true + ); + }); + openedWalletsByPath.remove(currentWalletDirPath); + print("wallet closed"); + } try { // -- rename the waller folder -- final currentWalletDir = Directory(await pathForWalletDir(name: name, type: type)); diff --git a/cw_monero/lib/monero_wallet_service.dart b/cw_monero/lib/monero_wallet_service.dart index bc59499f9..1933bab79 100644 --- a/cw_monero/lib/monero_wallet_service.dart +++ b/cw_monero/lib/monero_wallet_service.dart @@ -1,4 +1,6 @@ +import 'dart:ffi'; import 'dart:io'; +import 'dart:isolate'; import 'package:cw_core/monero_wallet_utils.dart'; import 'package:cw_core/pathForWallet.dart'; import 'package:cw_core/unspent_coins_info.dart'; @@ -14,6 +16,8 @@ import 'package:cw_monero/monero_wallet.dart'; import 'package:flutter/widgets.dart'; import 'package:hive/hive.dart'; import 'package:polyseed/polyseed.dart'; +import 'package:cw_monero/api/wallet_manager.dart'; +import 'package:monero/monero.dart' as monero; class MoneroNewWalletCredentials extends WalletCredentials { MoneroNewWalletCredentials( @@ -174,6 +178,21 @@ class MoneroWalletService extends WalletService remove(String wallet) async { final path = await pathForWalletDir(name: wallet, type: getType()); + if (openedWalletsByPath[path] != null) { + // NOTE: this is realistically only required on windows. + print("closing wallet"); + final wmaddr = wmPtr!.address; + final waddr = openedWalletsByPath[path]!.address; + await Isolate.run(() { + monero.WalletManager_closeWallet( + Pointer.fromAddress(wmaddr), + Pointer.fromAddress(waddr), + false + ); + }); + openedWalletsByPath.remove(path); + print("wallet closed"); + } final file = Directory(path); final isExist = file.existsSync();