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.

138 lines
3.4 KiB

  1. BOOL
  2. pSetupGetKey (
  3. IN PINFCONTEXT pic,
  4. OUT PTSTR KeyBuf,
  5. OUT PBOOL KeyExistsOnLine
  6. )
  7. /*++
  8. Routine Description:
  9. pSetupGetKey copies the key for the specified INF context. If
  10. a key does not exist, then KeyBuf is reset.
  11. Arguments:
  12. pic - Specifies the INFCONTEXT that indicates which line to query
  13. KeyBuf - Receives the key, or is emptied of there is no key
  14. KeyExistsOnLine - Receives TRUE if the line has a key, or FALSE if not.
  15. Return Value:
  16. TRUE if successful, FALSE if not.
  17. --*/
  18. {
  19. UINT KeySize;
  20. PTSTR TempKeyBuf;
  21. PTSTR TempLineBuf;
  22. UINT LineSize;
  23. //
  24. // Get the key (if it exists)
  25. //
  26. *KeyExistsOnLine = FALSE;
  27. if (!SetupGetStringField (pic, 0, NULL, 0, &KeySize)) {
  28. //
  29. // Key does not exist
  30. //
  31. KeyBuf[0] = 0;
  32. return TRUE;
  33. }
  34. //
  35. // Use the caller's buffer if it is big enough
  36. //
  37. KeySize *= sizeof (TCHAR);
  38. if (KeySize >= MAX_KEY * sizeof (TCHAR)) {
  39. TempKeyBuf = (PTSTR) MemAlloc (g_hHeap, 0, KeySize);
  40. if (!TempKeyBuf) {
  41. LOG ((LOG_ERROR, "Setup Get Key: Could not allocate temp buffer"));
  42. return FALSE;
  43. }
  44. } else {
  45. TempKeyBuf = KeyBuf;
  46. }
  47. __try {
  48. if (!SetupGetStringField (pic, 0, TempKeyBuf, KeySize, NULL)) {
  49. DEBUGMSG ((DBG_WHOOPS, "pSetupGetKey: Could not read specified INF line"));
  50. return FALSE;
  51. }
  52. //
  53. // Get the line and compare against the key
  54. //
  55. if (SetupGetLineText (pic, NULL, NULL, NULL, NULL, 0, &LineSize)) {
  56. //
  57. // If the sizes are the same, we must actually get the text, then
  58. // compare the key against the line
  59. //
  60. LineSize *= sizeof (TCHAR);
  61. if (LineSize == KeySize) {
  62. TempLineBuf = (PTSTR) MemAlloc (g_hHeap, 0, LineSize);
  63. if (!TempLineBuf) {
  64. LOG ((LOG_ERROR, "Setup Get Key: Could not allocate line buffer"));
  65. return FALSE;
  66. }
  67. __try {
  68. if (!SetupGetLineText (pic, NULL, NULL, NULL, TempLineBuf, LineSize, NULL)) {
  69. DEBUGMSG ((DBG_WHOOPS, "pSetupGetKey: Could not get line text"));
  70. return FALSE;
  71. }
  72. if (!StringCompare (TempLineBuf, TempKeyBuf)) {
  73. //
  74. // There is no key for this line
  75. //
  76. TempKeyBuf[0] = 0;
  77. } else {
  78. //
  79. // There is a key for this line
  80. //
  81. *KeyExistsOnLine = TRUE;
  82. }
  83. }
  84. __finally {
  85. MemFree (g_hHeap, 0, TempLineBuf);
  86. }
  87. } else {
  88. //
  89. // Since the sizes are different, we know there is a key
  90. //
  91. *KeyExistsOnLine = TRUE;
  92. }
  93. }
  94. //
  95. // If we were not using the caller's buffer, copy as much of the
  96. // key as will fit
  97. //
  98. if (TempKeyBuf != KeyBuf) {
  99. _tcssafecpy (KeyBuf, TempKeyBuf, MAX_KEY);
  100. }
  101. }
  102. __finally {
  103. if (TempKeyBuf != KeyBuf) {
  104. MemFree (g_hHeap, 0, TempKeyBuf);
  105. }
  106. }
  107. return TRUE;
  108. }