Commit 4be0a960 authored by Jeremy Bokobza's avatar Jeremy Bokobza

Made sure the wallet folder exists or creating it if it doesn't

parent 09435caa
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
...@@ -43,10 +42,10 @@ namespace Breeze.Wallet.Controllers ...@@ -43,10 +42,10 @@ namespace Breeze.Wallet.Controllers
try try
{ {
// get the folder path // get the wallet folder
string folderPath = string.IsNullOrEmpty(request.FolderPath) ? this.GetDefaultFolderPath() : request.FolderPath; DirectoryInfo walletFolder = GetWalletFolder(request.FolderPath);
var mnemonic = this.walletWrapper.Create(request.Password, folderPath, request.Name, request.Network); var mnemonic = this.walletWrapper.Create(request.Password, walletFolder.FullName, request.Name, request.Network);
return this.Json(mnemonic); return this.Json(mnemonic);
} }
catch (NotSupportedException e) catch (NotSupportedException e)
...@@ -74,10 +73,10 @@ namespace Breeze.Wallet.Controllers ...@@ -74,10 +73,10 @@ namespace Breeze.Wallet.Controllers
try try
{ {
// get the folder path // get the wallet folder
string folderPath = string.IsNullOrEmpty(request.FolderPath) ? this.GetDefaultFolderPath() : request.FolderPath; DirectoryInfo walletFolder = GetWalletFolder(request.FolderPath);
var wallet = this.walletWrapper.Load(request.Password, folderPath, request.Name); var wallet = this.walletWrapper.Load(request.Password, walletFolder.FullName, request.Name);
return this.Json(wallet); return this.Json(wallet);
} }
...@@ -114,12 +113,11 @@ namespace Breeze.Wallet.Controllers ...@@ -114,12 +113,11 @@ namespace Breeze.Wallet.Controllers
try try
{ {
// get the folder path // get the wallet folder
string folderPath = string.IsNullOrEmpty(request.FolderPath) ? this.GetDefaultFolderPath() : request.FolderPath; DirectoryInfo walletFolder = GetWalletFolder(request.FolderPath);
var wallet = this.walletWrapper.Recover(request.Password, folderPath, request.Name, request.Network, request.Mnemonic); var wallet = this.walletWrapper.Recover(request.Password, walletFolder.FullName, request.Name, request.Network, request.Mnemonic);
return this.Json(wallet); return this.Json(wallet);
} }
catch (FileNotFoundException e) catch (FileNotFoundException e)
{ {
...@@ -287,12 +285,12 @@ namespace Breeze.Wallet.Controllers ...@@ -287,12 +285,12 @@ namespace Breeze.Wallet.Controllers
{ {
try try
{ {
var defaultWalletsPath = this.GetDefaultFolderPath(); DirectoryInfo walletsFolder = GetWalletFolder();
WalletFileModel model = new WalletFileModel WalletFileModel model = new WalletFileModel
{ {
WalletsPath = defaultWalletsPath, WalletsPath = walletsFolder.FullName,
WalletsFiles = Directory.EnumerateFiles(defaultWalletsPath, "*.json", SearchOption.TopDirectoryOnly).Select(p => Path.GetFileName(p)) WalletsFiles = Directory.EnumerateFiles(walletsFolder.FullName, "*.json", SearchOption.TopDirectoryOnly).Select(p => Path.GetFileName(p))
}; };
return this.Json(model); return this.Json(model);
...@@ -304,10 +302,24 @@ namespace Breeze.Wallet.Controllers ...@@ -304,10 +302,24 @@ namespace Breeze.Wallet.Controllers
} }
/// <summary> /// <summary>
/// Get the default folder in which the wallets will be stored. /// Gets a folder.
/// </summary>
/// <returns>The path folder of the folder.</returns>
/// <remarks>The folder is created if it doesn't exist.</remarks>
private static DirectoryInfo GetWalletFolder(string folderPath = null)
{
if (string.IsNullOrEmpty(folderPath))
{
folderPath = GetDefaultWalletFolderPath();
}
return Directory.CreateDirectory(folderPath);
}
/// <summary>
/// Gets the path of the default folder in which the wallets will be stored.
/// </summary> /// </summary>
/// <returns>The folder path for Windows, Linux or OSX systems.</returns> /// <returns>The folder path for Windows, Linux or OSX systems.</returns>
private string GetDefaultFolderPath() private static string GetDefaultWalletFolderPath()
{ {
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment