/// <summary> /// Loads command XML files present in the saveDirectory into <see cref="CommandFile"/>s /// </summary> /// <returns></returns> public List <CommandFile> LoadFiles() { List <CommandFile> result = new List <CommandFile>(); foreach (var path in Directory.EnumerateFiles(saveDirectory)) { string contents = File.ReadAllText(path); CommandFile file = new CommandFile(errorLogger); bool loaded = file.FromXML(contents); if (loaded) { result.Add(file); } } return(result); }
/// <summary> /// Loads the specified file. If that file can be loaded, it is copied into the DAL's save space. /// Returns the file loaded, or null if unsuccessful. /// This does NOT add to the command handlers. /// </summary> internal CommandFile LoadCopySingleCommand(string fromPath, bool overwrite = true) { bool loaded = false; CommandFile file = null; try { string contents = File.ReadAllText(fromPath); file = new CommandFile(errorLogger); loaded = file.FromXML(contents); if (loaded) { string newPath = Path.Combine(saveDirectory, Path.GetFileName(fromPath)); File.Copy(fromPath, newPath, overwrite); } } catch (Exception) { // That's fine, we can ignore. } return(loaded ? file : null); }