home *** CD-ROM | disk | FTP | other *** search
- #include "FileResource.h"
- #include "String.h"
-
- FileResource::FileResource(const String & name)
- {
- hfile = CreateFile( LPCTSTR(name), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL );
- }
-
- FileResource::~FileResource()
- {
- if( hfile == INVALID_HANDLE_VALUE )
- return;
- CloseHandle( hfile ); hfile = INVALID_HANDLE_VALUE;
- }
-
- bool FileResource::operator!()const
- {
- return hfile == INVALID_HANDLE_VALUE;
- }
-
- void FileResource::reset()
- {
- if( hfile == INVALID_HANDLE_VALUE )
- return;
- SetFilePointer( hfile, 0, NULL, FILE_BEGIN );
- }
-
- unsigned FileResource::read(void * data, unsigned count)
- {
- if( hfile == INVALID_HANDLE_VALUE )
- return 0;
- DWORD read = 0;
- if( ReadFile( hfile, data, count, &read, NULL ) == 0 )
- return 0;
- return read;
- }
-
- unsigned FileResource::get_size()
- {
- if( hfile == INVALID_HANDLE_VALUE )
- return 0;
- return GetFileSize( hfile, NULL );
- }
-