fix NTFS issues

This commit is contained in:
Czarek Nakamoto 2024-05-21 13:23:56 +02:00
parent d78f524f1c
commit c5a532a138
2 changed files with 37 additions and 1 deletions

View file

@ -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<void> 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));

View file

@ -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<MoneroNewWalletCredentials,
@override
Future<void> 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();