diff --git a/src/NSmartProxy.Infrastructure/ConfigHelper.cs b/src/NSmartProxy.Infrastructure/ConfigHelper.cs index 202ca93..fefd021 100644 --- a/src/NSmartProxy.Infrastructure/ConfigHelper.cs +++ b/src/NSmartProxy.Infrastructure/ConfigHelper.cs @@ -1,4 +1,6 @@ -using Newtonsoft.Json; +using System.Diagnostics; +using System.Dynamic; +using Newtonsoft.Json; using NSmartProxy.Data; using System.IO; @@ -6,6 +8,17 @@ namespace NSmartProxy.Infrastructure { public static class ConfigHelper { + public static string AppSettingFullPath + { + get + { + var processModule = Process.GetCurrentProcess().MainModule; + return Path.GetDirectoryName(processModule?.FileName) + + Path.DirectorySeparatorChar + + "appsettings.json"; + } + } + /// /// 读配置 /// @@ -38,7 +51,7 @@ public static T SaveChanges(this T config, string path) IndentChar = ' ' }; serializer.Serialize(jsonWriter, config); - + sw.Close(); } diff --git a/src/NSmartProxy.Infrastructure/StringUtil.cs b/src/NSmartProxy.Infrastructure/StringUtil.cs index 2fe5f5d..46befd0 100644 --- a/src/NSmartProxy.Infrastructure/StringUtil.cs +++ b/src/NSmartProxy.Infrastructure/StringUtil.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Runtime.InteropServices.ComTypes; using System.Text; using NSmartProxy.Data; using NSmartProxy.Infrastructure; @@ -216,7 +217,7 @@ public static bool IsNum(this string str) /// /// /// - public static byte[] DecompressInSnappy(byte[] compressed,int offset ,int length) + public static byte[] DecompressInSnappy(byte[] compressed, int offset, int length) { SnappyDecompressor sd = new SnappyDecompressor(); try @@ -225,6 +226,7 @@ public static byte[] DecompressInSnappy(byte[] compressed,int offset ,int length } catch (Exception ex) { + _ = ex; //啥情況? return null; } diff --git a/src/NSmartProxy.ServerHost/NSmartProxy.ServerHost.csproj b/src/NSmartProxy.ServerHost/NSmartProxy.ServerHost.csproj index 337d5d6..60e1c9b 100644 --- a/src/NSmartProxy.ServerHost/NSmartProxy.ServerHost.csproj +++ b/src/NSmartProxy.ServerHost/NSmartProxy.ServerHost.csproj @@ -26,8 +26,10 @@ - - PreserveNewest + + Always + Always + true PreserveNewest diff --git a/src/NSmartProxy.ServerHost/ServerHost.cs b/src/NSmartProxy.ServerHost/ServerHost.cs index 8b58cfd..a141c2f 100644 --- a/src/NSmartProxy.ServerHost/ServerHost.cs +++ b/src/NSmartProxy.ServerHost/ServerHost.cs @@ -15,7 +15,7 @@ namespace NSmartProxy.ServerHost { - public class ServerHost:IMicroService + public class ServerHost : IMicroService { private static Mutex mutex = new Mutex(true, "{8639B0AD-A27C-4F15-B3D9-08035D0FC6D6}"); @@ -45,7 +45,7 @@ public void Info(object message) public IConfigurationRoot Configuration { get; set; } - public const string CONFIG_FILE_PATH = "./appsettings.json"; + private static readonly string ConfigFilePath = ConfigHelper.AppSettingFullPath; public void Start() { @@ -74,7 +74,7 @@ private void InitLogConfig() Logger.Debug($"*** {NSPVersion.NSmartProxyServerName} ***"); var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile(CONFIG_FILE_PATH); + .AddJsonFile(ConfigFilePath); Configuration = builder.Build(); } @@ -83,17 +83,17 @@ private static void StartNSPServer() { NSPServerConfig serverConfig = null; //初始化配置 - if (!File.Exists(CONFIG_FILE_PATH)) + if (!File.Exists(ConfigFilePath)) { serverConfig = new NSPServerConfig(); - serverConfig.SaveChanges(CONFIG_FILE_PATH); + serverConfig.SaveChanges(ConfigFilePath); } else { - serverConfig = ConfigHelper.ReadAllConfig(CONFIG_FILE_PATH); + serverConfig = ConfigHelper.ReadAllConfig(ConfigFilePath); } - + Server srv = new Server(new Log4netLogger()); @@ -108,7 +108,7 @@ private static void StartNSPServer() srv .SetConfiguration(serverConfig) .SetAnonymousLogin(true) - .SetServerConfigPath(CONFIG_FILE_PATH) + .SetServerConfigPath(ConfigFilePath) .Start() .Wait(); } @@ -150,7 +150,7 @@ private static void StartNSPServer() public void Stop() { // - Console.WriteLine(NSPVersion.NSmartProxyClientName +" STOPPED."); + Console.WriteLine(NSPVersion.NSmartProxyClientName + " STOPPED."); Environment.Exit(0); } } diff --git a/src/NSmartProxyClient/NSmartProxyClient.cs b/src/NSmartProxyClient/NSmartProxyClient.cs index 4fbb1bf..8a37870 100644 --- a/src/NSmartProxyClient/NSmartProxyClient.cs +++ b/src/NSmartProxyClient/NSmartProxyClient.cs @@ -48,10 +48,10 @@ public void Info(object message) public static ILog Logger; public static IConfigurationRoot Configuration { get; set; } private static LoginInfo _currentLoginInfo; - private static string appSettingFilePath; + private static readonly string ConfigFilePath = ConfigHelper.AppSettingFullPath; public void Start(string[] args) { - appSettingFilePath = Directory.GetCurrentDirectory() + "/appsettings.json"; + //appSettingFilePath = Directory.GetCurrentDirectory() + "/appsettings.json"; //log var loggerRepository = LogManager.CreateRepository("NSmartClientRouterRepository"); XmlConfigurator.Configure(loggerRepository, new FileInfo("log4net.config")); @@ -88,7 +88,7 @@ private static async Task StartClient() Router clientRouter = new Router(new Log4netLogger()); //read config from config file. - clientRouter.SetConfiguration(ConfigHelper.ReadAllConfig(appSettingFilePath)); + clientRouter.SetConfiguration(ConfigHelper.ReadAllConfig(ConfigFilePath)); if (_currentLoginInfo != null) { clientRouter.SetLoginInfo(_currentLoginInfo); diff --git a/src/NSmartProxyClient/NSmartProxyClient.csproj b/src/NSmartProxyClient/NSmartProxyClient.csproj index 543f480..5f49818 100644 --- a/src/NSmartProxyClient/NSmartProxyClient.csproj +++ b/src/NSmartProxyClient/NSmartProxyClient.csproj @@ -23,12 +23,13 @@ - - PreserveNewest - - - PreserveNewest + + + Always + Always + true + diff --git a/src/NSmartProxyClient/Program.cs b/src/NSmartProxyClient/Program.cs index 7daa288..7a84edb 100644 --- a/src/NSmartProxyClient/Program.cs +++ b/src/NSmartProxyClient/Program.cs @@ -15,9 +15,9 @@ static void Main() ServiceRunner.Run(config => { var name = Global.NSPServerServiceName; - config.SetDisplayName(Global.NSPServerServiceName); - config.SetName(Global.NSPServerDisplayName); - config.SetDescription(NSPVersion.NSmartProxyServerName); + config.SetDisplayName(Global.NSPClientServiceName); + config.SetName(Global.NSPClientServiceDisplayName); + config.SetDescription(NSPVersion.NSmartProxyClientName); config.Service(serviceConfig => { diff --git a/src/build_test.cmd b/src/build_test.cmd new file mode 100644 index 0000000..181dbaa --- /dev/null +++ b/src/build_test.cmd @@ -0,0 +1,46 @@ +rem windows only +rem NSP v1.2 +@ECHO off + +set Ver=v1.2pre3 +set BuildPath=%~dp0../build + +set nsp_client_path=%BuildPath%/nspclient_%Ver% +set nsp_server_path=%BuildPath%/nspserver_%Ver% + + +set nsp_client_scd_win_path=%BuildPath%/nspclient_scd_win_%Ver% + + + +set nsp_server_scd_win_path=%BuildPath%/nspserver_scd_win_%Ver% + + +set nsp_client_winfform_path=%BuildPath%/nspclient_winform_%Ver% + +rem del %~dp0/../build/*.* +rem NSPClient +dotnet publish .\NSmartProxyClient\NSmartProxyClient.csproj -c release -o %nsp_client_path% + +rem NSPServer +dotnet publish .\NSmartProxy.ServerHost\NSmartProxy.ServerHost.csproj -c release -o %nsp_server_path% + +rem NSPClient_SCD +dotnet publish .\NSmartProxyClient\NSmartProxyClient.csproj -r win-x64 -c Release /p:PublishSingleFile=true -o %nsp_client_scd_win_path% + + +rem NSPServer_SCD +dotnet publish .\NSmartProxy.ServerHost\NSmartProxy.ServerHost.csproj -r win-x64 -c Release /p:PublishSingleFile=true -o %nsp_server_scd_win_path% + +rem NSPWinform +MSBuild .\NSmartProxyWinform\NSmartProxyWinform.csproj /t:build /p:OutDir=%nsp_client_winfform_path% +powershell del %nsp_client_winfform_path%/*.pdb +powershell del %nsp_client_winfform_path%/*.xml + +rem ilmerge +rem ruined :< + +rem compress + +powershell explorer %~dp0..\build +pause \ No newline at end of file