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 Microsoft.Win32;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using Read64bitRegistryFrom32bitApp;
|
||||||
|
|
||||||
namespace LBWordLibrary
|
namespace LBWordLibrary
|
||||||
{
|
{
|
||||||
@@ -34,31 +35,118 @@ namespace LBWordLibrary
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public bool WordPDFExporterInstalled
|
private static bool? _WordPDFExporterInstalled = null;
|
||||||
|
public static bool WordPDFExporterInstalled
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
if (_WordPDFExporterInstalled == null)
|
||||||
|
{
|
||||||
// this is to determine if ExportAsFixedFormat was installed in MSOffice
|
// this is to determine if ExportAsFixedFormat was installed in MSOffice
|
||||||
// This key only worked for Vista
|
// This key only worked for Vista
|
||||||
//RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"Installer\Components\12B306B24E250DD428FC7016B6FB4BD8");
|
//RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"Installer\Components\12B306B24E250DD428FC7016B6FB4BD8");
|
||||||
// This key works for Windows Vista and Windows 7
|
// This key works for Windows Vista and Windows 7
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\0E5C161912A2A6C4C93C76678926C56C");
|
string keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\0E5C161912A2A6C4C93C76678926C56C";
|
||||||
if (key != null)
|
bool validKey = RegistryWOW6432.CheckRegKey64Valid(RegHive.HKEY_LOCAL_MACHINE, keyPath);
|
||||||
{
|
_WordPDFExporterInstalled = validKey;
|
||||||
key.Close();
|
if(!validKey)
|
||||||
return true;
|
_MyLog.WarnFormat("MSWord2007 PDF Export Registry Key Missing");
|
||||||
}
|
//RegistryKey key = Registry.LocalMachine.OpenSubKey(keyPath, RegistryKeyPermissionCheck.ReadSubTree);
|
||||||
_MyLog.WarnFormat("MSWord2007 PDF Export Registry Key Missing");
|
//if (key == null)
|
||||||
return false;
|
//{
|
||||||
|
// 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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_MyLog.WarnFormat("MSWord2007 PDF Export Registry Key Failure {0} - {1}", ex.GetType().Name, ex.Message);
|
_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;
|
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)
|
private bool CanCreatePDFFile(string pdfFileName)
|
||||||
{
|
{
|
||||||
@@ -126,14 +214,21 @@ namespace LBWordLibrary
|
|||||||
if (((int)Convert.ToSingle(Version)) > 12)
|
if (((int)Convert.ToSingle(Version)) > 12)
|
||||||
return CreatePDF2007(pdfFileName, DebugStatus);
|
return CreatePDF2007(pdfFileName, DebugStatus);
|
||||||
if (((int)Convert.ToSingle(Version)) == 12 && WordPDFExporterInstalled)
|
if (((int)Convert.ToSingle(Version)) == 12 && WordPDFExporterInstalled)
|
||||||
|
{
|
||||||
|
//_MyLog.WarnFormat("Word PDF Exporter Installed - MSWord Version = '{0}'" , Version);
|
||||||
return CreatePDF2007(pdfFileName, DebugStatus);
|
return CreatePDF2007(pdfFileName, DebugStatus);
|
||||||
else if (VolianPDFInstalled)
|
}
|
||||||
|
if (VolianPDFInstalled)
|
||||||
{
|
{
|
||||||
_MyLog.WarnFormat("Using VolianPDFWriter - MSWord Version = '{0}'", Version);
|
_MyLog.WarnFormat("Using VolianPDFWriter - MSWord Version = '{0}'", Version);
|
||||||
return CreatePDF2003BG(pdfFileName);
|
return CreatePDF2003BG(pdfFileName);
|
||||||
}
|
}
|
||||||
else
|
//else // Force PDF Export
|
||||||
throw new Exception("No PDF Writer support installed for MS Word sections");
|
//{
|
||||||
|
// _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)
|
public string CreatePDF2003FG(string pdfFileName, bool openPDF)
|
||||||
{
|
{
|
||||||
|
110
PROMS/LBWordLibrary/RegHive.cs
Normal file
110
PROMS/LBWordLibrary/RegHive.cs
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Read64bitRegistryFrom32bitApp
|
||||||
|
{
|
||||||
|
public enum RegSAM
|
||||||
|
{
|
||||||
|
QueryValue = 0x0001,
|
||||||
|
SetValue = 0x0002,
|
||||||
|
CreateSubKey = 0x0004,
|
||||||
|
EnumerateSubKeys = 0x0008,
|
||||||
|
Notify = 0x0010,
|
||||||
|
CreateLink = 0x0020,
|
||||||
|
WOW64_32Key = 0x0200,
|
||||||
|
WOW64_64Key = 0x0100,
|
||||||
|
WOW64_Res = 0x0300,
|
||||||
|
Read = 0x00020019,
|
||||||
|
Write = 0x00020006,
|
||||||
|
Execute = 0x00020019,
|
||||||
|
AllAccess = 0x000f003f
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RegHive
|
||||||
|
{
|
||||||
|
public static UIntPtr HKEY_LOCAL_MACHINE = new UIntPtr(0x80000002u);
|
||||||
|
public static UIntPtr HKEY_CURRENT_USER = new UIntPtr(0x80000001u);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RegistryWOW6432
|
||||||
|
{
|
||||||
|
#region Member Variables
|
||||||
|
#region Read 64bit Reg from 32bit app
|
||||||
|
[DllImport("Advapi32.dll")]
|
||||||
|
static extern uint RegOpenKeyEx(
|
||||||
|
UIntPtr hKey,
|
||||||
|
string lpSubKey,
|
||||||
|
uint ulOptions,
|
||||||
|
int samDesired,
|
||||||
|
out int phkResult);
|
||||||
|
|
||||||
|
[DllImport("Advapi32.dll")]
|
||||||
|
static extern uint RegCloseKey(int hKey);
|
||||||
|
|
||||||
|
[DllImport("advapi32.dll", EntryPoint = "RegQueryValueEx")]
|
||||||
|
public static extern int RegQueryValueEx(
|
||||||
|
int hKey, string lpValueName,
|
||||||
|
int lpReserved,
|
||||||
|
ref uint lpType,
|
||||||
|
System.Text.StringBuilder lpData,
|
||||||
|
ref uint lpcbData);
|
||||||
|
#endregion
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Functions
|
||||||
|
static public string GetRegKey64Value(UIntPtr inHive, String inKeyName, String inPropertyName)
|
||||||
|
{
|
||||||
|
return GetRegKey64Value(inHive, inKeyName, RegSAM.WOW64_64Key, inPropertyName);
|
||||||
|
}
|
||||||
|
static public string GetRegKey32Value(UIntPtr inHive, String inKeyName, String inPropertyName)
|
||||||
|
{
|
||||||
|
return GetRegKey64Value(inHive, inKeyName, RegSAM.WOW64_32Key, inPropertyName);
|
||||||
|
}
|
||||||
|
static public string GetRegKey64Value(UIntPtr inHive, String inKeyName, RegSAM in32or64key, String inPropertyName)
|
||||||
|
{
|
||||||
|
int hkey = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
uint lResult = RegOpenKeyEx(RegHive.HKEY_LOCAL_MACHINE, inKeyName, 0, (int)RegSAM.QueryValue | (int)in32or64key, out hkey);
|
||||||
|
if (0 != lResult) return null;
|
||||||
|
uint lpType = 0;
|
||||||
|
uint lpcbData = 1024;
|
||||||
|
StringBuilder AgeBuffer = new StringBuilder(1024);
|
||||||
|
RegQueryValueEx(hkey, inPropertyName, 0, ref lpType, AgeBuffer, ref lpcbData);
|
||||||
|
string Age = AgeBuffer.ToString();
|
||||||
|
return Age;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (0 != hkey) RegCloseKey(hkey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static public bool CheckRegKey64Valid(UIntPtr inHive, String inKeyName)
|
||||||
|
{
|
||||||
|
return CheckRegKey64Valid(inHive, inKeyName, RegSAM.WOW64_64Key);
|
||||||
|
}
|
||||||
|
static public bool GetRegKey32Valid(UIntPtr inHive, String inKeyName)
|
||||||
|
{
|
||||||
|
return CheckRegKey64Valid(inHive, inKeyName, RegSAM.WOW64_32Key);
|
||||||
|
}
|
||||||
|
static public bool CheckRegKey64Valid(UIntPtr inHive, String inKeyName, RegSAM in32or64key)
|
||||||
|
{
|
||||||
|
int hkey = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
uint lResult = RegOpenKeyEx(RegHive.HKEY_LOCAL_MACHINE, inKeyName, 0, (int)RegSAM.QueryValue | (int)in32or64key, out hkey);
|
||||||
|
if (0 != lResult) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (0 != hkey) RegCloseKey(hkey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Enums
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
@@ -810,6 +810,12 @@ namespace VEPROMS.CSLA.Library
|
|||||||
{
|
{
|
||||||
if(sel.Text.ToUpper() == "<U-TEXT>") val =lookup.DocVersionInfo.DocVersionConfig.Unit_Text;
|
if(sel.Text.ToUpper() == "<U-TEXT>") val =lookup.DocVersionInfo.DocVersionConfig.Unit_Text;
|
||||||
else if (sel.Text.ToUpper() == "<U-NUMBER>") val = lookup.DocVersionInfo.DocVersionConfig.Unit_Number;
|
else if (sel.Text.ToUpper() == "<U-NUMBER>") val = lookup.DocVersionInfo.DocVersionConfig.Unit_Number;
|
||||||
|
else if (sel.Text.ToUpper() == "<U-NAME>") val = lookup.DocVersionInfo.DocVersionConfig.Unit_Name;
|
||||||
|
else if (sel.Text.ToUpper() == "<U-ID>") val = lookup.DocVersionInfo.DocVersionConfig.Unit_ID;
|
||||||
|
else if (sel.Text.ToUpper() == "<U-OTHER TEXT>") val = lookup.DocVersionInfo.DocVersionConfig.Other_Unit_Text;
|
||||||
|
else if (sel.Text.ToUpper() == "<U-OTHER NUMBER>") val = lookup.DocVersionInfo.DocVersionConfig.Other_Unit_Number;
|
||||||
|
else if (sel.Text.ToUpper() == "<U-OTHER NAME>") val = lookup.DocVersionInfo.DocVersionConfig.Other_Unit_Name;
|
||||||
|
else if (sel.Text.ToUpper() == "<U-OTHER ID>") val = lookup.DocVersionInfo.DocVersionConfig.Other_Unit_ID;
|
||||||
//val = "<U-ID>",MyDocVersion.DocVersionConfig.Unit_ID);
|
//val = "<U-ID>",MyDocVersion.DocVersionConfig.Unit_ID);
|
||||||
//text = text.Replace(@"<S\u8209?ID>", _MyItemInfo.MyDocVersion.DocVersionConfig.Unit_ProcedureSetID);
|
//text = text.Replace(@"<S\u8209?ID>", _MyItemInfo.MyDocVersion.DocVersionConfig.Unit_ProcedureSetID);
|
||||||
//text = text.Replace("<U>", _MyItemInfo.MyDocVersion.DocVersionConfig.Unit_Number);
|
//text = text.Replace("<U>", _MyItemInfo.MyDocVersion.DocVersionConfig.Unit_Number);
|
||||||
|
@@ -187,7 +187,7 @@ namespace Volian.Controls.Library
|
|||||||
this._MyDSOFramer.Open(MyDSOFile.MyFile.FullName);
|
this._MyDSOFramer.Open(MyDSOFile.MyFile.FullName);
|
||||||
}
|
}
|
||||||
LBDocumentClass doc = new LBDocumentClass(_MyDSOFramer.ActiveDocument);
|
LBDocumentClass doc = new LBDocumentClass(_MyDSOFramer.ActiveDocument);
|
||||||
Console.WriteLine("Version {0}", doc.Application.Version);
|
//Console.WriteLine("Version {0}", doc.Application.Version);
|
||||||
float ver;
|
float ver;
|
||||||
if (!float.TryParse(doc.Application.Version, out ver))
|
if (!float.TryParse(doc.Application.Version, out ver))
|
||||||
ver = 12.0F;
|
ver = 12.0F;
|
||||||
|
@@ -268,26 +268,27 @@ namespace Volian.Controls.Library
|
|||||||
Application.DoEvents();
|
Application.DoEvents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private bool _ProcessingSelectedValueChanged = false;
|
private bool _ProcessingSelectedValueChanged = false;
|
||||||
private void listBoxUsages_SelectedValueChanged(object sender, EventArgs e)
|
private void listBoxUsages_SelectedValueChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (!_InitializingLibDocList)
|
if (!_InitializingLibDocList)
|
||||||
{
|
{
|
||||||
if (_ProcessingSelectedValueChanged) return;
|
if (_ProcessingSelectedValueChanged) return;
|
||||||
_ProcessingSelectedValueChanged = true;
|
_ProcessingSelectedValueChanged = true;
|
||||||
if (listBoxUsages.SelectedIndex == -1) return;
|
if (listBoxUsages.SelectedIndex == -1) return;
|
||||||
DocumentInfo di = LibDocList[listBoxLibDocs.SelectedIndex];
|
DocumentInfo di = LibDocList[listBoxLibDocs.SelectedIndex];
|
||||||
// see if the library document actually has data - data migration may have created a 'null' content within the
|
// see if the library document actually has data - data migration may have created a 'null' content within the
|
||||||
// record for missing library documents.
|
// record for missing library documents.
|
||||||
if (di.DocContent == null)
|
if (di.DocContent == null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("No Content in this document");
|
MessageBox.Show("No Content in this document");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_DisplayTabControl.OpenItem(di.LibraryDocumentUsageList[listBoxUsages.SelectedIndex]);
|
if (listBoxUsages.SelectedIndex < di.LibraryDocumentUsageList.Count && listBoxUsages.SelectedIndex >= 0)
|
||||||
_ProcessingSelectedValueChanged = false;
|
_DisplayTabControl.OpenItem(di.LibraryDocumentUsageList[listBoxUsages.SelectedIndex]);
|
||||||
}
|
_ProcessingSelectedValueChanged = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private void btnPrint_Click(object sender, EventArgs e)
|
private void btnPrint_Click(object sender, EventArgs e)
|
||||||
|
Reference in New Issue
Block a user