xml -> ini conversion tool

This commit is contained in:
Chris Forbes
2009-11-29 10:44:12 +13:00
parent 54074de6cf
commit b4b3877d05
7 changed files with 553 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
namespace OpenRa.FileFormats
{
public class IniWriter
{
readonly string Filename;
public IniWriter(string filename) { Filename = Path.GetFullPath(filename); }
public void Set(string section, string key, string value)
{
WritePrivateProfileString(section, key, value, Filename);
}
public string Get(string section, string key, string defaultValue)
{
var sb = new StringBuilder(1024);
GetPrivateProfileString(section, key, defaultValue, sb, sb.Length, Filename);
return sb.ToString();
}
public string Get(string section, string key)
{
return Get(section, key, "");
}
[DllImport("kernel32")]
static extern int WritePrivateProfileString(string section, string key, string value, string filename);
[DllImport("kernel32")]
static extern int GetPrivateProfileString(string section, string key, string defaultValue,
StringBuilder value, int length, string filename);
}
}