-
Notifications
You must be signed in to change notification settings - Fork 8
Eco.EM.Framework.FileManager
Here you will find the documentation on the features in the File Manager part of the framework.
Documentation may be incomplete and might need additions, we will update this when we can.
Usage:
using Eco.EM.Framework.FileManager;
The File Manager is great for creating and reading your Config files.
Our file manger outputs to a basic format of .json but it can open and read and save .eco format files as well!
We present
ReadingFromFile
WriteToFile
How to use:
const string filename = "MyMod";
FileManager<DataStructure>.ReadFromFile(Base.SaveLocation, filename); filename you can set
FileManager<DataStructure>.WriteToFile(datainput, Base.SaveLocation, filename);
Base.SaveLocation = ServerInstallFolder/Configs/Mods
You can also do this with the file manager for your own folder:
const string filename = "MyMod";
FileManager<DataStructure>.WriteToFile(datainput, Base.SaveLocation + "/Foldername", filename);
FileManager<DataStructure>.ReadFromFile(Base.SaveLocation + "/Foldername", filename);
The file manager will automatically create the directory if it doesn't exist
You can set the file name as a string const and use that or use a direct string:
const string filename = "MyMod";
FileManager<DataStructure>.WriteToFile(datainput, Base.SaveLocation + "/Foldername", filename);
FileManager<DataStructure>.WriteToFile(datainput, Base.SaveLocation + "/Foldername", "MyMod");
Should you not want to use the Base.SaveLocation you can use your own:
const string filename = "MyMod";
FileManager<DataStructure>.WriteToFile(datainput, "/Mods/YourFolderHere", filename);
FileManager<DataStructure>.ReadFromFile("/Mods/YourFolderHere", filename);
I recommend using the base save location as in case the mods folder gets deleted all your config files will remain safe.
All configs are saved in .json format
To make easy configs This is a basic Save and Load for a basic config setup:
public PluginConfig<ConfigName> ConfigName; //your data structure
public IPluginConfig PluginConfig => ConfigName;
public void LoadConfig()
{
ConfigName = new PluginConfig<ConfigName>(configFileName); // const string or direct string
}
Or using Linq
public void LoadConfig() => DailyLogs = new PluginConfig<ConfigName>(configFileName);
public void SaveConfig()
{
ConfigName.SaveAsync();
}
For your data structure:
public class ConfigName
{
public int Numer {get;}
}
This would save to your config file like:
{
"Number" : 0
}