From 538282844f1b4321ebbfee2ac1ba70a2ae4d804f Mon Sep 17 00:00:00 2001 From: Jimmy Date: Mon, 10 Jun 2024 04:42:01 +0800 Subject: [PATCH 1/8] fix exception message --- src/Neo.CLI/CLI/MainService.cs | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/Neo.CLI/CLI/MainService.cs b/src/Neo.CLI/CLI/MainService.cs index 7e96af9e85..3c9a41b633 100644 --- a/src/Neo.CLI/CLI/MainService.cs +++ b/src/Neo.CLI/CLI/MainService.cs @@ -33,6 +33,7 @@ using System.Net; using System.Numerics; using System.Reflection; +using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; @@ -377,15 +378,36 @@ public async void Start(CommandLineOptions options) CustomApplicationSettings(options, Settings.Default); try { - NeoSystem = new NeoSystem(protocol, Settings.Default.Storage.Engine, string.Format(Settings.Default.Storage.Path, protocol.Network.ToString("X8"))); + NeoSystem = new NeoSystem(protocol, Settings.Default.Storage.Engine, + string.Format(Settings.Default.Storage.Path, protocol.Network.ToString("X8"))); } - catch (DllNotFoundException) + catch (DllNotFoundException ex) when (ex.Message.Contains("libleveldb")) { - ConsoleHelper.Error("DLL not found, please install Microsoft Visual C++ Redistributable." + Environment.NewLine + - "See https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist" + Environment.NewLine + - "Press any key to exit."); + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + ConsoleHelper.Error("DLL not found, please install Microsoft Visual C++ Redistributable." + + Environment.NewLine + + "See https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist" + + Environment.NewLine + + "Press any key to exit."); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + ConsoleHelper.Error("DLL not found, please get libleveldb.dylib." + + Environment.NewLine + + "For AppleSilicon https://github.com/neo-project/neo/releases/download/v3.7.4/neo-cli-osx-arm64.zip" + + Environment.NewLine + + "For Intel https://github.com/neo-project/neo/releases/download/v3.7.4/neo-cli-osx-x64.zip" + + Environment.NewLine + + "Press any key to exit."); + } + Console.ReadKey(); Environment.Exit(-1); + } + catch (DllNotFoundException ex) + { + } NeoSystem.AddService(this); From ad6dfe6edc90f911888c371b862cf6b8e43dbf49 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Mon, 10 Jun 2024 04:52:21 +0800 Subject: [PATCH 2/8] add detailed check --- src/Neo.CLI/CLI/MainService.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Neo.CLI/CLI/MainService.cs b/src/Neo.CLI/CLI/MainService.cs index 3c9a41b633..9b5ecbd3af 100644 --- a/src/Neo.CLI/CLI/MainService.cs +++ b/src/Neo.CLI/CLI/MainService.cs @@ -385,11 +385,21 @@ public async void Start(CommandLineOptions options) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - ConsoleHelper.Error("DLL not found, please install Microsoft Visual C++ Redistributable." + - Environment.NewLine + - "See https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist" + - Environment.NewLine + - "Press any key to exit."); + if (File.Exists("libleveldb.dll")) + { + ConsoleHelper.Error("Dependency DLL not found, please install Microsoft Visual C++ Redistributable." + + Environment.NewLine + + "See https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist" + + Environment.NewLine + + "Press any key to exit."); + } + else + { + ConsoleHelper.Error("DLL not found, please get libleveldb.dll." + + Environment.NewLine + + "Press any key to exit."); + } + } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { From 93c22a9186b5fe2e67e18b359d2a7db1ed6e1041 Mon Sep 17 00:00:00 2001 From: Shargon Date: Mon, 10 Jun 2024 01:22:45 -0700 Subject: [PATCH 3/8] Update src/Neo.CLI/CLI/MainService.cs --- src/Neo.CLI/CLI/MainService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Neo.CLI/CLI/MainService.cs b/src/Neo.CLI/CLI/MainService.cs index 9b5ecbd3af..2082cb8f4b 100644 --- a/src/Neo.CLI/CLI/MainService.cs +++ b/src/Neo.CLI/CLI/MainService.cs @@ -415,7 +415,7 @@ public async void Start(CommandLineOptions options) Console.ReadKey(); Environment.Exit(-1); } - catch (DllNotFoundException ex) + catch (DllNotFoundException) { } From 8287c3998539e1ad66d29ef925637bbcd7798d44 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Mon, 10 Jun 2024 19:18:47 +0800 Subject: [PATCH 4/8] directly send them to release page --- src/Neo.CLI/CLI/MainService.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Neo.CLI/CLI/MainService.cs b/src/Neo.CLI/CLI/MainService.cs index 2082cb8f4b..af1d2fd362 100644 --- a/src/Neo.CLI/CLI/MainService.cs +++ b/src/Neo.CLI/CLI/MainService.cs @@ -405,9 +405,7 @@ public async void Start(CommandLineOptions options) { ConsoleHelper.Error("DLL not found, please get libleveldb.dylib." + Environment.NewLine + - "For AppleSilicon https://github.com/neo-project/neo/releases/download/v3.7.4/neo-cli-osx-arm64.zip" + - Environment.NewLine + - "For Intel https://github.com/neo-project/neo/releases/download/v3.7.4/neo-cli-osx-x64.zip" + + "From https://github.com/neo-project/neo/releases" + Environment.NewLine + "Press any key to exit."); } From 051f35b06a368b0d8f3ca648df13bf39a055c98c Mon Sep 17 00:00:00 2001 From: Jimmy Date: Mon, 10 Jun 2024 21:38:37 +0800 Subject: [PATCH 5/8] update msg. --- src/Neo.CLI/CLI/MainService.cs | 44 ++++++++++------------------------ 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/src/Neo.CLI/CLI/MainService.cs b/src/Neo.CLI/CLI/MainService.cs index af1d2fd362..36847234a1 100644 --- a/src/Neo.CLI/CLI/MainService.cs +++ b/src/Neo.CLI/CLI/MainService.cs @@ -381,42 +381,22 @@ public async void Start(CommandLineOptions options) NeoSystem = new NeoSystem(protocol, Settings.Default.Storage.Engine, string.Format(Settings.Default.Storage.Path, protocol.Network.ToString("X8"))); } - catch (DllNotFoundException ex) when (ex.Message.Contains("libleveldb")) - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - if (File.Exists("libleveldb.dll")) - { - ConsoleHelper.Error("Dependency DLL not found, please install Microsoft Visual C++ Redistributable." + - Environment.NewLine + - "See https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist" + - Environment.NewLine + - "Press any key to exit."); - } - else - { - ConsoleHelper.Error("DLL not found, please get libleveldb.dll." + - Environment.NewLine + - "Press any key to exit."); - } - - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - ConsoleHelper.Error("DLL not found, please get libleveldb.dylib." + - Environment.NewLine + - "From https://github.com/neo-project/neo/releases" + - Environment.NewLine + - "Press any key to exit."); - } - + catch (DllNotFoundException ex) + { + var message = ex.Message.Contains("libleveldb") ? "LevelDB dependency DLL not found." : "Neo CLI is broken."; + var additionalInfo = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) + ? File.Exists("libleveldb.dll") + ? "Please install Microsoft Visual C++ Redistributable.\nSee https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist" + : "Please get libleveldb.dll." + : RuntimeInformation.IsOSPlatform(OSPlatform.OSX) + ? "Please get libleveldb.dylib.\nFrom https://github.com/neo-project/neo/releases" + : "Please reinstall Neo CLI.\nFrom https://github.com/neo-project/neo/releases"; + + ConsoleHelper.Error($"{message}\n{additionalInfo}\nPress any key to exit."); Console.ReadKey(); Environment.Exit(-1); } - catch (DllNotFoundException) - { - } NeoSystem.AddService(this); LocalNode = NeoSystem.LocalNode.Ask(new LocalNode.GetInstance()).Result; From 0bd472a47a064b7928a4885269e52db4cb8f6fcd Mon Sep 17 00:00:00 2001 From: Jimmy Date: Mon, 10 Jun 2024 21:41:37 +0800 Subject: [PATCH 6/8] fix its readibility --- src/Neo.CLI/CLI/MainService.cs | 51 ++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/src/Neo.CLI/CLI/MainService.cs b/src/Neo.CLI/CLI/MainService.cs index 36847234a1..45ee960f7a 100644 --- a/src/Neo.CLI/CLI/MainService.cs +++ b/src/Neo.CLI/CLI/MainService.cs @@ -381,21 +381,39 @@ public async void Start(CommandLineOptions options) NeoSystem = new NeoSystem(protocol, Settings.Default.Storage.Engine, string.Format(Settings.Default.Storage.Path, protocol.Network.ToString("X8"))); } - catch (DllNotFoundException ex) - { - var message = ex.Message.Contains("libleveldb") ? "LevelDB dependency DLL not found." : "Neo CLI is broken."; - var additionalInfo = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) - ? File.Exists("libleveldb.dll") - ? "Please install Microsoft Visual C++ Redistributable.\nSee https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist" - : "Please get libleveldb.dll." - : RuntimeInformation.IsOSPlatform(OSPlatform.OSX) - ? "Please get libleveldb.dylib.\nFrom https://github.com/neo-project/neo/releases" - : "Please reinstall Neo CLI.\nFrom https://github.com/neo-project/neo/releases"; - - ConsoleHelper.Error($"{message}\n{additionalInfo}\nPress any key to exit."); + catch (DllNotFoundException ex) when (ex.Message.Contains("libleveldb")) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + if (File.Exists("libleveldb.dll")) + { + DisplayError("Dependency DLL not found, please install Microsoft Visual C++ Redistributable.", + "See https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist"); + } + else + { + DisplayError("DLL not found, please get libleveldb.dll."); + } + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + DisplayError("DLL not found, please get libleveldb.dylib.", + "From https://github.com/neo-project/neo/releases"); + } + else + { + DisplayError("Neo CLI is broken, please reinstall it.", + "From https://github.com/neo-project/neo/releases"); + } + Console.ReadKey(); Environment.Exit(-1); } + catch (DllNotFoundException) + { + DisplayError("Neo CLI is broken, please reinstall it.", + "From https://github.com/neo-project/neo/releases"); + } NeoSystem.AddService(this); @@ -469,6 +487,15 @@ public async void Start(CommandLineOptions options) ConsoleHelper.Error(ex.GetBaseException().Message); } } + + return; + + void DisplayError(string primaryMessage, string secondaryMessage = null) + { + ConsoleHelper.Error(primaryMessage + Environment.NewLine + + (secondaryMessage != null ? secondaryMessage + Environment.NewLine : "") + + "Press any key to exit."); + } } public void Stop() From beac0c175f0e6e2e82c51822669b683b3284c4c8 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Mon, 10 Jun 2024 22:43:01 +0800 Subject: [PATCH 7/8] fix issue --- src/Neo.CLI/CLI/MainService.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Neo.CLI/CLI/MainService.cs b/src/Neo.CLI/CLI/MainService.cs index 45ee960f7a..c0f9e0afa8 100644 --- a/src/Neo.CLI/CLI/MainService.cs +++ b/src/Neo.CLI/CLI/MainService.cs @@ -406,8 +406,6 @@ public async void Start(CommandLineOptions options) "From https://github.com/neo-project/neo/releases"); } - Console.ReadKey(); - Environment.Exit(-1); } catch (DllNotFoundException) { @@ -490,11 +488,13 @@ public async void Start(CommandLineOptions options) return; - void DisplayError(string primaryMessage, string secondaryMessage = null) + void DisplayError(string primaryMessage, string? secondaryMessage = null) { ConsoleHelper.Error(primaryMessage + Environment.NewLine + (secondaryMessage != null ? secondaryMessage + Environment.NewLine : "") + "Press any key to exit."); + Console.ReadKey(); + Environment.Exit(-1); } } From f3e8a40ee884b7a1484f242f2388c1e5523aa721 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Mon, 10 Jun 2024 22:48:37 +0800 Subject: [PATCH 8/8] use shared library to replace DLL on macos --- src/Neo.CLI/CLI/MainService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Neo.CLI/CLI/MainService.cs b/src/Neo.CLI/CLI/MainService.cs index c0f9e0afa8..88967c82ea 100644 --- a/src/Neo.CLI/CLI/MainService.cs +++ b/src/Neo.CLI/CLI/MainService.cs @@ -397,7 +397,7 @@ public async void Start(CommandLineOptions options) } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - DisplayError("DLL not found, please get libleveldb.dylib.", + DisplayError("Shared library libleveldb.dylib not found, please get libleveldb.dylib.", "From https://github.com/neo-project/neo/releases"); } else