From 90135f7bd830d9aafac720ac86b6913791dbe848 Mon Sep 17 00:00:00 2001 From: Ricardo Prado <38396062+lock9@users.noreply.github.com> Date: Thu, 16 May 2024 16:38:37 -0300 Subject: [PATCH] Fix: Relative paths not working properly when creating checkpoints #437 (#438) --- src/neoxp/ExpressChainManagerFactory.cs | 14 +++++++++++++- src/neoxp/Extensions/FileSystemExtensions.cs | 20 ++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/neoxp/ExpressChainManagerFactory.cs b/src/neoxp/ExpressChainManagerFactory.cs index c541fb20..0340dff2 100644 --- a/src/neoxp/ExpressChainManagerFactory.cs +++ b/src/neoxp/ExpressChainManagerFactory.cs @@ -29,7 +29,19 @@ public ExpressChainManagerFactory(IFileSystem fileSystem) this.fileSystem = fileSystem; } - string ResolveChainFileName(string path) => fileSystem.ResolveFileName(path, EXPRESS_EXTENSION, () => DEFAULT_EXPRESS_FILENAME); + string ResolveChainFileName(string path) => fileSystem.ResolveFileName(path, EXPRESS_EXTENSION, () => + { + + var homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile, Environment.SpecialFolderOption.DoNotVerify); + var folder = fileSystem.Path.Combine(homeDir, ".neo-express"); + + if (!fileSystem.Path.Exists(folder)) + fileSystem.Directory.CreateDirectory(folder); + + var fileName = fileSystem.Path.Combine(folder, DEFAULT_EXPRESS_FILENAME); + + return fileName; + }); internal static ExpressChain CreateChain(int nodeCount, byte? addressVersion, byte[]? privateKey = null) { diff --git a/src/neoxp/Extensions/FileSystemExtensions.cs b/src/neoxp/Extensions/FileSystemExtensions.cs index 760f95fb..c86ab46a 100644 --- a/src/neoxp/Extensions/FileSystemExtensions.cs +++ b/src/neoxp/Extensions/FileSystemExtensions.cs @@ -26,25 +26,13 @@ public static string ResolveFileName(this IFileSystem fileSystem, string fileNam fileName = getDefaultFileName(); } - if (extension.Equals(fileSystem.Path.GetExtension(fileName), StringComparison.InvariantCultureIgnoreCase) == false) - fileName = $"{fileName}{extension}"; - - if (fileSystem.Path.IsPathFullyQualified(fileName) == false) + if (!fileSystem.Path.IsPathFullyQualified(fileName)) { - var defaultFileName = fileSystem.Path.Combine(fileSystem.Directory.GetCurrentDirectory(), fileName); - if (fileSystem.File.Exists(defaultFileName) == false) - { - var homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile, Environment.SpecialFolderOption.DoNotVerify); - var folder = fileSystem.Path.Combine(homeDir, ".neo-express"); - if (fileSystem.Path.Exists(folder) == false) - fileSystem.Directory.CreateDirectory(folder); - fileName = fileSystem.Path.Combine(folder, fileName); - } - else - fileName = defaultFileName; + fileName = fileSystem.Path.Combine(fileSystem.Directory.GetCurrentDirectory(), fileName); } - return fileName; + return extension.Equals(fileSystem.Path.GetExtension(fileName), StringComparison.OrdinalIgnoreCase) + ? fileName : fileName + extension; } public static string GetTempFolder(this IFileSystem fileSystem)