예제 #1
0
        public void TryRepairPrinter_PrinterHelperDoesNotExist_ShowsErrorAndFails()
        {
            var errorWasShown = false;

            HandleMessageInteraction(MessageOptions.YesNo, _applicationTranslation.RepairPrinterAskUserUac, interaction => interaction.Response = MessageResponse.Yes);
            HandleMessageInteraction(MessageOptions.OK, _applicationTranslation.GetSetupFileMissingMessage("PrinterHelper.exe"), interaction => errorWasShown = true);
            _file.Exists(_printerHelperPath).Returns(false);

            var repairPrinter = BuildRepairPrinterAssistant();

            var result = repairPrinter.TryRepairPrinter(new[] { "PDFCreator" });

            _shellExecuteHelper.DidNotReceiveWithAnyArgs().RunAsAdmin("", "");
            Assert.IsTrue(errorWasShown);
            Assert.IsFalse(result);
        }
예제 #2
0
        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.GetPdfforgeAssemblyDirectory();
                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);
        }
        public void TryRepairSpoolPath()
        {
            Logger.Error(
                "The spool folder is not accessible due to a permission problem. PDFCreator will not work this way");

            var username = _environment.UserName;

            Logger.Debug("UserName is {0}", username);

            var title   = _translation.SpoolFolderAccessDenied;
            var message = _translation.GetSpoolFolderAskToRepairMessage(_tempFolder);

            Logger.Debug("Asking to start repair..");
            if (ShowMessage(message, title, MessageOptions.YesNo, MessageIcon.Exclamation) == MessageResponse.Yes)
            {
                var repairToolPath = _assemblyHelper.GetPdfforgeAssemblyDirectory();
                repairToolPath = _path.Combine(repairToolPath, "RepairFolderPermissions.exe");

                var repairToolParameters = $"\"{username}\" \"{_tempFolder}\"";

                Logger.Debug("RepairTool path is: {0}", repairToolPath);
                Logger.Debug("Parameters: {0}", repairToolParameters);

                if (!_file.Exists(repairToolPath))
                {
                    Logger.Error("RepairFolderPermissions.exe does not exist!");
                    title   = _translation.RepairToolNotFound;
                    message = _translation.GetSetupFileMissingMessage(_path.GetFileName(repairToolPath));

                    ShowMessage(message, title, MessageOptions.OK, MessageIcon.Error);
                    return;
                }

                Logger.Debug("Starting RepairTool...");
                var result = _shellExecuteHelper.RunAsAdmin(repairToolPath, repairToolParameters);
                Logger.Debug("Done: {0}", result);
            }
        }