From 25429f085093d89d543a0b90e30d0d62d1b7dac9 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期二, 30 八月 2022 09:37:38 +0800
Subject: [PATCH] 合并了IOS的代码

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlAutoBackupLogic.cs | 1066 ++++++++++++++++++++++++++++-------------------------------
 1 files changed, 507 insertions(+), 559 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlAutoBackupLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlAutoBackupLogic.cs
old mode 100755
new mode 100644
index af1fb24..0997e67
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlAutoBackupLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlAutoBackupLogic.cs
@@ -1,566 +1,514 @@
-锘縰sing Newtonsoft.Json;
-using Shared.Common;
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Shared.Phone.UserCenter
-{
-    /// <summary>
-    /// 鑷姩澶囦唤鐨勯�昏緫
-    /// </summary>
-    public class HdlAutoBackupLogic
-    {
-        #region 鈻� 鍙橀噺澹版槑___________________________
-
-        #endregion
-
-        #region 鈻� 涓婁紶澶囦唤___________________________
-
-        /// <summary>
-        /// 鎵ц涓婁紶鑷姩澶囦唤鏁版嵁(0:娌℃湁鍙笂浼犵殑鑷姩澶囦唤鏁版嵁 1:鎴愬姛 -1锛氬け璐�)
-        /// </summary>
-        /// <returns></returns>
-        public async static Task<int> DoUpLoadAutoBackupData()
-        {
-            //鑾峰彇app鐨勮嚜鍔ㄥ浠�
-            var data = await HdlBackupLogic.Current.GetBackupListNameFromDB(1);
-            if (data == null)
-            {
-                return -1;
-            }
-
-            if (data.Count == 0)
-            {
-                //鍒犻櫎鍏ㄩ儴鐨勮嚜鍔ㄥ浠界殑鏈湴鏂囦欢
-                DeleteAllAutoBackupFile();
-                //濡傛灉娌℃湁鑷姩澶囦唤鏁版嵁,鍒欐妸鏈湴鍏ㄩ儴涓滆タ涓婁紶
-                var pathTemp = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
-                //澶嶅埗鏈湴鎵�鏈夋枃浠惰繃鍘�
-                List<string> listAllFile = Global.FileListByHomeId();
-                foreach (string fileName in listAllFile)
-                {
-                    string oldFile = UserCenterLogic.CombinePath(fileName);
-                    string newFile = System.IO.Path.Combine(pathTemp, fileName);
-                    //澶嶅埗鏂囦欢
-                    System.IO.File.Copy(oldFile, newFile, true);
-                }
-            }
-
-            //缂栬緫鏂囦欢
-            List<string> listEditor = GetAutoBackupEditorFile();
-            //鍒犻櫎鏂囦欢
-            List<string> listDelete = GetAutoBackupDeleteFile();
-            //娌℃湁鏁版嵁
-            if (listEditor.Count == 0 && listDelete.Count == 0)
-            {
-                return 0;
-            }
-
-            //寮�鍚繘搴︽潯
-            ProgressBar.SetMaxValue(listEditor.Count + listDelete.Count);
-            ProgressBar.Show();
-
-            //涓婁紶鏂囦欢鍒颁簯绔�
-            bool result = await UpLoadBackupFileToDB(listEditor);
-            if (result == false)
-            {
-                ProgressBar.Close();
-                return -1;
-            }
-
-            //鍒犻櫎鏂囦欢
-            result = await DoDeleteFileFromDB(listDelete);
-            if (result == false)
-            {
-                ProgressBar.Close();
-                return -1;
-            }
-
-            ProgressBar.Close();
-
-            return 1;
-        }
-
-        /// <summary>
-        /// 涓婁紶鏂囦欢鍒颁簯绔�
-        /// </summary>
-        /// <param name="listFile"></param>
-        /// <returns></returns>
-        private async static Task<bool> UpLoadBackupFileToDB(List<string> listFile)
-        {
-            string backUpDir = System.IO.Path.Combine(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
-            foreach (string file in listFile)
-            {
-                var datainfo = new FileInfoData();
-                datainfo.BackupFileName = file;
-                datainfo.BackupFileContent = ReadDirctoryFileByName(backUpDir, file);
-                if (datainfo.BackupFileContent == null)
-                {
-                    continue;
-                }
-                var list = new List<FileInfoData>();
-                list.Add(datainfo);
-
-                //鎵ц鏄笂浼�
-                bool falge = await DoUpLoadInfoToDB(list);
-                if (falge == false)
-                {
-                    return false;
-                }
-                //璁剧疆杩涘害鍊�
-                ProgressBar.SetValue(list.Count);
-            }
-            return true;
-        }
-
-        /// <summary>
-        /// 浜戠鎵ц鍒犻櫎鎸囧畾鏂囦欢
-        /// </summary>
-        /// <param name="listData">鍒犻櫎鐨勬枃浠�</param>
-        /// <returns></returns>
-        private async static Task<bool> DoDeleteFileFromDB(List<string> listData)
-        {
-            if (listData.Count == 0)
-            {
-                return true;
-            }
-
-            //鑾峰彇app鐨勮嚜鍔ㄥ浠�
-            var data = await HdlBackupLogic.Current.GetBackupListNameFromDB(1);
-            if (data == null || data.Count == 0)
-            {
-                return true;
-            }
-            //鑷姩澶囦唤鍙湁涓�涓�
-            var autoBackupId = data[0].Id;
-            var nowZigbeeNumHomeId = Shared.Common.Config.Instance.Home.Id;
-
-            var upData = new DeleteFilePra();
-            upData.BackupClassId = autoBackupId;
-            upData.HomeId = nowZigbeeNumHomeId;
-            upData.DeleteFileNameLists = listData;
-            //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
-            upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
-
-            bool falge = await UserCenterLogic.GetResultStatuByRequestHttps("App/DeleteAppBackupFile", true, upData);
-            if (falge == false)
-            {
-                return false;
-            }
-
-            //鍒犻櫎鏂囦欢
-            string strroot = Common.Config.Instance.FullPath;
-            var backPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupdeleteDirectory);
-            foreach (var file in listData)
-            {
-                string fullName = System.IO.Path.Combine(backPath, file);
-                System.IO.File.Delete(fullName);
-            }
-            return true;
-        }
-
-        /// <summary>
-        /// 鎵ц涓婁紶鏂囦欢鍒颁簯绔�
-        /// </summary>
-        /// <param name="listData">涓婁紶鐨勬暟鎹�</param>
-        /// <returns></returns>
-        private async static Task<bool> DoUpLoadInfoToDB(List<FileInfoData> listData)
-        {
-            var nowZigbeeNumHomeId = Shared.Common.Config.Instance.Home.Id;
-
-            var upData = new UpLoadDataPra();
-            upData.HomeId = nowZigbeeNumHomeId;
-            upData.UploadSubFileLists = listData;
-            //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
-            upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
-
-            bool falge = await UserCenterLogic.GetResultStatuByRequestHttps("App/HomeAppAutoDataBackup", true, upData);
-            if (falge == false)
-            {
-                return false;
-            }
-
-            //鍒犻櫎鏂囦欢
-            string strroot = Common.Config.Instance.FullPath;
-            var backPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
-            foreach (var file in listData)
-            {
-                string fullName = System.IO.Path.Combine(backPath, file.BackupFileName);
-                System.IO.File.Delete(fullName);
-            }
-
-            return true;
-        }
-
-        #endregion
-
-        #region 鈻� 鑾峰彇鏂囦欢___________________________
-
+锘縰sing Newtonsoft.Json;
+using Shared.Common;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Shared.Phone.UserCenter
+{
+    /// <summary>
+    /// 鑷姩澶囦唤鐨勯�昏緫
+    /// </summary>
+    public class HdlAutoBackupLogic
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        #endregion
+
+        #region 鈻� 涓婁紶澶囦唤___________________________
+
         /// <summary>
-        /// 鑾峰彇鎸囧畾鏂囦欢澶逛笅闈㈢殑鏂囦欢鍐呭
+        /// 鎵嬪姩鎵ц涓婁紶鑷姩澶囦唤鏁版嵁(0:娌℃湁鍙笂浼犵殑鑷姩澶囦唤鏁版嵁 1:鎴愬姛 -1锛氬け璐�)
         /// </summary>
-        /// <param name="dirctory">鎸囧畾鏂囦欢澶圭殑鍚嶅瓧(涓嶆槸鍏ㄨ矾寰�)</param>
-        /// <param name="fileName">File name.</param>
-        private static byte[] ReadDirctoryFileByName(string dirctory, string fileName)
+        /// <returns></returns>
+        public static int DoUpLoadAutoBackupDataByHand()
         {
-            var path = UserCenterLogic.CombinePath(dirctory, fileName);
-            if (System.IO.File.Exists(path) == false)
-            {
-                return null;
-            }
-            return Shared.IO.FileUtils.ReadFile(path);
-        }
-
-        /// <summary>
-        /// 鑾峰彇鑷姩澶囦唤鐩綍涓嬬殑娣诲姞鎴栬�呯紪杈戠殑鏂囦欢
-        /// </summary>
-        /// <returns></returns>
-        public static List<string> GetAutoBackupEditorFile()
-        {
-            string strroot = Common.Config.Instance.FullPath;
-            var path = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
-
-            return GetFileFromDirectory(path);
-        }
-
-        /// <summary>
-        /// 鑾峰彇鑷姩澶囦唤鐩綍涓嬬殑鍒犻櫎鐨勬枃浠�
-        /// </summary>
-        /// <returns></returns>
-        public static List<string> GetAutoBackupDeleteFile()
-        {
-            string strroot = Common.Config.Instance.FullPath;
-            var path = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupdeleteDirectory);
-
-            return GetFileFromDirectory(path);
-        }
-
-        /// <summary>
-        /// 鑾峰彇鎸囧畾鏂囦欢澶归噷闈㈢殑鍏ㄩ儴鏂囦欢 
-        /// </summary>
-        /// <param name="directory">鏂囦欢璺緞锛堝叏鍚嶏級</param>
-        /// <returns></returns>
-        public static List<string> GetFileFromDirectory(string directory)
-        {
-            if (System.IO.Directory.Exists(directory) == false)
-            {
-                return new List<string>();
+            //缂栬緫鏂囦欢
+            List<string> listEditor = GetAutoBackupEditorFile();
+            //鍒犻櫎鏂囦欢
+            List<string> listDelete = GetAutoBackupDeleteFile();
+            //娌℃湁鏁版嵁
+            if (listEditor.Count == 0 && listDelete.Count == 0)
+            {
+                return 0;
             }
 
-            List<string> list = new List<string>();
-            var files = System.IO.Directory.GetFiles(directory);
-            foreach (var file in files)
+            //寮�鍚繘搴︽潯 姝e湪涓婁紶澶囦唤鏂囦欢
+            ProgressFormBar.Current.Start();
+            ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileUploading));
+
+            //涓婁紶鏂囦欢鍒颁簯绔�
+            bool result = UpLoadBackupFileToDB(listEditor);
+            if (result == false)
             {
-                var f = file.Substring(directory.Length + 1);
-                list.Add(f);
+                ProgressFormBar.Current.Close();
+                return -1;
             }
-            return list;
-        }
-
-        #endregion
-
-        #region 鈻� 璁剧疆鏂囦欢鐘舵�乢______________________
-
-        /// <summary>
-        /// 娣诲姞鎴栬�呬慨鏀规枃浠�
-        /// </summary>
-        /// <param name="fileName">鏂囦欢鐨勫悕瀛�,涓嶅惈璺緞</param>
-        public static void AddOrEditorFile(string fileName)
-        {
-            //鏍圭洰褰�
-            string strroot = Common.Config.Instance.FullPath;
-            if (strroot == string.Empty)
-            {
-                return;
-            }
-            //鑷姩澶囦唤鐩綍
-            string strBackPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
-
-
-            //鑷姩鍒犻櫎澶囦唤鐩綍
-            string strdelBackPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupdeleteDirectory);
-            //濡傛灉鍒犻櫎鍒楄〃閲岄潰鏈夎繖涓笢瑗跨殑璇濓紝绉婚櫎鎺�
-            string delFile = System.IO.Path.Combine(strdelBackPath, fileName);
-            if (System.IO.File.Exists(delFile) == true)
-            {
-                System.IO.File.Delete(delFile);
-            }
-
-            string soureFile = System.IO.Path.Combine(strroot, fileName);
-            string newFile = System.IO.Path.Combine(strBackPath, fileName);
-            if (System.IO.Directory.Exists(strBackPath) == false)
-            {
-                //棰勫垱寤轰釜浜轰腑蹇冨叏閮ㄧ殑鏂囦欢澶�
-                UserCenterLogic.CreatAllUserCenterDirectory();
-            }
-
-            //鍘熷師鏈湰鐨勫鍒舵枃浠跺埌鎸囧畾鏂囦欢澶�
-            CopyFile(soureFile, newFile);
-        }
-
-        /// <summary>
-        /// 鍒犻櫎鏂囦欢
-        /// </summary>
-        /// <param name="fileName">鏂囦欢鐨勫悕瀛�,涓嶅惈璺緞</param>
-        public static void DeleteFile(string fileName)
-        {
-            //鏍圭洰褰�
-            string strroot = Common.Config.Instance.FullPath;
-            if (strroot == string.Empty)
-            {
-                return;
-            }
-            //鑷姩鍒犻櫎澶囦唤鐩綍
-            string strBackPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupdeleteDirectory);
-
-            string newFile = System.IO.Path.Combine(strBackPath, fileName);
-
-            //鍒涘缓涓�涓┖鏂囦欢
-            var file = System.IO.File.Create(newFile);
-            file.Close();
-        }
-
-        #endregion
-
-        #region 鈻� 鍚屾鏁版嵁___________________________
-
-        /// <summary>
-        /// 鍚屾浜戠鏁版嵁(浠呴檺APP鍚姩涔嬪悗) -1锛氬紓甯�   0:宸茬粡鍚屾杩囷紝涓嶉渶瑕佸悓姝�  1锛氭甯稿悓姝�  
-        /// </summary>
-        /// <returns></returns>
-        public static async Task<int> SynchronizeDbAutoBackupData()
-        {
-            //鍒ゆ柇鏄惁鑳藉鍚屾鏁版嵁
-            string checkFile = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoDownLoadBackupCheckFile);
-            //濡傛灉鏈湴宸茬粡鎷ユ湁浜嗚繖涓枃浠讹紝鍒欒鏄庝笉鏄柊鎵嬫満锛屼笉鍐嶈嚜鍔ㄨ繕鍘�
-            if (System.IO.File.Exists(checkFile) == true)
-            {
-                //鍚屾鏈嶅姟鍣ㄧ殑鍒嗕韩鍐呭
-                await HdlShardLogic.Current.SynchronizeDbSharedContent();
-                return 0;
-            }
-
-            //鏆傛椂涓嶆敮鎸佹垚鍛�
-            if (UserCenterResourse.UserInfo.AuthorityNo == 3)
-            {
-                //鍚屾鏈嶅姟鍣ㄧ殑鍒嗕韩鍐呭
-                await HdlShardLogic.Current.SynchronizeDbSharedContent();
-                //鍒涘缓涓�涓┖鏂囦欢(鏍囪瘑宸茬粡瀹屾垚鍚屾)
-                var file = System.IO.File.Create(checkFile);
-                file.Close();
-                return 1;
-            }
-
-            //鑾峰彇app鐨勮嚜鍔ㄥ浠�
-            var data = await HdlBackupLogic.Current.GetBackupListNameFromDB(1);
-            if (data == null)
-            {
-                return -1;
-            }
-            if (data.Count == 0)
-            {
-                //鍚屾鏈嶅姟鍣ㄧ殑鍒嗕韩鍐呭
-                await HdlShardLogic.Current.SynchronizeDbSharedContent();
-                //鍒涘缓涓�涓┖鏂囦欢(鏍囪瘑宸茬粡瀹屾垚鍚屾)
-                var file = System.IO.File.Create(checkFile);
-                file.Close();
-                return 1;
-            }
-            //鑷姩澶囦唤鍙湁涓�涓�
-            string backId = data[0].Id;
-
-            //寮哄埗鎸囧畾鏂囨湰闄勫姞淇℃伅锛氳处鍙锋暟鎹悓姝ヤ腑
-            ProgressBar.SetAppendText(Language.StringByID(R.MyInternationalizationString.uAccountDataIsSynchronizing));
-
-            //浠庝簯绔幏鍙栧浠界殑鏂囦欢锛岀劧鍚庡瓨鍏ユ湰鍦版寚瀹氱殑涓存椂鏂囦欢澶�
-            string tempDir = await HdlBackupLogic.Current.GetBackFileFromDBAndSetToLocation(backId);
-            if (tempDir == null)
-            {
-                //鍒犻櫎妫�娴嬫枃浠�
-                System.IO.File.Delete(checkFile);
-                //鍚屾澶辫触
-                return -1;
-            }
-            //濡傛灉璇诲彇鍒扮殑鏂囦欢瀹屽叏娌℃湁闂锛屽垯娓呯悊鏈湴鐨勬枃浠�
-            UserCenterLogic.DeleteAllLocationFile(false);
-
-            //娌℃湁閿欒鐨勮瘽锛屽垯绉诲姩鍒板綋鍓嶄綇瀹呮枃浠跺す涓嬮潰
-            Global.MoveDirectoryFileToHomeDirectory(tempDir, true);
-
-            //鍒涘缓涓�涓┖鏂囦欢(鏍囪瘑宸茬粡瀹屾垚鍚屾)
-            var file2 = System.IO.File.Create(checkFile);
-            file2.Close();
-
-            return 1;
-        }
-
-        #endregion
-
-        #region 鈻� 涓�鑸柟娉昣__________________________
-
-        /// <summary>
-        /// 澶嶅埗鏂囦欢
-        /// </summary>
-        /// <param name="sourseFile">鎸囧畾鏂囦欢锛堝叏鍚嶏級</param>
-        /// <param name="newFile">鏂版枃浠讹紙鍏ㄥ悕锛�</param>
-        private static void CopyFile(string sourseFile, string newFile)
-        {
-            try
-            {
-                if (System.IO.File.Exists(sourseFile) == false)
-                {
-                    return;
-                }
-                System.IO.File.Copy(sourseFile, newFile, true);
-            }
-            catch { }
-        }
-
-        /// <summary>
-        /// 鍒犻櫎鍏ㄩ儴鐨勮嚜鍔ㄥ浠界殑鏈湴鏂囦欢(姝ゅ嚱鏁扮敤浜庤鍙栬嚜鍔ㄥ浠界殑鏃跺�欎娇鐢�)
-        /// </summary>
-        public static void DeleteAllAutoBackupFile()
-        {
-            //娓呯┖鑷姩澶囦唤銆愭枃浠跺す銆�(缂栬緫,杩藉姞)
-            string dirPath = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
-            System.IO.Directory.Delete(dirPath, true);
-            System.IO.Directory.CreateDirectory(dirPath);
-
-            //娓呯┖鑷姩澶囦唤銆愭枃浠跺す銆�(鍒犻櫎)
-            dirPath = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupdeleteDirectory);
-            System.IO.Directory.Delete(dirPath, true);
-            System.IO.Directory.CreateDirectory(dirPath);
-        }
-
-        #endregion
-
-        #region 鈻� 澶囦唤鎻愰啋___________________________
-
-        /// <summary>
-        /// 淇濆瓨澶囦唤鎻愰啋璁剧疆鍒版湰鍦�
-        /// </summary>
-        /// <param name="notPrompted">涓嶅啀鎻愮ず</param>
-        /// <param name="day"></param>
-        public static void SaveBackupNotPrompted(bool notPrompted, int day = -1)
-        {
-            //鏂囦欢鍏ㄨ矾寰�
-            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupNotPromptedFile);
-            BackupNotPrompted info = null;
-            if (System.IO.File.Exists(fullName) == true)
-            {
-                var data = Global.ReadFileByDirectory(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupNotPromptedFile);
-                info = JsonConvert.DeserializeObject<BackupNotPrompted>(System.Text.Encoding.UTF8.GetString(data));
-            }
-            if (info == null)
-            {
-                info = new BackupNotPrompted();
-            }
-
-            info.NotPrompted = notPrompted;
-            if (day != -1)
-            {
-                info.OldDay = DateTime.Now.ToString("yyyy-MM-dd");
-                info.Day = day;
-            }
-            //淇濆瓨
-            var saveData = JsonConvert.SerializeObject(info);
-            var byteData = System.Text.Encoding.UTF8.GetBytes(saveData);
-            Global.WriteFileToDirectoryByBytes(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupNotPromptedFile, byteData);
-        }
-
-        /// <summary>
-        /// 鏄剧ず鑷姩澶囦唤鐨勭晫闈�
-        /// </summary>
-        public static void ShowAutoBackupPromptedForm()
-        {
-            if (UserCenterResourse.UserInfo.AuthorityNo == 3)
-            {
-                //鏆備笉鏀寔鎴愬憳
-                return;
-            }
-            string strroot = Common.Config.Instance.FullPath;
-            var path = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
-
-            List<string> listFile1 = GetFileFromDirectory(path);
-            List<string> listFile2 = GetAutoBackupDeleteFile();
-
-            if (listFile1.Count == 0 && listFile2.Count == 0)
-            {
-                return;
-            }
-            if (listFile1.Count == 1 && listFile1[0] == "Room_Favorite.json")
-            {
-                //杩欎釜涓滆タ濂藉儚APP鍚姩鐨勬椂鍊欓兘浼氬垱寤虹殑鏍峰瓙
-                return;
-            }
-
-            //鏂囦欢鍏ㄨ矾寰�
-            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupNotPromptedFile);
-            if (System.IO.File.Exists(fullName) == false)
-            {
-                //Application.RunOnMainThread(() =>
-                //{
-                //    var form = new HdlBackup.HdlAutoBackupSettionForm();
-                //    form.AddForm();
-                //});
-                return;
-            }
-            BackupNotPrompted info = null;
-            var data = Global.ReadFileByDirectory(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupNotPromptedFile);
-            info = JsonConvert.DeserializeObject<BackupNotPrompted>(System.Text.Encoding.UTF8.GetString(data));
-            if (info.NotPrompted == true)
-            {
-                //涓嶅啀鎻愮ず
-                return;
-            }
-            if (info.Day == 0)
-            {
-                //Application.RunOnMainThread(() =>
-                //{
-                //    var form = new HdlBackup.HdlAutoBackupSettionForm();
-                //    form.AddForm();
-                //});
-                //return;
-            }
-
-            DateTime oldTime = Convert.ToDateTime(info.OldDay);
-            int intDay = (DateTime.Now - oldTime).Days;
-            //鏃堕棿宸茬粡瓒呰繃
-            if (intDay > info.Day)
-            {
-                //Application.RunOnMainThread(() =>
-                //{
-                //    var form = new HdlBackup.HdlAutoBackupSettionForm();
-                //    form.AddForm();
-                //});
-            }
-        }
-
-        #endregion
-
-        #region 鈻� 鏁版嵁缁撴瀯___________________________
-
-        /// <summary>
-        /// 鑷姩澶囦唤涓嶉渶瑕佸啀娆℃彁閱掔殑缁撴瀯浣�
-        /// </summary>
-        private class BackupNotPrompted
-        {
-            /// <summary>
-            /// 涓嶅啀鎻愮ず
-            /// </summary>
-            public bool NotPrompted = false;
-            /// <summary>
-            /// 鍓嶄竴娆$殑鏃ユ湡锛�2019-01-01(鏍煎紡)
-            /// </summary>
-            public string OldDay = string.Empty;
-            /// <summary>
-            /// 鐩搁殧鏃ユ湡澶╂暟
-            /// </summary>
-            public int Day = 0;
-        }
-
-        #endregion
-    }
-}
+
+            //鍒犻櫎鏂囦欢
+            result = DoDeleteFileFromDB(listDelete);
+            if (result == false)
+            {
+                ProgressFormBar.Current.Close();
+                return -1;
+            }
+
+            ProgressFormBar.Current.Close();
+
+            return 1;
+        }
+
+        /// <summary>
+        /// 涓婁紶鏂囦欢鍒颁簯绔�
+        /// </summary>
+        /// <param name="listFile">缂栬緫鎴栬�呮坊鍔犵殑鏂囦欢(鐩墠宸茬粡涓嶆槸涓婁紶瀹冧簡)</param>
+        /// <returns></returns>
+        private static bool UpLoadBackupFileToDB(List<string> listFile)
+        {
+            string localPath = Config.Instance.FullPath;
+
+            //灏嗘ā鏉挎暟鎹繚瀛樺埌鍒版寚瀹氱殑鏂囦欢澶逛腑
+            var templateName = TemplateData.TemplateCommonLogic.Current.GetNewTemplateFileName(new DateTime(2000, 12, 31, 12, 59, 57));
+            var templateFile = TemplateData.TemplateCommonLogic.Current.SaveTemplateDataToFile(templateName, "HomeTemplate");
+
+            //灏嗘ā鏉縝in鏂囦欢绉诲姩鍒板浠芥枃浠跺す涓�
+            var localTemplateName = System.IO.Path.Combine(localPath, templateName);
+            try { System.IO.File.Move(templateFile, localTemplateName); }
+            catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex, "绉诲姩妯℃澘澶辫触"); }
+
+            //鑾峰彇鏈湴鏂囦欢
+            var listAllFile = HdlFileLogic.Current.GetRootPathListFile();
+            var listUpFile = new List<string>();
+            foreach (string fileName in listAllFile)
+            {
+                //鍒ゆ柇鎸囧畾鏂囦欢鏄惁闇�瑕佷笂浼�(鏍圭洰褰曠殑鎵嶅垽鏂�)
+                if (HdlBackupLogic.Current.IsNotUpLoadFile(fileName) == true)
+                {
+                    continue;
+                }
+                //鍏朵粬鍥剧墖鐨勮祫婧愭枃浠�,鍙湁鍦ㄥ彉鏇翠簡鐨勬椂鍊�,鎵嶄笂浼�
+                if (fileName.EndsWith(".png") == true && listFile.Contains(fileName) == false)
+                {
+                    continue;
+                }
+                listUpFile.Add(fileName);
+            }
+
+            int listFileCount = listUpFile.Count;
+            for (int i = 0; i < listUpFile.Count; i++)
+            {
+                string file = listUpFile[i];
+                var datainfo = new FileInfoData();
+                datainfo.BackupFileName = file;
+                datainfo.BackupFileContent = HdlFileLogic.Current.ReadFileByteContent(System.IO.Path.Combine(localPath, file));
+                if (datainfo.BackupFileContent == null)
+                {
+                    continue;
+                }
+
+                var upData = new UpLoadDataPra();
+                upData.HomeId = Config.Instance.Home.Id;
+                upData.UploadSubFileLists = new List<FileInfoData> { datainfo };
+                //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
+                upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
+
+                //鎵ц鏄笂浼�
+                bool falge = UserCenterLogic.GetResultStatuByRequestHttps("App/HomeAppAutoDataBackup", true, upData, null, true);
+                if (falge == false)
+                {
+                    return false;
+                }
+                //璁剧疆杩涘害鍊�
+                ProgressFormBar.Current.SetValue(i + 1, listFileCount);
+            }
+
+            //鍒犻櫎鎺夎繖涓ā鏉挎枃浠�
+            HdlFileLogic.Current.DeleteFile(localTemplateName);
+
+            //鍒犻櫎鏂囦欢
+            var backPath = DirNameResourse.AutoBackupDirectory;
+            foreach (var file in listFile)
+            {
+                string fullName = System.IO.Path.Combine(backPath, file);
+                HdlFileLogic.Current.DeleteFile(fullName);
+            }
+
+            return true;
+        }
+
+        /// <summary>
+        /// 浜戠鎵ц鍒犻櫎鎸囧畾鏂囦欢
+        /// </summary>
+        /// <param name="listData">鍒犻櫎鐨勬枃浠�</param>
+        /// <returns></returns>
+        private static bool DoDeleteFileFromDB(List<string> listData)
+        {
+            if (listData.Count == 0)
+            {
+                return true;
+            }
+
+            //鑾峰彇app鐨勮嚜鍔ㄥ浠�
+            var data = HdlBackupLogic.Current.GetBackupListNameFromDB(1);
+            if (data == null || data.Count == 0)
+            {
+                return true;
+            }
+            //鑷姩澶囦唤鍙湁涓�涓�
+            var autoBackupId = data[0].Id;
+
+            var upData = new DeleteFilePra();
+            upData.BackupClassId = autoBackupId;
+            upData.HomeId = Config.Instance.Home.Id;
+            upData.DeleteFileNameLists = listData;
+            //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
+            upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
+
+            bool falge = UserCenterLogic.GetResultStatuByRequestHttps("App/DeleteAppBackupFile", true, upData);
+            if (falge == false)
+            {
+                return false;
+            }
+
+            //鍒犻櫎鏂囦欢
+            var backPath = DirNameResourse.AutoBackupdeleteDirectory;
+            foreach (var file in listData)
+            {
+                string fullName = System.IO.Path.Combine(backPath, file);
+                HdlFileLogic.Current.DeleteFile(fullName);
+            }
+            return true;
+        }
+
+        #endregion
+
+        #region 鈻� 鑾峰彇鏂囦欢___________________________
+
+        /// <summary>
+        /// 鑾峰彇鑷姩澶囦唤鐩綍涓嬬殑娣诲姞鎴栬�呯紪杈戠殑鏂囦欢
+        /// </summary>
+        /// <returns></returns>
+        public static List<string> GetAutoBackupEditorFile()
+        {
+            return HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.AutoBackupDirectory);
+        }
+
+        /// <summary>
+        /// 鑾峰彇鑷姩澶囦唤鐩綍涓嬬殑鍒犻櫎鐨勬枃浠�
+        /// </summary>
+        /// <returns></returns>
+        public static List<string> GetAutoBackupDeleteFile()
+        {
+            return HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.AutoBackupdeleteDirectory);
+        }
+
+        #endregion
+
+        #region 鈻� 璁剧疆鏂囦欢鐘舵�乢______________________
+
+        /// <summary>
+        /// 娣诲姞鎴栬�呬慨鏀规枃浠�
+        /// </summary>
+        /// <param name="fileName">鏂囦欢鐨勫悕瀛�,涓嶅惈璺緞</param>
+        public static void AddOrEditorFile(string fileName)
+        {
+            fileName = System.IO.Path.GetFileName(fileName);
+            //鑷姩澶囦唤鐩綍
+            string strBackPath = DirNameResourse.AutoBackupDirectory;
+            if (System.IO.Directory.Exists(strBackPath) == false)
+            {
+                //棰勫垱寤轰釜浜轰腑蹇冨叏閮ㄧ殑鏂囦欢澶�
+                HdlFileLogic.Current.CreatAllUserCenterDirectory();
+            }
+
+            //鑷姩鍒犻櫎澶囦唤鐩綍
+            string strdelBackPath = DirNameResourse.AutoBackupdeleteDirectory;
+            //濡傛灉鍒犻櫎鍒楄〃閲岄潰鏈夎繖涓笢瑗跨殑璇濓紝绉婚櫎鎺�
+            string delFile = System.IO.Path.Combine(strdelBackPath, fileName);
+            HdlFileLogic.Current.DeleteFile(delFile);
+
+            string soureFile = System.IO.Path.Combine(Common.Config.Instance.FullPath, fileName);
+            string newFile = System.IO.Path.Combine(strBackPath, fileName);
+
+            //鍘熷師鏈湰鐨勫鍒舵枃浠跺埌鎸囧畾鏂囦欢澶�
+            HdlFileLogic.Current.CopyFile(soureFile, newFile);
+        }
+
+        /// <summary>
+        /// 鍒犻櫎鏂囦欢
+        /// </summary>
+        /// <param name="fileName">鏂囦欢鐨勫悕瀛�,涓嶅惈璺緞</param>
+        public static void DeleteFile(string fileName)
+        {
+            fileName = System.IO.Path.GetFileName(fileName);
+            //鑷姩鍒犻櫎澶囦唤鐩綍
+            string strBackPath = DirNameResourse.AutoBackupdeleteDirectory;
+            string newFile = System.IO.Path.Combine(strBackPath, fileName);
+
+            //鍒涘缓涓�涓┖鏂囦欢
+            var file = System.IO.File.Create(newFile);
+            file.Close();
+
+            //鑷姩澶囦唤鐩綍
+            strBackPath = DirNameResourse.AutoBackupDirectory;
+            //濡傛灉澶囦唤鍒楄〃閲岄潰鏈夎繖涓笢瑗跨殑璇濓紝绉婚櫎鎺�
+            string delFile = System.IO.Path.Combine(strBackPath, fileName);
+
+            HdlFileLogic.Current.DeleteFile(delFile);
+        }
+
+        #endregion
+
+        #region 鈻� 鍚屾鏁版嵁___________________________
+
+        /// <summary>
+        /// 鍚屾浜戠鏁版嵁(浠呴檺APP鍚姩涔嬪悗) -1锛氬紓甯�   0:宸茬粡鍚屾杩囷紝涓嶉渶瑕佸悓姝�  1锛氭甯稿悓姝�  2:娌℃湁鑷姩澶囦唤鏁版嵁
+        /// </summary>
+        /// <returns></returns>
+        public static int SynchronizeDbAutoBackupData()
+        {
+            //鏆傛椂涓嶆敮鎸佹垚鍛�
+            if (UserCenterResourse.UserInfo.AuthorityNo == 3)
+            {
+                //鍚屾鏈嶅姟鍣ㄧ殑鍒嗕韩鍐呭
+                HdlShardLogic.Current.SynchronizeDbSharedContent();
+                return 1;
+            }
+            //鍒ゆ柇鏄惁鑳藉鍚屾鏁版嵁
+            string checkFile = DirNameResourse.AutoDownLoadBackupCheckFile;
+            //濡傛灉鏈湴宸茬粡鎷ユ湁浜嗚繖涓枃浠讹紝鍒欒鏄庝笉鏄柊鎵嬫満锛屼笉鍐嶈嚜鍔ㄨ繕鍘�
+            if (System.IO.File.Exists(checkFile) == true)
+            {
+                return 0;
+            }
+
+            //鑾峰彇app鐨勮嚜鍔ㄥ浠�
+            var data = HdlBackupLogic.Current.GetBackupListNameFromDB(1);
+            if (data == null)
+            {
+                return -1;
+            }
+            if (data.Count == 0)
+            {
+                //鍒涘缓涓�涓┖鏂囦欢(鏍囪瘑宸茬粡瀹屾垚鍚屾)
+                var file = System.IO.File.Create(checkFile);
+                file.Close();
+                return 2;
+            }
+            //鑷姩澶囦唤鍙湁涓�涓�
+            string backId = data[0].Id;
+
+            //璐﹀彿鏁版嵁鍚屾涓�
+            ProgressFormBar.Current.Start();
+            ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uAccountDataIsSynchronizing));
+
+            //浠庝簯绔幏鍙栧浠界殑鏂囦欢锛岀劧鍚庡瓨鍏ユ湰鍦版寚瀹氱殑涓存椂鏂囦欢澶�
+            string tempDir = HdlBackupLogic.Current.GetBackFileFromDBAndSetToLocation(backId);
+            if (tempDir == null)
+            {
+                //鍒犻櫎妫�娴嬫枃浠�
+                System.IO.File.Delete(checkFile);
+                //鍏抽棴杩涘害鏉�
+                ProgressFormBar.Current.Close();
+                //鍚屾澶辫触
+                return -1;
+            }
+            //濡傛灉璇诲彇鍒扮殑鏂囦欢瀹屽叏娌℃湁闂锛屽垯娓呯悊鏈湴鐨勬枃浠�
+            HdlFileLogic.Current.DeleteAllLocationFile(false);
+
+            //娌℃湁閿欒鐨勮瘽锛屽垯绉诲姩鍒板綋鍓嶄綇瀹呮枃浠跺す涓嬮潰
+            HdlFileLogic.Current.MoveDirectoryFileToHomeDirectory(tempDir, true);
+
+            //鍒涘缓涓�涓┖鏂囦欢(鏍囪瘑宸茬粡瀹屾垚鍚屾)
+            var file2 = System.IO.File.Create(checkFile);
+            file2.Close();
+
+            //閲嶆柊鍒锋柊浣忓畢瀵硅薄
+            UserCenterLogic.RefreshHomeObject();
+            //鏍规嵁妯℃澘鏂囦欢,鎭㈠鏁版嵁
+            TemplateData.TemplateCommonLogic.Current.RecoverDataByTemplateBinFile();
+            //寮哄埗鐢熸垚璁惧鍜岀綉鍏虫枃浠�
+            TemplateData.TemplateCommonLogic.Current.CreatDeviceAndGatewayFileFromMemoryByForce();
+
+            //鍏抽棴杩涘害鏉�
+            ProgressFormBar.Current.Close();
+
+            return 1;
+        }
+
+        #endregion
+
+        #region 鈻� 涓�鑸柟娉昣__________________________
+
+        /// <summary>
+        /// 鍒犻櫎鍏ㄩ儴鐨勮嚜鍔ㄥ浠界殑鏈湴鏂囦欢(姝ゅ嚱鏁扮敤浜庤鍙栬嚜鍔ㄥ浠界殑鏃跺�欎娇鐢�)
+        /// </summary>
+        public static void DeleteAllAutoBackupFile()
+        {
+            //娓呯┖鑷姩澶囦唤銆愭枃浠跺す銆�(缂栬緫,杩藉姞)
+            string dirPath = DirNameResourse.AutoBackupDirectory;
+            HdlFileLogic.Current.DeleteDirectory(dirPath);
+            HdlFileLogic.Current.CreateDirectory(dirPath, true);
+
+            //娓呯┖鑷姩澶囦唤銆愭枃浠跺す銆�(鍒犻櫎)
+            dirPath = DirNameResourse.AutoBackupdeleteDirectory;
+            HdlFileLogic.Current.DeleteDirectory(dirPath);
+            HdlFileLogic.Current.CreateDirectory(dirPath, true);
+        }
+
+        #endregion
+
+        #region 鈻� 澶囦唤鎻愰啋___________________________
+
+        /// <summary>
+        /// 淇濆瓨澶囦唤鎻愰啋璁剧疆鍒版湰鍦�
+        /// </summary>
+        /// <param name="notPrompted">涓嶅啀鎻愮ず</param>
+        /// <param name="day"></param>
+        public static void SaveBackupNotPrompted(bool notPrompted, int day = -1)
+        {
+            //鏂囦欢鍏ㄨ矾寰�
+            string fullName = DirNameResourse.AutoBackupNotPromptedFile;
+            BackupNotPrompted info = null;
+            if (System.IO.File.Exists(fullName) == true)
+            {
+                var data = HdlFileLogic.Current.ReadFileByteContent(fullName);
+                info = JsonConvert.DeserializeObject<BackupNotPrompted>(System.Text.Encoding.UTF8.GetString(data));
+            }
+            if (info == null)
+            {
+                info = new BackupNotPrompted();
+            }
+
+            info.NotPrompted = notPrompted;
+            if (day != -1)
+            {
+                info.OldDay = DateTime.Now.ToString("yyyy-MM-dd");
+                info.Day = day;
+            }
+            //淇濆瓨
+            HdlFileLogic.Current.SaveFileContent(fullName, info);
+        }
+
+        /// <summary>
+        /// 鏄剧ず鑷姩澶囦唤鐨勭晫闈�
+        /// </summary>
+        public static void ShowAutoBackupPromptedForm()
+        {
+            if (UserCenterResourse.UserInfo.AuthorityNo == 3)
+            {
+                //鏆備笉鏀寔鎴愬憳
+                return;
+            }
+
+            //鍒ゆ柇鏄惁鏈夋枃浠跺彉鏇翠簡
+            if (CheckAutoBackupFileIsChanged() == false)
+            {
+                return;
+            }
+            //鍒ゆ柇鑳藉惁鏄剧ず鑷姩澶囦唤鐨勭晫闈�
+            if (CheckCanShowAutoBackupForm() == true)
+            {
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    var form = new HdlBackup.HdlAutoBackupForm();
+                    form.AddForm();
+                });
+            }
+        }
+
+        /// <summary>
+        /// 妫�娴嬭嚜鍔ㄥ浠芥枃浠舵槸鍚﹀彉鏇磋繃
+        /// </summary>
+        /// <returns></returns>
+        private static bool CheckAutoBackupFileIsChanged()
+        {
+            List<string> listFile1 = HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.AutoBackupDirectory);
+            List<string> listFile2 = GetAutoBackupDeleteFile();
+
+            if (listFile1.Count == 0 && listFile2.Count == 0)
+            {
+                //娌℃湁鏂囦欢鍙樻洿
+                return false;
+            }
+            if (listFile2.Count > 0)
+            {
+                //鏈夋枃浠惰鍒犻櫎
+                return true;
+            }
+            foreach (var fileName in listFile1)
+            {
+                //浣忓畢鍜屾敹钘忔枃浠�,涓嶄綔涓哄垽鏂爣鍑�
+                if (fileName.StartsWith("House_") == true
+                  || fileName == "Room_Favorite.json")
+                {
+                    continue;
+                }
+                return true;
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// 妫�娴嬭兘鍚︽樉绀鸿嚜鍔ㄥ浠界殑鐣岄潰
+        /// </summary>
+        /// <returns></returns>
+        private static bool CheckCanShowAutoBackupForm()
+        {
+            //鏂囦欢鍏ㄨ矾寰�
+            string fullName = DirNameResourse.AutoBackupNotPromptedFile;
+            if (System.IO.File.Exists(fullName) == false)
+            {
+                //鏈湴娌℃湁瀛樺湪杩欎釜鏂囦欢
+                return true;
+            }
+            BackupNotPrompted info = null;
+            var data = HdlFileLogic.Current.ReadFileByteContent(fullName);
+            info = JsonConvert.DeserializeObject<BackupNotPrompted>(System.Text.Encoding.UTF8.GetString(data));
+            if (info.NotPrompted == true)
+            {
+                //涓嶅啀鎻愮ず
+                return false;
+            }
+            if (info.Day == 0)
+            {
+                return true;
+            }
+
+            DateTime oldTime = Convert.ToDateTime(info.OldDay);
+            int intDay = (DateTime.Now - oldTime).Days;
+            //鏃堕棿宸茬粡瓒呰繃
+            if (intDay >= info.Day)
+            {
+                return true;
+            }
+            return false;
+        }
+
+        #endregion
+
+        #region 鈻� 鏁版嵁缁撴瀯___________________________
+
+        /// <summary>
+        /// 鑷姩澶囦唤涓嶉渶瑕佸啀娆℃彁閱掔殑缁撴瀯浣�
+        /// </summary>
+        private class BackupNotPrompted
+        {
+            /// <summary>
+            /// 涓嶅啀鎻愮ず
+            /// </summary>
+            public bool NotPrompted = false;
+            /// <summary>
+            /// 鍓嶄竴娆$殑鏃ユ湡锛�2019-01-01(鏍煎紡)
+            /// </summary>
+            public string OldDay = string.Empty;
+            /// <summary>
+            /// 鐩搁殧鏃ユ湡澶╂暟
+            /// </summary>
+            public int Day = 0;
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0