wei
2020-12-17 bb6ad792b598927a5459a5fb6f6c27fb1aa9e94e
HDL_ON/Common/FileUtlis.cs
@@ -5,7 +5,7 @@
namespace HDL_ON.Common
{
    public class FileUtlis
    public  class FileUtlis
    {
        static Common.FileUtlis _temp;
        public static Common.FileUtlis Files
@@ -23,6 +23,22 @@
        /// 根目录
        /// </summary>
        string RootPath = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "/";
        string accountPath;
        string AccountPath {
            get
            {
                if (string.IsNullOrEmpty(accountPath) || !accountPath.Contains(UserInfo.Current.ID))
                {
                    accountPath = Path.Combine(RootPath, UserInfo.Current.ID);
                    if (!Directory.Exists(accountPath))
                    {
                        Directory.CreateDirectory(accountPath);
                    }
                }
                return accountPath + "/";
            }
        }
        /// <summary>
        /// 住宅文件夹路径
        /// </summary>
@@ -31,9 +47,9 @@
        {
            get
            {
                if (string.IsNullOrEmpty(regionPath))
                if (string.IsNullOrEmpty(regionPath) || !regionPath.Contains(DB_ResidenceData.Instance.CurrentRegion.RegionID ))
                {
                    regionPath = Path.Combine(RootPath, DB_ResidenceData.residenceData.CurReginID);
                    regionPath = Path.Combine(AccountPath, DB_ResidenceData.Instance.CurrentRegion.RegionID);
                    if (!Directory.Exists(regionPath))
                    {
                        Directory.CreateDirectory(regionPath);
@@ -42,16 +58,9 @@
                return regionPath + "/";
            }
        }
        /// <summary>
        /// 用户信息路径
        /// </summary>
        string userInfoPath
        {
            get
            {
                return "UserInfo_File";
            }
        }
        //public List<>
        /// <summary>
        /// 遍历文件
@@ -110,6 +119,90 @@
                fs = new FileStream(Path.Combine(RegionPath, fileName), FileMode.Create, FileAccess.Write);
                fs.Write(bytes, 0, bytes.Length);
                fs.Flush();
                MainPage.Log($"SaveFile:{fileName}");//Path:{RegionPath}
                return true;
            }
            catch (Exception ex)
            {
                MainPage.Log("FileUtiles Code 113:" + ex.ToString());
                return false;
            }
            finally
            {
                try
                {
                    if (fs != null)
                    {
                        fs.Close();
                    }
                }
                catch (Exception ex)
                {
                    MainPage.Log("FileUtils Code 121 :" + ex.ToString());
                }
            }
        }
        /// <summary>
        /// 读取userInfo文件
        /// </summary>
        /// <returns></returns>
        public byte[] ReadAppConfig()
        {
            var fileName = "OnAppConfig";
            FileStream fs = null;
            try
            {
                if (File.Exists(Path.Combine(RootPath, fileName)))
                {
                    fs = new FileStream(Path.Combine(RootPath, fileName), FileMode.Open, FileAccess.Read);
                }
                else if (File.Exists(fileName))
                {
                    fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                }
                else
                {
                    return new byte[0];
                }
                byte[] bytes = new byte[fs.Length];
                fs.Read(bytes, 0, bytes.Length);
                return bytes;
            }
            catch
            {
                return new byte[0];
            }
            finally
            {
                try
                {
                    if (fs != null)
                    {
                        fs.Close();
                    }
                }
                catch
                {
                }
            }
        }
        /// <summary>
        /// 保存userInfo
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public bool WirteAppConfig(byte[] bytes)
        {
            var fileName = "OnAppConfig";
            FileStream fs = null;
            try
            {
                fs = new FileStream(Path.Combine(RootPath, fileName), FileMode.Create, FileAccess.Write);
                fs.Write(bytes, 0, bytes.Length);
                fs.Flush();
                MainPage.Log("SaveFile:" + fileName);
                return true;
            }
@@ -134,6 +227,8 @@
            }
        }
        public byte[] ReadFile(string fileName)
        {
            FileStream fs = null;