put back some files that vanished for absolutely no reason
This commit is contained in:
parent
b8406d117e
commit
5c2aaef09e
2 changed files with 165 additions and 0 deletions
92
WebBrowser/Config.cs
Normal file
92
WebBrowser/Config.cs
Normal file
|
@ -0,0 +1,92 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace XeroBrowser
|
||||
{
|
||||
internal class Config
|
||||
{
|
||||
private static string Cfg_File = Environment.GetEnvironmentVariable("appdata") + "/Xero Browser/prefrences.conf";
|
||||
private const string SEPERATOR = "=";
|
||||
private static Dictionary<string, string> cfgEntries = new Dictionary<string, string>();
|
||||
|
||||
static Config()
|
||||
{
|
||||
loadCfg();
|
||||
}
|
||||
|
||||
private static void loadCfg()
|
||||
{
|
||||
cfgEntries.Clear();
|
||||
if (!File.Exists(Cfg_File))
|
||||
saveCfg();
|
||||
|
||||
using (StreamReader cfgReader = File.OpenText(Cfg_File))
|
||||
{
|
||||
for (string? line = cfgReader.ReadLine(); line is not null; line = cfgReader.ReadLine())
|
||||
{
|
||||
if (line.StartsWith("#")) continue;
|
||||
string[] values = line.Split(SEPERATOR.First());
|
||||
cfgEntries.Add(values.First().Trim(), String.Join(SEPERATOR, values.Skip(1)).Trim());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
private static void saveCfg()
|
||||
{
|
||||
using (StreamWriter cfgWriter = File.CreateText(Cfg_File))
|
||||
{
|
||||
cfgWriter.WriteLine("############################################################################################");
|
||||
cfgWriter.WriteLine("# Caution: This is your settings file for Xero Browser! #");
|
||||
cfgWriter.WriteLine("# Modifying anything in this file could cause things to break and is thus not reccomended. #");
|
||||
cfgWriter.WriteLine("# Continue at your own risk! #");
|
||||
cfgWriter.WriteLine("############################################################################################");
|
||||
foreach (KeyValuePair<String, String> values in cfgEntries)
|
||||
{
|
||||
cfgWriter.WriteLine(String.Join(SEPERATOR, new String[] { values.Key.Trim(), values.Value.Trim() }));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetEntry(string key, string value)
|
||||
{
|
||||
key = key.Trim();
|
||||
value = value.Trim().Replace("\n", String.Empty).Replace("\r", String.Empty);
|
||||
|
||||
if (EntryExists(key))
|
||||
cfgEntries[key] = value;
|
||||
else
|
||||
cfgEntries.Add(key, value);
|
||||
|
||||
saveCfg();
|
||||
}
|
||||
public static bool EntryExists(string key)
|
||||
{
|
||||
return cfgEntries.ContainsKey(key);
|
||||
}
|
||||
|
||||
public static string GetEntry(string key)
|
||||
{
|
||||
return EntryExists(key) ? cfgEntries[key] : String.Empty;
|
||||
}
|
||||
public static void RemoveEntry(string key)
|
||||
{
|
||||
cfgEntries.Remove(key.Trim());
|
||||
saveCfg();
|
||||
}
|
||||
public static string GetEntry(string key, string defaultValue)
|
||||
{
|
||||
if (!EntryExists(key))
|
||||
{
|
||||
SetEntry(key, defaultValue);
|
||||
return defaultValue;
|
||||
}
|
||||
return GetEntry(key);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in a new issue