Replace kernel32 imports with ini-parser for portability
This commit is contained in:
parent
63ec0be520
commit
e74f9eec52
5 changed files with 1218 additions and 20 deletions
20
dep/ini-parser/INIFileParser.License
Normal file
20
dep/ini-parser/INIFileParser.License
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2008 Ricardo Amores Hernández
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
BIN
dep/ini-parser/INIFileParser.dll
Normal file
BIN
dep/ini-parser/INIFileParser.dll
Normal file
Binary file not shown.
1181
dep/ini-parser/INIFileParser.xml
Normal file
1181
dep/ini-parser/INIFileParser.xml
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,35 +1,29 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using IniParser;
|
||||
using IniParser.Model;
|
||||
|
||||
namespace MHServerEmu.Common.Config
|
||||
{
|
||||
public class IniFile
|
||||
{
|
||||
private const int ReadBufferSize = 255;
|
||||
|
||||
[DllImport("kernel32")]
|
||||
private static extern int GetPrivateProfileString(string section, string key, string defaultValue, StringBuilder returnedString, int size, string path);
|
||||
[DllImport("kernel32")]
|
||||
private static extern int GetPrivateProfileInt(string section, string key, int defaultValue, string filePath);
|
||||
[DllImport("kernel32")]
|
||||
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
|
||||
|
||||
private string _path;
|
||||
private FileIniDataParser _parser;
|
||||
private IniData _iniData;
|
||||
|
||||
public IniFile(string path)
|
||||
{
|
||||
_path = path;
|
||||
_parser = new();
|
||||
_iniData = _parser.ReadFile(_path);
|
||||
}
|
||||
|
||||
public string ReadString(string section, string key)
|
||||
{
|
||||
StringBuilder stringBuilder = new(ReadBufferSize);
|
||||
GetPrivateProfileString(section, key, "", stringBuilder, ReadBufferSize, _path);
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
public int ReadInt(string section, string key) => GetPrivateProfileInt(section, key, 0, _path);
|
||||
public string ReadString(string section, string key) => _iniData[section][key];
|
||||
public int ReadInt(string section, string key) => Convert.ToInt32(_iniData[section][key]);
|
||||
public bool ReadBool(string section, string key) => Convert.ToBoolean(ReadString(section, key));
|
||||
public void WriteValue(string section, string key, string value) => WritePrivateProfileString(section, key, value, _path);
|
||||
|
||||
public void WriteValue(string section, string key, string value)
|
||||
{
|
||||
_iniData[section][key] = value;
|
||||
_parser.WriteFile(_path, _iniData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@
|
|||
<Reference Include="Google.ProtocolBuffers">
|
||||
<HintPath>..\..\dep\protobuf-csharp\Google.ProtocolBuffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="INIFileParser">
|
||||
<HintPath>..\..\dep\ini-parser\INIFileParser.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="K4os.Compression.LZ4">
|
||||
<HintPath>..\..\dep\K4os.Compression.LZ4\K4os.Compression.LZ4.dll</HintPath>
|
||||
</Reference>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue