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.

121 lines
3.2 KiB

  1. /*
  2. Copyright (c) Microsoft Corporation
  3. */
  4. #include "stdinc.h"
  5. #include <windows.h>
  6. #include "sxsp.h"
  7. #include <stdio.h>
  8. #include <setupapi.h>
  9. #include "fusionhandle.h"
  10. #include "sxspath.h"
  11. #include "sxsapi.h"
  12. #include "sxsid.h"
  13. #include "sxsidp.h"
  14. #include "strongname.h"
  15. #include "fusiontrace.h"
  16. BOOL
  17. SxspCopyFile(
  18. DWORD dwFlags,
  19. PCWSTR pszSource,
  20. PCWSTR pszDestination
  21. )
  22. {
  23. BOOL fSuccess = FALSE;
  24. FN_TRACE_WIN32(fSuccess);
  25. BOOL fFileWasInUse = FALSE;
  26. DWORD dwCopyStyle = 0;
  27. PARAMETER_CHECK((dwFlags & ~(SXSP_COPY_FILE_FLAG_REPLACE_EXISTING | SXSP_COPY_FILE_FLAG_COMPRESSION_AWARE)) == 0);
  28. PARAMETER_CHECK(pszSource != NULL);
  29. PARAMETER_CHECK(pszDestination != NULL);
  30. {
  31. // NTRAID#NTBUG9 - 591001 - 2002/03/30 - mgrier - missing return value check
  32. SetFileAttributesW(pszDestination, 0);
  33. IFW32FALSE_ORIGINATE_AND_EXIT(
  34. ::CopyFileW(
  35. pszSource,
  36. pszDestination,
  37. (dwFlags & SXSP_COPY_FILE_FLAG_REPLACE_EXISTING) == 0));
  38. }
  39. fSuccess = TRUE;
  40. Exit:
  41. return fSuccess;
  42. }
  43. BOOL
  44. SxspGetFileSize(
  45. DWORD dwFlags,
  46. PCWSTR file,
  47. ULONGLONG &fileSize
  48. )
  49. {
  50. BOOL fSuccess = FALSE;
  51. FN_TRACE_WIN32(fSuccess);
  52. PWSTR pszActualSource = NULL;
  53. fileSize = 0;
  54. PARAMETER_CHECK(file != NULL);
  55. PARAMETER_CHECK((dwFlags & ~(SXSP_GET_FILE_SIZE_FLAG_COMPRESSION_AWARE | SXSP_GET_FILE_SIZE_FLAG_GET_COMPRESSED_SOURCE_SIZE)) == 0);
  56. PARAMETER_CHECK((dwFlags & SXSP_GET_FILE_SIZE_FLAG_COMPRESSION_AWARE) || !(dwFlags & SXSP_GET_FILE_SIZE_FLAG_GET_COMPRESSED_SOURCE_SIZE));
  57. if (dwFlags & SXSP_GET_FILE_SIZE_FLAG_COMPRESSION_AWARE)
  58. {
  59. DWORD dwTemp = 0;
  60. DWORD dwSourceFileSize = 0;
  61. DWORD dwTargetFileSize = 0;
  62. UINT uiCompressionType = 0;
  63. dwTemp = ::SetupGetFileCompressionInfoW(
  64. file,
  65. &pszActualSource,
  66. &dwSourceFileSize,
  67. &dwTargetFileSize,
  68. &uiCompressionType);
  69. if (dwTemp != ERROR_SUCCESS)
  70. {
  71. ::SetLastError(dwTemp);
  72. ORIGINATE_WIN32_FAILURE_AND_EXIT(SetupGetFileCompressionInfoW, dwTemp);
  73. }
  74. if (pszActualSource != NULL)
  75. {
  76. ::LocalFree((HLOCAL) pszActualSource);
  77. pszActualSource = NULL;
  78. }
  79. if (dwFlags & SXSP_GET_FILE_SIZE_FLAG_GET_COMPRESSED_SOURCE_SIZE)
  80. fileSize = dwSourceFileSize;
  81. else
  82. fileSize = dwTargetFileSize;
  83. }
  84. else
  85. {
  86. LARGE_INTEGER liFileSize = {0};
  87. WIN32_FILE_ATTRIBUTE_DATA wfad;
  88. wfad.nFileSizeLow = 0;
  89. wfad.nFileSizeHigh = 0;
  90. IFW32FALSE_ORIGINATE_AND_EXIT(::GetFileAttributesExW(file, GetFileExInfoStandard, &wfad));
  91. liFileSize.LowPart = wfad.nFileSizeLow;
  92. liFileSize.HighPart = wfad.nFileSizeHigh;
  93. fileSize = liFileSize.QuadPart;
  94. }
  95. fSuccess = TRUE;
  96. Exit:
  97. if (pszActualSource != NULL)
  98. {
  99. CSxsPreserveLastError ple;
  100. ::LocalFree((HLOCAL) pszActualSource);
  101. ple.Restore();
  102. }
  103. return fSuccess;
  104. }