-
Notifications
You must be signed in to change notification settings - Fork 71
/
class_OfficeInfo.ahk
95 lines (88 loc) · 3.24 KB
/
class_OfficeInfo.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
; https://autohotkey.com/boards/viewtopic.php?f=6&t=23164
; Updated: Sept. 7, 2016
class OfficeInfo
{
__New()
{
static Programs := { "Excel": "{00020813-0000-0000-C000-000000000046}"
, "Office": "{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}"
, "Outlook": "{00062FFF-0000-0000-C000-000000000046}"
, "PowerPoint": "{91493440-5A91-11CF-8700-00AA0060263B}"
, "Publisher": "{0002123C-0000-0000-C000-000000000046}"
, "Word": "{00020905-0000-0000-C000-000000000046}" }
ObjRawSet(this, "_Unlocked", true)
for ProgramName, ProgramGUID in Programs
new this._ProgramInfo(ProgramGUID, this)
this.Delete("_Unlocked")
}
__Get(aName)
{
if !this.HasKey("_Unlocked")
throw Exception( "`nThe requested key does not exist. Specifically:`n`n"
. "Key: " aName )
}
__Set(aName, aValue)
{
if !this.HasKey("_Unlocked")
throw Exception( "`nCannot create new keys. Specifically:`n`n"
. "Key: " aName "`n"
. "Value: " aValue )
else
ObjRawSet(this, aName, aValue)
return this[aName]
}
class _ProgramInfo
{
__New(GUID, Parent)
{
this.GUID := GUID
this.Parent := Parent
this.GetTypeLibVersion()
this.GetTypeLib()
this.GetFlatTypeLib()
}
GetTypeLibVersion()
{
Loop, Reg, % "HKCR\TypeLib\" this.GUID, K
{
for i, VerPart in StrSplit(A_LoopRegName, ".")
{
if VerPart is integer
Version .= VerPart "."
else if VerPart is xdigit
Version .= Format("{:i}", "0x" VerPart) "."
}
return this.Version := RTrim(Version, ".")
}
}
GetTypeLib()
{
try return this.TypeLib := ImportTypeLib(this.GUID, this.Version)
catch e
OutputDebug, % "Failed to load type library!`n"
. "GUID: " this.GUID "`n"
. "Version: " this.Version "`n"
. "Message: " e.Message "`n"
. "What: " e.What "`n"
. "Extra: " e.Extra "`n"
. "File: " e.File "`n"
. "Line: " e.Line "`n"
}
GetFlatTypeLib()
{
this.Enumerate(this.TypeLib)
return this.Parent
}
; Get each item in the type library and place it in the parent OfficeInfo object.
Enumerate(a, Depth:=2)
{
try for k, v in a
{
if IsObject(v) && Depth > 1
this.Enumerate(v, Depth - 1)
else if !this.Parent[k] && !ITL.Properties.IsInternalProperty(k)
this.Parent[k] := v ; store retrieved value in parent
}
}
}
}