FileObject.cpp 1010 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // FileObject.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "FileObject.h"
  5. #include "file64.h"
  6. #define SECTOR_SIZE 2048
  7. // CFileObject
  8. IMPLEMENT_DYNAMIC(CFileObject, CBaseObject)
  9. CFileObject::CFileObject(const CString& filePath)
  10. : CBaseObject(filePath)
  11. , m_pStream(NULL)
  12. {
  13. }
  14. CFileObject::~CFileObject()
  15. {
  16. if (m_pStream != NULL)
  17. m_pStream->Release();
  18. }
  19. // CFileObject member functions
  20. ULONGLONG CFileObject::GetSizeOnDisc()
  21. {
  22. CFileStatus64 status;
  23. if (CFile64::GetStatus(m_path, status))
  24. {
  25. if (status.m_size > 0)
  26. {
  27. return ((status.m_size / SECTOR_SIZE) + 1) * SECTOR_SIZE;
  28. }
  29. }
  30. return 0;
  31. }
  32. IStream* CFileObject::GetStream()
  33. {
  34. if (m_pStream == NULL)
  35. {
  36. USES_CONVERSION;
  37. SHCreateStreamOnFileEx(A2W(m_path),
  38. STGM_READ|STGM_SHARE_DENY_NONE|STGM_DELETEONRELEASE,
  39. FILE_ATTRIBUTE_NORMAL,
  40. FALSE,
  41. NULL,
  42. &m_pStream);
  43. }
  44. return m_pStream;
  45. }