sofii/SoFii/EmbeddedResources.cs

38 lines
1.3 KiB
C#
Raw Normal View History

2023-10-08 00:10:21 +00:00
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();
}
}
}