Installer now working - uninstall still broken

This commit is contained in:
S T Chan 2014-01-03 20:39:09 -05:00
parent 3fafd9d411
commit 041ff0d11d
11 changed files with 248 additions and 7 deletions

BIN
Lib/WixNetFxExtension.dll Normal file

Binary file not shown.

BIN
Lib/WixUIExtension.dll Normal file

Binary file not shown.

View File

@ -145,6 +145,12 @@
</Page>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)PdfScribeInstall\PrimaryOutputHarvest\$(TargetFileName)"
copy "$(TargetPath).config" "$(SolutionDir)PdfScribeInstall\PrimaryOutputHarvest\$(TargetFileName).config"
copy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)PdfScribeInstall\PrimaryOutputHarvest\$(TargetName).pdb"
</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View File

@ -100,6 +100,10 @@
<Compile Include="NativeMethods.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)PdfScribeInstall\PrimaryOutputHarvest\$(TargetFileName)"
copy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)PdfScribeInstall\PrimaryOutputHarvest\$(TargetName).pdb"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View File

@ -93,12 +93,18 @@ namespace PdfScribeCore
#endregion
public void AddTraceListener(TraceListener additionalListener)
{
this.logEventSource.Listeners.Add(additionalListener);
}
#region Constructors
public PdfScribeInstaller()
{
this.logEventSource = new TraceSource(logEventSourceNameDefault);
this.logEventSource.Switch = new SourceSwitch("PdfScribeCoreSwitch");
this.logEventSource.Switch.Level = SourceLevels.All;
}
/// <summary>
/// This override sets the
@ -115,6 +121,8 @@ namespace PdfScribeCore
{
throw new ArgumentNullException("eventSourceName");
}
this.logEventSource.Switch = new SourceSwitch("PdfScribeCoreSwitch");
this.logEventSource.Switch.Level = SourceLevels.All;
}
#endregion
@ -507,21 +515,41 @@ namespace PdfScribeCore
undoInstallActions.Push(this.DeletePdfScribePortMonitorDll);
if (AddPdfScribePortMonitor(driverSourceDirectory))
{
this.logEventSource.TraceEvent(TraceEventType.Verbose,
(int)TraceEventType.Verbose,
"Port monitor successfully installed.");
undoInstallActions.Push(this.RemovePdfScribePortMonitor);
if (CopyPrinterDriverFiles(driverSourceDirectory, printerDriverFiles.Concat(printerDriverDependentFiles).ToArray()))
{
this.logEventSource.TraceEvent(TraceEventType.Verbose,
(int)TraceEventType.Verbose,
"Printer drivers copied or already exist.");
undoInstallActions.Push(this.RemovePdfScribePortMonitor);
if (AddPdfScribePort())
{
this.logEventSource.TraceEvent(TraceEventType.Verbose,
(int)TraceEventType.Verbose,
"Redirection port added.");
undoInstallActions.Push(this.RemovePDFScribePrinterDriver);
if (InstallPdfScribePrinterDriver())
{
this.logEventSource.TraceEvent(TraceEventType.Verbose,
(int)TraceEventType.Verbose,
"Printer driver installed.");
undoInstallActions.Push(this.DeletePdfScribePrinter);
if (AddPdfScribePrinter())
{
this.logEventSource.TraceEvent(TraceEventType.Verbose,
(int)TraceEventType.Verbose,
"Virtual printer installed.");
undoInstallActions.Push(this.RemovePdfScribePortConfig);
if (ConfigurePdfScribePort(outputHandlerCommand, outputHandlerArguments))
{
this.logEventSource.TraceEvent(TraceEventType.Verbose,
(int)TraceEventType.Verbose,
"Printer configured.");
printerInstalled = true;
}
else
// Failed to configure port
this.logEventSource.TraceEvent(TraceEventType.Error,
@ -582,6 +610,7 @@ namespace PdfScribeCore
}
}
}
this.logEventSource.Flush();
return printerInstalled;
}
@ -754,7 +783,7 @@ namespace PdfScribeCore
{
bool pdfScribePrinterDriverInstalled = false;
if (IsPrinterDriverInstalled(DRIVERNAME))
if (!IsPrinterDriverInstalled(DRIVERNAME))
{
String driverSourceDirectory = RetrievePrinterDriverDirectory();

30
PdfScribeInstall.sln Normal file
View File

@ -0,0 +1,30 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "PdfScribeInstall", "PdfScribeInstall\PdfScribeInstall.wixproj", "{3C255536-A7F1-4913-9C7F-966DFFEE01BC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3C255536-A7F1-4913-9C7F-966DFFEE01BC}.Debug|Any CPU.ActiveCfg = Debug|x64
{3C255536-A7F1-4913-9C7F-966DFFEE01BC}.Debug|x64.ActiveCfg = Debug|x64
{3C255536-A7F1-4913-9C7F-966DFFEE01BC}.Debug|x64.Build.0 = Debug|x64
{3C255536-A7F1-4913-9C7F-966DFFEE01BC}.Debug|x86.ActiveCfg = Debug|x86
{3C255536-A7F1-4913-9C7F-966DFFEE01BC}.Debug|x86.Build.0 = Debug|x86
{3C255536-A7F1-4913-9C7F-966DFFEE01BC}.Release|Any CPU.ActiveCfg = Release|x64
{3C255536-A7F1-4913-9C7F-966DFFEE01BC}.Release|x64.ActiveCfg = Release|x64
{3C255536-A7F1-4913-9C7F-966DFFEE01BC}.Release|x64.Build.0 = Release|x64
{3C255536-A7F1-4913-9C7F-966DFFEE01BC}.Release|x86.ActiveCfg = Release|x86
{3C255536-A7F1-4913-9C7F-966DFFEE01BC}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>3.7</ProductVersion>
<ProjectGuid>{3c255536-a7f1-4913-9c7f-966dffee01bc}</ProjectGuid>
<SchemaVersion>2.0</SchemaVersion>
<OutputName>PdfScribeInstall</OutputName>
<OutputType>Package</OutputType>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>Debug</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<DefineConstants>Debug</DefineConstants>
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Platform)\$(Configuration)\</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Platform)\$(Configuration)\</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<DefineConstants>Debug</DefineConstants>
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Platform)\$(Configuration)\</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Platform)\$(Configuration)\</IntermediateOutputPath>
</PropertyGroup>
<ItemGroup>
<Compile Include="Product.wxs" />
</ItemGroup>
<ItemGroup>
<WixExtension Include="WixUIExtension">
<HintPath>..\Lib\WixUIExtension.dll</HintPath>
<Name>WixUIExtension</Name>
</WixExtension>
<WixExtension Include="WixNetFxExtension">
<HintPath>..\Lib\WixNetFxExtension.dll</HintPath>
<Name>WixNetFxExtension</Name>
</WixExtension>
</ItemGroup>
<Import Project="$(WixTargetsPath)" />
<!--
To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Wix.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="Pdf Scribe" Language="1033" Version="1.0.0.0" Manufacturer="S T Chan" UpgradeCode="409ff0d1-1c3a-4f8d-8a5a-350705977809">
<Package InstallerVersion="301" Compressed="yes" InstallScope="perMachine"
InstallPrivileges="elevated"
Description="PDF Scribe Virtual Printer"
Comments="PDF Scribe Virtual Printer 1.0.0 installation package"/>
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate EmbedCab="yes"/>
<Feature Id="ProductFeature" Title="PdfScribe" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
<!-- .Net 4.0 Prerequisite -->
<PropertyRef Id="NETFRAMEWORK40FULL"/>
<Condition Message="This application requires .NET Framework 4.0. Please install the .NET Framework then run this installer again.">
<![CDATA[Installed OR NETFRAMEWORK40FULL]]>
</Condition>
<!-- Check if the user has administrator privileges -->
<Property Id="MSIUSEREALADMINDETECTION" Value="1" />
<!-- Custom Actions -->
<Binary Id="PdfScribeInstallCustomAction.CA.dll" SourceFile="PrimaryOutputHarvest\PdfScribeInstallCustomAction.CA.dll" />
<CustomAction Id="SetCustomActionDataValues"
Return="check"
Property="InstallPrinter"
Value="DriverSourceDirectory=[INSTALLFOLDER];OutputCommand=[INSTALLFOLDER]PdfScribe.exe;OutputCommandArguments=" />
<CustomAction Id="InstallPrinter"
Return="check"
Execute="deferred"
BinaryKey="PdfScribeInstallCustomAction.CA.dll"
DllEntry="InstallPdfScribePrinter" Impersonate="no" />
<CustomAction Id="UninstallPrinter"
Return="ignore"
Execute="deferred"
BinaryKey="PdfScribeInstallCustomAction.CA.dll"
DllEntry="UninstallPdfScribePrinter" Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="SetCustomActionDataValues" After="InstallFiles" >NOT Installed</Custom>
<Custom Action="InstallPrinter" After="SetCustomActionDataValues" >NOT Installed</Custom>
<Custom Action="UninstallPrinter" Before="RemoveFiles" >Installed AND NOT UPGRADINGPRODUCTCODE</Custom>
</InstallExecuteSequence>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFiles64Folder">
<Directory Id="INSTALLFOLDER" Name="PdfScribe" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
<!-- <Component Id="ProductComponent"> -->
<!-- TODO: Insert files, registry keys, and other resources here. -->
<Component Id="PdfScribeBase" Guid="{7A339C63-AEA3-491C-8CB1-C78D21426EC1}">
<File Source="PrimaryOutputHarvest\PdfScribeInstallCustomAction.CA.dll" />
<File Id="PdfScribeCoreDll" Source="PrimaryOutputHarvest\PdfScribeCore.dll" />
<File Source="PrimaryOutputHarvest\PdfScribeCore.pdb" />
<File Source="PrimaryOutputHarvest\PdfScribe.exe.config" />
<File Id="PdfScribeExe" Source="PrimaryOutputHarvest\PdfScribe.exe" KeyPath="yes" />
<!-- Third party components -->
<File Source="..\Lib\gsdll64.dll" />
<File Source="..\Lib\Microsoft.WindowsAPICodePack.dll" />
<File Source="..\Lib\Microsoft.WindowsAPICodePack.pdb" />
<File Source="..\Lib\redmon64pdfscribe.dll" />
<File Source="..\Lib\PS5UI.DLL" />
<File Source="..\Lib\PSCRIPT.HLP" />
<File Source="..\Lib\PSCRIPT.NTF" />
<File Source="..\Lib\PSCRIPT5.DLL" />
<File Source="..\Lib\SCPDFPRN.ppd" />
</Component>
<!-- </Component> -->
</ComponentGroup>
</Fragment>
</Wix>

View File

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
@ -15,12 +17,15 @@ namespace PdfScribeInstallCustomAction
public class CustomActions
{
static readonly String traceSourceName = "PdfScribeInstaller";
[CustomAction]
public static ActionResult CheckIfPrinterNotInstalled(Session session)
{
ActionResult resultCode;
PdfScribeInstaller installer = new PdfScribeInstaller();
TextWriterTraceListener installTraceListener = new TextWriterTraceListener("C:\\testout.txt");
PdfScribeInstaller installer = new PdfScribeInstaller(traceSourceName);
installer.AddTraceListener(installTraceListener);
if (installer.IsPdfScribePrinterInstalled())
resultCode = ActionResult.Success;
else
@ -39,7 +44,13 @@ namespace PdfScribeInstallCustomAction
String outputCommand = session.CustomActionData["OutputCommand"];
String outputCommandArguments = session.CustomActionData["OutputCommandArguments"];
PdfScribeInstaller installer = new PdfScribeInstaller();
TextWriterTraceListener installTraceListener = new TextWriterTraceListener("C:\\testout.txt");
installTraceListener.TraceOutputOptions = TraceOptions.Timestamp;
PdfScribeInstaller installer = new PdfScribeInstaller(traceSourceName);
installer.AddTraceListener(installTraceListener);
if (installer.InstallPdfScribePrinter(driverSourceDirectory,
outputCommand,
@ -48,6 +59,9 @@ namespace PdfScribeInstallCustomAction
else
printerInstalled = ActionResult.Failure;
installTraceListener.Flush();
installTraceListener.Close();
return printerInstalled;
}
@ -57,7 +71,7 @@ namespace PdfScribeInstallCustomAction
{
ActionResult printerUninstalled;
PdfScribeInstaller installer = new PdfScribeInstaller();
PdfScribeInstaller installer = new PdfScribeInstaller(traceSourceName);
if (installer.UninstallPdfScribePrinter())
printerUninstalled = ActionResult.Success;
else

View File

@ -92,4 +92,9 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(WixCATargetsPath)" />
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)PdfScribeInstall\PrimaryOutputHarvest\$(TargetFileName)"
copy "$(TargetDir)$(TargetName).CA.dll" "$(SolutionDir)PdfScribeInstall\PrimaryOutputHarvest\$(TargetName).CA.dll"
copy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)PdfScribeInstall\PrimaryOutputHarvest\$(TargetName).pdb"</PostBuildEvent>
</PropertyGroup>
</Project>

View File

@ -17,6 +17,7 @@ namespace PdfScribeUnitTests
public UnitTests()
{ }
#endregion
#if DEBUG
#region PdfScribeCore Tests
//[Test]
@ -36,11 +37,12 @@ namespace PdfScribeUnitTests
//[Test]
public void Test_AddPdfScribePort()
{
var scribeInstaller = new PdfScribeInstaller();
scribeInstaller.AddPdfScribePort_Test();
}
[Test]
//[Test]
public void Test_IsPrinterDriverInstalled()
{
var scribeInstaller = new PdfScribeInstaller();
@ -53,7 +55,7 @@ namespace PdfScribeUnitTests
scribeInstaller.InstallPdfScribePrinter(@"C:\Code\PdfScribe\Lib\", String.Empty, String.Empty);
}
//[Test]
[Test]
public void Test_UninstallPdfScribePrinter()
{
var scribeInstaller = new PdfScribeInstaller();
@ -83,5 +85,7 @@ namespace PdfScribeUnitTests
{
var errorDialog = new PdfScribe.ErrorDialogPresenter("Error Caption", "Error Instructions", "Message text");
}
#endif
}
}