Leaked source code of windows server 2003
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.

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