浏览代码

常规工具备份

yuzhengyang 9 年之前
父节点
当前提交
b960aa2932

+ 7 - 19
Fork.Net/Y.Controls/Loadings/SimpleLoading.Designer.cs

@@ -29,28 +29,18 @@
         private void InitializeComponent()
         {
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SimpleLoading));
-            this.PnMain = new System.Windows.Forms.Panel();
             this.pictureBox1 = new System.Windows.Forms.PictureBox();
-            this.PnMain.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
             this.SuspendLayout();
             // 
-            // PnMain
-            // 
-            this.PnMain.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(173)))), ((int)(((byte)(238)))));
-            this.PnMain.Controls.Add(this.pictureBox1);
-            this.PnMain.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.PnMain.Location = new System.Drawing.Point(0, 0);
-            this.PnMain.Name = "PnMain";
-            this.PnMain.Size = new System.Drawing.Size(643, 351);
-            this.PnMain.TabIndex = 1;
-            // 
             // pictureBox1
             // 
+            this.pictureBox1.BackColor = System.Drawing.Color.Transparent;
+            this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
             this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
-            this.pictureBox1.Location = new System.Drawing.Point(200, 71);
+            this.pictureBox1.Location = new System.Drawing.Point(0, 0);
             this.pictureBox1.Name = "pictureBox1";
-            this.pictureBox1.Size = new System.Drawing.Size(202, 163);
+            this.pictureBox1.Size = new System.Drawing.Size(208, 113);
             this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
             this.pictureBox1.TabIndex = 1;
             this.pictureBox1.TabStop = false;
@@ -59,19 +49,17 @@
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.Controls.Add(this.PnMain);
+            this.BackColor = System.Drawing.Color.Transparent;
+            this.Controls.Add(this.pictureBox1);
             this.Name = "SimpleLoading";
-            this.Size = new System.Drawing.Size(643, 351);
+            this.Size = new System.Drawing.Size(208, 113);
             this.Load += new System.EventHandler(this.SimpleLoading_Load);
-            this.PnMain.ResumeLayout(false);
             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
             this.ResumeLayout(false);
 
         }
 
         #endregion
-
-        private System.Windows.Forms.Panel PnMain;
         private System.Windows.Forms.PictureBox pictureBox1;
     }
 }

+ 7 - 23
Fork.Net/Y.Controls/Loadings/SimpleLoading.cs

@@ -12,8 +12,6 @@ namespace Y.Controls.Loadings
 {
     public partial class SimpleLoading : UserControl
     {
-        private int _opacity = 125;
-
         public SimpleLoading()
         {
             InitializeComponent();
@@ -21,31 +19,17 @@ namespace Y.Controls.Loadings
 
         private void SimpleLoading_Load(object sender, EventArgs e)
         {
-            
-        }
 
-        [Bindable(true), Category("Custom"), DefaultValue(125), Description("背景的透明度. 有效值0-255")]
-        public int Opacity
-        {
-            get { return _opacity; }
-            set
-            {
-                if (value > 255) value = 255;
-                else if (value < 0) value = 0;
-                _opacity = value;
-                this.Invalidate();
-            }
         }
-        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
+        public void ShowIt()
         {
-            if (this._opacity > 0)
-            {
-                e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(this._opacity, this.BackColor)),
-                                         this.ClientRectangle);
-            }
+            Dock = DockStyle.Fill;
+            Show();
         }
-        public void Show() {
-             
+        public void HideIt()
+        {
+            Dock = DockStyle.None;
+            Hide();
         }
     }
 }

Fork.Net/Y.Controls/Resource/Image/WelcomeLoading.gif → Fork.Net/Y.Controls/Resource/Image/SimpleLoading.gif


+ 1 - 1
Fork.Net/Y.Controls/Y.Controls.csproj

@@ -65,7 +65,7 @@
     </EmbeddedResource>
   </ItemGroup>
   <ItemGroup>
-    <Content Include="Resource\Image\WelcomeLoading.gif" />
+    <Content Include="Resource\Image\SimpleLoading.gif" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 

+ 19 - 0
Fork.Net/Y.Utils/ComputerUtils/ComputerPermissionTool.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Principal;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Y.Utils.ComputerUtils
+{
+    public class ComputerPermissionTool
+    {
+        public static bool IsAdministrator()
+        {
+            WindowsIdentity identity = WindowsIdentity.GetCurrent();
+            WindowsPrincipal principal = new WindowsPrincipal(identity);
+            return principal.IsInRole(WindowsBuiltInRole.Administrator);
+        }
+    }
+}

+ 37 - 0
Fork.Net/Y.Utils/ComputerUtils/ComputerTool.cs

@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Management;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Y.Utils.ComputerUtils
+{
+    public class ComputerTool
+    {
+        public static string GetCpuId()
+        {
+            try
+            {
+                //获取CPU序列号代码     
+                string cpuInfo = "";//cpu序列号     
+                ManagementClass mc = new ManagementClass("Win32_Processor");
+                ManagementObjectCollection moc = mc.GetInstances();
+                foreach (ManagementObject mo in moc)
+                {
+                    cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
+                }
+                moc = null;
+                mc = null;
+                return cpuInfo;
+            }
+            catch
+            {
+                return "unknow";
+            }
+            finally
+            {
+            }
+        }
+    }
+}

+ 63 - 0
Fork.Net/Y.Utils/ComputerUtils/RegisterTool.cs

@@ -0,0 +1,63 @@
+using Microsoft.Win32;
+using System;
+
+namespace Y.Utils.ComputerUtils
+{
+    public class RegisterTool
+    {
+        /// <summary>
+        /// 写入注册表项
+        /// </summary>
+        /// <param name="key">SOFTWARE\\NC_VideoConferenceSystem</param>
+        /// <param name="name">RegTime</param>
+        /// <param name="value">yyyy-MM-dd hh:mm:ss</param>
+        public static bool Write(string key, string name, string value)
+        {
+            try
+            {
+                RegistryKey RKey = Registry.LocalMachine.OpenSubKey(key, true);
+                if (RKey == null)
+                    RKey = Registry.LocalMachine.CreateSubKey(key);
+                RKey.SetValue(name, value);
+                return true;
+            }
+            catch (Exception e)
+            {
+                return false;
+            }
+        }
+        /// <summary>
+        /// 读取注册表项
+        /// </summary>
+        /// <param name="key">SOFTWARE\\NC_VideoConferenceSystem</param>
+        /// <param name="name">Path</param>
+        /// <returns></returns>
+        public static string Read(string key, string name)
+        {
+            try
+            {
+                RegistryKey RKey = Registry.LocalMachine.OpenSubKey(key, true);
+                if (RKey != null)
+                {
+                    return RKey.GetValue(name) != null ? RKey.GetValue(name).ToString() : "";
+                }
+            }
+            catch (Exception e) { }
+            return null;
+        }
+        public static bool Delete(string key, string name)
+        {
+            try
+            {
+                RegistryKey RKey = Registry.LocalMachine.OpenSubKey(key, true);
+                if (RKey != null)
+                    RKey.DeleteValue(name);
+                return true;
+            }
+            catch (Exception e)
+            {
+                return false;
+            }
+        }
+    }
+}

+ 2 - 0
Fork.Net/Y.Utils/ComputerUtils/WindowsAPI.cs

@@ -91,6 +91,8 @@ namespace Y.Utils.ComputerUtils
         /// <returns></returns>
         [DllImport("user32.dll")]
         public extern static int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
+        [DllImport("user32.dll")]
+        public static extern int GetWindowTextLength(IntPtr hWnd);
         #endregion
     }
 }

+ 25 - 0
Fork.Net/Y.Utils/FileUtils/FileTool.cs

@@ -54,5 +54,30 @@ namespace Y.Utils.FileUtils
                 return result;
             return null;
         }
+        public static bool Delete(string file)
+        {
+            try
+            {
+                if (File.Exists(file))
+                {
+                    File.Delete(file);
+                    return true;
+                }
+            }
+            catch { }
+            return false;
+        }
+        public static bool Delete(string[] files)
+        {
+            bool result = true;
+            if (!ListTool.IsNullOrEmpty(files))
+            {
+                foreach (var file in files)
+                {
+                    result = result || Delete(file);
+                }
+            }
+            return result;
+        }
     }
 }

+ 13 - 5
Fork.Net/Y.Utils/NetworkUtils/EmailHelper.cs

@@ -61,7 +61,7 @@ namespace Y.Utils.NetworkUtils
             }
         }
 
-        private string GetSmtp(string fromMail)
+        private static string GetSmtp(string fromMail)
         {
             string result = "";
             if (!string.IsNullOrWhiteSpace(fromMail) && fromMail.IndexOf('@') > 0)
@@ -69,10 +69,18 @@ namespace Y.Utils.NetworkUtils
                 string ext = fromMail.Substring(fromMail.IndexOf('@') + 1);
                 switch (ext)
                 {
-                    case "163.com": { result = "smtp.163.com"; break; }
-                    case "gmail.com": { result = "smtp.gmail.com"; break; }
-                    case "qq.com": { result = "smtp.qq.com"; break; }
-                    case "sina.com": { result = "smtp.sina.com"; break; }
+                    case "163.com":
+                        result = "smtp.163.com";
+                        break;
+                    case "gmail.com":
+                        result = "smtp.gmail.com";
+                        break;
+                    case "qq.com":
+                        result = "smtp.qq.com";
+                        break;
+                    case "sina.com":
+                        result = "smtp.sina.com";
+                        break;
                 }
             }
             return result;

+ 396 - 0
Fork.Net/Y.Utils/TxtUtils/IniTool.cs

@@ -0,0 +1,396 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Y.Utils.TxtUtils
+{
+    public class IniTool
+    {
+
+        #region INI文件操作  
+
+        /* 
+         * 针对INI文件的API操作方法,其中的节点(Section)、键(KEY)都不区分大小写 
+         * 如果指定的INI文件不存在,会自动创建该文件。 
+         *  
+         * CharSet定义的时候使用了什么类型,在使用相关方法时必须要使用相应的类型 
+         *      例如 GetPrivateProfileSectionNames声明为CharSet.Auto,那么就应该使用 Marshal.PtrToStringAuto来读取相关内容 
+         *      如果使用的是CharSet.Ansi,就应该使用Marshal.PtrToStringAnsi来读取内容 
+         *       
+         */
+
+        #region API声明  
+
+        /// <summary>  
+        /// 获取所有节点名称(Section)  
+        /// </summary>  
+        /// <param name="lpszReturnBuffer">存放节点名称的内存地址,每个节点之间用\0分隔</param>  
+        /// <param name="nSize">内存大小(characters)</param>  
+        /// <param name="lpFileName">Ini文件</param>  
+        /// <returns>内容的实际长度,为0表示没有内容,为nSize-2表示内存大小不够</returns>  
+        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
+        private static extern uint GetPrivateProfileSectionNames(IntPtr lpszReturnBuffer, uint nSize, string lpFileName);
+
+        /// <summary>  
+        /// 获取某个指定节点(Section)中所有KEY和Value  
+        /// </summary>  
+        /// <param name="lpAppName">节点名称</param>  
+        /// <param name="lpReturnedString">返回值的内存地址,每个之间用\0分隔</param>  
+        /// <param name="nSize">内存大小(characters)</param>  
+        /// <param name="lpFileName">Ini文件</param>  
+        /// <returns>内容的实际长度,为0表示没有内容,为nSize-2表示内存大小不够</returns>  
+        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
+        private static extern uint GetPrivateProfileSection(string lpAppName, IntPtr lpReturnedString, uint nSize, string lpFileName);
+
+        /// <summary>  
+        /// 读取INI文件中指定的Key的值  
+        /// </summary>  
+        /// <param name="lpAppName">节点名称。如果为null,则读取INI中所有节点名称,每个节点名称之间用\0分隔</param>  
+        /// <param name="lpKeyName">Key名称。如果为null,则读取INI中指定节点中的所有KEY,每个KEY之间用\0分隔</param>  
+        /// <param name="lpDefault">读取失败时的默认值</param>  
+        /// <param name="lpReturnedString">读取的内容缓冲区,读取之后,多余的地方使用\0填充</param>  
+        /// <param name="nSize">内容缓冲区的长度</param>  
+        /// <param name="lpFileName">INI文件名</param>  
+        /// <returns>实际读取到的长度</returns>  
+        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
+        private static extern uint GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, [In, Out] char[] lpReturnedString, uint nSize, string lpFileName);
+
+        //另一种声明方式,使用 StringBuilder 作为缓冲区类型的缺点是不能接受\0字符,会将\0及其后的字符截断,  
+        //所以对于lpAppName或lpKeyName为null的情况就不适用  
+        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
+        private static extern uint GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, uint nSize, string lpFileName);
+
+        //再一种声明,使用string作为缓冲区的类型同char[]  
+        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
+        private static extern uint GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, string lpReturnedString, uint nSize, string lpFileName);
+
+        /// <summary>  
+        /// 将指定的键值对写到指定的节点,如果已经存在则替换。  
+        /// </summary>  
+        /// <param name="lpAppName">节点,如果不存在此节点,则创建此节点</param>  
+        /// <param name="lpString">Item键值对,多个用\0分隔,形如key1=value1\0key2=value2  
+        /// <para>如果为string.Empty,则删除指定节点下的所有内容,保留节点</para>  
+        /// <para>如果为null,则删除指定节点下的所有内容,并且删除该节点</para>  
+        /// </param>  
+        /// <param name="lpFileName">INI文件</param>  
+        /// <returns>是否成功写入</returns>  
+        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
+        [return: MarshalAs(UnmanagedType.Bool)]     //可以没有此行  
+        private static extern bool WritePrivateProfileSection(string lpAppName, string lpString, string lpFileName);
+
+        /// <summary>  
+        /// 将指定的键和值写到指定的节点,如果已经存在则替换  
+        /// </summary>  
+        /// <param name="lpAppName">节点名称</param>  
+        /// <param name="lpKeyName">键名称。如果为null,则删除指定的节点及其所有的项目</param>  
+        /// <param name="lpString">值内容。如果为null,则删除指定节点中指定的键。</param>  
+        /// <param name="lpFileName">INI文件</param>  
+        /// <returns>操作是否成功</returns>  
+        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
+        [return: MarshalAs(UnmanagedType.Bool)]
+        private static extern bool WritePrivateProfileString(string lpAppName, string lpKeyName, string lpString, string lpFileName);
+
+        #endregion
+
+        #region 封装  
+
+        /// <summary>  
+        /// 读取INI文件中指定INI文件中的所有节点名称(Section)  
+        /// </summary>  
+        /// <param name="iniFile">Ini文件</param>  
+        /// <returns>所有节点,没有内容返回string[0]</returns>  
+        public static string[] GetAllSectionNames(string iniFile)
+        {
+            uint MAX_BUFFER = 32767;    //默认为32767  
+
+            string[] sections = new string[0];      //返回值  
+
+            //申请内存  
+            IntPtr pReturnedString = Marshal.AllocCoTaskMem((int)MAX_BUFFER * sizeof(char));
+            uint bytesReturned = GetPrivateProfileSectionNames(pReturnedString, MAX_BUFFER, iniFile);
+            if (bytesReturned != 0)
+            {
+                //读取指定内存的内容  
+                string local = Marshal.PtrToStringAuto(pReturnedString, (int)bytesReturned).ToString();
+
+                //每个节点之间用\0分隔,末尾有一个\0  
+                sections = local.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
+            }
+
+            //释放内存  
+            Marshal.FreeCoTaskMem(pReturnedString);
+
+            return sections;
+        }
+
+        /// <summary>  
+        /// 获取INI文件中指定节点(Section)中的所有条目(key=value形式)  
+        /// </summary>  
+        /// <param name="iniFile">Ini文件</param>  
+        /// <param name="section">节点名称</param>  
+        /// <returns>指定节点中的所有项目,没有内容返回string[0]</returns>  
+        public static string[] GetAllItems(string iniFile, string section)
+        {
+            //返回值形式为 key=value,例如 Color=Red  
+            uint MAX_BUFFER = 32767;    //默认为32767  
+
+            string[] items = new string[0];      //返回值  
+
+            //分配内存  
+            IntPtr pReturnedString = Marshal.AllocCoTaskMem((int)MAX_BUFFER * sizeof(char));
+
+            uint bytesReturned = GetPrivateProfileSection(section, pReturnedString, MAX_BUFFER, iniFile);
+
+            if (!(bytesReturned == MAX_BUFFER - 2) || (bytesReturned == 0))
+            {
+
+                string returnedString = Marshal.PtrToStringAuto(pReturnedString, (int)bytesReturned);
+                items = returnedString.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
+            }
+
+            Marshal.FreeCoTaskMem(pReturnedString);     //释放内存  
+
+            return items;
+        }
+
+        /// <summary>  
+        /// 获取INI文件中指定节点(Section)中的所有条目的Key列表  
+        /// </summary>  
+        /// <param name="iniFile">Ini文件</param>  
+        /// <param name="section">节点名称</param>  
+        /// <returns>如果没有内容,反回string[0]</returns>  
+        public static string[] GetAllItemKeys(string iniFile, string section)
+        {
+            string[] value = new string[0];
+            const int SIZE = 1024 * 10;
+
+            if (string.IsNullOrEmpty(section))
+            {
+                throw new ArgumentException("必须指定节点名称", "section");
+            }
+
+            char[] chars = new char[SIZE];
+            uint bytesReturned = GetPrivateProfileString(section, null, null, chars, SIZE, iniFile);
+
+            if (bytesReturned != 0)
+            {
+                value = new string(chars).Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
+            }
+            chars = null;
+
+            return value;
+        }
+
+        /// <summary>  
+        /// 读取INI文件中指定KEY的字符串型值  
+        /// </summary>  
+        /// <param name="iniFile">Ini文件</param>  
+        /// <param name="section">节点名称</param>  
+        /// <param name="key">键名称</param>  
+        /// <param name="defaultValue">如果没此KEY所使用的默认值</param>  
+        /// <returns>读取到的值</returns>  
+        public static string GetStringValue(string iniFile, string section, string key, string defaultValue)
+        {
+            string value = defaultValue;
+            const int SIZE = 1024 * 10;
+
+            if (string.IsNullOrEmpty(section))
+            {
+                throw new ArgumentException("必须指定节点名称", "section");
+            }
+
+            if (string.IsNullOrEmpty(key))
+            {
+                throw new ArgumentException("必须指定键名称(key)", "key");
+            }
+
+            StringBuilder sb = new StringBuilder(SIZE);
+            uint bytesReturned = GetPrivateProfileString(section, key, defaultValue, sb, SIZE, iniFile);
+
+            if (bytesReturned != 0)
+            {
+                value = sb.ToString();
+            }
+            sb = null;
+
+            return value;
+        }
+
+        /// <summary>  
+        /// 在INI文件中,将指定的键值对写到指定的节点,如果已经存在则替换  
+        /// </summary>  
+        /// <param name="iniFile">INI文件</param>  
+        /// <param name="section">节点,如果不存在此节点,则创建此节点</param>  
+        /// <param name="items">键值对,多个用\0分隔,形如key1=value1\0key2=value2</param>  
+        /// <returns></returns>  
+        public static bool WriteItems(string iniFile, string section, string items)
+        {
+            if (string.IsNullOrEmpty(section))
+            {
+                throw new ArgumentException("必须指定节点名称", "section");
+            }
+
+            if (string.IsNullOrEmpty(items))
+            {
+                throw new ArgumentException("必须指定键值对", "items");
+            }
+
+            return WritePrivateProfileSection(section, items, iniFile);
+        }
+
+        /// <summary>  
+        /// 在INI文件中,指定节点写入指定的键及值。如果已经存在,则替换。如果没有则创建。  
+        /// </summary>  
+        /// <param name="iniFile">INI文件</param>  
+        /// <param name="section">节点</param>  
+        /// <param name="key">键</param>  
+        /// <param name="value">值</param>  
+        /// <returns>操作是否成功</returns>  
+        public static bool WriteValue(string iniFile, string section, string key, string value)
+        {
+            if (string.IsNullOrEmpty(section))
+            {
+                throw new ArgumentException("必须指定节点名称", "section");
+            }
+
+            if (string.IsNullOrEmpty(key))
+            {
+                throw new ArgumentException("必须指定键名称", "key");
+            }
+
+            if (value == null)
+            {
+                throw new ArgumentException("值不能为null", "value");
+            }
+
+            return WritePrivateProfileString(section, key, value, iniFile);
+
+        }
+
+        /// <summary>  
+        /// 在INI文件中,删除指定节点中的指定的键。  
+        /// </summary>  
+        /// <param name="iniFile">INI文件</param>  
+        /// <param name="section">节点</param>  
+        /// <param name="key">键</param>  
+        /// <returns>操作是否成功</returns>  
+        public static bool DeleteKey(string iniFile, string section, string key)
+        {
+            if (string.IsNullOrEmpty(section))
+            {
+                throw new ArgumentException("必须指定节点名称", "section");
+            }
+
+            if (string.IsNullOrEmpty(key))
+            {
+                throw new ArgumentException("必须指定键名称", "key");
+            }
+
+            return WritePrivateProfileString(section, key, null, iniFile);
+        }
+
+        /// <summary>  
+        /// 在INI文件中,删除指定的节点。  
+        /// </summary>  
+        /// <param name="iniFile">INI文件</param>  
+        /// <param name="section">节点</param>  
+        /// <returns>操作是否成功</returns>  
+        public static bool DeleteSection(string iniFile, string section)
+        {
+            if (string.IsNullOrEmpty(section))
+            {
+                throw new ArgumentException("必须指定节点名称", "section");
+            }
+
+            return WritePrivateProfileString(section, null, null, iniFile);
+        }
+
+        /// <summary>  
+        /// 在INI文件中,删除指定节点中的所有内容。  
+        /// </summary>  
+        /// <param name="iniFile">INI文件</param>  
+        /// <param name="section">节点</param>  
+        /// <returns>操作是否成功</returns>  
+        public static bool EmptySection(string iniFile, string section)
+        {
+            if (string.IsNullOrEmpty(section))
+            {
+                throw new ArgumentException("必须指定节点名称", "section");
+            }
+
+            return WritePrivateProfileSection(section, string.Empty, iniFile);
+        }
+
+        /// <summary>
+        /// 测试
+        /// </summary>
+        private void Test()
+        {
+
+            string file = "F:\\TestIni.ini";
+
+            //写入/更新键值  
+            WriteValue(file, "Desktop", "Color", "Red");
+            WriteValue(file, "Desktop", "Width", "3270");
+
+            WriteValue(file, "Toolbar", "Items", "Save,Delete,Open");
+            WriteValue(file, "Toolbar", "Dock", "True");
+
+            //写入一批键值  
+            WriteItems(file, "Menu", "File=文件\0View=视图\0Edit=编辑");
+
+            //获取文件中所有的节点  
+            string[] sections = GetAllSectionNames(file);
+
+            //获取指定节点中的所有项  
+            string[] items = GetAllItems(file, "Menu");
+
+            //获取指定节点中所有的键  
+            string[] keys = GetAllItemKeys(file, "Menu");
+
+            //获取指定KEY的值  
+            string value = GetStringValue(file, "Desktop", "color", null);
+
+            //删除指定的KEY  
+            DeleteKey(file, "desktop", "color");
+
+            //删除指定的节点  
+            DeleteSection(file, "desktop");
+
+            //清空指定的节点  
+            EmptySection(file, "toolbar");
+
+        }
+
+        /// <summary>
+        /// 扩展:插入布尔类型数据
+        /// </summary>
+        /// <param name="iniFile"></param>
+        /// <param name="section"></param>
+        /// <param name="key"></param>
+        /// <param name="value"></param>
+        /// <returns></returns>
+        public static bool WriteValue(string iniFile, string section, string key, bool value)
+        {
+            return WriteValue(iniFile, section, key, value ? "true" : "false");
+        }
+        /// <summary>
+        /// 扩展:读取布尔类型数据
+        /// </summary>
+        /// <param name="iniFile"></param>
+        /// <param name="section"></param>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        public static bool GetBoolValue(string iniFile, string section, string key)
+        {
+            string flag = GetStringValue(iniFile, section, key, "");
+            return flag == "true" ? true : false;
+        }
+        #endregion
+
+        #endregion
+    }
+}

+ 4 - 0
Fork.Net/Y.Utils/TxtUtils/TxtTool.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.IO;
 using System.Text;
 using Y.Utils.BaseUtils;
+using Y.Utils.FileUtils;
 
 namespace Y.Utils.TxtUtils
 {
@@ -12,6 +13,7 @@ namespace Y.Utils.TxtUtils
         {
             try
             {
+                DirTool.Create(Path.GetDirectoryName(file));
                 using (StreamWriter sw = new StreamWriter(file, true))
                 {
                     if (!ListTool.IsNullOrEmpty(txt))
@@ -27,6 +29,7 @@ namespace Y.Utils.TxtUtils
         {
             try
             {
+                DirTool.Create(Path.GetDirectoryName(file));
                 using (StreamWriter sw = new StreamWriter(file, true))
                 {
                     sw.WriteLine(txt);
@@ -40,6 +43,7 @@ namespace Y.Utils.TxtUtils
         {
             try
             {
+                DirTool.Create(Path.GetDirectoryName(file));
                 using (StreamWriter sw = new StreamWriter(file, false, Encoding.UTF8))
                 {
                     sw.WriteLine(txt);

+ 8 - 1
Fork.Net/Y.Utils/Y.Utils.csproj

@@ -9,8 +9,9 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Y.Utils</RootNamespace>
     <AssemblyName>Y.Utils</AssemblyName>
-    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
+    <TargetFrameworkProfile />
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
@@ -40,6 +41,8 @@
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Drawing" />
+    <Reference Include="System.Management" />
+    <Reference Include="System.Windows.Forms" />
     <Reference Include="System.Xml.Linq" />
     <Reference Include="System.Data.DataSetExtensions" />
     <Reference Include="Microsoft.CSharp" />
@@ -49,6 +52,9 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="BaseUtils\Class1.cs" />
+    <Compile Include="ComputerUtils\ComputerTool.cs" />
+    <Compile Include="ComputerUtils\ComputerPermissionTool.cs" />
+    <Compile Include="ComputerUtils\RegisterTool.cs" />
     <Compile Include="ImageUtils\BarCodeToHTML.cs" />
     <Compile Include="ComputerUtils\IPHelper.cs" />
     <Compile Include="FileUtils\FileCodeHelper.cs" />
@@ -71,6 +77,7 @@
     <Compile Include="FileUtils\FileTool.cs" />
     <Compile Include="BaseUtils\ListTool.cs" />
     <Compile Include="JsonUtils\JsonTool.cs" />
+    <Compile Include="TxtUtils\IniTool.cs" />
     <Compile Include="TxtUtils\LogTool.cs" />
     <Compile Include="TxtUtils\TxtTool.cs" />
     <Compile Include="BaseUtils\UnixTimeTool.cs" />