diff --git a/Common/PdfScribeSharedAssemblyInfo.cs b/Common/PdfScribeSharedAssemblyInfo.cs index 511b2cc..320ef98 100644 --- a/Common/PdfScribeSharedAssemblyInfo.cs +++ b/Common/PdfScribeSharedAssemblyInfo.cs @@ -11,6 +11,11 @@ using System.Runtime.InteropServices; [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] +#if DEBUG +[assembly: AssemblyConfiguration("DEBUG")] +#else +[assembly: AssemblyConfiguration("RELEASE")] +#endif // Version information for an assembly consists of the following four values: // diff --git a/PdfScribe.sln b/PdfScribe.sln index ee310c6..a76ad7b 100644 --- a/PdfScribe.sln +++ b/PdfScribe.sln @@ -35,8 +35,8 @@ Global {1EAD8E9A-A123-4C37-B31E-AEE1354DF003}.Debug|x64.Build.0 = Debug|x64 {1EAD8E9A-A123-4C37-B31E-AEE1354DF003}.Debug|x86.ActiveCfg = Debug|x86 {1EAD8E9A-A123-4C37-B31E-AEE1354DF003}.Debug|x86.Build.0 = Debug|x86 - {1EAD8E9A-A123-4C37-B31E-AEE1354DF003}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1EAD8E9A-A123-4C37-B31E-AEE1354DF003}.Release|Any CPU.Build.0 = Release|Any CPU + {1EAD8E9A-A123-4C37-B31E-AEE1354DF003}.Release|Any CPU.ActiveCfg = Release|x64 + {1EAD8E9A-A123-4C37-B31E-AEE1354DF003}.Release|Any CPU.Build.0 = Release|x64 {1EAD8E9A-A123-4C37-B31E-AEE1354DF003}.Release|x64.ActiveCfg = Release|x64 {1EAD8E9A-A123-4C37-B31E-AEE1354DF003}.Release|x64.Build.0 = Release|x64 {1EAD8E9A-A123-4C37-B31E-AEE1354DF003}.Release|x86.ActiveCfg = Release|x86 @@ -47,16 +47,20 @@ Global {09BB3AA3-96D3-4BA1-BCB3-4E17067F42B2}.Debug|x64.Build.0 = Debug|x64 {09BB3AA3-96D3-4BA1-BCB3-4E17067F42B2}.Debug|x86.ActiveCfg = Debug|x86 {09BB3AA3-96D3-4BA1-BCB3-4E17067F42B2}.Debug|x86.Build.0 = Debug|x86 - {09BB3AA3-96D3-4BA1-BCB3-4E17067F42B2}.Release|Any CPU.ActiveCfg = Release|x86 - {09BB3AA3-96D3-4BA1-BCB3-4E17067F42B2}.Release|x64.ActiveCfg = Release|x86 + {09BB3AA3-96D3-4BA1-BCB3-4E17067F42B2}.Release|Any CPU.ActiveCfg = Release|x64 + {09BB3AA3-96D3-4BA1-BCB3-4E17067F42B2}.Release|Any CPU.Build.0 = Release|x64 + {09BB3AA3-96D3-4BA1-BCB3-4E17067F42B2}.Release|x64.ActiveCfg = Release|x64 + {09BB3AA3-96D3-4BA1-BCB3-4E17067F42B2}.Release|x64.Build.0 = Release|x64 {09BB3AA3-96D3-4BA1-BCB3-4E17067F42B2}.Release|x86.ActiveCfg = Release|x86 {09BB3AA3-96D3-4BA1-BCB3-4E17067F42B2}.Release|x86.Build.0 = Release|x86 - {E8679E1B-8C89-4201-97D5-7E43C5A486C9}.Debug|Any CPU.ActiveCfg = Debug|x64 + {E8679E1B-8C89-4201-97D5-7E43C5A486C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E8679E1B-8C89-4201-97D5-7E43C5A486C9}.Debug|Any CPU.Build.0 = Debug|Any CPU {E8679E1B-8C89-4201-97D5-7E43C5A486C9}.Debug|x64.ActiveCfg = Debug|x64 {E8679E1B-8C89-4201-97D5-7E43C5A486C9}.Debug|x64.Build.0 = Debug|x64 {E8679E1B-8C89-4201-97D5-7E43C5A486C9}.Debug|x86.ActiveCfg = Debug|x86 {E8679E1B-8C89-4201-97D5-7E43C5A486C9}.Debug|x86.Build.0 = Debug|x86 {E8679E1B-8C89-4201-97D5-7E43C5A486C9}.Release|Any CPU.ActiveCfg = Release|x64 + {E8679E1B-8C89-4201-97D5-7E43C5A486C9}.Release|Any CPU.Build.0 = Release|x64 {E8679E1B-8C89-4201-97D5-7E43C5A486C9}.Release|x64.ActiveCfg = Release|x64 {E8679E1B-8C89-4201-97D5-7E43C5A486C9}.Release|x64.Build.0 = Release|x64 {E8679E1B-8C89-4201-97D5-7E43C5A486C9}.Release|x86.ActiveCfg = Release|x86 diff --git a/PdfScribe/ActivityNotification.xaml b/PdfScribe/ActivityNotification.xaml index 1774b61..eb918a4 100644 --- a/PdfScribe/ActivityNotification.xaml +++ b/PdfScribe/ActivityNotification.xaml @@ -1,4 +1,5 @@  /// Interaction logic for ActivityNotification.xaml /// - public partial class ActivityNotification : Window + internal partial class ActivityNotification : Window { - public ActivityNotification() + internal ActivityNotification() { InitializeComponent(); } diff --git a/PdfScribe/ErrorDialogPresenter.cs b/PdfScribe/ErrorDialogPresenter.cs index 7af74a2..52fd42f 100644 --- a/PdfScribe/ErrorDialogPresenter.cs +++ b/PdfScribe/ErrorDialogPresenter.cs @@ -38,8 +38,8 @@ namespace PdfScribe /// with a standard error icon, and /// just a Close button /// - /// Text that goes in the window caption - /// Instructional text (Appears next to the icon) + /// Text that goes in the window's caption + /// Instructional text (Appears next to the error icon) /// Smaller message detail text at bottom public void ShowSimple(String captionText, String instructionText, diff --git a/PdfScribe/Properties/AssemblyInfo.cs b/PdfScribe/Properties/AssemblyInfo.cs index d840ece..0c66335 100644 --- a/PdfScribe/Properties/AssemblyInfo.cs +++ b/PdfScribe/Properties/AssemblyInfo.cs @@ -8,9 +8,8 @@ using System.Windows; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("PdfScribe")] -[assembly: AssemblyDescription("Postscript output redirector")] -[assembly: AssemblyConfiguration("")] - +[assembly: AssemblyDescription("Postscript printer output redirector")] + // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. diff --git a/PdfScribeCore/PdfScribeInstaller.cs b/PdfScribeCore/PdfScribeInstaller.cs index 324bd4c..4147afc 100644 --- a/PdfScribeCore/PdfScribeInstaller.cs +++ b/PdfScribeCore/PdfScribeInstaller.cs @@ -77,6 +77,7 @@ namespace PdfScribeCore const string NATIVE_COULDNOTENABLE64REDIRECTION = "Could not enable 64-bit file system redirection."; const string NATIVE_COULDNOTREVERT64REDIRECTION = "Could not revert 64-bit file system redirection."; + const string INSTALL_ROLLBACK_FAILURE_AT_FUNCTION = "Partial uninstallation failure. Function {0} returned false."; #endregion @@ -108,20 +109,38 @@ namespace PdfScribeCore #region Port operations #if DEBUG - public int AddPdfScribePort_Test() + public bool AddPdfScribePort_Test() { return AddPdfScribePort(); } #endif - private int AddPdfScribePort() + private bool AddPdfScribePort() { - return DoXcvDataPortOperation(PORTNAME, PORTMONITOR, "AddPort"); + bool portAdded = false; + + int portAddResult = DoXcvDataPortOperation(PORTNAME, PORTMONITOR, "AddPort"); + switch (portAddResult) + { + case 0: + portAdded = true; + break; + } + return portAdded; } - public void DeletePdfScribePort() + public bool DeletePdfScribePort() { - DoXcvDataPortOperation(PORTNAME, PORTMONITOR, "DeletePort"); + bool portDeleted = false; + + int portDeleteResult = DoXcvDataPortOperation(PORTNAME, PORTMONITOR, "DeletePort"); + switch (portDeleteResult) + { + case 0: + portDeleted = true; + break; + } + return portDeleted; } /// @@ -130,7 +149,7 @@ namespace PdfScribeCore /// /// /// - /// I can't remember the name of the developer who wrote this code originally, + /// I can't remember the name/link of the developer who wrote this code originally, /// so I can't provide a link or credit. private int DoXcvDataPortOperation(string portName, string portMonitor, string xcvDataOperation) { @@ -284,7 +303,16 @@ namespace PdfScribeCore { bool monitorRemoved = false; if ((NativeMethods.DeleteMonitor(null, ENVIRONMENT_64, PORTMONITOR)) != 0) + { monitorRemoved = true; + // Try to remove the monitor DLL now + if (!DeletePdfScribePortMonitorDll()) + { + logEventSource.TraceEvent(TraceEventType.Warning, + (int)TraceEventType.Warning, + "Could not remove port monitor dll."); + } + } return monitorRemoved; } @@ -435,17 +463,12 @@ namespace PdfScribeCore driverDirectory, 1024, ref dirSizeInBytes)) - throw new ApplicationException("Could not retrieve printer driver directory."); + throw new DirectoryNotFoundException("Could not retrieve printer driver directory."); return driverDirectory.ToString(); } -#if DEBUG - public bool InstallSoftscanPrinter_Test() - { - String driverSourceDirectory = @"C:\Code\PdfScribe\Lib\"; - return InstallPdfScribePrinter(driverSourceDirectory); - } -#endif + + delegate bool undoInstall(); /// /// Installs the port monitor, port, @@ -460,24 +483,27 @@ namespace PdfScribeCore bool printerInstalled = false; + + Stack undoInstallActions = new Stack(); String driverDirectory = RetrievePrinterDriverDirectory(); + undoInstallActions.Push(this.RemovePdfScribePortMonitor); if (AddPdfScribePortMonitor(driverSourceDirectory)) { - - //if (CopyPrinterDriverFiles(driverSourceDirectory, driverFilesToCopy.Concat(dependentFilesToCopy).ToArray())) if (CopyPrinterDriverFiles(driverSourceDirectory, printerDriverFiles.Concat(printerDriverDependentFiles).ToArray())) { - if (AddPdfScribePort() == 0) + undoInstallActions.Push(this.RemovePdfScribePortMonitor); + if (AddPdfScribePort()) { + undoInstallActions.Push(this.RemovePDFScribePrinterDriver); if (InstallPdfScribePrinterDriver()) { + undoInstallActions.Push(this.DeletePdfScribePrinter); if (AddPdfScribePrinter()) { + undoInstallActions.Push(this.RemovePdfScribePortConfig); if (ConfigurePdfScribePort()) - { printerInstalled = true; - } else { // Failed to configure port @@ -507,6 +533,31 @@ namespace PdfScribeCore { //Failed to add port monitor } + if (printerInstalled == false) + { + // Printer installation failed - + // undo all the install steps + while (undoInstallActions.Count > 0) + { + undoInstall undoAction = undoInstallActions.Pop(); + try + { + if (!undoAction()) + { + this.logEventSource.TraceEvent(TraceEventType.Error, + (int)TraceEventType.Error, + String.Format(INSTALL_ROLLBACK_FAILURE_AT_FUNCTION, undoAction.Method.Name)); + } + } + catch (Win32Exception win32Ex) + { + this.logEventSource.TraceEvent(TraceEventType.Error, + (int)TraceEventType.Error, + String.Format(INSTALL_ROLLBACK_FAILURE_AT_FUNCTION, undoAction.Method.Name) + + String.Format(WIN32ERROR, win32Ex.ErrorCode.ToString())); + } + } + } return printerInstalled; } @@ -517,13 +568,18 @@ namespace PdfScribeCore /// public bool UninstallPdfScribePrinter() { - bool printerUninstalled = false; + bool printerUninstalled = true; - DeletePdfScribePrinter(); - RemovePDFScribePrinterDriver(); - DeletePdfScribePort(); - RemovePdfScribePortMonitor(); - RemovePdfScribePortConfig(); + if (!DeletePdfScribePrinter()) + printerUninstalled = false; + if (!RemovePDFScribePrinterDriver()) + printerUninstalled = false; + if (!DeletePdfScribePort()) + printerUninstalled = false; + if (!RemovePdfScribePortMonitor()) + printerUninstalled = false; + if (!RemovePdfScribePortConfig()) + printerUninstalled = false; return printerUninstalled; } @@ -660,18 +716,31 @@ namespace PdfScribeCore printerDriverInstalled = NativeMethods.AddPrinterDriver(null, 6, ref printerDriverInfo); if (printerDriverInstalled == false) { - int lastWinError = Marshal.GetLastWin32Error(); - throw new Win32Exception(Marshal.GetLastWin32Error(), "Could not add printer PDF Scribe printer driver."); + //int lastWinError = Marshal.GetLastWin32Error(); + //throw new Win32Exception(Marshal.GetLastWin32Error(), "Could not add printer PDF Scribe printer driver."); + logEventSource.TraceEvent(TraceEventType.Error, + (int)TraceEventType.Error, + "Could add PDF Scribe printer driver." + + String.Format(WIN32ERROR, Marshal.GetLastWin32Error().ToString())); } return printerDriverInstalled; } + + /// + /// + /// + /// public bool RemovePDFScribePrinterDriver() { bool driverRemoved = NativeMethods.DeletePrinterDriverEx(null, ENVIRONMENT_64, DRIVERNAME, DPD_DELETE_UNUSED_FILES, 3); if (!driverRemoved) { - throw new Win32Exception(Marshal.GetLastWin32Error(), "Could not remove PDF Scribe printer driver"); + //throw new Win32Exception(Marshal.GetLastWin32Error(), "Could not remove PDF Scribe printer driver"); + logEventSource.TraceEvent(TraceEventType.Error, + (int)TraceEventType.Error, + "Could not remove PDF Scribe printer driver." + + String.Format(WIN32ERROR, Marshal.GetLastWin32Error().ToString())); } return driverRemoved; } @@ -690,16 +759,20 @@ namespace PdfScribeCore pdfScribePrinter.pDatatype = "RAW"; pdfScribePrinter.Attributes = 0x00000002; - int softScanPrinterHandle = NativeMethods.AddPrinter(null, 2, ref pdfScribePrinter); - if (softScanPrinterHandle != 0) + int pdfScribePrinterHandle = NativeMethods.AddPrinter(null, 2, ref pdfScribePrinter); + if (pdfScribePrinterHandle != 0) { // Added ok - int closeCode = NativeMethods.ClosePrinter((IntPtr)softScanPrinterHandle); + int closeCode = NativeMethods.ClosePrinter((IntPtr)pdfScribePrinterHandle); printerAdded = true; } else { - throw new Win32Exception(Marshal.GetLastWin32Error(), "Could not add PDF Scribe virtual printer."); + //throw new Win32Exception(Marshal.GetLastWin32Error(), "Could not add PDF Scribe virtual printer."); + logEventSource.TraceEvent(TraceEventType.Error, + (int)TraceEventType.Error, + "Could not add PDF Scribe virtual printer." + + String.Format(WIN32ERROR, Marshal.GetLastWin32Error().ToString())); } return printerAdded; } @@ -723,7 +796,10 @@ namespace PdfScribeCore } else { - // log error + logEventSource.TraceEvent(TraceEventType.Error, + (int)TraceEventType.Error, + "Could not delete PDF Scribe virtual printer." + + String.Format(WIN32ERROR, Marshal.GetLastWin32Error().ToString())); } } finally @@ -758,9 +834,9 @@ namespace PdfScribeCore portConfiguration.SetValue("Description", "PDF Scribe", RegistryValueKind.String); portConfiguration.SetValue("Command", "", RegistryValueKind.String); portConfiguration.SetValue("Arguments", "", RegistryValueKind.String); - portConfiguration.SetValue("Printer", "", RegistryValueKind.String); + portConfiguration.SetValue("Printer", PRINTERNAME, RegistryValueKind.String); portConfiguration.SetValue("Output", 0, RegistryValueKind.DWord); - portConfiguration.SetValue("ShowWindow", 0, RegistryValueKind.DWord); + portConfiguration.SetValue("ShowWindow", 2, RegistryValueKind.DWord); portConfiguration.SetValue("RunUser", 1, RegistryValueKind.DWord); portConfiguration.SetValue("Delay", 300, RegistryValueKind.DWord); portConfiguration.SetValue("LogFileUse", 0, RegistryValueKind.DWord); diff --git a/PdfScribeCore/Properties/AssemblyInfo.cs b/PdfScribeCore/Properties/AssemblyInfo.cs index 4f61077..0f45d63 100644 --- a/PdfScribeCore/Properties/AssemblyInfo.cs +++ b/PdfScribeCore/Properties/AssemblyInfo.cs @@ -7,7 +7,6 @@ using System.Runtime.InteropServices; // associated with an assembly. [assembly: AssemblyTitle("PdfScribeCore")] [assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from diff --git a/PdfScribeInstallCustomAction/CustomAction.config b/PdfScribeInstallCustomAction/CustomAction.config index de951b7..983ab7e 100644 --- a/PdfScribeInstallCustomAction/CustomAction.config +++ b/PdfScribeInstallCustomAction/CustomAction.config @@ -20,7 +20,7 @@ --> - + diff --git a/PdfScribeInstallCustomAction/PdfScribeInstallCustomAction.csproj b/PdfScribeInstallCustomAction/PdfScribeInstallCustomAction.csproj index 3c3c308..59e35db 100644 --- a/PdfScribeInstallCustomAction/PdfScribeInstallCustomAction.csproj +++ b/PdfScribeInstallCustomAction/PdfScribeInstallCustomAction.csproj @@ -51,6 +51,26 @@ true true + + true + bin\Debug\ + DEBUG;TRACE + full + AnyCPU + prompt + true + true + + + bin\Release\ + TRACE + true + pdbonly + AnyCPU + prompt + true + true + diff --git a/PdfScribeUnitTests/PdfScribeUnitTests.csproj.user b/PdfScribeUnitTests/PdfScribeUnitTests.csproj.user index f8800ec..7f102a6 100644 --- a/PdfScribeUnitTests/PdfScribeUnitTests.csproj.user +++ b/PdfScribeUnitTests/PdfScribeUnitTests.csproj.user @@ -25,6 +25,7 @@ en-US false + ShowAllFiles diff --git a/PdfScribeUnitTests/Properties/AssemblyInfo.cs b/PdfScribeUnitTests/Properties/AssemblyInfo.cs index 8bad39a..0ff3b90 100644 --- a/PdfScribeUnitTests/Properties/AssemblyInfo.cs +++ b/PdfScribeUnitTests/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.*")] +//[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/PdfScribeUnitTests/UnitTests.cs b/PdfScribeUnitTests/UnitTests.cs index f32b5ad..421e1e7 100644 --- a/PdfScribeUnitTests/UnitTests.cs +++ b/PdfScribeUnitTests/UnitTests.cs @@ -37,7 +37,7 @@ namespace PdfScribeUnitTests public void Test_InstallPdfScribePrinter() { var scribeInstaller = new PdfScribeInstaller(); - scribeInstaller.InstallSoftscanPrinter_Test(); + scribeInstaller.InstallPdfScribePrinter(@"C:\Code\PdfScribe\Lib\"); } //[Test]