From e6a26ee148587327478d9a82624a820c907b6e16 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期三, 04 十一月 2020 14:58:15 +0800
Subject: [PATCH] 20201104

---
 HDL_ON/DAL/FileUtils.cs |  132 +++++++++++++++++---------------------------
 1 files changed, 51 insertions(+), 81 deletions(-)

diff --git a/HDL_ON/DAL/FileUtils.cs b/HDL_ON/DAL/FileUtils.cs
index cbb23b7..9e93101 100644
--- a/HDL_ON/DAL/FileUtils.cs
+++ b/HDL_ON/DAL/FileUtils.cs
@@ -4,17 +4,28 @@
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
 using Shared;
-using HDL_ON.UI;
+//using HDL_ON.UI;
 using HDL_ON.DAL.Net;
 using HDL_ON.DAL;
 using HDL_ON.Entity;
 
-namespace HDL_ON.MyIO
+namespace HDL_ON
 {
     public static class FileUtils
     {
         public static string RootPath = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "/";
 
+        /// <summary>
+        /// 鏄惁瀛樺湪鏂囦欢澶�
+        /// </summary>
+        /// <returns></returns>
+        public static bool IsExisFolder(string folderName)
+        {
+            bool result = false;
+            var path = Path.Combine(RootPath, folderName);
+            result = Directory.Exists(path);
+            return result;
+        }
         /// <summary>
         /// 鍒涘缓涓�涓綇瀹呯殑澶囦唤鏂囦欢澶�
         /// </summary>
@@ -44,8 +55,7 @@
         {
             foreach (var fileName in ReadRegionFiles(path))
             {
-                System.IO.File.Delete(System.IO.Path.Combine(path, fileName));
-                MainPage.Log("Del region file :" + fileName);
+                File.Delete(Path.Combine(path, fileName));
             }
         }
 
@@ -75,7 +85,11 @@
             foreach (FileInfo NextFile in thFolders)
             {
                 index++;
-                if (NextFile.Name == "null" || NextFile.Name == "UserConfig" || NextFile.Name == "Register_File" || NextFile.Name == "AccountListDB")
+                if (NextFile.Name == "headImage.png")
+                {
+                    continue;
+                }
+                if (NextFile.Name == "null" || NextFile.Name == "UserConfig" || NextFile.Name == "UserInfo_File" || NextFile.Name == "AccountListDB")
                 {
                     continue;
                 }
@@ -87,13 +101,11 @@
                 }
             }
         }
-
-
-
+        
         /// <summary>
         /// 閬嶅巻鏂囦欢
         /// </summary>
-        public static List<string> ReadFiles(bool reInit = true)
+        public static List<string> ReadFiles()
         {
             List<string> listFiles = new List<string>();
             DirectoryInfo TheFolder = new DirectoryInfo(RootPath);
@@ -101,14 +113,6 @@
             {
                 listFiles.Add(NextFile.Name);
             }
-            try
-            {
-                if (reInit)
-                {
-                    MainPage.LocationFiles = listFiles;
-                }
-            }
-            catch { }
             return listFiles;
         }
 
@@ -124,14 +128,11 @@
                 return;
             }
             DeleteFile(newFilePath);
-            System.IO.FileInfo fileInfo = new System.IO.FileInfo(Application.RootPath + oldFilePath);
+            FileInfo fileInfo = new FileInfo(Application.RootPath + oldFilePath);
             if (fileInfo.Exists)
             {
                 fileInfo.MoveTo(Application.RootPath + newFilePath);
             }
-            //if (!UserConfig.Instance.LocalFiles.Contains (newFilePath)) {
-            //    UserConfig.Instance.LocalFiles.Add (newFilePath);
-            //}
         }
 
 
@@ -148,9 +149,9 @@
                 MainPage.Log ("鏂囦欢澶癸細" + d.Name);
             }
 #endif
-            if (System.IO.Directory.Exists(srcPath))
+            if (Directory.Exists(srcPath))
             {
-                System.IO.DirectoryInfo folder = new System.IO.DirectoryInfo(srcPath);
+                DirectoryInfo folder = new DirectoryInfo(srcPath);
                 var path = Path.Combine(RootPath, destFolderPath);
                 if (Directory.Exists(path))
                 {
@@ -189,8 +190,8 @@
         /// <param name="filePath">File path.</param>
         public static bool Exists(string filePath)
         {
-            //System.MainPage.WriteLog ("Exists==" + System.IO.Path.Combine (RootPath, filePath));
-            return System.IO.File.Exists(System.IO.Path.Combine(RootPath, filePath));
+            //System.MainPage.WriteLog ("Exists==" + Path.Combine (RootPath, filePath));
+            return File.Exists(Path.Combine(RootPath, filePath));
         }
 
         /// <summary>
@@ -203,11 +204,8 @@
             {
                 return;
             }
-            System.IO.File.Delete(System.IO.Path.Combine(RootPath, fileName));
+            File.Delete(Path.Combine(RootPath, fileName));
             MainPage.Log("鍒犻櫎鏂囦欢鍚嶄负锛�" + fileName);
-            //if (UserConfig.Instance.LocalFiles.Contains (fileName)) {
-            //    UserConfig.Instance.LocalFiles.Remove (fileName);
-            //}
         }
 
         /// <summary>
@@ -219,35 +217,10 @@
             for (int j = 0; j < filesList.Count; j++)
             {
                 var f = filesList[j];
-                if (f == "linphonerc" || f == "AccountListDB")
+                if (f == "linphonerc" || f == "AccountListDB" || f == "UserInfo_File")
                     continue;
                 DeleteFile(f);
             }
-        }
-
-        /// <summary>
-        /// Reads the equipment message.
-        /// </summary>
-        /// <returns>The equipment json data.</returns>
-        /// <param name="common">Common.</param>
-        /// <param name="isList">If set to <c>true</c> is list.</param>
-        /// 
-        /// <param name="commonType">
-        /// Commons鏄墍鏈夎澶囩殑鍩虹被锛屼絾鏄綋浼犺繃鏉ョ殑Common鏄疞ightDevice鏃讹紝LightDevice涓嶆槸鐪熸鐨勮澶囷紝
-        /// 鐪熸鐨勮澶囨槸瀹冧笅闈㈢殑璋冨厜鍣紙LightDimming锛夋垨鑰呯户鐢靛櫒.
-        /// 鎵�浠ommon.GetType()鑾峰彇涓嶅埌鐪熷疄鐨勮澶囩被鍨�
-        /// 鎵�浠ヨ繖閲岃鎵嬪姩浼犲叆璁惧鐨勭被鍨�
-        /// </param>
-        public static void ReadFunctionMessage(Function common)
-        {
-        }
-
-        /// <summary>
-        /// Saves the equipment message.
-        /// </summary>
-        public static void SaveFunctionMessage(Function common )
-        {
-           
         }
 
         /// <summary>
@@ -263,17 +236,14 @@
                 return false;
             }
 
-            System.IO.FileStream fs = null;
+            FileStream fs = null;
 
             try
             {
-                fs = new FileStream(System.IO.Path.Combine(RootPath, fileName), FileMode.Create, FileAccess.Write);
+                fs = new FileStream(Path.Combine(RootPath, fileName), FileMode.Create, FileAccess.Write);
                 fs.Write(bytes, 0, bytes.Length);
                 fs.Flush();
                 MainPage.Log("SaveFile:" + fileName);
-                //if (!UserConfig.Instance.LocalFiles.Contains (fileName)) {
-                //    UserConfig.Instance.LocalFiles.Add (fileName);
-                //}
                 return true;
             }
             catch (Exception ex)
@@ -304,13 +274,13 @@
         /// <param name="fileName">File name.</param>
         /// <param name="inputStream">Input stream.</param>
         /// <param name="isNeedRootPath">If set to <c>true</c> is need root path.</param>
-        public static bool WriteFileByInputStream(string fileName, System.IO.Stream inputStream)
+        public static bool WriteFileByInputStream(string fileName, Stream inputStream)
         {
             if (fileName == null || (fileName = fileName.Trim()) == (""))
             {
                 return false;
             }
-            System.IO.FileStream fs = null;
+            FileStream fs = null;
 
             try
             {
@@ -320,7 +290,7 @@
                 {
                     if (fs == null)
                     {
-                        fs = new FileStream(System.IO.Path.Combine(RootPath, fileName), FileMode.Create, FileAccess.Write);
+                        fs = new FileStream(Path.Combine(RootPath, fileName), FileMode.Create, FileAccess.Write);
                     }
                     fs.Write(buffer, 0, length);
                     fs.Flush();
@@ -362,14 +332,14 @@
             {
                 fileName = "Phone/" + fileName;
             }
-            System.IO.FileStream fs = null;
+            FileStream fs = null;
             try
             {
-                if (System.IO.File.Exists(System.IO.Path.Combine(RootPath, fileName)))
+                if (File.Exists(Path.Combine(RootPath, fileName)))
                 {
-                    fs = new FileStream(System.IO.Path.Combine(RootPath, fileName), FileMode.Open, FileAccess.Read);
+                    fs = new FileStream(Path.Combine(RootPath, fileName), FileMode.Open, FileAccess.Read);
                 }
-                else if (System.IO.File.Exists(fileName))
+                else if (File.Exists(fileName))
                 {
                     fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                 }
@@ -403,14 +373,14 @@
 
         public static byte[] ReadFile(string fileName)
         {
-            System.IO.FileStream fs = null;
+            FileStream fs = null;
             try
             {
-                if (System.IO.File.Exists(System.IO.Path.Combine(RootPath, fileName)))
+                if (File.Exists(Path.Combine(RootPath, fileName)))
                 {
-                    fs = new FileStream(System.IO.Path.Combine(RootPath, fileName), FileMode.Open, FileAccess.Read);
+                    fs = new FileStream(Path.Combine(RootPath, fileName), FileMode.Open, FileAccess.Read);
                 }
-                else if (System.IO.File.Exists(fileName))
+                else if (File.Exists(fileName))
                 {
                     fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                 }
@@ -459,21 +429,21 @@
             {
                 directioryPath = "Phone/" + "MusicImage";
             }
-            directioryPath = System.IO.Path.Combine(RootPath, directioryPath);
-            if (!System.IO.Directory.Exists(directioryPath))
+            directioryPath = Path.Combine(RootPath, directioryPath);
+            if (!Directory.Exists(directioryPath))
             {
-                System.IO.Directory.CreateDirectory(directioryPath);
+                Directory.CreateDirectory(directioryPath);
             }
             #endregion
 
-            if (!System.IO.File.Exists(fileName))
+            if (!File.Exists(fileName))
             {
                 System.Threading.Tasks.Task.Run(() =>
                 {
                     FileStream fs = null;
                     try
                     {
-                        HDL_ON.DAL.Net.MyWebClient webClient = new HDL_ON.DAL.Net.MyWebClient();
+                        MyWebClient webClient = new MyWebClient();
                         byte[] recevieBytes = webClient.DownloadData(new Uri(url));
                         fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                         fs.Write(recevieBytes, 0, recevieBytes.Length);
@@ -500,10 +470,10 @@
         {
             var url = "http://tingapi.ting.baidu.com/v1/restserver/ting?from=qianqian&version=2.1.0&method=baidu.ting.search.catalogSug&format=json&query=" + artist;
             string directioryPath = "MusicImage";
-            directioryPath = System.IO.Path.Combine(RootPath, directioryPath);
-            if (!System.IO.Directory.Exists(directioryPath))
+            directioryPath = Path.Combine(RootPath, directioryPath);
+            if (!Directory.Exists(directioryPath))
             {
-                System.IO.Directory.CreateDirectory(directioryPath);
+                Directory.CreateDirectory(directioryPath);
             }
             try
             {
@@ -517,7 +487,7 @@
                     if (tempAlbum.albumname == album && artist == tempAlbum.artistname)
                     {
                         var bytes = new HDL_ON.DAL.Net.MyWebClient().DownloadData(new Uri(tempAlbum.artistpic.Split('@')[0] + "@s_1,w_160,h_160"));
-                        var filePath = System.IO.Path.Combine(directioryPath, "AlbumArtistImage_" + album);
+                        var filePath = Path.Combine(directioryPath, "AlbumArtistImage_" + album);
                         var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
                         fs.Write(bytes, 0, bytes.Length);
                         fs.Flush();
@@ -531,7 +501,7 @@
                     if (artist == tempArtist.artistname)
                     {
                         var bytes = new HDL_ON.DAL.Net.MyWebClient().DownloadData(new Uri(tempArtist.artistpic.Split('@')[0] + "@s_1,w_160,h_160"));
-                        var filePath = System.IO.Path.Combine(directioryPath, "AlbumArtistImage_" + artist);
+                        var filePath = Path.Combine(directioryPath, "AlbumArtistImage_" + artist);
                         var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
                         fs.Write(bytes, 0, bytes.Length);
                         fs.Flush();

--
Gitblit v1.8.0