mirror of
https://github.com/ProjectSWGCore/ScriptEditor.git
synced 2026-07-28 22:15:47 -04:00
Transfer Commit
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user