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.

259 lines
5.1 KiB

  1. #include "acFileAttr.h"
  2. #include "attr.h"
  3. #include "version.h"
  4. #include <assert.h>
  5. extern FILEATTR g_arrFileAttr[];
  6. LPVOID
  7. Alloc(
  8. SIZE_T cbSize)
  9. {
  10. return HeapAlloc(GetProcessHeap(), 0, cbSize);
  11. }
  12. BOOL
  13. Free(
  14. LPVOID p)
  15. {
  16. return HeapFree(GetProcessHeap(), 0, p);
  17. }
  18. BOOL APIENTRY
  19. DllMain(
  20. HANDLE hModule,
  21. DWORD ul_reason,
  22. LPVOID lpReserved)
  23. {
  24. return TRUE;
  25. }
  26. VOID
  27. CleanupFileManager(
  28. PFILEATTRMGR pMgr)
  29. {
  30. int i;
  31. for (i = 0; i < VTID_LASTID - 2; i++) {
  32. Free(pMgr->arrAttr[i].pszValue);
  33. pMgr->arrAttr[i].pszValue = NULL;
  34. pMgr->arrAttr[i].dwFlags = 0;
  35. pMgr->arrAttr[i].dwValue = 0;
  36. }
  37. DeleteVersionStruct(&pMgr->ver);
  38. Free(pMgr);
  39. }
  40. HANDLE
  41. ReadFileAttributes(
  42. LPCSTR pszFile,
  43. int* pnCount
  44. )
  45. {
  46. int i;
  47. PFILEATTRMGR pMgr = (PFILEATTRMGR)Alloc(sizeof(FILEATTRMGR));
  48. if (pMgr == NULL) {
  49. LogMsg("ReadFileAttributes: Failed to allocate %d bytes\n",
  50. sizeof(FILEATTRMGR));
  51. *pnCount = 0;
  52. return NULL;
  53. }
  54. ZeroMemory(pMgr, sizeof(FILEATTRMGR));
  55. pMgr->ver.pszFile = (PSTR)pszFile;
  56. // initialize the version information
  57. InitVersionStruct(&pMgr->ver);
  58. // query the values for each attribute
  59. for (i = 0; i < VTID_LASTID - 2; i++) {
  60. g_arrFileAttr[i].QueryValue(pMgr, pMgr->arrAttr + i);
  61. }
  62. // Post processing
  63. if (pMgr->arrAttr[VTID_FILEDATEHI - VTID_REQFILE - 1].dwValue == 0 &&
  64. pMgr->arrAttr[VTID_FILEDATELO - VTID_REQFILE - 1].dwValue == 0) {
  65. pMgr->arrAttr[VTID_FILEDATEHI - VTID_REQFILE - 1].dwFlags = 0;
  66. pMgr->arrAttr[VTID_FILEDATELO - VTID_REQFILE - 1].dwFlags = 0;
  67. }
  68. // mark that the initialization was successful
  69. pMgr->bInitialized = TRUE;
  70. *pnCount = i;
  71. return pMgr;
  72. }
  73. int
  74. GetAttrIndex(
  75. DWORD Id)
  76. {
  77. int nInd;
  78. for (nInd = 0; nInd < VTID_LASTID - 2; nInd++) {
  79. if (g_arrFileAttr[nInd].dwId == Id) {
  80. return nInd;
  81. }
  82. }
  83. return -1;
  84. }
  85. DWORD
  86. GetAttrId(
  87. int nAttrInd)
  88. {
  89. return g_arrFileAttr[nAttrInd].dwId;
  90. }
  91. BOOL
  92. IsAttrAvailable(
  93. HANDLE hFileMgr,
  94. int nAttrInd)
  95. {
  96. PFILEATTRMGR pMgr = (PFILEATTRMGR)hFileMgr;
  97. return (pMgr->arrAttr[nAttrInd].dwFlags & ATTR_FLAG_AVAILABLE);
  98. }
  99. PSTR
  100. GetAttrName(
  101. int nAttrInd)
  102. {
  103. return g_arrFileAttr[nAttrInd].pszDisplayName;
  104. }
  105. PSTR
  106. GetAttrNameXML(
  107. int nAttrInd)
  108. {
  109. return g_arrFileAttr[nAttrInd].pszNameXML;
  110. }
  111. PSTR
  112. GetAttrValue(
  113. HANDLE hFileMgr,
  114. int nAttrInd)
  115. {
  116. PFILEATTRMGR pMgr = (PFILEATTRMGR)hFileMgr;
  117. return pMgr->arrAttr[nAttrInd].pszValue;
  118. }
  119. BOOL
  120. SelectAttr(
  121. HANDLE hFileMgr,
  122. int nAttrInd,
  123. BOOL bSelect)
  124. {
  125. PFILEATTRMGR pMgr = (PFILEATTRMGR)hFileMgr;
  126. if (!(pMgr->arrAttr[nAttrInd].dwFlags & ATTR_FLAG_AVAILABLE)) {
  127. LogMsg("Attribute %s not available. Cannot be selected\n",
  128. g_arrFileAttr[nAttrInd].pszDisplayName);
  129. return FALSE;
  130. }
  131. if (bSelect) {
  132. pMgr->arrAttr[nAttrInd].dwFlags |= ATTR_FLAG_SELECTED;
  133. } else {
  134. pMgr->arrAttr[nAttrInd].dwFlags &= ~ATTR_FLAG_SELECTED;
  135. }
  136. return TRUE;
  137. }
  138. BOOL
  139. IsAttrSelected(
  140. HANDLE hFileMgr,
  141. int nAttrInd)
  142. {
  143. PFILEATTRMGR pMgr = (PFILEATTRMGR)hFileMgr;
  144. return (pMgr->arrAttr[nAttrInd].dwFlags & ATTR_FLAG_SELECTED);
  145. }
  146. int
  147. Dump(
  148. HANDLE hFileMgr,
  149. int nAttrInd,
  150. BYTE* pBlob)
  151. {
  152. PFILEATTRMGR pMgr = (PFILEATTRMGR)hFileMgr;
  153. return g_arrFileAttr[nAttrInd].DumpToBlob(nAttrInd + VTID_REQFILE + 1,
  154. pMgr->arrAttr + nAttrInd,
  155. pBlob);
  156. }
  157. BOOL
  158. BlobToString(
  159. BYTE* pBlob,
  160. DWORD cbSize,
  161. char* pszBuff)
  162. {
  163. DWORD attrId;
  164. DWORD cbRet;
  165. pszBuff += lstrlen(pszBuff);
  166. attrId = *(DWORD*)pBlob;
  167. while (attrId) {
  168. if (attrId >= VTID_LASTID) {
  169. LogMsg("Unsupported attribute %d\n", attrId);
  170. return FALSE;
  171. }
  172. if (attrId == VTID_REQFILE) {
  173. pBlob += sizeof(DWORD);
  174. cbRet = *(DWORD*)pBlob;
  175. if (!cbRet) {
  176. // should never happen
  177. cbRet = 1;
  178. }
  179. pBlob += sizeof(DWORD);
  180. wsprintf(pszBuff, "\r\nAttributes for %ws:\r\n", pBlob);
  181. pszBuff += lstrlen(pszBuff);
  182. pBlob += cbRet;
  183. } else {
  184. wsprintf(pszBuff, " %-22s ", g_arrFileAttr[attrId - VTID_REQFILE - 1].pszDisplayName);
  185. pszBuff += lstrlen(pszBuff);
  186. pBlob += sizeof(DWORD);
  187. cbRet = g_arrFileAttr[attrId - VTID_REQFILE - 1].BlobToString(pBlob, pszBuff);
  188. pszBuff += lstrlen(pszBuff);
  189. pBlob += cbRet;
  190. }
  191. attrId = *(DWORD*)pBlob;
  192. }
  193. return TRUE;
  194. }