From 77fe01dea69910c4f1ba82ae795edd3a02b7438f Mon Sep 17 00:00:00 2001 From: walon Date: Thu, 26 Aug 2021 16:56:29 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E4=B8=8D=E5=9C=A8Luban.Server=E6=88=96=E8=80=85Luban.?= =?UTF-8?q?ClientServer=E7=9B=AE=E5=BD=95=E8=BF=90=E8=A1=8CLuban.Server?= =?UTF-8?q?=E6=88=96=E8=80=85Luban.ClientServer=E6=97=B6=EF=BC=8C=E7=94=9F?= =?UTF-8?q?=E6=88=90=E4=BB=A3=E7=A0=81=E5=8F=91=E7=94=9F=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=89=BE=E5=88=B0Templates=E7=9B=AE=E5=BD=95=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=82=E5=A6=82=E6=9E=9C=E6=9C=AA=E6=8C=87=E5=AE=9A?= =?UTF-8?q?-t=E5=8F=82=E6=95=B0=EF=BC=8C=E8=87=AA=E5=8A=A8=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=A8=8B=E5=BA=8F=E6=89=80=E5=9C=A8=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E7=9A=84Templates=E7=9B=AE=E5=BD=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Luban.ClientServer/Program.cs | 7 ++++++- src/Luban.Common/Source/Utils/FileUtil.cs | 10 ++++++++++ src/Luban.Server/Properties/launchSettings.json | 3 +-- src/Luban.Server/Source/Program.cs | 6 +++++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Luban.ClientServer/Program.cs b/src/Luban.ClientServer/Program.cs index 699a4bb..ef24075 100644 --- a/src/Luban.ClientServer/Program.cs +++ b/src/Luban.ClientServer/Program.cs @@ -7,6 +7,7 @@ using Luban.Common.Utils; using Luban.Server; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -33,7 +34,7 @@ namespace Luban.ClientServer public string[] WatchDir { get; set; } - public string StringTemplateDir { get; set; } = "Templates"; + public string StringTemplateDir { get; set; } } private static void PrintUsage(string err) @@ -205,6 +206,10 @@ Options: ThreadPool.SetMinThreads(Math.Max(4, processorCount), 5); ThreadPool.SetMaxThreads(Math.Max(16, processorCount * 4), 10); + if (string.IsNullOrEmpty(options.StringTemplateDir)) + { + options.StringTemplateDir = FileUtil.GetPathRelateApplicationDirectory("Templates"); + } if (string.IsNullOrWhiteSpace(options.Host)) { options.Host = "127.0.0.1"; diff --git a/src/Luban.Common/Source/Utils/FileUtil.cs b/src/Luban.Common/Source/Utils/FileUtil.cs index 7ab3c6c..e9cc611 100644 --- a/src/Luban.Common/Source/Utils/FileUtil.cs +++ b/src/Luban.Common/Source/Utils/FileUtil.cs @@ -10,6 +10,16 @@ namespace Luban.Common.Utils { private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger(); + public static string GetApplicationDirectory() + { + return Path.GetDirectoryName(System.Reflection.Assembly.GetCallingAssembly().Location); + } + + public static string GetPathRelateApplicationDirectory(string relatePath) + { + return Path.Combine(GetApplicationDirectory(), relatePath); + } + public static string GetFileName(string path) { int index = path.Replace('\\', '/').LastIndexOf('/'); diff --git a/src/Luban.Server/Properties/launchSettings.json b/src/Luban.Server/Properties/launchSettings.json index e56f6da..13d062e 100644 --- a/src/Luban.Server/Properties/launchSettings.json +++ b/src/Luban.Server/Properties/launchSettings.json @@ -1,8 +1,7 @@ { "profiles": { "Luban.Server": { - "commandName": "Project", - "commandLineArgs": "-p 8899 -t ../../../Templates" + "commandName": "Project" } } } \ No newline at end of file diff --git a/src/Luban.Server/Source/Program.cs b/src/Luban.Server/Source/Program.cs index 7f91c49..94187e5 100644 --- a/src/Luban.Server/Source/Program.cs +++ b/src/Luban.Server/Source/Program.cs @@ -21,7 +21,7 @@ namespace Luban.Server public string LogLevel { get; set; } = "INFO"; [Option('t', "string template directory", Required = false, HelpText = "string template directory.")] - public string StringTemplateDir { get; set; } = "Templates"; + public string StringTemplateDir { get; set; } } private static CommandLineOptions ParseOptions(String[] args) @@ -48,6 +48,10 @@ namespace Luban.Server var options = ParseOptions(args); + if (string.IsNullOrEmpty(options.StringTemplateDir)) + { + options.StringTemplateDir = FileUtil.GetPathRelateApplicationDirectory("Templates"); + } Job.Common.Utils.StringTemplateUtil.TemplateDir = options.StringTemplateDir; Luban.Common.Utils.LogUtil.InitSimpleNLogConfigure(NLog.LogLevel.FromString(options.LogLevel));