浏览代码

修改Log工具类的构造方法(以前的设置可以一次性通过构造方法生成),文件备份功能还在继续开发中。

yuzhengyang 8 年之前
父节点
当前提交
265a5b7b99

+ 10 - 0
Fork.Net/Oreo.Plugins/Oreo.FileMan/Commons/R.cs

@@ -37,5 +37,15 @@ namespace Oreo.FileMan.Commons
         {
             public static FileBackupService FBS = new FileBackupService();
         }
+
+        public static class Settings
+        {
+            public static class FileBackup
+            {
+                public static string FileManBackup = @"D:\temp\FileManBackup\";//文件备份目录
+                public static int BACK_UP_INTERVAL = 5 * 1000;//备份文件间隔
+                public static int BACK_UP_COUNT = 5;//备份文件版本个数
+            }
+        }
     }
 }

+ 10 - 1
Fork.Net/Oreo.Plugins/Oreo.FileMan/Oreo.FileMan.csproj

@@ -26,7 +26,7 @@
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
-    <UseVSHostingProcess>false</UseVSHostingProcess>
+    <UseVSHostingProcess>true</UseVSHostingProcess>
     <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
@@ -126,6 +126,12 @@
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Services\FileBackupService.cs" />
+    <Compile Include="Views\FileRestoreForm.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Views\FileRestoreForm.Designer.cs">
+      <DependentUpon>FileRestoreForm.cs</DependentUpon>
+    </Compile>
     <Compile Include="Views\MainForm.cs">
       <SubType>Form</SubType>
     </Compile>
@@ -160,6 +166,9 @@
       <DependentUpon>Resources.resx</DependentUpon>
       <DesignTime>True</DesignTime>
     </Compile>
+    <EmbeddedResource Include="Views\FileRestoreForm.resx">
+      <DependentUpon>FileRestoreForm.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="Views\MainForm.resx">
       <DependentUpon>MainForm.cs</DependentUpon>
     </EmbeddedResource>

+ 96 - 26
Fork.Net/Oreo.Plugins/Oreo.FileMan/Partials/FileBackupPartial.Designer.cs

@@ -28,17 +28,26 @@
         /// </summary>
         private void InitializeComponent()
         {
+            this.components = new System.ComponentModel.Container();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
             this.DgvPath = new System.Windows.Forms.DataGridView();
             this.DgvPathName = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.DgvPathSize = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.BtAddPath = new System.Windows.Forms.Button();
             this.DgvFile = new System.Windows.Forms.DataGridView();
+            this.BtDelPath = new System.Windows.Forms.Button();
+            this.TmReadPaths = new System.Windows.Forms.Timer(this.components);
+            this.LbStatus = new System.Windows.Forms.Label();
+            this.TmStatus = new System.Windows.Forms.Timer(this.components);
             this.DgvFileName = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.DgvFilePath = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.DgvFileSize = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.DgvFileVersionHistory = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.DgvFileLastBackupTime = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.BtDelPath = new System.Windows.Forms.Button();
+            this.DgvFilePath = new System.Windows.Forms.DataGridViewTextBoxColumn();
             ((System.ComponentModel.ISupportInitialize)(this.DgvPath)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.DgvFile)).BeginInit();
             this.SuspendLayout();
@@ -47,18 +56,33 @@
             // 
             this.DgvPath.AllowUserToAddRows = false;
             this.DgvPath.AllowUserToDeleteRows = false;
+            this.DgvPath.AllowUserToResizeColumns = false;
+            this.DgvPath.AllowUserToResizeRows = false;
+            this.DgvPath.BackgroundColor = System.Drawing.Color.White;
             this.DgvPath.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
             this.DgvPath.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
             this.DgvPathName,
             this.DgvPathSize});
-            this.DgvPath.Location = new System.Drawing.Point(7, 38);
+            dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
+            dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Window;
+            dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.ControlText;
+            dataGridViewCellStyle1.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0);
+            dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.GradientActiveCaption;
+            dataGridViewCellStyle1.SelectionForeColor = System.Drawing.Color.Black;
+            dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
+            this.DgvPath.DefaultCellStyle = dataGridViewCellStyle1;
+            this.DgvPath.GridColor = System.Drawing.Color.Silver;
+            this.DgvPath.Location = new System.Drawing.Point(3, 32);
             this.DgvPath.Name = "DgvPath";
             this.DgvPath.ReadOnly = true;
             this.DgvPath.RowHeadersVisible = false;
+            this.DgvPath.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing;
             this.DgvPath.RowTemplate.Height = 23;
-            this.DgvPath.Size = new System.Drawing.Size(214, 275);
+            this.DgvPath.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
+            this.DgvPath.Size = new System.Drawing.Size(191, 291);
             this.DgvPath.TabIndex = 0;
-            this.DgvPath.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DgvPath_CellDoubleClick);
+            this.DgvPath.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DgvPath_CellClick);
             // 
             // DgvPathName
             // 
@@ -78,7 +102,7 @@
             // 
             // BtAddPath
             // 
-            this.BtAddPath.Location = new System.Drawing.Point(7, 6);
+            this.BtAddPath.Location = new System.Drawing.Point(3, 3);
             this.BtAddPath.Name = "BtAddPath";
             this.BtAddPath.Size = new System.Drawing.Size(75, 23);
             this.BtAddPath.TabIndex = 1;
@@ -90,21 +114,67 @@
             // 
             this.DgvFile.AllowUserToAddRows = false;
             this.DgvFile.AllowUserToDeleteRows = false;
+            this.DgvFile.AllowUserToResizeColumns = false;
+            this.DgvFile.AllowUserToResizeRows = false;
+            this.DgvFile.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
+            this.DgvFile.BackgroundColor = System.Drawing.Color.White;
             this.DgvFile.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
             this.DgvFile.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
             this.DgvFileName,
-            this.DgvFilePath,
             this.DgvFileSize,
             this.DgvFileVersionHistory,
-            this.DgvFileLastBackupTime});
-            this.DgvFile.Location = new System.Drawing.Point(252, 38);
+            this.DgvFileLastBackupTime,
+            this.DgvFilePath});
+            dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
+            dataGridViewCellStyle5.BackColor = System.Drawing.SystemColors.Window;
+            dataGridViewCellStyle5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            dataGridViewCellStyle5.ForeColor = System.Drawing.SystemColors.ControlText;
+            dataGridViewCellStyle5.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0);
+            dataGridViewCellStyle5.SelectionBackColor = System.Drawing.SystemColors.GradientActiveCaption;
+            dataGridViewCellStyle5.SelectionForeColor = System.Drawing.Color.Black;
+            dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
+            this.DgvFile.DefaultCellStyle = dataGridViewCellStyle5;
+            this.DgvFile.GridColor = System.Drawing.Color.Silver;
+            this.DgvFile.Location = new System.Drawing.Point(200, 32);
             this.DgvFile.Name = "DgvFile";
             this.DgvFile.ReadOnly = true;
             this.DgvFile.RowHeadersVisible = false;
+            this.DgvFile.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing;
             this.DgvFile.RowTemplate.Height = 23;
-            this.DgvFile.Size = new System.Drawing.Size(385, 275);
+            this.DgvFile.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
+            this.DgvFile.Size = new System.Drawing.Size(443, 291);
             this.DgvFile.TabIndex = 2;
             // 
+            // BtDelPath
+            // 
+            this.BtDelPath.Location = new System.Drawing.Point(119, 3);
+            this.BtDelPath.Name = "BtDelPath";
+            this.BtDelPath.Size = new System.Drawing.Size(75, 23);
+            this.BtDelPath.TabIndex = 6;
+            this.BtDelPath.Text = "删除目录";
+            this.BtDelPath.UseVisualStyleBackColor = true;
+            this.BtDelPath.Click += new System.EventHandler(this.BtDelPath_Click);
+            // 
+            // TmReadPaths
+            // 
+            this.TmReadPaths.Interval = 1000;
+            this.TmReadPaths.Tick += new System.EventHandler(this.TmReadPaths_Tick);
+            // 
+            // LbStatus
+            // 
+            this.LbStatus.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.LbStatus.Location = new System.Drawing.Point(365, 6);
+            this.LbStatus.Name = "LbStatus";
+            this.LbStatus.Size = new System.Drawing.Size(266, 16);
+            this.LbStatus.TabIndex = 7;
+            this.LbStatus.Text = "文件备份已开启:已备份 - 个文件";
+            this.LbStatus.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
+            // 
+            // TmStatus
+            // 
+            this.TmStatus.Interval = 1000;
+            this.TmStatus.Tick += new System.EventHandler(this.TmStatus_Tick);
+            // 
             // DgvFileName
             // 
             this.DgvFileName.HeaderText = "文件名";
@@ -112,15 +182,10 @@
             this.DgvFileName.ReadOnly = true;
             this.DgvFileName.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
             // 
-            // DgvFilePath
-            // 
-            this.DgvFilePath.HeaderText = "路径";
-            this.DgvFilePath.Name = "DgvFilePath";
-            this.DgvFilePath.ReadOnly = true;
-            this.DgvFilePath.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
-            // 
             // DgvFileSize
             // 
+            dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
+            this.DgvFileSize.DefaultCellStyle = dataGridViewCellStyle2;
             this.DgvFileSize.HeaderText = "大小";
             this.DgvFileSize.Name = "DgvFileSize";
             this.DgvFileSize.ReadOnly = true;
@@ -128,6 +193,8 @@
             // 
             // DgvFileVersionHistory
             // 
+            dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            this.DgvFileVersionHistory.DefaultCellStyle = dataGridViewCellStyle3;
             this.DgvFileVersionHistory.HeaderText = "历史版本";
             this.DgvFileVersionHistory.Name = "DgvFileVersionHistory";
             this.DgvFileVersionHistory.ReadOnly = true;
@@ -135,26 +202,26 @@
             // 
             // DgvFileLastBackupTime
             // 
+            dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
+            this.DgvFileLastBackupTime.DefaultCellStyle = dataGridViewCellStyle4;
             this.DgvFileLastBackupTime.HeaderText = "最后备份时间";
             this.DgvFileLastBackupTime.Name = "DgvFileLastBackupTime";
             this.DgvFileLastBackupTime.ReadOnly = true;
             this.DgvFileLastBackupTime.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
             // 
-            // BtDelPath
+            // DgvFilePath
             // 
-            this.BtDelPath.Location = new System.Drawing.Point(99, 6);
-            this.BtDelPath.Name = "BtDelPath";
-            this.BtDelPath.Size = new System.Drawing.Size(75, 23);
-            this.BtDelPath.TabIndex = 6;
-            this.BtDelPath.Text = "删除目录";
-            this.BtDelPath.UseVisualStyleBackColor = true;
-            this.BtDelPath.Click += new System.EventHandler(this.BtDelPath_Click);
+            this.DgvFilePath.HeaderText = "路径";
+            this.DgvFilePath.Name = "DgvFilePath";
+            this.DgvFilePath.ReadOnly = true;
+            this.DgvFilePath.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
             // 
             // FileBackupPartial
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.BackColor = System.Drawing.Color.White;
+            this.Controls.Add(this.LbStatus);
             this.Controls.Add(this.BtDelPath);
             this.Controls.Add(this.DgvFile);
             this.Controls.Add(this.BtAddPath);
@@ -176,10 +243,13 @@
         private System.Windows.Forms.Button BtDelPath;
         private System.Windows.Forms.DataGridViewTextBoxColumn DgvPathName;
         private System.Windows.Forms.DataGridViewTextBoxColumn DgvPathSize;
+        private System.Windows.Forms.Timer TmReadPaths;
+        private System.Windows.Forms.Label LbStatus;
+        private System.Windows.Forms.Timer TmStatus;
         private System.Windows.Forms.DataGridViewTextBoxColumn DgvFileName;
-        private System.Windows.Forms.DataGridViewTextBoxColumn DgvFilePath;
         private System.Windows.Forms.DataGridViewTextBoxColumn DgvFileSize;
         private System.Windows.Forms.DataGridViewTextBoxColumn DgvFileVersionHistory;
         private System.Windows.Forms.DataGridViewTextBoxColumn DgvFileLastBackupTime;
+        private System.Windows.Forms.DataGridViewTextBoxColumn DgvFilePath;
     }
 }

+ 103 - 32
Fork.Net/Oreo.Plugins/Oreo.FileMan/Partials/FileBackupPartial.cs

@@ -30,15 +30,12 @@ namespace Oreo.FileMan.Partials
         }
         private void FileBackupPartial_Load(object sender, EventArgs e)
         {
-            if (ListTool.HasElements(R.Services.FBS.Paths))
-            {
-                foreach (var p in R.Services.FBS.Paths)
-                {
-                    UIDgvPathAdd(DirTool.GetPathName(p.Path));
-                }
-            }
+            UIEnableButton(false);
+            TmReadPaths.Enabled = true;
+            TmStatus.Enabled = true;
         }
 
+        #region Event
         private void BtAddPath_Click(object sender, EventArgs e)
         {
             FolderBrowserDialog dialog = new FolderBrowserDialog();
@@ -66,24 +63,12 @@ namespace Oreo.FileMan.Partials
                         {
                             if (!db.Do<BackupPaths>().Any(x => x.Path == path))
                             {
-                                int row = DgvPath.Rows.Count;//当前目录列表总数 
                                 BackupPaths bp = new BackupPaths() { Path = path, Alias = Guid.NewGuid().ToString() };
                                 if (db.Add(bp) > 0)
                                 {
                                     R.Services.FBS.Paths.Add(bp);//添加到列表
                                     R.Services.FBS.AddToWatcherPath(bp.Path);//添加到监听
-                                    UIDgvPathAdd(name);//添加到列表UI
-
-                                    long size = 0;//目录下的文件大小
-                                    List<string> files = FileTool.GetAllFile(path);
-                                    if (ListTool.HasElements(files))
-                                    {
-                                        foreach (var f in files)
-                                        {
-                                            size += FileTool.Size(f);
-                                            UIDgvPathUpdate(row, name, ByteConvertTool.Fmt(size));//更新目录文件大小
-                                        }
-                                    }
+                                    UIDgvPathAdd(name, null);//添加到列表UI
                                 }
                             }
                         }
@@ -110,29 +95,110 @@ namespace Oreo.FileMan.Partials
                 }
             }
         }
-        private void DgvPath_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
+        private void DgvPath_CellClick(object sender, DataGridViewCellEventArgs e)
         {
-            if (e.RowIndex >= 0)
+            ShowFileDetails(e.RowIndex);
+        }
+        /// <summary>
+        /// 读取备份文件目录
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void TmReadPaths_Tick(object sender, EventArgs e)
+        {
+            if (R.Services.FBS.StatusOfReadBackupPaths)
             {
-                string path = R.Services.FBS.Paths[e.RowIndex].Path;
+                TmReadPaths.Enabled = false;
+                Task.Factory.StartNew(() =>
+                {
+                    if (ListTool.HasElements(R.Services.FBS.Paths))
+                    {
+                        foreach (var p in R.Services.FBS.Paths)
+                        {
+                            using (var db = new Muse())
+                            {
+                                long size = db.Do<BackupFiles>().Where(x => x.FullPath.Contains(p.Path)).Sum(x => x.Size);
+                                string name = DirTool.GetPathName(p.Path);//获取目录名称
+                                UIDgvPathAdd(name, ByteConvertTool.Fmt(size));//添加到列表UI
+                            }
+                        }
+                    }
+                    UIEnableButton(true);
+                });
+            }
+        }
+        private void TmStatus_Tick(object sender, EventArgs e)
+        {
+            LbStatus.Text = R.Services.FBS.IsStart ?
+                string.Format("文件备份已开启:已备份 {0} 个文件", R.Services.FBS.FileCount) : "文件监控已关闭";
+            LbStatus.ForeColor = R.Services.FBS.IsStart ? Color.Green : Color.Red;
+        }
+        #endregion
+
+        #region Function
+        void ShowFileDetails(int row)
+        {
+            if (row >= 0)
+            {
+                string path = R.Services.FBS.Paths[row].Path;
                 UIEnableButton(false);
                 DgvFile.Rows.Clear();
                 Task.Factory.StartNew(() =>
                 {
-                    List<string> files = FileTool.GetAllFile(path);
-                    if (ListTool.HasElements(files))
+                    using (var db = new Muse())
                     {
-                        foreach (var file in files)
+                        db.Context.Database.Log = (sql) =>
                         {
-                            UIDgvFileAdd(Path.GetFileName(file), file, FileTool.SizeFormat(file));
+                            R.Log.i(sql);
+                        };
+                        try
+                        {
+                            var result = db.Do<BackupFiles>().
+                                Where(x => x.FullPath.Contains(path)).
+                                GroupBy(x => new { x.FullPath }).
+                                Select(x => new
+                                {
+                                    Path = x.Max(o => o.FullPath),
+                                    BackPath = x.Max(o => o.BackupFullPath),
+                                    Count = x.Count(),
+                                    Time = x.Max(o => o.LastWriteTime),
+                                }).ToList();
+
+                            if (ListTool.HasElements(result))
+                            {
+                                foreach (var item in result)
+                                {
+                                    //BackupFiles bkfile = bkfiles.FirstOrDefault(x => x.FullPath == file);
+                                    //int versioncount = bkfiles.Count(x => x.FullPath == file);
+                                    //string lastwritetime = bkfile != null ? bkfile.LastWriteTime : "-";
+                                    string versiondesc = "第 " + item.Count + " 版";
+                                    UIDgvFileAdd(Path.GetFileName(item.Path), item.Path, FileTool.SizeFormat(item.BackPath), versiondesc, item.Time);
+                                }
+                            }
                         }
+                        catch (Exception e) { }
+
+                        //List<BackupFiles> bkfiles = db.Gets<BackupFiles>(x => x.FullPath.Contains(path), null).ToList();
+                        //List<string> files = FileTool.GetAllFile(path);
+                        //if (ListTool.HasElements(files))
+                        //{
+                        //    foreach (var file in files)
+                        //    {
+                        //        BackupFiles bkfile = bkfiles.FirstOrDefault(x => x.FullPath == file);
+                        //        int versioncount = bkfiles.Count(x => x.FullPath == file);
+                        //        string versiondesc = "第 " + versioncount + " 版";
+                        //        string lastwritetime = bkfile != null ? bkfile.LastWriteTime : "-";
+                        //        UIDgvFileAdd(Path.GetFileName(file), file, FileTool.SizeFormat(file), versiondesc, lastwritetime);
+                        //    }
+                        //}
                     }
                     UIEnableButton(true);
                 });
             }
         }
+        #endregion
 
-
+        #region UI
         /// <summary>
         /// 停用或启用所有按钮
         /// </summary>
@@ -142,17 +208,18 @@ namespace Oreo.FileMan.Partials
             BeginInvoke(new Action(() =>
             {
                 BtAddPath.Enabled = enable;
+                BtDelPath.Enabled = enable;
             }));
         }
         /// <summary>
         /// 添加到路径列表
         /// </summary>
         /// <param name="path"></param>
-        void UIDgvPathAdd(string name)
+        void UIDgvPathAdd(string name, string size)
         {
             BeginInvoke(new Action(() =>
             {
-                DgvPath.Rows.Add(new object[] { name, "-" });
+                DgvPath.Rows.Add(new object[] { name, size ?? "-" });
             }));
         }
         /// <summary>
@@ -184,12 +251,16 @@ namespace Oreo.FileMan.Partials
         /// <param name="file"></param>
         /// <param name="path"></param>
         /// <param name="size"></param>
-        void UIDgvFileAdd(string file, string path, string size)
+        void UIDgvFileAdd(string file, string path, string size, string version, string lasttime)
         {
             BeginInvoke(new Action(() =>
             {
-                DgvFile.Rows.Add(new object[] { file, path, size });
+                DgvFile.Rows.Add(new object[] { file, size, version, lasttime, path });
+                DgvFile.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
             }));
         }
+        #endregion
+
+
     }
 }

+ 9 - 3
Fork.Net/Oreo.Plugins/Oreo.FileMan/Partials/FileBackupPartial.resx

@@ -126,9 +126,6 @@
   <metadata name="DgvFileName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
-  <metadata name="DgvFilePath.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
   <metadata name="DgvFileSize.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
@@ -138,4 +135,13 @@
   <metadata name="DgvFileLastBackupTime.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
+  <metadata name="DgvFilePath.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="TmReadPaths.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
+  <metadata name="TmStatus.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>149, 17</value>
+  </metadata>
 </root>

+ 4 - 4
Fork.Net/Oreo.Plugins/Oreo.FileMan/Partials/FileTypePartial.cs

@@ -56,13 +56,13 @@ namespace Oreo.FileMan.Partials
             {
                 while (!IsDisposed)
                 {
-                    GetFileToDatabase2();
+                    GetFileToDatabase();
                     GetTypeFileCount();
                     Thread.Sleep(GetFileToDatabaseInterval);
                 }
             });
         }
-        private void GetFileToDatabase2()
+        private void GetFileToDatabase()
         {
             var drives = FileQueryEngine.GetReadyNtfsDrives().OrderBy(x => x.Name);
             if (ListTool.HasElements(drives))
@@ -70,7 +70,7 @@ namespace Oreo.FileMan.Partials
                 foreach (var drive in drives)
                 {
                     NewFileCount = 0;
-                    if (!drive.Name.Contains("E")) continue;//测试只读取D盘
+                    if (!drive.Name.Contains("J")) continue;//测试只读取D盘
                     //if (drive.Name.Contains("D")) continue;//测试时跳过D盘
                     //if (drive.Name.Contains("F")) continue;//测试时跳过F盘
 
@@ -94,7 +94,7 @@ namespace Oreo.FileMan.Partials
                             }
                         }
 
-                        //查询上次读取到的位置
+                        //查询上次读取到的位置(最后一条记录)
                         ulong filenumber = 0;
                         long usn = 0;
                         if (db.Any<UsnFiles>(x => x.Drive == drive.Name, null))

+ 6 - 0
Fork.Net/Oreo.Plugins/Oreo.FileMan/Program.cs

@@ -6,6 +6,7 @@ using System.Linq;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 using Y.Utils.AppUtils;
+using Y.Utils.IOUtils.LogUtils;
 
 namespace Oreo.FileMan
 {
@@ -19,7 +20,12 @@ namespace Oreo.FileMan
         {
             if (AppUnique.IsUnique("Oreo.FileMan"))
             {
+                R.Log = new Log(true, "Oreo.FileMan.Log");
+                Log.AllocConsole();
+
                 R.Services.FBS.Start();
+
+                R.Log.i("App is Runing...");
                 Application.EnableVisualStyles();
                 Application.SetCompatibleTextRenderingDefault(false);
                 Application.Run(new MainForm());

+ 28 - 12
Fork.Net/Oreo.Plugins/Oreo.FileMan/Services/FileBackupService.cs

@@ -1,4 +1,5 @@
-using Oreo.FileMan.DatabaseEngine;
+using Oreo.FileMan.Commons;
+using Oreo.FileMan.DatabaseEngine;
 using Oreo.FileMan.Models;
 using System;
 using System.Collections.Generic;
@@ -16,14 +17,15 @@ namespace Oreo.FileMan.Services
 {
     public class FileBackupService
     {
-        private FileWatcher Watcher = new FileWatcher(null);
-        public string FileManBackup = @"D:\temp\FileManBackup\";
-        public List<BackupPaths> Paths = new List<BackupPaths>();
+        public List<BackupPaths> Paths = new List<BackupPaths>();//要备份的文件夹
+        private FileWatcher Watcher = new FileWatcher(null);//文件监视器
+        private List<string> BackupFiles = new List<string>();//当前要备份的文件任务
 
-        List<string> BackupFiles = new List<string>();
-        int BACK_UP_INTERVAL = 5 * 1000;
-        int BACK_UP_COUNT = 5;
-        bool IsStart = false;
+        public bool IsStart = false;
+        public bool StatusOfReadBackupPaths = false;
+
+        public int FileCount { get { return _FileCount; } }
+        private int _FileCount = 0;
 
         public void Start()
         {
@@ -36,7 +38,9 @@ namespace Oreo.FileMan.Services
 
                 Task.Factory.StartNew(() =>
                 {
+                    ReadBackupFileCount();//读取备份文件总数
                     ReadBackupPaths();//读取备份文件夹列表
+                    StatusOfReadBackupPaths = true;
 
                     if (ListTool.HasElements(Paths))
                     {
@@ -96,21 +100,33 @@ namespace Oreo.FileMan.Services
                                 string pathalias = path.Alias;
                                 string pathfile = t.Substring(pathname.Length, t.Length - pathname.Length);
                                 string fileext = DateTimeConvert.CompactString(DateTime.Now);
-                                string fullpath = DirTool.Combine(FileManBackup, pathalias, pathfile + "." + fileext);
+                                string fullpath = DirTool.Combine(R.Settings.FileBackup.FileManBackup, pathalias, pathfile + "." + fileext);
 
                                 //删除冗余
                                 DeleteExcess(t);
                                 //备份文件
                                 BackupFile(t, fullpath);
+                                _FileCount++;
                             }
                         }
                     }
                 }
-                Thread.Sleep(BACK_UP_INTERVAL);
+                Thread.Sleep(R.Settings.FileBackup.BACK_UP_INTERVAL);
             }
         }
 
         /// <summary>
+        /// 读取备份文件总数
+        /// </summary>
+        private void ReadBackupFileCount()
+        {
+            //统计备份文件总数
+            using (var db = new Muse())
+            {
+                _FileCount = db.Do<BackupFiles>().Count();
+            }
+        }
+        /// <summary>
         /// 读取备份文件夹列表
         /// </summary>
         private void ReadBackupPaths()
@@ -187,12 +203,12 @@ namespace Oreo.FileMan.Services
             using (var db = new Muse())
             {
                 int count = db.Do<BackupFiles>().Count(x => x.FullPath == path);
-                if (count >= BACK_UP_COUNT)
+                if (count >= R.Settings.FileBackup.BACK_UP_COUNT)
                 {
                     var fs = db.Gets<BackupFiles>(x => x.FullPath == path, null).OrderBy(x => x.Id).ToList();
                     if (ListTool.HasElements(fs))
                     {
-                        for (int i = 0; i <= count - BACK_UP_COUNT; i++)
+                        for (int i = 0; i <= count - R.Settings.FileBackup.BACK_UP_COUNT; i++)
                         {
                             try
                             {

+ 109 - 0
Fork.Net/Oreo.Plugins/Oreo.FileMan/Views/FileRestoreForm.Designer.cs

@@ -0,0 +1,109 @@
+namespace Oreo.FileMan.Views
+{
+    partial class FileRestoreForm
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.BtClose = new System.Windows.Forms.Button();
+            this.DgvFiles = new System.Windows.Forms.DataGridView();
+            this.DgvFilesLastWriteTime = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.DgvFilesSize = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            ((System.ComponentModel.ISupportInitialize)(this.DgvFiles)).BeginInit();
+            this.SuspendLayout();
+            // 
+            // BtClose
+            // 
+            this.BtClose.FlatAppearance.BorderSize = 0;
+            this.BtClose.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
+            this.BtClose.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.BtClose.ForeColor = System.Drawing.Color.White;
+            this.BtClose.Location = new System.Drawing.Point(379, 12);
+            this.BtClose.Name = "BtClose";
+            this.BtClose.Size = new System.Drawing.Size(30, 23);
+            this.BtClose.TabIndex = 20;
+            this.BtClose.Text = "X";
+            this.BtClose.UseVisualStyleBackColor = true;
+            this.BtClose.Click += new System.EventHandler(this.BtClose_Click);
+            // 
+            // DgvFiles
+            // 
+            this.DgvFiles.AllowUserToAddRows = false;
+            this.DgvFiles.AllowUserToDeleteRows = false;
+            this.DgvFiles.AllowUserToResizeColumns = false;
+            this.DgvFiles.AllowUserToResizeRows = false;
+            this.DgvFiles.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
+            this.DgvFiles.BackgroundColor = System.Drawing.Color.White;
+            this.DgvFiles.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+            this.DgvFiles.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+            this.DgvFilesLastWriteTime,
+            this.DgvFilesSize});
+            this.DgvFiles.GridColor = System.Drawing.Color.Silver;
+            this.DgvFiles.Location = new System.Drawing.Point(36, 54);
+            this.DgvFiles.Name = "DgvFiles";
+            this.DgvFiles.ReadOnly = true;
+            this.DgvFiles.RowHeadersVisible = false;
+            this.DgvFiles.RowTemplate.Height = 23;
+            this.DgvFiles.Size = new System.Drawing.Size(352, 150);
+            this.DgvFiles.TabIndex = 21;
+            // 
+            // DgvFilesLastWriteTime
+            // 
+            this.DgvFilesLastWriteTime.HeaderText = "最后修改时间";
+            this.DgvFilesLastWriteTime.Name = "DgvFilesLastWriteTime";
+            this.DgvFilesLastWriteTime.ReadOnly = true;
+            // 
+            // DgvFilesSize
+            // 
+            this.DgvFilesSize.HeaderText = "文件大小";
+            this.DgvFilesSize.Name = "DgvFilesSize";
+            this.DgvFilesSize.ReadOnly = true;
+            // 
+            // FileRestoreForm
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(34)))), ((int)(((byte)(43)))), ((int)(((byte)(54)))));
+            this.ClientSize = new System.Drawing.Size(421, 282);
+            this.Controls.Add(this.DgvFiles);
+            this.Controls.Add(this.BtClose);
+            this.Name = "FileRestoreForm";
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
+            this.Text = "FileRestoreForm";
+            this.Load += new System.EventHandler(this.FileRestoreForm_Load);
+            ((System.ComponentModel.ISupportInitialize)(this.DgvFiles)).EndInit();
+            this.ResumeLayout(false);
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Button BtClose;
+        private System.Windows.Forms.DataGridView DgvFiles;
+        private System.Windows.Forms.DataGridViewTextBoxColumn DgvFilesLastWriteTime;
+        private System.Windows.Forms.DataGridViewTextBoxColumn DgvFilesSize;
+    }
+}

+ 31 - 0
Fork.Net/Oreo.Plugins/Oreo.FileMan/Views/FileRestoreForm.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using Y.Skin.YoForm.NoTitle;
+
+namespace Oreo.FileMan.Views
+{
+    public partial class FileRestoreForm : NoTitleForm
+    {
+        public FileRestoreForm()
+        {
+            InitializeComponent();
+        }
+
+        private void FileRestoreForm_Load(object sender, EventArgs e)
+        {
+
+        }
+
+        private void BtClose_Click(object sender, EventArgs e)
+        {
+            Close();
+        }
+    }
+}

+ 126 - 0
Fork.Net/Oreo.Plugins/Oreo.FileMan/Views/FileRestoreForm.resx

@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <metadata name="DgvFilesLastWriteTime.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="DgvFilesSize.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+</root>

+ 22 - 0
Fork.Net/Oreo.Plugins/Oreo.FileMan/Views/SettingsForm.Designer.cs

@@ -32,6 +32,7 @@
             this.button1 = new System.Windows.Forms.Button();
             this.label1 = new System.Windows.Forms.Label();
             this.label2 = new System.Windows.Forms.Label();
+            this.BtClose = new System.Windows.Forms.Button();
             this.SuspendLayout();
             // 
             // textBox1
@@ -53,6 +54,7 @@
             // label1
             // 
             this.label1.AutoSize = true;
+            this.label1.ForeColor = System.Drawing.Color.White;
             this.label1.Location = new System.Drawing.Point(24, 90);
             this.label1.Name = "label1";
             this.label1.Size = new System.Drawing.Size(41, 12);
@@ -62,23 +64,42 @@
             // label2
             // 
             this.label2.AutoSize = true;
+            this.label2.ForeColor = System.Drawing.Color.White;
             this.label2.Location = new System.Drawing.Point(26, 133);
             this.label2.Name = "label2";
             this.label2.Size = new System.Drawing.Size(41, 12);
             this.label2.TabIndex = 7;
             this.label2.Text = "label2";
             // 
+            // BtClose
+            // 
+            this.BtClose.FlatAppearance.BorderSize = 0;
+            this.BtClose.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
+            this.BtClose.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.BtClose.ForeColor = System.Drawing.Color.White;
+            this.BtClose.Location = new System.Drawing.Point(298, 12);
+            this.BtClose.Name = "BtClose";
+            this.BtClose.Size = new System.Drawing.Size(30, 23);
+            this.BtClose.TabIndex = 20;
+            this.BtClose.Text = "X";
+            this.BtClose.UseVisualStyleBackColor = true;
+            this.BtClose.Click += new System.EventHandler(this.BtClose_Click);
+            // 
             // SettingsForm
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(34)))), ((int)(((byte)(43)))), ((int)(((byte)(54)))));
             this.ClientSize = new System.Drawing.Size(340, 274);
+            this.Controls.Add(this.BtClose);
             this.Controls.Add(this.label2);
             this.Controls.Add(this.label1);
             this.Controls.Add(this.button1);
             this.Controls.Add(this.textBox1);
             this.Name = "SettingsForm";
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
             this.Text = "SettingsForm";
+            this.Load += new System.EventHandler(this.SettingsForm_Load);
             this.ResumeLayout(false);
             this.PerformLayout();
 
@@ -90,5 +111,6 @@
         private System.Windows.Forms.Button button1;
         private System.Windows.Forms.Label label1;
         private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.Button BtClose;
     }
 }

+ 10 - 0
Fork.Net/Oreo.Plugins/Oreo.FileMan/Views/SettingsForm.cs

@@ -17,5 +17,15 @@ namespace Oreo.FileMan.Views
         {
             InitializeComponent();
         }
+
+        private void SettingsForm_Load(object sender, EventArgs e)
+        {
+
+        }
+
+        private void BtClose_Click(object sender, EventArgs e)
+        {
+            Close();
+        }
     }
 }

+ 23 - 8
Fork.Net/Y.Utils/IOUtils/LogUtils/Log.cs

@@ -1,7 +1,10 @@
-//############################################################
+//************************************************************************
 //      https://github.com/yuzhengyang
-//      author:yuzhengyang
-//############################################################
+//      author:     yuzhengyang
+//      date:       2017.3.29 - 2017.7.6
+//      desc:       日志功能
+//      Copyright (c) yuzhengyang. All rights reserved.
+//************************************************************************
 
 //R.Log.IsWriteFile = true;
 //R.Log.LogLevel = LogLevel.Warning | LogLevel.Debug;
@@ -30,15 +33,27 @@ namespace Y.Utils.IOUtils.LogUtils
     public class Log
     {
         //输出的 Log 格式
-        const string LogFormat = "{0}  {1}  {2}";
-        const string TimeFormat = "HH:mm:ss.fff";
+        const string LOG_FORMAT = "{0}  {1}  {2}";
+        const string TIME_FORMAT = "HH:mm:ss.fff";
+        const string LOG_PATH = "Log";
 
         private object LogFileLock = new object();//写日志文件锁
 
         private bool IsWriteFile = false;//是否写日志文件
-        public string LogPath = "Log";
+        public string LogPath = LOG_PATH;
         public LogLevel LogLevel = LogLevel.All;//日志输出等级
 
+        public Log()
+        { }
+        public Log(bool isWrite, string logPath = LOG_PATH, LogLevel level = LogLevel.All)
+        {
+            if (isWrite && !string.IsNullOrWhiteSpace(logPath))
+            {
+                LogPath = logPath.Trim();
+                IsWriteFile = true;
+                LogLevel = level;
+            }
+        }
         public bool SetWriteFile(bool isWrite, string logPath)
         {
             if (isWrite && !string.IsNullOrWhiteSpace(logPath))
@@ -85,7 +100,7 @@ namespace Y.Utils.IOUtils.LogUtils
         private void Write(LogType type, string message)
         {
             Console.ForegroundColor = GetColor(type);
-            Console.WriteLine(LogFormat, DateTime.Now.ToString(TimeFormat), type.ToString(), message);
+            Console.WriteLine(LOG_FORMAT, DateTime.Now.ToString(TIME_FORMAT), type.ToString(), message);
             if (IsWriteFile) WriteFile(type, message);
         }
 
@@ -101,7 +116,7 @@ namespace Y.Utils.IOUtils.LogUtils
                     //创建日志目录
                     DirTool.Create(logPath);
                     //写出日志
-                    TxtTool.Append(file, string.Format(LogFormat, DateTime.Now.ToString(TimeFormat), type.ToString(), message));
+                    TxtTool.Append(file, string.Format(LOG_FORMAT, DateTime.Now.ToString(TIME_FORMAT), type.ToString(), message));
                 }
             }
         }