Transfer Commit

This commit is contained in:
Viaron
2014-08-06 20:29:53 -04:00
parent e3324de2ad
commit 64543d398d
25 changed files with 1799 additions and 0 deletions
+75
View File
@@ -0,0 +1,75 @@
using System;
using System.IO;
using System.Collections.Generic;
namespace ProjectSWGScriptEditor
{
public class Config
{
static public String returnValue(string key)
{
var config = File.OpenText("./pswgse.cfg");
while (config.BaseStream.CanSeek)
{
String[] entry = config.ReadLine().Split('=');
if (entry[0].Equals(key))
{
config.Close();
return entry[1].ToString();
}
}
config.Close();
return null;
}
static public Boolean containsKey(string key)
{
var config = File.OpenText("./pswgse.cfg");
while (config.BaseStream.CanSeek)
{
string line = config.ReadLine();
if (line == null)
{
config.Close();
return false;
}
String[] entry = line.Split('=');
if (entry[0].Equals(key))
{
config.Close();
return true;
}
}
config.Close();
return false;
}
static public void setValue(string key, object value)
{
var config = File.OpenText("./pswgse.cfg");
SortedList<string, string> entries = new SortedList<string, string>();
while (config.Peek() >= 0)
{
string temp = config.ReadLine();
if (temp != null)
{
string[] entry = temp.Split('=');
entries.Add(entry[0], entry[1]);
}
}
config.Close();
if (!entries.ContainsKey(key)) entries.Add(key, value.ToString());
else entries[key] = value.ToString();
List<string> listToSave = new List<string>();
for (int i = 0; i < entries.Count; i++) listToSave.Add(entries.Keys[i] + "=" + entries.Values[i]);
File.WriteAllLines("./pswgse.cfg", listToSave);
}
}
}