-
Notifications
You must be signed in to change notification settings - Fork 4
/
FileObject.cpp
59 lines (45 loc) · 1010 Bytes
/
FileObject.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// FileObject.cpp : implementation file
//
#include "stdafx.h"
#include "FileObject.h"
#include "file64.h"
#define SECTOR_SIZE 2048
// CFileObject
IMPLEMENT_DYNAMIC(CFileObject, CBaseObject)
CFileObject::CFileObject(const CString& filePath)
: CBaseObject(filePath)
, m_pStream(NULL)
{
}
CFileObject::~CFileObject()
{
if (m_pStream != NULL)
m_pStream->Release();
}
// CFileObject member functions
ULONGLONG CFileObject::GetSizeOnDisc()
{
CFileStatus64 status;
if (CFile64::GetStatus(m_path, status))
{
if (status.m_size > 0)
{
return ((status.m_size / SECTOR_SIZE) + 1) * SECTOR_SIZE;
}
}
return 0;
}
IStream* CFileObject::GetStream()
{
if (m_pStream == NULL)
{
USES_CONVERSION;
SHCreateStreamOnFileEx(A2W(m_path),
STGM_READ|STGM_SHARE_DENY_NONE|STGM_DELETEONRELEASE,
FILE_ATTRIBUTE_NORMAL,
FALSE,
NULL,
&m_pStream);
}
return m_pStream;
}