From 7bfe22e6233fe71f75af8f0b25563f64ff6f2372 Mon Sep 17 00:00:00 2001 From: fajiao <1519100073@qq.com> Date: Tue, 2 Aug 2022 15:51:42 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20Directory.GetCurrentDirectory=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=B8=8D=E6=98=AF=E7=9C=9F=E6=AD=A3=E7=9A=84?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=BA=94=E7=94=A8=E7=A8=8B=E5=BA=8F=E7=9A=84?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E6=96=B9=E6=B3=95=EF=BC=8C=E8=80=8C=E6=98=AF?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=91=BD=E4=BB=A4=E6=89=80=E5=9C=A8=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E3=80=82=E5=85=B7=E4=BD=93=E4=BF=AE=E6=94=B9=E6=9F=A5?= =?UTF-8?q?=E9=98=85=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutoWeightServer/Center/DeviceCenter.cs | 2 +- AutoWeightServer/UI/FrmMainServer.cs | 2 +- EC.Service/Transport/PhotoService.cs | 3 ++- EC.Utils/CommonUtil.cs | 10 ++++++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/AutoWeightServer/Center/DeviceCenter.cs b/AutoWeightServer/Center/DeviceCenter.cs index 83276cd..ed865d6 100644 --- a/AutoWeightServer/Center/DeviceCenter.cs +++ b/AutoWeightServer/Center/DeviceCenter.cs @@ -318,7 +318,7 @@ namespace EC.AutoWeightServer.Center return; YkPosManager.InitPrinter(); - var bmpPath = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine("Img", "logo.bmp")); + var bmpPath = Path.Combine(CommonUtil.GetWorkDirectory(), Path.Combine("Img", "logo.bmp")); YkPosManager.SetAlign(1);//居中 YkPosManager.PrintRasterBmp(new StringBuilder(bmpPath));//打印图片 diff --git a/AutoWeightServer/UI/FrmMainServer.cs b/AutoWeightServer/UI/FrmMainServer.cs index 9deb630..3aa2140 100644 --- a/AutoWeightServer/UI/FrmMainServer.cs +++ b/AutoWeightServer/UI/FrmMainServer.cs @@ -994,7 +994,7 @@ namespace EC.AutoWeightServer.UI private void CheckPhotoSaveCycle() { var now = DateTime.Now; - var workPath = Directory.GetCurrentDirectory(); + var workPath = CommonUtil.GetWorkDirectory(); var capDir = new DirectoryInfo(Path.Combine(workPath, "cap")); if (!capDir.Exists) return; diff --git a/EC.Service/Transport/PhotoService.cs b/EC.Service/Transport/PhotoService.cs index f89e028..061a7f9 100644 --- a/EC.Service/Transport/PhotoService.cs +++ b/EC.Service/Transport/PhotoService.cs @@ -1,5 +1,6 @@ using EC.Entity.Transport; using EC.Service.Base; +using EC.Utils; using System; using System.IO; @@ -39,7 +40,7 @@ namespace EC.Service.Transport public static string GetSaveImagePath(string license) { var now = DateTime.Now; - var workPath = Directory.GetCurrentDirectory(); + var workPath = CommonUtil.GetWorkDirectory(); var subPath = Path.Combine(new string[] { "cap", now.ToString("yyyy"), now.ToString("MM"), now.ToString("dd") }); //var subPath = Path.Combine("cap", now.ToString("yyyy-MM-dd")); var fileFolder = Path.Combine(workPath, subPath); diff --git a/EC.Utils/CommonUtil.cs b/EC.Utils/CommonUtil.cs index 6fb16c4..8f9fd6d 100644 --- a/EC.Utils/CommonUtil.cs +++ b/EC.Utils/CommonUtil.cs @@ -2,6 +2,7 @@ using Newtonsoft.Json.Linq; using System; using System.IO; +using System.Reflection; using System.Text.RegularExpressions; namespace EC.Utils @@ -216,5 +217,14 @@ namespace EC.Utils return null; } } + + private static string workDirectory; + + public static string GetWorkDirectory() + { + workDirectory = string.IsNullOrEmpty(workDirectory) ? Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) :workDirectory; + return workDirectory; + } + } } \ No newline at end of file