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.

176 lines
3.7 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "ownerlst.h"
  4. COwnerListEntry::COwnerListEntry(
  5. IDiskQuotaUser *pOwner
  6. ) : m_pOwner(pOwner)
  7. {
  8. if (m_pOwner)
  9. {
  10. TCHAR szDisplayName[MAX_PATH] = { TEXT('\0') };
  11. TCHAR szLogonName[MAX_PATH] = { TEXT('\0') };
  12. m_pOwner->AddRef();
  13. if (SUCCEEDED(m_pOwner->GetName(NULL, 0,
  14. szLogonName, ARRAYSIZE(szLogonName),
  15. szDisplayName, ARRAYSIZE(szDisplayName))))
  16. {
  17. if (TEXT('\0') != szDisplayName[0])
  18. {
  19. m_strOwnerName.Format(TEXT("%1 (%2)"), szDisplayName, szLogonName);
  20. }
  21. else if (TEXT('\0') != szLogonName[0])
  22. {
  23. m_strOwnerName = szLogonName;
  24. }
  25. else
  26. {
  27. //
  28. // If the account SID has NOT been resolved to a name, display
  29. // the SID as a string. We do the same thing in the Quota Entries
  30. // view.
  31. //
  32. BYTE Sid[MAX_SID_LEN];
  33. DWORD cchSidStr = MAX_PATH;
  34. if (SUCCEEDED(m_pOwner->GetSid(Sid, ARRAYSIZE(Sid))))
  35. {
  36. SidToString(Sid, m_strOwnerName.GetBuffer(cchSidStr), &cchSidStr);
  37. m_strOwnerName.ReleaseBuffer();
  38. }
  39. }
  40. }
  41. }
  42. }
  43. int
  44. COwnerListEntry::AddFile(
  45. LPCTSTR pszFile,
  46. bool bDirectory
  47. )
  48. {
  49. m_rgFiles.Append(COwnerListFile(pszFile, bDirectory));
  50. return m_rgFiles.Count() - 1;
  51. }
  52. int
  53. COwnerListEntry::FileCount(
  54. bool bIncludeDeleted // optional. Default = false.
  55. )
  56. {
  57. int cFiles = m_rgFiles.Count();
  58. int n = 0;
  59. for (int i = 0; i < cFiles; i++)
  60. {
  61. if (bIncludeDeleted || !m_rgFiles[i].IsEmpty())
  62. n++;
  63. }
  64. return n;
  65. }
  66. #if DBG
  67. void
  68. COwnerListEntry::Dump(
  69. void
  70. ) const
  71. {
  72. DBGERROR((TEXT("\tm_pOwner........: 0x%08X"), m_pOwner));
  73. DBGERROR((TEXT("\tm_strOwnerName..: \"%s\""), m_strOwnerName.Cstr()));
  74. int cFiles = m_rgFiles.Count();
  75. DBGERROR((TEXT("\tcFiles..........: %d"), cFiles));
  76. for (int i = 0; i < cFiles; i++)
  77. {
  78. DBGERROR((TEXT("\tFile[%3d].......: \"%s\""), i, m_rgFiles[i].Cstr()));
  79. }
  80. }
  81. #endif // DBG
  82. COwnerList::~COwnerList(
  83. void
  84. )
  85. {
  86. Clear();
  87. }
  88. void
  89. COwnerList::Clear(
  90. void
  91. )
  92. {
  93. int cOwners = m_rgpOwners.Count();
  94. for (int i = 0; i < cOwners; i++)
  95. {
  96. delete m_rgpOwners[i];
  97. m_rgpOwners[i] = NULL;
  98. }
  99. m_rgpOwners.Clear();
  100. }
  101. int
  102. COwnerList::AddOwner(
  103. IDiskQuotaUser *pOwner
  104. )
  105. {
  106. m_rgpOwners.Append(new COwnerListEntry(pOwner));
  107. return m_rgpOwners.Count() - 1;
  108. }
  109. IDiskQuotaUser *
  110. COwnerList::GetOwner(
  111. int iOwner
  112. ) const
  113. {
  114. //
  115. // Caller must call Release() when done with returned iface pointer.
  116. //
  117. return m_rgpOwners[iOwner]->GetOwner();
  118. }
  119. int
  120. COwnerList::FileCount(
  121. int iOwner,
  122. bool bIncludeDeleted // optional. Default = false
  123. ) const
  124. {
  125. int cFiles = 0;
  126. int iFirst = iOwner;
  127. int iLast = iOwner;
  128. if (-1 == iOwner)
  129. {
  130. //
  131. // Count ALL files.
  132. //
  133. iFirst = 0;
  134. iLast = m_rgpOwners.Count() - 1;
  135. }
  136. for (int i = iFirst; i <= iLast; i++)
  137. {
  138. cFiles += m_rgpOwners[i]->FileCount(bIncludeDeleted);
  139. }
  140. return cFiles;
  141. }
  142. #if DBG
  143. void
  144. COwnerList::Dump(
  145. void
  146. ) const
  147. {
  148. int cEntries = m_rgpOwners.Count();
  149. DBGERROR((TEXT("COwnerList::Dump - %d entries"), cEntries));
  150. for (int i = 0; i < cEntries; i++)
  151. {
  152. DBGERROR((TEXT("COwnerListEntry[%d] ========================="), i));
  153. m_rgpOwners[i]->Dump();
  154. }
  155. }
  156. #endif // DBG