/// <summary> /// Initialize everything, create cache /// </summary> public static void Initialize() { string location = Config.ReadString("Locale", "File", DefaultFileLocation.Location(RequestFile.Config) + "/default.xml"); _filepath = location; if (!File.Exists(_filepath)) { DirectoryInfo dirInfo = new FileInfo(_filepath).Directory; if (dirInfo != null) { string parent = dirInfo.ToString(); Util.FsUtil.CreateDirectoryIfNotExists(parent); } FileStream fs = File.Create(_filepath); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(XmlHead + XmlTail); sw.Close(); fs.Close(); } _xmldoc = new XmlDocument(); _xmldoc.Load(_filepath); LoadCache(); //everything's cached, we're ready to go IsInitialized = true; }
/// <summary> /// Load a config file /// </summary> /// <param name="location"></param> public static void LoadFile(string location = "") { if (string.IsNullOrEmpty(location)) { location = DefaultFileLocation.Location(RequestFile.Config) + CteFileName; } _filepath = location; Logger.Log(LogLevel.Info, "Config", "Loading file", _filepath); if (!File.Exists(_filepath)) { Logger.Log(LogLevel.Info, "Config", "Creating config file"); DirectoryInfo dirInfo = new FileInfo(_filepath).Directory; if (dirInfo != null) { string parent = dirInfo.ToString(); Util.FsUtil.CreateDirectoryIfNotExists(parent); } FileStream fs = File.Create(_filepath); StreamWriter sw = new StreamWriter(fs); sw.WriteLine("<xml></xml>"); sw.Close(); fs.Close(); } _xmldoc = new XmlDocument(); _xmldoc.Load(_filepath); LoadCache(); //everything's cached, we're ready to go }
public static void Initialize() { DefaultFileLocation.Initialize(); Logger.Initialize(); Config.Initialize(); Locale.Initialize(); //The filesystem to use (Only for server actions! e.g. logging and config are handled through the normal filesystem //This can be changed later on //e.g. when FTP connection settings are read from config or user presses connect button ServerFileSystem = new Filesystem.Local.LocalFileSystem(); }
/// <summary> /// Save a config file /// </summary> /// <param name="location"></param> public static void SaveFile(string location = "") { if (string.IsNullOrEmpty(location)) { location = DefaultFileLocation.Location(RequestFile.Config) + CteFileName; } if (_cache.Count == 0) { Logger.Log(LogLevel.Debug, "Config", "Didn't save file: nothing to save"); return; } _filepath = location; Logger.Log(LogLevel.Info, "Config", "Saving file", _filepath); SaveCache(); }