forked from lee-soft/ViStart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgramMenuHelper.bas
171 lines (121 loc) · 4.39 KB
/
ProgramMenuHelper.bas
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
Attribute VB_Name = "ProgramMenuHelper"
Option Explicit
'Various functions that minipulate Target collections
Const cNodeHeaderBoundary As Integer = 4
Private Declare Function VerQueryValueA Lib "Version.dll" _
(pBlock As Any, _
ByVal lpSubBlock As String, _
lplpBuffer As Any, _
puLen As Long) As Long
Private Declare Function lstrcpyA Lib "kernel32" _
(ByVal lpString1 As String, _
ByVal lpString2 As Long) As Long
Private m_logger As SeverityLogger
Private Property Get Logger() As SeverityLogger
If m_logger Is Nothing Then
Set m_logger = LogManager.GetLogger("ProgramMenuHelper")
End If
Set Logger = m_logger
End Property
Function CreateProgramFromPath(ByVal szProgramPath As String) As clsProgram
Dim thisProgram As clsProgram
Set thisProgram = New clsProgram
Set CreateProgramFromPath = thisProgram
Set thisProgram.Icon = IconManager.GetViIcon(szProgramPath, True)
thisProgram.Caption = ExtOrNot(GetFileName(szProgramPath))
thisProgram.Path = szProgramPath
End Function
Function CreateProgramFromNode(ByVal sourceNode As INode) As clsProgram
Dim thisProgram As clsProgram
Set thisProgram = New clsProgram
Set CreateProgramFromNode = thisProgram
thisProgram.szIcon = sourceNode.Icon.IconPath
Set thisProgram.Icon = IconManager.GetViIcon(thisProgram.szIcon, True)
thisProgram.Caption = sourceNode.Caption
thisProgram.Path = sourceNode.Tag
End Function
Function GetAppDescription(ByVal aExeName As String) As String
On Error GoTo Handler
Dim lBufferLen As Long
Dim bBuffer() As Byte
Dim lDummy As Long
Dim lReceive As Long
Dim pRecieve As Long
Dim sBuffer As String
lBufferLen = GetFileVersionInfoSize(aExeName, lDummy)
ReDim bBuffer(lBufferLen)
GetFileVersionInfo aExeName, 0&, lBufferLen, bBuffer(0)
'VerQueryValue bBuffer(0), "\StringFileInfo\040904B0\FileDescription", pRecieve, lReceive ' 040904E4 (Crashes randomy in XP and maybe more)
VerQueryValueA bBuffer(0), "\StringFileInfo\040904B0\FileDescription", pRecieve, lReceive ' 040904E4
sBuffer = String$(255, 0)
lstrcpyA sBuffer, pRecieve
sBuffer = Mid$(sBuffer, 1, InStr(sBuffer, Chr$(0)) - 1)
GetAppDescription = sBuffer
Exit Function
Handler:
Logger.Error Err.Description, "GetAppDescription", aExeName
End Function
Public Function GetStringFromPointer(ByVal PtrStr As Long)
Dim sBuffer As String
sBuffer = String$(255, 0)
lstrcpyA sBuffer, PtrStr
sBuffer = Mid$(sBuffer, 1, InStr(sBuffer, Chr$(0)) - 1)
GetStringFromPointer = sBuffer
End Function
Public Function GetString(ByVal PtrStr As Long) As String
Dim StrBuff As String * 256
'Check for zero address
If PtrStr = 0 Then
GetString = vbNullString
Exit Function
End If
'Copy data from PtrStr to buffer.
win.CopyMemory ByVal StrBuff, ByVal PtrStr, 256
'Strip any trailing nulls from string.
GetString = StripNulls(StrBuff)
End Function
Public Function StripNulls(OriginalStr As String) As String
'Strip any trailing nulls from input string.
If (InStr(OriginalStr, Chr$(0)) > 0) Then
OriginalStr = Left$(OriginalStr, InStr(OriginalStr, Chr$(0)) - 1)
End If
'Return modified string.
StripNulls = OriginalStr
End Function
Public Function IsValidArray(arr As Variant) As Boolean
On Error Resume Next
If LBound(arr) = UBound(arr) Then
IsValidArray = False
Exit Function
Else
IsValidArray = True
End If
End Function
Public Function MakeSearchable(ByVal srcString As String) As String
Dim lngCharPosition As Long
lngCharPosition = InStrRev(srcString, ".")
If lngCharPosition > 1 Then
srcString = Mid$(srcString, 1, lngCharPosition - 1) & " " & Mid$(srcString, lngCharPosition)
End If
MakeSearchable = UCase$(srcString)
End Function
Function NodeSize(ByRef cTarget) As Integer
Dim Obj As Object
NodeSize = cTarget.count - (cNodeHeaderBoundary - 1)
End Function
Function IsCollection(ByRef cTarget) As Boolean
On Error GoTo Handler
If cTarget.count <> 0 Then
IsCollection = True
End If
Exit Function
Handler:
IsCollection = False
End Function
Function ExistInCol(ByRef cTarget As Collection, sKey) As Boolean
On Error GoTo Handler
ExistInCol = Not (IsEmpty(cTarget(sKey)))
Exit Function
Handler:
ExistInCol = False
End Function