Save backup wallets
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -35,6 +35,7 @@ namespace WalletWasabi.Gui
}
public static string WalletsDir => Path.Combine(DataDir, "Wallets");
+ public static string WalletBackupsDir => Path.Combine(DataDir, "WalletBackups");
public static Network Network => Config.Network;
public static string IndexFilePath => Path.Combine(DataDir, $"Index{Network}.dat");
@@ -164,8 +165,18 @@ namespace WalletWasabi.Gui
CancelWalletServiceInitialization?.Cancel();
CancelWalletServiceInitialization = null;
- WalletService?.Dispose();
+ if (WalletService != null)
+ {
+ if (WalletService.KeyManager != null) // This should not ever happen.
+ {
+ string backupWalletFilePath = Path.Combine(WalletBackupsDir, Path.GetFileName(WalletService.KeyManager.FilePath));
+ WalletService.KeyManager?.ToFile(backupWalletFilePath);
+ Logger.LogInfo($"{nameof(KeyManager)} backup saved to {backupWalletFilePath}.", nameof(Global));
+ }
+ WalletService.Dispose();
WalletService = null;
+ }
+
Logger.LogInfo($"{nameof(WalletService)} is stopped.", nameof(Global));
if (ChaumianClient != null)
@@ -178,10 +189,7 @@ namespace WalletWasabi.Gui
public static async Task DisposeAsync()
{
- CancelWalletServiceInitialization?.Cancel();
-
- WalletService?.Dispose();
- Logger.LogInfo($"{nameof(WalletService)} is stopped.", nameof(Global));
+ await DisposeInWalletDependentServicesAsync();
UpdateChecker?.Dispose();
Logger.LogInfo($"{nameof(UpdateChecker)} is stopped.", nameof(Global));
@@ -201,12 +209,6 @@ namespace WalletWasabi.Gui
RegTestMemPoolServingNode.Disconnect();
Logger.LogInfo($"{nameof(RegTestMemPoolServingNode)} is disposed.", nameof(Global));
}
-
- if (ChaumianClient != null)
- {
- await ChaumianClient.StopAsync();
- }
- Logger.LogInfo($"{nameof(ChaumianClient)} is stopped.", nameof(Global));
}
}
}

MODIFY
WalletWasabi/KeyManagement/KeyManager.cs
WalletWasabi/KeyManagement/KeyManager.cs
@@ -105,7 +105,11 @@ namespace WalletWasabi.KeyManagement
{
FilePath = string.IsNullOrWhiteSpace(filePath) ? null : filePath;
if (FilePath == null) return;
+ MakeSureContainingDirectoryExists(filePath);
+ }
+ private static void MakeSureContainingDirectoryExists(string filePath)
+ {
var directoryPath = Path.GetDirectoryName(Path.GetFullPath(filePath));
Directory.CreateDirectory(directoryPath);
}
@@ -113,11 +117,16 @@ namespace WalletWasabi.KeyManagement
public void ToFile()
{
if (FilePath == null) return;
+ ToFile(FilePath);
+ }
+ public void ToFile(string filePath)
+ {
+ MakeSureContainingDirectoryExists(filePath);
lock (ToFileLock)
{
string jsonString = JsonConvert.SerializeObject(this, Formatting.Indented);
- File.WriteAllText(FilePath,
+ File.WriteAllText(filePath,
jsonString,
Encoding.UTF8);
}

Save backup wallets