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));