瀏覽代碼

统一缓存路径

章政 8 年之前
父節點
當前提交
3cde9d2964

+ 15 - 2
UAS-MES/Entity/SystemInf.cs

@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 
 namespace UAS_MES.Entity
 {
@@ -56,5 +57,17 @@ namespace UAS_MES.Entity
         /// 是否允许打印程序
         /// </summary>
         public static bool EnablePrint;
+        /// <summary>
+        /// 缓存数据的文件夹
+        /// </summary>
+        public static string CacheFolder= Environment.GetEnvironmentVariable("windir").Substring(0, 1)+@":\UAS_MES\CacheFile\";
+        /// <summary>
+        /// 日志文件的缓存路径
+        /// </summary>
+        public static string LogFolder = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":\UAS_MES\Log\";
+        /// <summary>
+        /// 缓存的XML文件的路径和名称
+        /// </summary>
+        public static string CacheFilePath= Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":\UAS_MES\CacheFile\CacheInfo.xml";
     }
-}
+}

+ 0 - 1
UAS-MES/FunctionCode/Make/Make_ColorBoxLabelPrint.cs

@@ -97,7 +97,6 @@ namespace UAS_MES.Make
             {
                 lbl = new ApplicationClass();
                 BaseUtil.WriteLbl(lbl);
-                ftpOperater ftp = new ftpOperater();
             }
             catch (Exception ex)
             {

+ 3 - 3
UAS-MES/Main.cs

@@ -83,7 +83,7 @@ namespace UAS_MES
         private void Main_Load(object sender, EventArgs e)
         {
             //杀死全部未关闭的打印进程
-            string[] lines = System.IO.File.ReadAllLines(lblpath + @"\" + "lblprocess" + ".txt");
+            string[] lines = System.IO.File.ReadAllLines(SystemInf.CacheFolder+ "lblprocess.txt");
             foreach (string line in lines)
             {
                 if (line != "")
@@ -104,12 +104,12 @@ namespace UAS_MES
                         catch (Exception)
                         {
                         }
-                        FileStream fs = new FileStream(lblpath + @"\" + "lblprocess" + ".txt", FileMode.Open, FileAccess.Read);
+                        FileStream fs = new FileStream(SystemInf.CacheFolder+ "lblprocess.txt", FileMode.Open, FileAccess.Read);
                         StreamReader sr = new StreamReader(fs);
                         String s = sr.ReadToEnd();
                         sr.Close();
                         fs.Close();
-                        FileStream fas = new FileStream(lblpath + @"\" + "lblprocess" + ".txt", FileMode.Create, FileAccess.ReadWrite);
+                        FileStream fas = new FileStream(SystemInf.CacheFolder + "lblprocess.txt", FileMode.Create, FileAccess.ReadWrite);
                         StreamWriter sw = new StreamWriter(fas);
                         sw.Write(s.Replace(line+"\r\n",""));
                         sw.Flush();

+ 11 - 11
UAS-MES/Program.cs

@@ -4,6 +4,7 @@ using System.Security.Principal;
 using System.Text;
 using System.Windows.Forms;
 using System.Xml;
+using UAS_MES.Entity;
 using UAS_MES.PublicMethod;
 
 namespace UAS_MES
@@ -35,22 +36,21 @@ namespace UAS_MES
                 Application.AddMessageFilter(g);
                 //启用异常记录日志的操作
                 string sysdisc = Environment.GetEnvironmentVariable("windir").Substring(0, 1);
-                string lblpath = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":\Log\cacheInfo";
                 //创建标签缓存的文件夹
                 if (!Directory.Exists(ftpOperater.DownLoadTo))
                     Directory.CreateDirectory(ftpOperater.DownLoadTo);
-                if (!Directory.Exists(sysdisc + @":\Log"))
-                    Directory.CreateDirectory(sysdisc + @":\Log");
-                FileStream fs = new FileStream(sysdisc + @":\Log\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
+                if (!Directory.Exists(SystemInf.LogFolder))
+                    Directory.CreateDirectory(SystemInf.LogFolder);
+                FileStream fs = new FileStream(SystemInf.LogFolder + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                 fs.Close();
                 //创建存储登录信息的文件
-                if (!Directory.Exists(sysdisc + @":\Log\cacheInfo"))
-                    Directory.CreateDirectory(sysdisc + @":\Log\cacheInfo");
-                FileStream fcaches = new FileStream(sysdisc + @":\Log\cacheInfo\cacheInfo.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite);
+                if (!Directory.Exists(SystemInf.CacheFolder))
+                    Directory.CreateDirectory(SystemInf.CacheFolder);
+                FileStream fcaches = new FileStream(SystemInf.CacheFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                 fcaches.Close();
                 //判断是否xml文件大小为0
-                FileInfo info = new FileInfo(sysdisc + @":\Log\cacheInfo\cacheInfo.xml");
-                if (info.Length==0)
+                FileInfo info = new FileInfo(SystemInf.CacheFilePath);
+                if (info.Length == 0)
                 {
                     XmlDocument doc = new XmlDocument();
                     //创建类型声明节点  
@@ -59,10 +59,10 @@ namespace UAS_MES
                     //创建根节点  
                     XmlElement xeRoot = doc.CreateElement("cacheInfo");
                     doc.AppendChild(xeRoot);
-                    doc.Save(Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":\Log\cacheInfo\cacheInfo.xml");
+                    doc.Save(SystemInf.CacheFilePath);
                 }
                 //创建记录打印进程的文件
-                FileStream fas = new FileStream(lblpath + @"\" + "lblprocess" + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
+                FileStream fas = new FileStream(SystemInf.CacheFolder + "lblprocess.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                 fas.Close();
                 if (principal.IsInRole(WindowsBuiltInRole.Administrator))
                     Application.Run(new Login());

+ 4 - 5
UAS-MES/PublicMethod/BaseUtil.cs

@@ -987,8 +987,7 @@ namespace UAS_MES.PublicMethod
             }
             var temp = ProInf.Keys.Max();
             String str = SystemInf.ProcessesID + "|" + ProInf[temp];
-            string lblpath = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":\Log\cacheInfo";
-            FileStream fs = new FileStream(lblpath + @"\" + "lblprocess" + ".txt", FileMode.Append, FileAccess.Write);
+            FileStream fs = new FileStream(SystemInf.CacheFolder + "lblprocess.txt", FileMode.Append, FileAccess.Write);
             StreamWriter sw = new StreamWriter(fs);
             sw.WriteLine(str, Encoding.UTF8);
             sw.Close();
@@ -1005,7 +1004,7 @@ namespace UAS_MES.PublicMethod
                 XmlReaderSettings settings = new XmlReaderSettings();
                 //忽略文档里面的注释
                 settings.IgnoreComments = true;
-                XmlReader reader = XmlReader.Create(Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":\Log\cacheInfo\cacheInfo.xml", settings);
+                XmlReader reader = XmlReader.Create(SystemInf.CacheFilePath, settings);
                 doc.Load(reader);
                 //先得到根节点
                 XmlNode rootNode = doc.SelectSingleNode("cacheInfo");
@@ -1057,7 +1056,7 @@ namespace UAS_MES.PublicMethod
                 XmlReaderSettings settings = new XmlReaderSettings();
                 //忽略文档里面的注释
                 settings.IgnoreComments = true;
-                XmlReader reader = XmlReader.Create(Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":\Log\cacheInfo\cacheInfo.xml", settings);
+                XmlReader reader = XmlReader.Create(SystemInf.CacheFilePath, settings);
                 doc.Load(reader);
                 //先得到根节点
                 XmlNode rootNode = doc.SelectSingleNode("cacheInfo");
@@ -1088,7 +1087,7 @@ namespace UAS_MES.PublicMethod
                 }
                 //关闭Reader
                 reader.Close();
-                doc.Save(Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":\Log\cacheInfo\cacheInfo.xml");
+                doc.Save(SystemInf.CacheFilePath);
             }
             catch (Exception e)
             {

+ 2 - 1
UAS-MES/PublicMethod/LogManager.cs

@@ -1,11 +1,12 @@
 using System;
 using System.IO;
+using UAS_MES.Entity;
 
 namespace UAS_MES.PublicMethod
 {
     class LogManager
     {
-        public static string LogAddress = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":\" + @"Log\";
+        public static string LogAddress = SystemInf.LogFolder;
         /// <summary>
         /// 记录操作
         /// </summary>