sofii/SoFii/EmbeddedResources.cs
2023-10-08 02:10:21 +02:00

37 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
namespace SoFii {
public static class EmbeddedResources {
public static void LoadLines(string name, Action<string> onLine) {
using(Stream stream = Program.CurrentAssembly.GetManifestResourceStream($@"{Program.CurrentAssemblyName.Name}.{name}"))
using(StreamReader sr = new StreamReader(stream, true)) {
string line;
while(!string.IsNullOrEmpty(line = sr.ReadLine()))
onLine(line);
}
}
public static string[] GetDNSServers() {
List<string> items = new List<string>();
LoadLines("DNSServers.txt", line => {
if(!line.StartsWith("#"))
items.Add(line.Trim());
});
return items.ToArray();
}
public static ColourCharInfo[] GetColourChars() {
List<ColourCharInfo> items = new List<ColourCharInfo>();
LoadLines("NameColours.txt", line => {
string[] parts = line.Split(' ');
if(parts.Length > 1)
items.Add(ColourCharInfo.FromStrings(parts[0], parts[1]));
});
return items.ToArray();
}
}
}