-
Notifications
You must be signed in to change notification settings - Fork 1
/
Settings.cs
73 lines (70 loc) · 2.76 KB
/
Settings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace BioLib
{
public static class Settings
{
/* Creating a new dictionary with a string as the key and a string as the value. */
static Dictionary<string,string> Default = new Dictionary<string,string>();
/// <summary>
/// The function "GetSettings" returns the value associated with a given name from a dictionary,
/// or an empty string if the name is not found.
/// </summary>
/// <param name="name">The name parameter is a string that represents the name of the setting
/// that you want to retrieve.</param>
/// <returns>
/// The method is returning a string value. If the specified name exists in the Default
/// dictionary, the corresponding value is returned. Otherwise, an empty string is returned.
/// </returns>
public static string GetSettings(string name)
{
if(Default.ContainsKey(name)) return Default[name];
return "";
}
/// <summary>
/// The function "AddSettings" adds a name-value pair to the "Default" dictionary.
/// </summary>
/// <param name="name">The name parameter is a string that represents the name of the
/// setting.</param>
/// <param name="val">The "val" parameter is a string value that represents the value to be
/// added to the settings.</param>
public static void AddSettings(string name,string val)
{
Default.Add(name, val);
}
static string path = System.IO.Path.GetDirectoryName(Environment.ProcessPath);
/// <summary>
/// The Save function writes the key-value pairs from the Default dictionary to a text file.
/// </summary>
public static void Save()
{
string val = "";
foreach (var item in Default)
{
val += item.Key + "=" + item.Value + Environment.NewLine;
}
File.WriteAllText(path + "/Settings.txt", val);
}
/// <summary>
/// The Load function reads settings from a file and adds them to a dictionary.
/// </summary>
/// <returns>
/// If the file "Settings.txt" does not exist, the method will return without doing anything.
/// </returns>
public static void Load()
{
if (!File.Exists(path + "/Settings.txt"))
return;
string[] sts = File.ReadAllLines(path + "/Settings.txt");
foreach (string item in sts)
{
string[] st = item.Split('=');
Default.Add(st[0], st[1]);
}
}
}
}