// May throw exception. Returned path may not exist. private string GetFileFullPath(string nameBase, ExportCommand cmd, int n) { var fileName = nameBase + n.ToString().PadLeft(2, '0') + cmd.Extension; return(Path.Combine(ExportDirectory(cmd).RemoveIllegalPathChars(), fileName.RemoveIllegalFileNameChars())); }
private Status Export(string nameBase, ExportCommand c, int i) { try { var fileName = GetFileFullPath(nameBase, c, i); // Although the file name has been checked to have no conflict, if the user choose // to export multiple files to the same folder, the file names can still collide. var newName = File.Exists(fileName) ? GenerateFileName(nameBase + i.ToString().PadLeft(2, '0'), c) : fileName; File.WriteAllText(newName, Providers.Types.GetExportText(c.ProviderType, route, navaids, airports)); return(new Status(newName, true, "", false)); } catch (Exception ex) { LoggerInstance.Log(ex); var mayBePermissionIssue = ex is UnauthorizedAccessException || ex is SecurityException; return(new Status(c.CustomDirectory, false, ex.Message, mayBePermissionIssue)); } }
public bool Equals(ExportCommand other) { return(ProviderType == other.ProviderType && Directory == other.Directory && Extension == other.Extension && Enabled == other.Enabled); }
private bool FileExist(string nameBase, ExportCommand cmd, int n) { return(DefaultIfThrows(() => { var filePath = GetFileFullPath(nameBase, cmd, n); return File.Exists(filePath); }, false)); }
/// Returned path may be null or not exist. private string ExportDirectory(ExportCommand c) => Providers.Types.ExportDirectory(c.DefaultSimulator, c, options());
private static string GenerateFileName(string nameBase, ExportCommand c) { return(FileNameGenerator.Generate(c.CustomDirectory.RemoveIllegalPathChars(), nameBase, c.Extension, n => "_" + n.ToString(), 1)); }
private static bool FileExist(string nameBase, ExportCommand cmd, int n) { var filePath = GetFileFullPath(nameBase, cmd, n); return(File.Exists(filePath)); }