ソースを参照

更新工具(日期、计算机API、文件处理、Json处理、Ini配置文件处理、文本处理)

yuzhengyang 9 年 前
コミット
96ee32eabd

+ 7 - 0
Fork.Net/Y.Utils/BaseUtils/DateTimeTool.cs

@@ -19,5 +19,12 @@ namespace Y.Utils.BaseUtils
             DateTime result = new DateTime(today.Year, today.Month, today.Day);
             DateTime result = new DateTime(today.Year, today.Month, today.Day);
             return result;
             return result;
         }
         }
+        public static Tuple<int, int> ToMS(double second)
+        {
+            int Minute = 0, Second = 0;
+            Minute = (int)second / 60;
+            Second = (int)second % 60;
+            return new Tuple<int, int>(Minute, Second);
+        }
     }
     }
 }
 }

+ 9 - 8
Fork.Net/Y.Utils/ComputerUtils/ComputerTool.cs

@@ -11,19 +11,18 @@ namespace Y.Utils.ComputerUtils
     {
     {
         public static string GetCpuId()
         public static string GetCpuId()
         {
         {
+            ManagementClass mc = null;
+            ManagementObjectCollection moc = null;
+            string ProcessorId = "";
             try
             try
             {
             {
-                //获取CPU序列号代码     
-                string cpuInfo = "";//cpu序列号     
-                ManagementClass mc = new ManagementClass("Win32_Processor");
-                ManagementObjectCollection moc = mc.GetInstances();
+                mc = new ManagementClass("Win32_Processor");
+                moc = mc.GetInstances();
                 foreach (ManagementObject mo in moc)
                 foreach (ManagementObject mo in moc)
                 {
                 {
-                    cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
+                    ProcessorId = mo.Properties["ProcessorId"].Value.ToString();
                 }
                 }
-                moc = null;
-                mc = null;
-                return cpuInfo;
+                return ProcessorId;
             }
             }
             catch
             catch
             {
             {
@@ -31,6 +30,8 @@ namespace Y.Utils.ComputerUtils
             }
             }
             finally
             finally
             {
             {
+                if (moc != null) moc.Dispose();
+                if (mc != null) mc.Dispose();
             }
             }
         }
         }
     }
     }

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

@@ -63,6 +63,10 @@ namespace Y.Utils.FileUtils
                     File.Delete(file);
                     File.Delete(file);
                     return true;
                     return true;
                 }
                 }
+                else
+                {
+                    return true;
+                }
             }
             }
             catch { }
             catch { }
             return false;
             return false;

+ 9 - 0
Fork.Net/Y.Utils/JsonUtils/JsonTool.cs

@@ -19,6 +19,15 @@ namespace Y.Utils.JsonUtils
             }
             }
             return null;
             return null;
         }
         }
+        public static T ToObjFromStr<T>(string str)
+        {
+            string json = str;
+            if (!string.IsNullOrWhiteSpace(json))
+            {
+                try { return JsonConvert.DeserializeObject<T>(json); } catch (Exception e) { }
+            }
+            return default(T);
+        }
         public static T ToObjFromFile<T>(string file)
         public static T ToObjFromFile<T>(string file)
         {
         {
             string json = TxtTool.Read(file);
             string json = TxtTool.Read(file);

+ 1 - 1
Fork.Net/Y.Utils/TxtUtils/IniTool.cs

@@ -387,7 +387,7 @@ namespace Y.Utils.TxtUtils
         public static bool GetBoolValue(string iniFile, string section, string key)
         public static bool GetBoolValue(string iniFile, string section, string key)
         {
         {
             string flag = GetStringValue(iniFile, section, key, "");
             string flag = GetStringValue(iniFile, section, key, "");
-            return flag == "true" ? true : false;
+            return flag.ToLower() == "true" ? true : false;
         }
         }
         #endregion
         #endregion
 
 

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

@@ -68,5 +68,21 @@ namespace Y.Utils.TxtUtils
             catch (Exception e) { }
             catch (Exception e) { }
             return null;
             return null;
         }
         }
+        public static List<string> ReadLine(string file)
+        {
+            try
+            {
+                using (StreamReader sr = new StreamReader(file, Encoding.UTF8))
+                {
+                    List<string> result = new List<string>();
+                    string line;
+                    while ((line = sr.ReadLine()) != null)
+                        result.Add(line.ToString());
+                    return result;
+                }
+            }
+            catch (Exception e) { }
+            return null;
+        }
     }
     }
 }
 }