old mode 100755
new mode 100644
| | |
| | | using System; |
| | | using System.IO; |
| | | using System.Collections.Generic; |
| | | using System.Threading; |
| | | |
| | | namespace Shared.IO |
| | | { |
| | |
| | | { |
| | | foreach (var fileName in ReadRegionFiles (path)) { |
| | | System.IO.File.Delete (System.IO.Path.Combine (path, fileName)); |
| | | Console.WriteLine ("Del region file :" + fileName); |
| | | Utlis.WriteLine ("Del region file :" + fileName); |
| | | } |
| | | } |
| | | |
| | |
| | | System.IO.FileInfo fileInfo = new System.IO.FileInfo (regionRootPath + NextFile.Name); |
| | | if (fileInfo.Exists) { |
| | | fileInfo.MoveTo (Application.RootPath + NextFile.Name); |
| | | Console.WriteLine ("Restroe : "+ NextFile.Name); |
| | | Utlis.WriteLine ("Restroe : "+ NextFile.Name); |
| | | } |
| | | Application.RunOnMainThread (() => { |
| | | int pro = (int)(index * 1.0 / folderCount * 50) + 50; |
| | |
| | | #if DEBUG |
| | | DirectoryInfo root = new DirectoryInfo (RootPath); |
| | | foreach (DirectoryInfo d in root.GetDirectories ()) { |
| | | Console.WriteLine ("文件夹:" + d.Name); |
| | | Utlis.WriteLine ("文件夹:" + d.Name); |
| | | } |
| | | #endif |
| | | if (System.IO.Directory.Exists (srcPath)) { |
| | |
| | | List<string> listFiles = new List<string> (); |
| | | DirectoryInfo TheFolder = new DirectoryInfo (path); |
| | | foreach (FileInfo NextFile in TheFolder.GetFiles ()) { |
| | | Console.WriteLine (NextFile.Name); |
| | | Utlis.WriteLine (NextFile.Name); |
| | | } |
| | | #endif |
| | | } |
| | | |
| | | #if DEBUG |
| | | foreach (DirectoryInfo d in root.GetDirectories ()) { |
| | | Console.WriteLine ("文件夹:" + d.Name); |
| | | Utlis.WriteLine ("文件夹:" + d.Name); |
| | | } |
| | | #endif |
| | | } |
| | |
| | | /// <param name="filePath">File path.</param> |
| | | public static bool Exists (string filePath) |
| | | { |
| | | //System.Console.WriteLine ("Exists==" + System.IO.Path.Combine (RootPath, filePath)); |
| | | //Utlis.WriteLine ("Exists==" + System.IO.Path.Combine (RootPath, filePath)); |
| | | return System.IO.File.Exists (System.IO.Path.Combine (RootPath, filePath)); |
| | | } |
| | | |
| | |
| | | /// <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)); |
| | | Console.WriteLine ("删除文件名为:" + fileName); |
| | | Utlis.WriteLine ("删除文件名为:" + fileName); |
| | | //if (UserConfig.Instance.LocalFiles.Contains (fileName)) { |
| | | // UserConfig.Instance.LocalFiles.Remove (fileName); |
| | | //} |
| | |
| | | DeleteFile (f); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除所有回路设备数据 |
| | | /// </summary> |
| | | public static void DeleteAllCommon () { |
| | | //找出需要显示的设备 |
| | | var filesList = ReadFiles ().FindAll ((obj) => { |
| | | string [] str = obj.Split ('_'); |
| | | return obj.StartsWith ("Equipment_") && str.Length == 5; |
| | | }); |
| | | |
| | | for (int j = 0; j < filesList.Count; j++) { |
| | | var f = filesList [j]; |
| | | DeleteFile (f); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Reads the equipment message. |
| | |
| | | fileName += "_" + (loopID.Length < 2 ? "0" + loopID : loopID); |
| | | } |
| | | common.SavePath = fileName; |
| | | Console.WriteLine (fileName); |
| | | Utlis.WriteLine (fileName); |
| | | 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> |
| | | /// 增加 读写锁,当资源处于写入模式时,其他线程写入需要等待本次写入结束之后才能继续写入 |
| | | /// 用于解决多线程环境写入文件问题 |
| | | /// </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; |
| | |
| | | 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 (); |
| | | Console.WriteLine ("SaveFile:" + fileName); |
| | | //Utlis.WriteLine ("SaveFile:" + fileName + " : " + bytes.Length.ToString()); |
| | | //if (!UserConfig.Instance.LocalFiles.Contains (fileName)) { |
| | | // UserConfig.Instance.LocalFiles.Add (fileName); |
| | | //} |
| | | return true; |
| | | } catch (Exception ex) { |
| | | Console.WriteLine ("FileUtiles Code 113:" + ex.ToString ()); |
| | | 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) { |
| | | Console.WriteLine ("FileUtils Code 121 :" + ex.ToString ()); |
| | | Utlis.WriteLine ("FileUtils Code 121 :" + ex.ToString ()); |
| | | } |
| | | } |
| | | } |