private string DetermineOutfileBody() { var outputDir = PathSafe.GetDirectoryName(OutputFilenameTemplate) ?? ""; var filenameBase = PathSafe.GetFileNameWithoutExtension(OutputFilenameTemplate) ?? "output"; //var outfilebody = PathSafe.Combine(outputDir, filenameBase); return(PathSafe.Combine(outputDir, filenameBase)); }
/// <param name="originalFilename">Original file name</param> public UniqueFilenameBase(string originalFilename, IPathUtil pathUtil) { if (originalFilename == null) { throw new ArgumentNullException(nameof(originalFilename)); } _pathUtil = pathUtil; OriginalFilename = originalFilename; LastUniqueFilename = originalFilename; _directory = _pathSafe.GetDirectoryName(OriginalFilename) ?? ""; _fileBody = _pathSafe.GetFileNameWithoutExtension(OriginalFilename); _extension = _pathSafe.GetExtension(OriginalFilename); }
public UniqueFilename(string originalFilename, IDirectory directory, IFile file) { if (originalFilename == null) { throw new ArgumentNullException("originalFilename"); } _directoryWrap = directory; _fileWrap = file; OriginalFilename = originalFilename; LastUniqueFilename = originalFilename; _directory = _pathSafe.GetDirectoryName(OriginalFilename) ?? ""; _fileBody = _pathSafe.GetFileNameWithoutExtension(OriginalFilename); _extension = _pathSafe.GetExtension(OriginalFilename); }
/// <summary> /// Adds ellipsis "(...)" to a path with a length longer than 255. /// </summary> /// <param name="filePath">full path to file</param> /// <param name="length">maximum length of the string. This must be between 10 and MAX_PATH (260)</param> /// <returns>file path with ellipsis to ensure length under the max length </returns> public string EllipsisForPath(string filePath, int length) { if (filePath == null) { throw new ArgumentNullException(nameof(filePath)); } if (filePath.EndsWith("\\")) { throw new ArgumentException("The path has to be a file", nameof(filePath)); } if ((length < 10) || (length > MAX_PATH)) { throw new ArgumentException($"The desired length must be between 10 and {MAX_PATH}", nameof(length)); } if (filePath.Length > length) { const string ellipsis = "(...)"; var path = GetLongDirectoryName(filePath) ?? ""; var file = _pathSafe.GetFileNameWithoutExtension(filePath); var ext = _pathSafe.GetExtension(filePath); var remainingLength = length - path.Length - ellipsis.Length - ext.Length - 1; // substract -1 to account for the slash between path and filename if (remainingLength < 4) { throw new ArgumentException(filePath); } var partLength = remainingLength / 2; file = file.Substring(0, partLength) + ellipsis + file.Substring(file.Length - partLength, partLength); filePath = _pathSafe.Combine(path, file + ext); } return(filePath); }
/// <summary> /// Get the list of Ghostscript Parameters. This List contains of a basic set of parameters together with some /// device-specific /// parameters that will be added by the device implementation /// </summary> /// <param name="ghostscriptVersion"></param> /// <returns>A list of parameters that will be passed to Ghostscript</returns> public IList <string> GetGhostScriptParameters(GhostscriptVersion ghostscriptVersion) { IList <string> parameters = new List <string>(); parameters.Add("gs"); parameters.Add("-sFONTPATH=" + OsHelper.WindowsFontsFolder); parameters.Add("-dNOPAUSE"); parameters.Add("-dBATCH"); if (!HasValidExtension(Job.OutputFilenameTemplate, Job.Profile.OutputFormat)) { MakeValidExtension(Job.OutputFilenameTemplate, Job.Profile.OutputFormat); } AddOutputfileParameter(parameters); AddDeviceSpecificParameters(parameters); // Add user-defined parameters if (!string.IsNullOrEmpty(Job.Profile.Ghostscript.AdditionalGsParameters)) { var args = FileUtil.Instance.CommandLineToArgs(Job.Profile.Ghostscript.AdditionalGsParameters); foreach (var s in args) { parameters.Add(s); } } //Dictonary-Parameters must be the last Parameters if (DistillerDictonaries.Count > 0) { parameters.Add("-c"); foreach (var parameter in DistillerDictonaries) { parameters.Add(parameter); } } //Don't add further paramters here, since the distiller-parameters should be the last! parameters.Add("-f"); if (Job.Profile.Stamping.Enabled) { // Compose name of the stamp file based on the location and name of the inf file var stampFileName = PathSafe.Combine(Job.JobTempFolder, PathSafe.GetFileNameWithoutExtension(Job.JobInfo.InfFile) + ".stm"); CreateStampFile(stampFileName, Job.Profile); parameters.Add(stampFileName); } if (Job.Profile.CoverPage.Enabled) { parameters.Add(Job.Profile.CoverPage.File); } foreach (var sfi in Job.JobInfo.SourceFiles) { parameters.Add(sfi.Filename); } if (Job.Profile.AttachmentPage.Enabled) { parameters.Add(Job.Profile.AttachmentPage.File); } //Compose name of the pdfmark file based on the location and name of the inf file var pdfMarkFileName = PathSafe.Combine(Job.JobTempFolder, "metadata.mtd"); Directory.CreateDirectory(Job.JobTempFolder); Directory.CreateDirectory(Job.JobTempFolder + @"\tempoutput"); CreatePdfMarksFile(pdfMarkFileName); // Add pdfmark file as input file to set metadata parameters.Add(pdfMarkFileName); return(parameters); }