private string CreateInfFile(IList <JobFolderFile> jobFolderFiles, string jobFolder, AppStartParameters appStartParameters) { var firstDirectConversionFile = jobFolderFiles[0].OriginalFilePath; var fileName = PathSafe.GetFileName(firstDirectConversionFile); var shortFileName = fileName; if (fileName.Length > 12) { shortFileName = fileName.Substring(0, 12); } var infFile = PathSafe.Combine(jobFolder, shortFileName + ".inf"); var jobInfo = new JobInfo(); foreach (var jobFolderFile in jobFolderFiles) { var sfi = CreateSourceFileInfo(jobFolderFile, appStartParameters); jobInfo.SourceFiles.Add(sfi); } _jobInfoManager.SaveToInfFile(jobInfo, infFile); Logger.Debug("Created inf-file for ps-file: " + infFile); return(infFile); }
public string GetFontFilename(Font font) { RegistryKey[] registryKeys = { Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\Fonts", false), Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\Fonts", false), Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Fonts", false) }; try { foreach (RegistryKey fonts in registryKeys) { if (fonts != null) { var name = MatchRegistryFontKey(font, fonts); if (!string.IsNullOrEmpty(name)) { return(PathSafe.GetFileName(fonts.GetValue(name).ToString())); } } } _logger.Warn($"Incompatible Font: {font.Name} {font.Style.ToString()}"); return(null); } finally { foreach (RegistryKey key in registryKeys) { key?.Dispose(); } } }
public JobInfo Duplicate(JobInfo jobInfo, string profileGuid = null) { var jobInfoDuplicate = new JobInfo(); jobInfoDuplicate.Metadata = jobInfo.Metadata.Copy(); jobInfoDuplicate.JobType = jobInfo.JobType; jobInfoDuplicate.PrintDateTime = jobInfo.PrintDateTime; jobInfoDuplicate.PrinterName = jobInfo.PrinterName; jobInfoDuplicate.PrinterParameter = profileGuid == null ? jobInfo.PrinterParameter : ""; jobInfoDuplicate.ProfileParameter = profileGuid ?? jobInfo.ProfileParameter; jobInfoDuplicate.OutputFileParameter = jobInfo.OutputFileParameter; jobInfoDuplicate.OriginalFilePath = jobInfo.OriginalFilePath; jobInfoDuplicate.InfFile = "DuplicateInfFileDummy_" + Guid.NewGuid(); var sfiFilename = PathSafe.GetFileName(jobInfo.SourceFiles[0].Filename); var duplicateJobFolder = _jobFolderBuilder.CreateJobFolderInSpool(sfiFilename); foreach (var sfi in jobInfo.SourceFiles) { var sfiDuplicate = _sourceFileInfoDuplicator.Duplicate(sfi, duplicateJobFolder, profileGuid); jobInfoDuplicate.SourceFiles.Add(sfiDuplicate); } return(jobInfoDuplicate); }
/// <summary> /// Creates a directory that does not exist yet. It takes a path and appends a counting number (_2, _3, etc) to ensure /// this in a readable way. /// </summary> /// <returns>The uniqified directory path</returns> public string MakeUniqueDirectory(string path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if (string.IsNullOrEmpty(path)) { throw new ArgumentException("Argument may not be empty string", nameof(path)); } var directory = PathSafe.GetDirectoryName(path) ?? ""; var fileBody = PathSafe.GetFileName(path); var i = 2; while (_directoryWrap.Exists(path) || _fileWrap.Exists(path)) { path = PathSafe.Combine(directory, fileBody + "_" + i); i++; } return(path); }
private void EnableSaveToDesktop(Job job) { job.Profile.SaveFileTemporary = false; var filename = PathSafe.GetFileName(job.OutputFileTemplate); var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); job.OutputFileTemplate = PathSafe.Combine(desktopFolder, filename); }
public string GetDownloadPath(string downloadUrl) { var downloadLocation = _tempFolderProvider.TempFolder; _directory.CreateDirectory(downloadLocation); var uri = new Uri(downloadUrl); var filename = PathSafe.GetFileName(uri.LocalPath); return(PathSafe.Combine(downloadLocation, filename)); }
public void ShowSaveFileDialog_SetValuesFromUserInput_SetFilepathAndOutputFormatInJob() { var skipPrintDialogCommand = BuildCommand(); var job = BuildJob(_pdfProfile); skipPrintDialogCommand.Execute(job); var result = _saveFileQuery .GetFileName(PathSafe.GetDirectoryName(job.OutputFileTemplate), PathSafe.GetFileName(job.OutputFileTemplate), job.Profile.OutputFormat); Assert.AreEqual(result.Data.Filepath, job.OutputFileTemplate); Assert.AreEqual(result.Data.OutputFormat, job.Profile.OutputFormat); }
/// <summary> /// Creates a directory that does not exist yet. It takes a path and appends a counting number (_2, _3, etc) to ensure /// this in a readable way. /// </summary> /// <returns>The uniqified directory path</returns> public string MakeUniqueDirectory() { var directory = PathSafe.GetDirectoryName(_path) ?? ""; var fileBody = PathSafe.GetFileName(_path); var i = 2; while (_directoryWrap.Exists(_path) || _fileWrap.Exists(_path)) { _path = PathSafe.Combine(directory, fileBody + "_" + i); i++; } return(_path); }
private IList <HistoricFile> CreateHistoricFiles(Job job) { var historicFiles = new List <HistoricFile>(); foreach (var file in job.OutputFiles) { var fileName = PathSafe.GetFileName(file); var directory = PathSafe.GetDirectoryName(file); var hash = BuildHash(file); var historicFile = new HistoricFile(file, fileName, directory, hash); historicFiles.Add(historicFile); } return(historicFiles); }
private string CreateJobFolderInSpool(string file) { var psFilename = PathSafe.GetFileName(file); if (psFilename.Length > 23) { psFilename = psFilename.Substring(0, 23); } var jobFolder = PathSafe.Combine(_spoolerProvider.SpoolFolder, psFilename); jobFolder = new UniqueDirectory(jobFolder).MakeUniqueDirectory(); _directory.CreateDirectory(jobFolder); Logger.Trace("Created spool directory for ps-file job: " + jobFolder); return(jobFolder); }
public bool TryRepairPrinter(IEnumerable <string> printerNames) { Logger.Error("It looks like the printers are broken. This needs to be fixed to allow PDFCreator to work properly"); var title = _translation.RepairPrinterNoPrintersInstalled; var message = _translation.RepairPrinterAskUserUac; Logger.Debug("Asking to start repair.."); var response = ShowMessage(message, title, MessageOptions.YesNo, MessageIcon.Exclamation); if (response == MessageResponse.Yes) { var applicationPath = _assemblyHelper.GetAssemblyDirectory(); var printerHelperPath = PathSafe.Combine(applicationPath, "PrinterHelper.exe"); if (!_file.Exists(printerHelperPath)) { Logger.Error("PrinterHelper.exe does not exist!"); title = _translation.Error; message = _translation.GetSetupFileMissingMessage(PathSafe.GetFileName(printerHelperPath)); ShowMessage(message, title, MessageOptions.OK, MessageIcon.Error); return(false); } Logger.Debug("Reinstalling Printers..."); var pdfcreatorPath = _nameProvider.GetPortApplicationPath(); var printerNameString = GetPrinterNameString(printerNames); var installParams = $"RepairPrinter -name={printerNameString} -PortApplication=\"{pdfcreatorPath}\""; var installResult = _shellExecuteHelper.RunAsAdmin(printerHelperPath, installParams); Logger.Debug("Done: {0}", installResult); } Logger.Debug("Now we'll check again, if the printer is installed"); if (IsRepairRequired()) { Logger.Warn("The printer could not be repaired."); return(false); } Logger.Info("The printer was repaired successfully"); return(true); }
public void ShowSaveFileDialog_SetValuesFromUserInput_FilepathAndOutputFormatHasChanged() { var skipPrintDialogCommand = BuildCommand(); var job = BuildJob(_pdfProfile); var diffFilenameTemplate = job.OutputFileTemplate; var diffOutputFormat = job.Profile.OutputFormat; skipPrintDialogCommand.Execute(job); _saveFileQuery .GetFileName(PathSafe.GetDirectoryName(job.OutputFileTemplate), PathSafe.GetFileName(job.OutputFileTemplate), job.Profile.OutputFormat); Assert.AreNotEqual(job.OutputFileTemplate, diffFilenameTemplate); Assert.AreNotEqual(job.Profile.OutputFormat, diffOutputFormat); }
public void Execute(object parameter) { var job = parameter as Job; var folder = PathSafe.GetDirectoryName(job.OutputFileTemplate) ?? ""; var filename = PathSafe.GetFileName(job.OutputFileTemplate) ?? ""; var result = _saveFileQuery.GetFileName(folder, filename, job.Profile.OutputFormat); if (!result.Success) { throw new AbortWorkflowException("User cancelled in SaveFileDialog"); } job.OutputFileTemplate = result.Data.Filepath; job.Profile.OutputFormat = result.Data.OutputFormat; }
private string ComposeSampleCommand(string scriptPath, string additionalParams) { if (string.IsNullOrEmpty(scriptPath) || (scriptPath.Trim().Length == 0)) { return(""); } var scriptCall = PathSafe.GetFileName(_scriptActionHelper.ComposeScriptPath(scriptPath, TokenReplacer)); if (!string.IsNullOrEmpty(additionalParams)) { scriptCall += " " + _scriptActionHelper.ComposeScriptParameters(additionalParams, new[] { @"C:\File1.pdf", @"C:\File2.pdf" }, TokenReplacer); } else { scriptCall += @" C:\File1.pdf C:\File2.pdf"; } return(scriptCall); }
public string GetPreview(string scriptPath, string additionalParams, TokenReplacer tokenReplacer) { if (string.IsNullOrEmpty(scriptPath) || (scriptPath.Trim().Length == 0)) { return(""); } var scriptCall = PathSafe.GetFileName(ComposeScriptPath(scriptPath, tokenReplacer)); if (!string.IsNullOrEmpty(additionalParams)) { scriptCall += " " + ComposeScriptParameters(additionalParams, new[] { @"C:\File1.pdf", @"C:\File2.pdf" }, tokenReplacer); } else { scriptCall += @" C:\File1.pdf C:\File2.pdf"; } return(scriptCall); }
private async Task <MacroCommandIsDoneEventArgs> BrowseFileWithNotificationForTooLongInput(object arg) { var job = _getJob(); var inputFilePath = job.OutputFileTemplate; var inputDirectory = PathSafe.GetDirectoryName(inputFilePath); var inputFilename = PathSafe.GetFileName(inputFilePath); _directoryHelper.CreateDirectory(inputDirectory); var result = await GetFileOrRetry(inputDirectory, inputFilename, job.Profile.OutputFormat); if (result.Success) { job.OutputFileTemplate = result.Data.Filepath; job.Profile.OutputFormat = result.Data.OutputFormat; _updateUi(); _setLastConfirmedPath(result.Data.Filepath); return(new MacroCommandIsDoneEventArgs(ResponseStatus.Success)); } _setLastConfirmedPath(""); return(new MacroCommandIsDoneEventArgs(ResponseStatus.Cancel)); }
private void SetOutputFilenameAndFolder(string filenameTemplate) { OutputFilename = PathSafe.GetFileName(filenameTemplate); OutputFolder = PathSafe.GetDirectoryName(filenameTemplate); }
protected override void AddDeviceSpecificParameters(IList <string> parameters) { parameters.Add("-c"); var markstring = new StringBuilder(); markstring.Append("mark "); markstring.Append("/NoCancel false "); markstring.Append("/BitsPerPixel 24 "); //random = true color //var _printer = new PrinterSettings(); switch (Job.Profile.Printing.SelectPrinter) { case SelectPrinter.DefaultPrinter: //printer.PrinterName returns default printer if (!_printer.IsValid) { Logger.Error("The default printer (" + Job.Profile.Printing.PrinterName + ") is invalid!"); throw new Exception("100"); } markstring.Append("/OutputFile (\\\\\\\\spool\\\\" + _printer.PrinterName.Replace("\\", "\\\\") + ") "); break; case SelectPrinter.SelectedPrinter: _printer.PrinterName = Job.Profile.Printing.PrinterName; //Hint: setting PrinterName, does not change the systems default if (!_printer.IsValid) { Logger.Error("The selected printer (" + Job.Profile.Printing.PrinterName + ") is invalid!"); throw new Exception("101"); } markstring.Append("/OutputFile (\\\\\\\\spool\\\\" + _printer.PrinterName.Replace("\\", "\\\\") + ") "); break; case SelectPrinter.ShowDialog: default: //add nothing to trigger the Windows-Printing-Dialog break; } markstring.Append("/UserSettings "); markstring.Append("1 dict "); markstring.Append("dup /DocumentName (" + PathSafe.GetFileName(Job.OutputFiles[0]) + ") put "); markstring.Append("(mswinpr2) finddevice "); markstring.Append("putdeviceprops "); markstring.Append("setdevice"); parameters.Add(markstring.ToString()); //No duplex settings for PrinterDialog if (Job.Profile.Printing.SelectPrinter == SelectPrinter.ShowDialog) { return; } switch (Job.Profile.Printing.Duplex) { case DuplexPrint.LongEdge: //Book if (_printer.CanDuplex) { parameters.Add("<< /Duplex true /Tumble false >> setpagedevice "); } break; case DuplexPrint.ShortEdge: //Calendar if (_printer.CanDuplex) { parameters.Add("<< /Duplex true /Tumble true >> setpagedevice "); } break; case DuplexPrint.Disable: default: //Nothing break; } }
protected override ActionResult DoActionProcessing(Job job) { var ftpAccount = job.Accounts.GetFtpAccount(job.Profile); Logger.Debug("Creating ftp connection.\r\nServer: " + ftpAccount.Server + "\r\nUsername: "******"Exception while login to ftp server: "); ftpClient.Disconnect(); return(new ActionResult(ErrorCode.Ftp_LoginError)); } var fullDirectory = job.TokenReplacer.ReplaceTokens(job.Profile.Ftp.Directory).Trim(); if (!ValidName.IsValidFtpPath(fullDirectory)) { Logger.Warn("Directory contains invalid characters \"" + fullDirectory + "\""); fullDirectory = ValidName.MakeValidFtpPath(fullDirectory); } Logger.Debug("Directory on ftp server: " + fullDirectory); try { if (!ftpClient.DirectoryExists(fullDirectory)) { ftpClient.CreateDirectory(fullDirectory); } } catch (Exception ex) { Logger.Error(ex, "Exception while setting directory on ftp server: "); ftpClient.Disconnect(); return(new ActionResult(ErrorCode.Ftp_DirectoryError)); } foreach (var file in job.OutputFiles) { var targetFile = PathSafe.GetFileName(file); targetFile = ValidName.MakeValidFtpPath(targetFile); if (job.Profile.Ftp.EnsureUniqueFilenames) { Logger.Debug("Make unique filename for " + targetFile); try { var uf = new UniqueFilenameForFtp(targetFile, ftpClient, _pathUtil); targetFile = uf.CreateUniqueFileName(); Logger.Debug("-> The unique filename is \"" + targetFile + "\""); } catch (Exception ex) { Logger.Error(ex, "Exception while generating unique filename: "); ftpClient.Disconnect(); return(new ActionResult(ErrorCode.Ftp_DirectoryReadError)); } } try { ftpClient.UploadFile(file, fullDirectory + "/" + targetFile); } catch (Exception ex) { Logger.Error(ex, "Exception while uploading the file \"" + file); ftpClient.Disconnect(); return(new ActionResult(ErrorCode.Ftp_UploadError)); } } ftpClient.Disconnect(); return(new ActionResult()); }