more refactoring

This commit is contained in:
S T Chan 2013-12-18 23:58:43 -05:00
parent ca5fe19474
commit 5a00b62203
2 changed files with 18 additions and 10 deletions

View File

@ -86,15 +86,22 @@ namespace PdfScribeCore
private int AddPdfScribePort() private int AddPdfScribePort()
{ {
return DoXcvDataPortOperation(PORTNAME, "AddPort"); return DoXcvDataPortOperation(PORTNAME, PORTMONITOR, "AddPort");
} }
public void DeletePdfScribePort(string portName) public void DeletePdfScribePort()
{ {
DoXcvDataPortOperation(portName, "DeletePort"); DoXcvDataPortOperation(PORTNAME, PORTMONITOR, "DeletePort");
} }
private int DoXcvDataPortOperation(string portName, string xcvDataOperation) /// <summary>
///
/// </summary>
/// <param name="portName"></param>
/// <param name="xcvDataOperation"></param>
/// <returns></returns>
/// <remarks>I can't remember the name of the coder who wrote this code originally</remarks>
private int DoXcvDataPortOperation(string portName, string portMonitor, string xcvDataOperation)
{ {
int win32ErrorCode; int win32ErrorCode;
@ -107,7 +114,7 @@ namespace PdfScribeCore
IntPtr hPrinter = IntPtr.Zero; IntPtr hPrinter = IntPtr.Zero;
if (NativeMethods.OpenPrinter(",XcvMonitor " + PORTMONITOR, ref hPrinter, def) != 0) if (NativeMethods.OpenPrinter(",XcvMonitor " + portMonitor, ref hPrinter, def) != 0)
{ {
if (!portName.EndsWith("\0")) if (!portName.EndsWith("\0"))
portName += "\0"; // Must be a null terminated string portName += "\0"; // Must be a null terminated string
@ -467,7 +474,7 @@ namespace PdfScribeCore
DeletePdfScribePrinter(); DeletePdfScribePrinter();
RemovePDFScribePrinterDriver(); RemovePDFScribePrinterDriver();
DeletePdfScribePort(PORTNAME); DeletePdfScribePort();
RemovePdfScribePortMonitor(); RemovePdfScribePortMonitor();
RemovePdfScribePortConfig(); RemovePdfScribePortConfig();
return printerUninstalled; return printerUninstalled;
@ -669,11 +676,12 @@ namespace PdfScribeCore
bool registryChangesMade = false; bool registryChangesMade = false;
// Add all the registry info // Add all the registry info
// for the port and monitor // for the port and monitor
RegistryKey portConfiguration = Registry.LocalMachine.CreateSubKey("SYSTEM\\CurrentControlSet\\Control\\Print\\Monitors\\" + RegistryKey portConfiguration;
PORTMONITOR +
"\\Ports\\" + PORTNAME);
try try
{ {
portConfiguration = Registry.LocalMachine.CreateSubKey("SYSTEM\\CurrentControlSet\\Control\\Print\\Monitors\\" +
PORTMONITOR +
"\\Ports\\" + PORTNAME);
portConfiguration.SetValue("Description", "PDF Scribe", RegistryValueKind.String); portConfiguration.SetValue("Description", "PDF Scribe", RegistryValueKind.String);
portConfiguration.SetValue("Command", "", RegistryValueKind.String); portConfiguration.SetValue("Command", "", RegistryValueKind.String);
portConfiguration.SetValue("Arguments", "", RegistryValueKind.String); portConfiguration.SetValue("Arguments", "", RegistryValueKind.String);

View File

@ -23,7 +23,7 @@ namespace PdfScribeUnitTests
public void Test_DeletePdfScribePort() public void Test_DeletePdfScribePort()
{ {
var scribeInstaller = new PdfScribeInstaller(); var scribeInstaller = new PdfScribeInstaller();
scribeInstaller.DeletePdfScribePort("PDFSCRIBE:"); scribeInstaller.DeletePdfScribePort();
} }
//[Test] //[Test]