Added logic to support reading a 64 bit registry from 32 bit code.
Fixed logic to check to see if MSWord 2007 has the addin installed for PDF Export Added Unit RO support for MSWord Sections for U-Name, U-ID, U-Other Text, U-Other Number, U-Other Name, and U-OtherID Fixed code to handle Library Documents being remove from a list. Removed Debug Output
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Reflection;
|
||||
using Microsoft.Win32;
|
||||
using System.Windows.Forms;
|
||||
using System.Text.RegularExpressions;
|
||||
using Read64bitRegistryFrom32bitApp;
|
||||
|
||||
namespace LBWordLibrary
|
||||
{
|
||||
@@ -34,31 +35,118 @@ namespace LBWordLibrary
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool WordPDFExporterInstalled
|
||||
private static bool? _WordPDFExporterInstalled = null;
|
||||
public static bool WordPDFExporterInstalled
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_WordPDFExporterInstalled == null)
|
||||
{
|
||||
// this is to determine if ExportAsFixedFormat was installed in MSOffice
|
||||
// This key only worked for Vista
|
||||
//RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"Installer\Components\12B306B24E250DD428FC7016B6FB4BD8");
|
||||
// This key works for Windows Vista and Windows 7
|
||||
try
|
||||
{
|
||||
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\0E5C161912A2A6C4C93C76678926C56C");
|
||||
if (key != null)
|
||||
{
|
||||
key.Close();
|
||||
return true;
|
||||
}
|
||||
_MyLog.WarnFormat("MSWord2007 PDF Export Registry Key Missing");
|
||||
return false;
|
||||
string keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\0E5C161912A2A6C4C93C76678926C56C";
|
||||
bool validKey = RegistryWOW6432.CheckRegKey64Valid(RegHive.HKEY_LOCAL_MACHINE, keyPath);
|
||||
_WordPDFExporterInstalled = validKey;
|
||||
if(!validKey)
|
||||
_MyLog.WarnFormat("MSWord2007 PDF Export Registry Key Missing");
|
||||
//RegistryKey key = Registry.LocalMachine.OpenSubKey(keyPath, RegistryKeyPermissionCheck.ReadSubTree);
|
||||
//if (key == null)
|
||||
//{
|
||||
// RegistryKey localMachine64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
|
||||
// key = localMachine64.OpenSubKey(keystring, RegistryKeyPermissionCheck.ReadSubTree);
|
||||
//}
|
||||
//if (key != null)
|
||||
//{
|
||||
// key.Close();
|
||||
// _WordPDFExporterInstalled = true;
|
||||
// return (bool) _WordPDFExporterInstalled;
|
||||
//}
|
||||
//_WordPDFExporterInstalled = FindEXP_PDF();
|
||||
return (bool) _WordPDFExporterInstalled;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_MyLog.WarnFormat("MSWord2007 PDF Export Registry Key Failure {0} - {1}", ex.GetType().Name, ex.Message);
|
||||
_WordPDFExporterInstalled = false;
|
||||
return (bool) _WordPDFExporterInstalled;
|
||||
}
|
||||
|
||||
}
|
||||
return (bool) _WordPDFExporterInstalled;
|
||||
}
|
||||
}
|
||||
private static bool FindEXP_PDF()
|
||||
{
|
||||
bool retval = false;
|
||||
DateTime dtStart = DateTime.Now;
|
||||
try
|
||||
{
|
||||
//string keystr = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\0E5C161912A2A6C4C93C76678926C56C";
|
||||
RegistryKey key = null;
|
||||
string keystr = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components";
|
||||
while (key == null && keystr != "")
|
||||
{
|
||||
key = Registry.LocalMachine.OpenSubKey(keystr, RegistryKeyPermissionCheck.ReadSubTree);
|
||||
keystr = keystr.Substring(0, keystr.LastIndexOf("\\"));
|
||||
}
|
||||
if (FindKeys(key, "EXP_PDF.DLL"))
|
||||
retval = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddKeyFound(string.Format("{0} - {1}", ex.GetType().Name, ex.Message));
|
||||
}
|
||||
finally
|
||||
{
|
||||
DateTime dtEnd = DateTime.Now;
|
||||
TimeSpan ts = TimeSpan.FromTicks(dtEnd.Ticks - dtStart.Ticks);
|
||||
AddKeyFound(string.Format("{0} Seconds", ts.TotalSeconds));
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
private static bool FindKeys(RegistryKey key, string find)
|
||||
{
|
||||
string[] keyNames = key.GetSubKeyNames();
|
||||
foreach (string keyName in keyNames)
|
||||
{
|
||||
using (RegistryKey subKey = key.OpenSubKey(keyName, RegistryKeyPermissionCheck.ReadSubTree))
|
||||
{
|
||||
if (FindKeys(subKey, find)) return true;
|
||||
}
|
||||
}
|
||||
if (FindNames(key, find)) return true;
|
||||
return false;
|
||||
}
|
||||
private static bool FindNames(RegistryKey key, string find)
|
||||
{
|
||||
string[] names = key.GetValueNames();
|
||||
foreach (string name in names)
|
||||
{
|
||||
if (FindNames(key, name, find)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static bool FindNames(RegistryKey key, string name, string find)
|
||||
{
|
||||
RegistryValueKind kind = key.GetValueKind(name);
|
||||
if (kind == RegistryValueKind.String)
|
||||
{
|
||||
string val = (string)key.GetValue(name);
|
||||
if (val.Contains(find))
|
||||
{
|
||||
AddKeyFound(string.Format("'{0}'\r\n Value {1} = '{2}'", key.ToString(), name, val));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void AddKeyFound(string str)
|
||||
{
|
||||
_MyLog.WarnFormat("RegistryKeySearch: {0}",str);
|
||||
}
|
||||
private bool CanCreatePDFFile(string pdfFileName)
|
||||
{
|
||||
@@ -126,14 +214,21 @@ namespace LBWordLibrary
|
||||
if (((int)Convert.ToSingle(Version)) > 12)
|
||||
return CreatePDF2007(pdfFileName, DebugStatus);
|
||||
if (((int)Convert.ToSingle(Version)) == 12 && WordPDFExporterInstalled)
|
||||
{
|
||||
//_MyLog.WarnFormat("Word PDF Exporter Installed - MSWord Version = '{0}'" , Version);
|
||||
return CreatePDF2007(pdfFileName, DebugStatus);
|
||||
else if (VolianPDFInstalled)
|
||||
}
|
||||
if (VolianPDFInstalled)
|
||||
{
|
||||
_MyLog.WarnFormat("Using VolianPDFWriter - MSWord Version = '{0}'", Version);
|
||||
return CreatePDF2003BG(pdfFileName);
|
||||
}
|
||||
else
|
||||
throw new Exception("No PDF Writer support installed for MS Word sections");
|
||||
//else // Force PDF Export
|
||||
//{
|
||||
// _MyLog.WarnFormat("Force PDF Export for Michelle - MSWord Version = '{0}'", Version);
|
||||
// return CreatePDF2007(pdfFileName, DebugStatus);
|
||||
throw new Exception("No PDF Writer support installed for MS Word sections");
|
||||
//}
|
||||
}
|
||||
public string CreatePDF2003FG(string pdfFileName, bool openPDF)
|
||||
{
|
||||
|
Reference in New Issue
Block a user