private static string CreateJobFolderInSpool(string psFile, string spoolFolder) { var psFilename = PathSafe.GetFileName(psFile); var jobFolder = PathSafe.Combine(spoolFolder, psFilename); jobFolder = new UniqueDirectory(jobFolder).MakeUniqueDirectory(); Directory.CreateDirectory(jobFolder); Logger.Trace("Created spool directory for ps-file job: " + jobFolder); return(jobFolder); }
private void StartDownload(string downloadUrl) { _webClient = new WebClient(); _webClient.DownloadProgressChanged += WebClientOnDownloadProgressChanged; _webClient.DownloadFileCompleted += WebClientOnDownloadFileCompleted; var uri = new Uri(downloadUrl); var filename = _pathSafe.GetFileName(uri.LocalPath); _downloadSpeed = new DownloadSpeed(_webClient); _downloadLocation = _tempFolderProvider.TempFolder; _directory.CreateDirectory(_downloadLocation); _downloadLocation = _pathSafe.Combine(_downloadLocation, filename); _webClient.DownloadFileAsync(uri, _downloadLocation); }
/// <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); }
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 {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); }
private string ComposeFilename(Job job) { var filePath = _targetFileNameComposer.ComposeTargetFileName(job); var folderName = _pathSafe.GetDirectoryName(filePath); if (string.IsNullOrEmpty(folderName)) { folderName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); } var filename = _pathSafe.GetFileName(filePath); if (string.IsNullOrEmpty(filename)) { filename = "document.pdf"; } return(_pathSafe.Combine(folderName, filename)); }
public bool TryRepairPrinter(IEnumerable <string> printerNames) { Logger.Error( "It looks like the printers are broken. This needs to be fixed to allow clawPDF to work properly"); var title = _translator.GetTranslation("Application", "RepairPrinterNoPrintersInstalled", "No printers installed"); var message = _translator.GetFormattedTranslation("Application", "RepairPrinterAskUser", "You do not have any clawPDF printers installed. Most likely there was a problem during the setup or the installation has been altered afterwards.\r\nDo you want to fix this by reinstalling the clawPDF printers?\r\n\r\nNote: You might be asked twice to grant admin privileges while fixing the problem."); Logger.Debug("Asking to start repair.."); if (MessageWindow.ShowTopMost(message, title, MessageWindowButtons.YesNo, MessageWindowIcon.Exclamation) == MessageWindowResponse.Yes) { var applicationPath = _assemblyHelper.GetCurrentAssemblyDirectory(); var printerHelperPath = _pathSafe.Combine(applicationPath, "SetupHelper.exe"); if (!File.Exists(printerHelperPath)) { Logger.Error("SetupHelper.exe does not exist!"); title = _translator.GetTranslation("Application", "Error", "Error"); message = _translator.GetFormattedTranslation("Application", "SetupFileMissing", "An important clawPDF file is missing ('{0}'). Please reinstall clawPDF!", _pathSafe.GetFileName(printerHelperPath)); MessageWindow.ShowTopMost(message, title, MessageWindowButtons.OK, MessageWindowIcon.Error); return(false); } var shellExecuteHelper = new ShellExecuteHelper(); //Logger.Debug("Uninstalling Printers..."); //var uninstallResult = shellExecuteHelper.RunAsAdmin(printerHelperPath, @"/Driver=Remove"); //Logger.Debug("Done: {0}", uninstallResult); Logger.Debug("Reinstalling Printers..."); var clawPdfPath = _pathSafe.Combine(applicationPath, "clawPDF.exe"); var printerNameString = GetPrinterNameString(printerNames); //var installParams = $"/InstallPrinter {printerNameString} /PortApplication \"{clawPdfPath}\""; var installResult = shellExecuteHelper.RunAsAdmin(printerHelperPath, @"/Driver=Add"); Logger.Debug("Done: {0}", installResult); } Logger.Debug("Now we'll check again, if the printer is installed"); if (IsRepairRequired()) { Logger.Info("The printer could not be repaired."); title = _translator.GetTranslation("Application", "Error", "Error"); message = _translator.GetFormattedTranslation("Application", "RepairPrinterFailed", "clawPDF was not able to repair your printers. Please contact your administrator or the support to assist you in with this problem."); MessageWindow.ShowTopMost(message, title, MessageWindowButtons.OK, MessageWindowIcon.Exclamation); return(false); } Logger.Info("The printer was repaired successfully"); return(true); }