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.

174 lines
3.9 KiB

  1. #if !defined(_FUSION_INC_STRINGCLASS_INL_INCLUDED_)
  2. #define _FUSION_INC_STRINGCLASS_INL_INCLUDED_
  3. #pragma once
  4. inline
  5. BOOL
  6. CString::Win32FormatFileTime(
  7. const FILETIME &rft
  8. )
  9. {
  10. BOOL fSuccess = FALSE;
  11. if ((rft.dwLowDateTime == 0) && (rft.dwHighDateTime == 0))
  12. IFW32FALSE_EXIT(this->Win32Assign(L"n/a"));
  13. else
  14. {
  15. SYSTEMTIME st;
  16. int iResult;
  17. int cchDate = 0;
  18. int cchTime = 0;
  19. IFW32FALSE_EXIT(::FileTimeToSystemTime(&rft, &st));
  20. iResult = ::GetDateFormatW(
  21. LOCALE_USER_DEFAULT,
  22. LOCALE_USE_CP_ACP,
  23. &st,
  24. NULL,
  25. NULL,
  26. 0);
  27. if (iResult == 0)
  28. goto Exit;
  29. cchDate = iResult - 1;
  30. iResult = ::GetTimeFormatW(
  31. LOCALE_USER_DEFAULT,
  32. LOCALE_USE_CP_ACP,
  33. &st,
  34. NULL,
  35. NULL,
  36. 0);
  37. if (iResult == 0)
  38. goto Exit;
  39. cchTime = iResult - 1;
  40. IFW32FALSE_EXIT(this->Win32ResizeBuffer(cchDate + 1 + cchTime + 1, eDoNotPreserveBufferContents));
  41. iResult = ::GetDateFormatW(
  42. LOCALE_USER_DEFAULT,
  43. LOCALE_USE_CP_ACP,
  44. &st,
  45. NULL,
  46. this->GetBufferPtr(),
  47. cchDate + 1);
  48. if (iResult == 0)
  49. goto Exit;
  50. ASSERT(iResult == (cchDate + 1));
  51. this->GetBufferPtr()[cchDate] = L' ';
  52. iResult = ::GetTimeFormatW(
  53. LOCALE_USER_DEFAULT,
  54. LOCALE_USE_CP_ACP,
  55. &st,
  56. NULL,
  57. this->GetBufferPtr() + cchDate + 1,
  58. cchTime + 1);
  59. if (iResult == 0)
  60. goto Exit;
  61. ASSERT(iResult == (cchTime + 1));
  62. m_cch = (cchDate + 1 + cchTime);
  63. }
  64. Exit:
  65. return fSuccess;
  66. }
  67. inline
  68. BOOL
  69. CString::Win32GetFileSize(
  70. ULARGE_INTEGER &ruli
  71. ) const
  72. {
  73. BOOL fSuccess = FALSE;
  74. FN_TRACE_WIN32(fSuccess);
  75. WIN32_FILE_ATTRIBUTE_DATA wfad;
  76. IFW32FALSE_EXIT(::GetFileAttributesExW(*this, GetFileExInfoStandard, &wfad));
  77. ruli.LowPart = wfad.nFileSizeLow;
  78. ruli.HighPart = wfad.nFileSizeHigh;
  79. fSuccess = TRUE;
  80. Exit:
  81. return fSuccess;
  82. }
  83. inline
  84. BOOL
  85. CString::Win32CopyIntoBuffer(
  86. PWSTR *ppszCursor,
  87. SIZE_T cbBuffer,
  88. SIZE_T *cbBytesWritten,
  89. PVOID pvBase,
  90. ULONG *pulOffset,
  91. ULONG *pulLength
  92. )
  93. {
  94. BOOL fSuccess = FALSE;
  95. FN_TRACE_WIN32(fSuccess);
  96. PWSTR pszCursor;
  97. SSIZE_T dptr;
  98. SIZE_T cbRequired;
  99. if (pulOffset != NULL)
  100. *pulOffset = 0;
  101. if (pulLength != NULL)
  102. *pulLength = 0;
  103. PARAMETER_CHECK(ppszCursor != NULL);
  104. pszCursor = *ppszCursor;
  105. dptr = ((SSIZE_T) pszCursor) - ((SSIZE_T) pvBase);
  106. // If they're asking for an offset or length and the cursor is too far from the base,
  107. // fail.
  108. PARAMETER_CHECK((pulOffset == NULL) || (dptr <= ULONG_MAX));
  109. cbRequired = (m_cch != 0) ? ((m_cch + 1) * sizeof(WCHAR)) : 0;
  110. if (cbBuffer < cbRequired)
  111. {
  112. ::SetLastError(ERROR_INSUFFICIENT_BUFFER);
  113. goto Exit;
  114. }
  115. if (cbRequired > ULONG_MAX)
  116. {
  117. ::SetLastError(ERROR_INSUFFICIENT_BUFFER);
  118. goto Exit;
  119. }
  120. memcpy(pszCursor, static_cast<PCWSTR>(*this), cbRequired);
  121. if (pulOffset != NULL)
  122. {
  123. if (cbRequired != 0)
  124. *pulOffset = (ULONG) dptr;
  125. }
  126. if (pulLength != NULL)
  127. *pulLength = (ULONG) cbRequired;
  128. *cbBytesWritten += cbRequired;
  129. *ppszCursor = (PWSTR) (((ULONG_PTR) pszCursor) + cbRequired);
  130. fSuccess = TRUE;
  131. Exit:
  132. return fSuccess;
  133. }
  134. #endif