From 5a5a2b696866f947b6025d26c3302e8ffef46435 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期一, 11 一月 2021 16:11:20 +0800
Subject: [PATCH] 2021-01-11 1.更新MQTT连接和本地搜索网关方法。2.子账号相关接口完善

---
 Crabtree/SmartHome/IO/FileUtils.cs |   36 ++++++++++++++++++++++++------------
 1 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/Crabtree/SmartHome/IO/FileUtils.cs b/Crabtree/SmartHome/IO/FileUtils.cs
index 559f8b7..b0c1f85 100644
--- a/Crabtree/SmartHome/IO/FileUtils.cs
+++ b/Crabtree/SmartHome/IO/FileUtils.cs
@@ -1,6 +1,7 @@
 锘縰sing System;
 using System.IO;
 using System.Collections.Generic;
+using System.Threading;
 
 namespace Shared.IO
 {
@@ -160,7 +161,7 @@
         /// <param name="fileName">File name.</param>
         public static void DeleteFile (string fileName)
         {
-            if (fileName == null || fileName == "Language.ini" || fileName == "AccountListDB") {
+            if (fileName == null || fileName == "Language.ini" || fileName == "AccountListDB" || fileName == "CommonConfig") {
                 return;
             }
             System.IO.File.Delete (System.IO.Path.Combine (RootPath, fileName));
@@ -242,13 +243,19 @@
 			WriteFileByBytes (fileName, SimpleControl.CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (common)));
 		}
 
-		/// <summary>
-		/// Writes the file by bytes.
-		/// </summary>
-		/// <returns><c>true</c>, if file by bytes was writed, <c>false</c> otherwise.</returns>
-		/// <param name="fileName">File name.</param>
-		/// <param name="bytes">Bytes.</param>
-		public static bool WriteFileByBytes (string fileName, byte [] bytes)
+  		/// <summary>
+        /// 澧炲姞 璇诲啓閿侊紝褰撹祫婧愬浜庡啓鍏ユā寮忔椂锛屽叾浠栫嚎绋嬪啓鍏ラ渶瑕佺瓑寰呮湰娆″啓鍏ョ粨鏉熶箣鍚庢墠鑳界户缁啓鍏�
+        /// 鐢ㄤ簬瑙e喅澶氱嚎绋嬬幆澧冨啓鍏ユ枃浠堕棶棰�
+        /// </summary>
+        static ReaderWriterLockSlim LogWriteLock = new ReaderWriterLockSlim ();
+
+	    /// <summary>
+        /// Writes the file by bytes.
+        /// </summary>
+        /// <returns><c>true</c>, if file by bytes was writed, <c>false</c> otherwise.</returns>
+        /// <param name="fileName">File name.</param>
+        /// <param name="bytes">Bytes.</param>
+        public static bool WriteFileByBytes (string fileName, byte [] bytes)
 		{
 			if (fileName == null || (fileName = fileName.Trim ()) == ("")) {
 				return false;
@@ -257,10 +264,13 @@
 			System.IO.FileStream fs = null;
 
 			try {
-				fs = new FileStream (System.IO.Path.Combine (RootPath, fileName), FileMode.Create, FileAccess.Write);
+                //璁剧疆璇诲啓閿佷负鍐欏叆妯″紡鐙崰璧勬簮锛屽叾浠栧啓鍏ヨ姹傞渶瑕佺瓑寰呮湰娆″啓鍏ョ粨鏉熶箣鍚庢墠鑳界户缁啓鍏�
+                LogWriteLock.EnterWriteLock ();
+
+                fs = new FileStream (System.IO.Path.Combine (RootPath, fileName), FileMode.Create, FileAccess.Write);
 				fs.Write (bytes, 0, bytes.Length);
 				fs.Flush ();
-				Utlis.WriteLine ("SaveFile:" + fileName);
+				//Utlis.WriteLine ("SaveFile:" + fileName + " : " + bytes.Length.ToString());
                 //if (!UserConfig.Instance.LocalFiles.Contains (fileName)) {
                 //    UserConfig.Instance.LocalFiles.Add (fileName);
                 //}
@@ -269,8 +279,10 @@
 				Utlis.WriteLine ("FileUtiles Code 113:" + ex.ToString ());
 				return false;
 			} finally {
-				try {
-					if (fs != null) {
+                try {
+                    //閫�鍑哄啓鍏ユā寮忥紝閲婃斁璧勬簮鍗犵敤
+                    LogWriteLock.ExitWriteLock ();
+                    if (fs != null) {
 						fs.Close ();
 					}
 				} catch (Exception ex) {

--
Gitblit v1.8.0