diff --git a/Ini.Net.sln b/Ini.Net.sln index 46b29e3..9a32853 100644 --- a/Ini.Net.sln +++ b/Ini.Net.sln @@ -1,28 +1,37 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Express 2013 for Windows Desktop -VisualStudioVersion = 12.0.30723.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ini.Net", "src\Ini.Net\Ini.Net.csproj", "{109977DF-DDCB-4CB8-B658-51DF6DA2842C}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ini.Net.Tests", "test\Ini.Net.Tests\Ini.Net.Tests.csproj", "{B99D6813-2B82-4EB3-B043-BFCDDCBB745B}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {109977DF-DDCB-4CB8-B658-51DF6DA2842C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {109977DF-DDCB-4CB8-B658-51DF6DA2842C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {109977DF-DDCB-4CB8-B658-51DF6DA2842C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {109977DF-DDCB-4CB8-B658-51DF6DA2842C}.Release|Any CPU.Build.0 = Release|Any CPU - {B99D6813-2B82-4EB3-B043-BFCDDCBB745B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B99D6813-2B82-4EB3-B043-BFCDDCBB745B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B99D6813-2B82-4EB3-B043-BFCDDCBB745B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B99D6813-2B82-4EB3-B043-BFCDDCBB745B}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30011.22 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ini.Net", "src\Ini.Net\Ini.Net.csproj", "{109977DF-DDCB-4CB8-B658-51DF6DA2842C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ini.Net.Tests", "test\Ini.Net.Tests\Ini.Net.Tests.csproj", "{B99D6813-2B82-4EB3-B043-BFCDDCBB745B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{2D7766BC-9287-4DB6-BE11-8E19C4F72416}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {109977DF-DDCB-4CB8-B658-51DF6DA2842C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {109977DF-DDCB-4CB8-B658-51DF6DA2842C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {109977DF-DDCB-4CB8-B658-51DF6DA2842C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {109977DF-DDCB-4CB8-B658-51DF6DA2842C}.Release|Any CPU.Build.0 = Release|Any CPU + {B99D6813-2B82-4EB3-B043-BFCDDCBB745B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B99D6813-2B82-4EB3-B043-BFCDDCBB745B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B99D6813-2B82-4EB3-B043-BFCDDCBB745B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B99D6813-2B82-4EB3-B043-BFCDDCBB745B}.Release|Any CPU.Build.0 = Release|Any CPU + {2D7766BC-9287-4DB6-BE11-8E19C4F72416}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2D7766BC-9287-4DB6-BE11-8E19C4F72416}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2D7766BC-9287-4DB6-BE11-8E19C4F72416}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2D7766BC-9287-4DB6-BE11-8E19C4F72416}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EAE21322-BA5A-4FF3-B63B-30FA5D546792} + EndGlobalSection +EndGlobal diff --git a/src/Ini.Net/IniFile.cs b/src/Ini.Net/IniFile.cs index 7fa022f..b4cb0db 100644 --- a/src/Ini.Net/IniFile.cs +++ b/src/Ini.Net/IniFile.cs @@ -3,6 +3,8 @@ using System.Text; using System.Runtime.InteropServices; using System.Collections.Generic; +using System.Text.RegularExpressions; + namespace Ini.Net { @@ -37,9 +39,9 @@ public class IniFile private static extern int GetPrivateProfileSection(string lpAppName, byte[] lpszReturnBuffer, int nSize, string lpFileName); private const int SIZE = 255; - private const string DATETIME_MASK = "yyyy/MM/dd HH:mm:ss"; - private const string DATE_MASK = "yyyy/MM/dd"; - + private const string DATETIME_MASK = "MM/dd/yyyy hh:mm:ss tt"; + private const string DATE_MASK = "MM/dd/yyyy"; + public string FileName { get; private set; } public IniFile(string fileName) @@ -56,7 +58,11 @@ private void SetFileName(string fileName) string basePath = System.IO.Directory.GetCurrentDirectory(); this.FileName = Path.Combine(basePath, this.FileName); } - } + } + private bool IsNumeric(string input) + { + return Regex.IsMatch(input, @"^\d+$"); + } public void DeleteKey(string section, string key) { @@ -73,18 +79,50 @@ public string ReadString(string section, string key) var temp = new StringBuilder(SIZE); GetPrivateProfileString(section, key, null, temp, SIZE, this.FileName); return temp.ToString(); + } + + public string ReadString(string section, string key, string notfound) + { + if (!KeyExists(section, key)) + { + return notfound; + } + return ReadString(section, key); } public bool ReadBoolean(string section, string key) { - string value = ReadString(section, key); - return value.ToUpper().Equals("TRUE"); + string value = ReadString(section, key); + bool rtn = (IsNumeric(value)) ? Convert.ToBoolean(Convert.ToInt32(value)) : value.ToUpper().Equals("TRUE"); + return rtn; + } + + public bool ReadBoolean(string section, string key, bool notfound) + { + if (!KeyExists(section, key)) + { + return notfound; + } + return ReadBoolean(section, key); } public decimal ReadDecimal(string section, string key) { + if (!KeyExists(section, key)) + { + return new decimal(-1); + } string value = ReadString(section, key); return decimal.Parse(value.Trim(), System.Globalization.CultureInfo.InvariantCulture); + } + + public decimal ReadDecimal(string section, string key, decimal notfound) + { + if (!KeyExists(section, key)) + { + return notfound; + } + return ReadDecimal(section, key); } public double ReadDouble(string section, string key) @@ -93,38 +131,84 @@ public double ReadDouble(string section, string key) return double.Parse(value.Trim(), System.Globalization.CultureInfo.InvariantCulture); } + public double ReadDouble(string section, string key, double notfound) + { + if (!KeyExists(section, key)) + { + return notfound; + } + return ReadDouble(section, key); + } + public float ReadFloat(string section, string key) { string value = ReadString(section, key); return float.Parse(value, System.Globalization.CultureInfo.InvariantCulture); + } + + public float ReadFloat(string section, string key, float notfound) + { + if (!KeyExists(section, key)) + { + return notfound; + } + return ReadFloat(section, key); } public int ReadInteger(string section, string key) { string value = ReadString(section, key); return Convert.ToInt32(value.Trim()); + } + + public int ReadInteger(string section, string key, int notfound) + { + if (!KeyExists(section, key)) + { + return notfound; + } + return ReadInteger(section, key); } public DateTime ReadDateTime(string section, string key) { string value = ReadString(section, key); - return DateTime.ParseExact(value, DATETIME_MASK, - System.Globalization.CultureInfo.InvariantCulture); + return Convert.ToDateTime(value); + //return DateTime.ParseExact(value, DATETIME_MASK, + // System.Globalization.CultureInfo.InvariantCulture); + } + + public DateTime ReadDateTime(string section, string key, DateTime notfound) + { + if (!KeyExists(section, key)) + { + return notfound; + } + return ReadDateTime(section, key); } public DateTime ReadDate(string section, string key) { - string value = ReadString(section, key); - return DateTime.ParseExact(value, DATE_MASK, - System.Globalization.CultureInfo.InvariantCulture); + string value = ReadString(section, key); + DateTime rtn = Convert.ToDateTime(value); + return Convert.ToDateTime(rtn.ToString(DATE_MASK)); + } + + public DateTime ReadDate(string section, string key, DateTime notfound) + { + if (!KeyExists(section, key)) + { + return notfound; + } + return ReadDate(section, key); } public bool WriteString(string section, string key, string value) { long l = WritePrivateProfileString(section, key, value, this.FileName); return l > 0; - } - + } + public bool WriteBoolean(string section, string key, bool value) { string str = value.ToString().ToUpper(); @@ -187,5 +271,6 @@ public IDictionary ReadSection(string section) } return result; } - } + } + } diff --git a/src/Ini.Net/bin/Debug/Ini.Net.dll b/src/Ini.Net/bin/Debug/Ini.Net.dll new file mode 100644 index 0000000..8d1282a Binary files /dev/null and b/src/Ini.Net/bin/Debug/Ini.Net.dll differ diff --git a/src/Ini.Net/bin/Debug/Ini.Net.pdb b/src/Ini.Net/bin/Debug/Ini.Net.pdb new file mode 100644 index 0000000..f0b7ef3 Binary files /dev/null and b/src/Ini.Net/bin/Debug/Ini.Net.pdb differ diff --git a/src/Ini.Net/obj/Debug/Ini.Net.csproj.CoreCompileInputs.cache b/src/Ini.Net/obj/Debug/Ini.Net.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..a7fc8d9 --- /dev/null +++ b/src/Ini.Net/obj/Debug/Ini.Net.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +eab9205dc0e7654e3a6f813edcfafc4967e4b51c diff --git a/src/Ini.Net/obj/Debug/Ini.Net.csproj.FileListAbsolute.txt b/src/Ini.Net/obj/Debug/Ini.Net.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..abfc06b --- /dev/null +++ b/src/Ini.Net/obj/Debug/Ini.Net.csproj.FileListAbsolute.txt @@ -0,0 +1,6 @@ +D:\projects\Ini.Net\src\Ini.Net\bin\Debug\Ini.Net.dll +D:\projects\Ini.Net\src\Ini.Net\bin\Debug\Ini.Net.pdb +D:\projects\Ini.Net\src\Ini.Net\obj\Debug\Ini.Net.csprojAssemblyReference.cache +D:\projects\Ini.Net\src\Ini.Net\obj\Debug\Ini.Net.csproj.CoreCompileInputs.cache +D:\projects\Ini.Net\src\Ini.Net\obj\Debug\Ini.Net.dll +D:\projects\Ini.Net\src\Ini.Net\obj\Debug\Ini.Net.pdb diff --git a/src/Ini.Net/obj/Debug/Ini.Net.csprojAssemblyReference.cache b/src/Ini.Net/obj/Debug/Ini.Net.csprojAssemblyReference.cache new file mode 100644 index 0000000..6ee7271 Binary files /dev/null and b/src/Ini.Net/obj/Debug/Ini.Net.csprojAssemblyReference.cache differ diff --git a/src/Ini.Net/obj/Debug/Ini.Net.dll b/src/Ini.Net/obj/Debug/Ini.Net.dll new file mode 100644 index 0000000..8d1282a Binary files /dev/null and b/src/Ini.Net/obj/Debug/Ini.Net.dll differ diff --git a/src/Ini.Net/obj/Debug/Ini.Net.pdb b/src/Ini.Net/obj/Debug/Ini.Net.pdb new file mode 100644 index 0000000..f0b7ef3 Binary files /dev/null and b/src/Ini.Net/obj/Debug/Ini.Net.pdb differ diff --git a/test/Ini.Net.Tests/IniFileTests.cs b/test/Ini.Net.Tests/IniFileTests.cs index 337bdba..eaa1ee4 100644 --- a/test/Ini.Net.Tests/IniFileTests.cs +++ b/test/Ini.Net.Tests/IniFileTests.cs @@ -71,8 +71,8 @@ public void TestReadString() this.iniFile.WriteString(section, key, value); string gotValue = this.iniFile.ReadString(section, key); Assert.AreEqual(value, gotValue); - } - + } + [TestMethod] public void TestReadBoolean() { @@ -256,7 +256,7 @@ public void TestWriteDateTime() StringBuilder sb = new StringBuilder(); sb.AppendLine("[breno]"); - sb.AppendLine("somedatetime=1984/09/11 17:40:01"); + sb.AppendLine("somedatetime=09/11/1984 05:40:01 PM"); string expectedText = sb.ToString(); Assert.AreEqual(expectedText, gotText); @@ -271,7 +271,7 @@ public void TestWriteDate() StringBuilder sb = new StringBuilder(); sb.AppendLine("[breno]"); - sb.AppendLine("birthdate=1984/09/11"); + sb.AppendLine("birthdate=09/11/1984"); string expectedText = sb.ToString(); Assert.AreEqual(expectedText, gotText); diff --git a/test/Ini.Net.Tests/bin/Debug/Ini.Net.Tests.dll b/test/Ini.Net.Tests/bin/Debug/Ini.Net.Tests.dll new file mode 100644 index 0000000..c41d3ad Binary files /dev/null and b/test/Ini.Net.Tests/bin/Debug/Ini.Net.Tests.dll differ diff --git a/test/Ini.Net.Tests/bin/Debug/Ini.Net.Tests.pdb b/test/Ini.Net.Tests/bin/Debug/Ini.Net.Tests.pdb new file mode 100644 index 0000000..e04c667 Binary files /dev/null and b/test/Ini.Net.Tests/bin/Debug/Ini.Net.Tests.pdb differ diff --git a/test/Ini.Net.Tests/bin/Debug/Ini.Net.dll b/test/Ini.Net.Tests/bin/Debug/Ini.Net.dll new file mode 100644 index 0000000..8d1282a Binary files /dev/null and b/test/Ini.Net.Tests/bin/Debug/Ini.Net.dll differ diff --git a/test/Ini.Net.Tests/bin/Debug/Ini.Net.pdb b/test/Ini.Net.Tests/bin/Debug/Ini.Net.pdb new file mode 100644 index 0000000..f0b7ef3 Binary files /dev/null and b/test/Ini.Net.Tests/bin/Debug/Ini.Net.pdb differ diff --git a/test/Ini.Net.Tests/bin/Debug/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll b/test/Ini.Net.Tests/bin/Debug/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll new file mode 100644 index 0000000..36b90ae Binary files /dev/null and b/test/Ini.Net.Tests/bin/Debug/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll differ