From 488efb508eb0648773fe7b68e810e04bcd7ca075 Mon Sep 17 00:00:00 2001 From: wei <kaede@kaededeMacBook-Air.local> Date: 星期五, 11 十二月 2020 15:58:15 +0800 Subject: [PATCH] 20201211 --- HDL_ON/Common/FileUtlis.cs | 205 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 196 insertions(+), 9 deletions(-) diff --git a/HDL_ON/Common/FileUtlis.cs b/HDL_ON/Common/FileUtlis.cs index 013e023..60198fe 100644 --- a/HDL_ON/Common/FileUtlis.cs +++ b/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.CurReginID); + 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(UserInfo.Current.CurReginID )) { - regionPath = Path.Combine(RootPath, DB_ResidenceData.residenceData.CurReginID); + regionPath = Path.Combine(AccountPath, UserInfo.Current.CurReginID); if (!Directory.Exists(regionPath)) { Directory.CreateDirectory(regionPath); @@ -42,15 +58,15 @@ return regionPath + "/"; } } + + /// <summary> - /// 鐢ㄦ埛淇℃伅璺緞 + /// 鏂囦欢鏄惁瀛樺湪 /// </summary> - string userInfoPath + /// <param name="filePath">File path.</param> + public bool Exists(string filePath) { - get - { - return "UserInfo_File"; - } + return File.Exists(Path.Combine(Files.RootPath, filePath)); } /// <summary> @@ -133,6 +149,177 @@ } } } + /// <summary> + /// 璇诲彇userInfo鏂囦欢 + /// </summary> + /// <returns></returns> + public byte[] ReadUserInfo() + { + var fileName = "UserInfo_File"; + 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 WirteUserinfo(byte[] bytes) + { + var fileName = "UserInfo_File"; + 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; + } + 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(AccountPath, fileName))) + { + fs = new FileStream(Path.Combine(AccountPath, 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(AccountPath, fileName), FileMode.Create, FileAccess.Write); + fs.Write(bytes, 0, bytes.Length); + fs.Flush(); + MainPage.Log("SaveFile:" + fileName); + 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()); + } + } + } + + public byte[] ReadFile(string fileName) { -- Gitblit v1.8.0