mirror of
https://git.tonybark.com/tonytins/CyberBits.git
synced 2026-05-12 05:23:34 -04:00
Moved a lot of core functionality into new Common library
- Remove System.IO from Implicit Usings.
This commit is contained in:
parent
1f2032dcf8
commit
fb013f2b15
18 changed files with 169 additions and 14 deletions
31
CyberBits.Common/FileFetcher.cs
Normal file
31
CyberBits.Common/FileFetcher.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
namespace CyberBits.Common;
|
||||
|
||||
public static class FileFetcher
|
||||
{
|
||||
public static string LoadTextFile(string filename, bool userDir = false)
|
||||
{
|
||||
var location = "res";
|
||||
|
||||
if (userDir)
|
||||
location = "user";
|
||||
|
||||
using var file = FileAccess.Open($"{location}://{filename}", FileAccess.ModeFlags.Read);
|
||||
var contents = file.GetAsText();
|
||||
|
||||
file.Close();
|
||||
return contents;
|
||||
}
|
||||
|
||||
public static ConfigFile LoadConfig(string filename, bool userDir = false)
|
||||
{
|
||||
var config = new ConfigFile();
|
||||
|
||||
// Load data from a file.
|
||||
var err = config.Load(LoadTextFile(filename, userDir));
|
||||
|
||||
if (err != Error.Ok)
|
||||
sys.Environment.Exit(sys.Environment.ExitCode);
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue