Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

409 lines
12 KiB

  1. Attribute VB_Name = "DatabaseAndHHT"
  2. Option Explicit
  3. Public Const ROOT_TID_C As Long = 1
  4. Public Const INVALID_ID_C As Long = -1
  5. Public Const NODE_FOR_ORPHANS_C As String = "Orphaned Nodes and Topics"
  6. Public Const ALL_SKUS_C As Long = &HFFFFFFFF
  7. Public Const MAX_TITLE_LENGTH_C As Long = 120
  8. Public Const MAX_KEYWORD_LENGTH_C As Long = 120
  9. Public Const PREFERRED_ORDER_DELTA_C As Long = 20000
  10. Public Const MAX_ORDER_C As Long = 2000000000
  11. Public Const LOC_INCLUDE_ALL_C As String = "ALL"
  12. Public Const LOC_INCLUDE_ENU_C As String = "ENU"
  13. Public Const LOC_INCLUDE_LOC_C As String = "LOC"
  14. Public Const NAVMODEL_DEFAULT_NUM_C As Long = 0
  15. Public Const NAVMODEL_SERVER_NUM_C As Long = 1
  16. Public Const NAVMODEL_DESKTOP_NUM_C As Long = 2
  17. Public Const NAVMODEL_DEFAULT_STR_C As String = "Default"
  18. Public Const NAVMODEL_SERVER_STR_C As String = "Server"
  19. Public Const NAVMODEL_DESKTOP_STR_C As String = "Desktop"
  20. Public Const AG_CORE_MAX_C As Long = 1000
  21. Public Const AG_MICROSOFT_INTERNAL_MAX_C As Long = 10000
  22. ' Values in the DBParameters table
  23. Public Const DB_VERSION_C As String = "DBVersion"
  24. Public Const PRODUCT_ID_C As String = "ProductId"
  25. Public Const PRODUCT_VERSION_C As String = "ProductVersion"
  26. Public Const DISPLAY_NAME_C As String = "DisplayName"
  27. Public Const BROKEN_LINK_WORKING_DIR_C As String = "BrokenLinkWorkingDir"
  28. Public Const MINIMUM_KEYWORD_VALIDATION_C As String = "MinimumKeywordValidation"
  29. Public Const AUTHORING_GROUP_C As String = "AuthoringGroup"
  30. Public Const VENDOR_STRING_C As String = "VendorString"
  31. Public Const DOM_FRAGMENT_PKG_C As String = "DomFragmentPackageDesc"
  32. Public Const DOM_FRAGMENT_HHT_C As String = "DomFragmentHHT"
  33. Public Const LOCK_KEYWORDS_C As String = "LockKeywords"
  34. Public Const LOCK_STOP_SIGNS_C As String = "LockStopSigns"
  35. Public Const LOCK_STOP_WORDS_C As String = "LockStopWords"
  36. Public Const LOCK_SYNONYMS_C As String = "LockSynonyms"
  37. Public Const LOCK_SYNONYM_SETS_C As String = "LockSynonymSets"
  38. Public Const LOCK_TAXONOMY_C As String = "LockTaxonomy"
  39. Public Const LOCK_TYPES_C As String = "LockTypes"
  40. Public Const HHT_TAXONOMY_ENTRIES_C As String = "TAXONOMY_ENTRIES"
  41. Public Const HHT_TAXONOMY_ENTRY_C As String = "TAXONOMY_ENTRY"
  42. Public Const HHT_METADATA_C As String = "METADATA"
  43. ' All Caps => Used in real HHT recognized by HcUpdate
  44. Public Const HHT_CATEGORY_C As String = "CATEGORY"
  45. Public Const HHT_ENTRY_C As String = "ENTRY"
  46. Public Const HHT_URI_C As String = "URI"
  47. Public Const HHT_ICONURI_C As String = "ICONURI"
  48. Public Const HHT_TITLE_C As String = "TITLE"
  49. Public Const HHT_DESCRIPTION_C As String = "DESCRIPTION"
  50. Public Const HHT_TYPE_C As String = "TYPE"
  51. Public Const HHT_VISIBLE_C As String = "VISIBLE"
  52. Public Const HHT_ACTION_C As String = "ACTION"
  53. Public Const HHT_KEYWORD_C As String = "KEYWORD"
  54. Public Const HHT_PRIORITY_C As String = "PRIORITY"
  55. Public Const HHT_INSERTMODE_C As String = "INSERTMODE"
  56. Public Const HHT_INSERTLOCATION_C As String = "INSERTLOCATION"
  57. Public Const HHT_SUBSITE_C As String = "SUBSITE"
  58. Public Const HHT_NAVIGATIONMODEL_C As String = "NAVIGATIONMODEL"
  59. Public Const HHTVAL_ADD_C As String = "ADD"
  60. Public Const HHTVAL_TOP_C As String = "TOP"
  61. Public Const HHTVAL_AFTER_NODE_C As String = "AFTER_NODE"
  62. Public Const HHTVAL_AFTER_TOPIC_C As String = "AFTER_TOPIC"
  63. ' Lower case => internal attributes, not recognized by HcUpdate
  64. Public Const HHT_dbparameters_C As String = "dbparameters"
  65. Public Const HHT_dbparameter_C As String = "dbparameter"
  66. Public Const HHT_name_C As String = "name"
  67. Public Const HHT_value_C As String = "value"
  68. Public Const HHT_tid_C As String = "tid"
  69. Public Const HHT_comments_C As String = "comments"
  70. Public Const HHT_locinclude_C As String = "locinclude"
  71. Public Const HHT_skus_C As String = "skus"
  72. Public Const HHT_modifiedtime_C As String = "modifiedtime"
  73. Public Const HHT_username_C As String = "username"
  74. Public Const HHT_leaf_C As String = "leaf"
  75. Public Const HHT_parenttid_C As String = "parenttid"
  76. Public Const HHT_basefile_C As String = "basefile"
  77. Public Const HHT_keywords_C As String = "keywords"
  78. Public Const HHT_orderunderparent_C As String = "orderunderparent"
  79. Public Const HHT_authoringgroup_C As String = "authoringgroup"
  80. Public Const HHT_allowedskus_C As String = "allowedskus"
  81. ' For a Node, if CATEGORY is "A" and ENTRY is "B", then category2 is "A/B"
  82. Public Const HHT_category2_C As String = "category2"
  83. ' Broken link attributes
  84. Public Const HHT_brokenlinkwinme_C As String = "blwm"
  85. Public Const HHT_brokenlinkstd_C As String = "blst"
  86. Public Const HHT_brokenlinkpro_C As String = "blpr"
  87. Public Const HHT_brokenlinkpro64_C As String = "blpr64"
  88. Public Const HHT_brokenlinksrv_C As String = "blsr"
  89. Public Const HHT_brokenlinkadv_C As String = "blad"
  90. Public Const HHT_brokenlinkadv64_C As String = "blad64"
  91. Public Const HHT_brokenlinkdat_C As String = "bldt"
  92. Public Const HHT_brokenlinkdat64_C As String = "bldt64"
  93. Public Enum SKU_E
  94. SKU_STANDARD_E = &H1
  95. SKU_PROFESSIONAL_E = &H2
  96. SKU_SERVER_E = &H4
  97. SKU_ADVANCED_SERVER_E = &H8
  98. SKU_DATA_CENTER_SERVER_E = &H10
  99. SKU_PROFESSIONAL_64_E = &H20
  100. SKU_ADVANCED_SERVER_64_E = &H40
  101. SKU_DATA_CENTER_SERVER_64_E = &H80
  102. SKU_WINDOWS_MILLENNIUM_E = &H100
  103. End Enum
  104. Public Enum HELPDIR_E
  105. HELPDIR_HELP_MSITS_E = 0
  106. HELPDIR_HELP_HCP_E = 1
  107. HELPDIR_SYSTEM_E = 2
  108. HELPDIR_VENDOR_E = 3
  109. End Enum
  110. Public Enum CONTEXT_E
  111. CONTEXT_ANYWHERE_E = 0
  112. CONTEXT_AT_END_OF_WORD_E = 1
  113. End Enum
  114. Public Function XmlSKU( _
  115. ByVal i_enumSKU As SKU_E _
  116. ) As String
  117. Select Case i_enumSKU
  118. Case SKU_STANDARD_E
  119. XmlSKU = "Personal_32"
  120. Case SKU_PROFESSIONAL_E
  121. XmlSKU = "Professional_32"
  122. Case SKU_SERVER_E
  123. XmlSKU = "Server_32"
  124. Case SKU_ADVANCED_SERVER_E
  125. XmlSKU = "AdvancedServer_32"
  126. Case SKU_DATA_CENTER_SERVER_E
  127. XmlSKU = "DataCenter_32"
  128. Case SKU_PROFESSIONAL_64_E
  129. XmlSKU = "Professional_64"
  130. Case SKU_ADVANCED_SERVER_64_E
  131. XmlSKU = "AdvancedServer_64"
  132. Case SKU_DATA_CENTER_SERVER_64_E
  133. XmlSKU = "DataCenter_64"
  134. Case SKU_WINDOWS_MILLENNIUM_E
  135. XmlSKU = "WinMe" ' Here for conveniece only.
  136. End Select
  137. End Function
  138. Public Function DisplayNameForSKU( _
  139. ByVal i_enumSKU As SKU_E _
  140. ) As String
  141. Select Case i_enumSKU
  142. Case SKU_STANDARD_E
  143. DisplayNameForSKU = "32-bit Personal"
  144. Case SKU_PROFESSIONAL_E
  145. DisplayNameForSKU = "32-bit Professional"
  146. Case SKU_SERVER_E
  147. DisplayNameForSKU = "32-bit Server"
  148. Case SKU_ADVANCED_SERVER_E
  149. DisplayNameForSKU = "32-bit Advanced Server"
  150. Case SKU_DATA_CENTER_SERVER_E
  151. DisplayNameForSKU = "32-bit Datacenter Server"
  152. Case SKU_PROFESSIONAL_64_E
  153. DisplayNameForSKU = "64-bit Professional"
  154. Case SKU_ADVANCED_SERVER_64_E
  155. DisplayNameForSKU = "64-bit Advanced Server"
  156. Case SKU_DATA_CENTER_SERVER_64_E
  157. DisplayNameForSKU = "64-bit Datacenter Server"
  158. Case SKU_WINDOWS_MILLENNIUM_E
  159. DisplayNameForSKU = "Windows Me"
  160. End Select
  161. End Function
  162. Public Function AbbreviationToSKU( _
  163. ByVal i_strSKU As String _
  164. ) As Long
  165. Dim strSKU As String
  166. strSKU = UCase$(i_strSKU)
  167. AbbreviationToSKU = 0
  168. Select Case strSKU
  169. Case "STD"
  170. AbbreviationToSKU = SKU_STANDARD_E
  171. Case "PRO"
  172. AbbreviationToSKU = SKU_PROFESSIONAL_E
  173. Case "SRV"
  174. AbbreviationToSKU = SKU_SERVER_E
  175. Case "ADV"
  176. AbbreviationToSKU = SKU_ADVANCED_SERVER_E
  177. Case "DAT"
  178. AbbreviationToSKU = SKU_DATA_CENTER_SERVER_E
  179. Case "PRO64"
  180. AbbreviationToSKU = SKU_PROFESSIONAL_64_E
  181. Case "ADV64"
  182. AbbreviationToSKU = SKU_ADVANCED_SERVER_64_E
  183. Case "DAT64"
  184. AbbreviationToSKU = SKU_DATA_CENTER_SERVER_64_E
  185. Case "WINME"
  186. AbbreviationToSKU = SKU_WINDOWS_MILLENNIUM_E
  187. End Select
  188. End Function
  189. Public Function FormatKeywordsForTaxonomy( _
  190. ByVal i_strKeywords As String _
  191. ) As String
  192. ' This function sorts the Keywords and removes duplicates.
  193. On Error GoTo LErrorHandler
  194. Dim arrStrKIDs() As String
  195. Dim arrKIDs() As Long
  196. Dim intIndex1 As Long
  197. Dim intIndex2 As Long
  198. Dim intKID As Long
  199. Dim intLastKID As Long
  200. If (Trim$(i_strKeywords) = "") Then
  201. FormatKeywordsForTaxonomy = ""
  202. Exit Function
  203. End If
  204. arrStrKIDs = Split(i_strKeywords, " ")
  205. ReDim arrKIDs(UBound(arrStrKIDs))
  206. For intIndex1 = LBound(arrStrKIDs) To UBound(arrStrKIDs)
  207. If (arrStrKIDs(intIndex1) <> "") Then
  208. arrKIDs(intIndex2) = arrStrKIDs(intIndex1)
  209. intIndex2 = intIndex2 + 1
  210. End If
  211. Next
  212. ReDim Preserve arrKIDs(intIndex2 - 1)
  213. InsertionSort arrKIDs
  214. FormatKeywordsForTaxonomy = " "
  215. intLastKID = INVALID_ID_C
  216. For intIndex1 = LBound(arrKIDs) To UBound(arrKIDs)
  217. intKID = arrKIDs(intIndex1)
  218. If (intKID <> intLastKID) Then
  219. intLastKID = intKID
  220. FormatKeywordsForTaxonomy = FormatKeywordsForTaxonomy & intKID & " "
  221. End If
  222. Next
  223. Exit Function
  224. LErrorHandler:
  225. Err.Clear
  226. Err.Raise errBadKeywordsFormat
  227. End Function
  228. Public Function NavModelNumber( _
  229. ByVal i_strNavModel As String _
  230. ) As String
  231. If (i_strNavModel = "") Then
  232. NavModelNumber = NAVMODEL_DEFAULT_NUM_C
  233. Exit Function
  234. End If
  235. Select Case i_strNavModel
  236. Case NAVMODEL_DEFAULT_STR_C
  237. NavModelNumber = NAVMODEL_DEFAULT_NUM_C
  238. Case NAVMODEL_SERVER_STR_C
  239. NavModelNumber = NAVMODEL_SERVER_NUM_C
  240. Case NAVMODEL_DESKTOP_STR_C
  241. NavModelNumber = NAVMODEL_DESKTOP_NUM_C
  242. End Select
  243. End Function
  244. Public Function NavModelString( _
  245. ByVal i_strNavModel As String _
  246. ) As String
  247. Dim intNavModel As Long
  248. If (i_strNavModel = "") Then
  249. NavModelString = NAVMODEL_DEFAULT_STR_C
  250. Exit Function
  251. Else
  252. intNavModel = i_strNavModel
  253. End If
  254. Select Case intNavModel
  255. Case NAVMODEL_DEFAULT_NUM_C
  256. NavModelString = NAVMODEL_DEFAULT_STR_C
  257. Case NAVMODEL_SERVER_NUM_C
  258. NavModelString = NAVMODEL_SERVER_STR_C
  259. Case NAVMODEL_DESKTOP_NUM_C
  260. NavModelString = NAVMODEL_DESKTOP_STR_C
  261. End Select
  262. End Function
  263. Public Function HhtPreamble( _
  264. ByVal u_DomDoc As MSXML2.DOMDocument, _
  265. ByVal i_blnNestedTaxonomyEntries As Boolean _
  266. ) As MSXML2.IXMLDOMNode
  267. Dim PI As MSXML2.IXMLDOMProcessingInstruction
  268. Dim DOMComment As MSXML2.IXMLDOMComment
  269. Dim Node As MSXML2.IXMLDOMNode
  270. Dim Element As MSXML2.IXMLDOMElement
  271. u_DomDoc.preserveWhiteSpace = True
  272. Set PI = u_DomDoc.createProcessingInstruction("xml", "version='1.0' encoding='UTF-16'")
  273. u_DomDoc.appendChild PI
  274. Set DOMComment = u_DomDoc.createComment("Insert your comments here")
  275. u_DomDoc.appendChild DOMComment
  276. Set Element = u_DomDoc.createElement(HHT_METADATA_C)
  277. Set Node = u_DomDoc.appendChild(Element)
  278. If (i_blnNestedTaxonomyEntries) Then
  279. Set Element = u_DomDoc.createElement(HHT_TAXONOMY_ENTRIES_C)
  280. Set Node = Node.appendChild(Element)
  281. End If
  282. Set HhtPreamble = Node
  283. End Function
  284. Public Function TableExists( _
  285. ByVal i_Catalog As ADOX.Catalog, _
  286. ByVal i_strTableName As String _
  287. ) As Boolean
  288. Dim tbl As ADOX.Table
  289. Dim strTableName As String
  290. TableExists = False
  291. strTableName = UCase$(i_strTableName)
  292. For Each tbl In i_Catalog.Tables
  293. If (strTableName = UCase$(tbl.Name)) Then
  294. TableExists = True
  295. Exit For
  296. End If
  297. Next
  298. End Function
  299. Public Function ColumnExists( _
  300. ByVal i_Catalog As ADOX.Catalog, _
  301. ByVal i_strTableName As String, _
  302. ByVal i_strColumnName As String _
  303. ) As Boolean
  304. Dim col As Column
  305. Dim strColumnName As String
  306. ColumnExists = False
  307. strColumnName = UCase$(i_strColumnName)
  308. For Each col In i_Catalog.Tables(i_strTableName).Columns
  309. If (UCase$(col.Name) = strColumnName) Then
  310. ColumnExists = True
  311. Exit For
  312. End If
  313. Next
  314. End Function
  315. Public Function DeleteTable( _
  316. ByVal i_Catalog As ADOX.Catalog, _
  317. ByVal i_strTableName As String _
  318. ) As Boolean
  319. On Error GoTo LErrorHandler
  320. If (TableExists(i_Catalog, i_strTableName)) Then
  321. i_Catalog.Tables.Delete i_strTableName
  322. End If
  323. DeleteTable = True
  324. Exit Function
  325. LErrorHandler:
  326. DeleteTable = False
  327. End Function