home *** CD-ROM | disk | FTP | other *** search
- #include <win32/windows.h>
- #include <String.hpp>
- #include "ResourceFileWindows.h"
- #include <safe_new.h>
-
- struct ResourceFileWindows::Impl
- {
- HANDLE hfile;
- };
-
- ResourceFileWindows::ResourceFileWindows(const String & name)
- : pimpl( new Impl() )
- {
- pimpl->hfile = CreateFile( name.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL );
- }
-
- ResourceFileWindows::~ResourceFileWindows()
- {
- if( pimpl->hfile != INVALID_HANDLE_VALUE )
- {
- CloseHandle( pimpl->hfile ); pimpl->hfile = INVALID_HANDLE_VALUE;
- }
- delete pimpl; pimpl = NULL;
- }
-
- bool ResourceFileWindows::operator!()const
- {
- return pimpl->hfile == INVALID_HANDLE_VALUE;
- }
-
- /*void ResourceFileWindows::reset()
- {
- if( pimpl->hfile == INVALID_HANDLE_VALUE )
- return;
- SetFilePointer( pimpl->hfile, 0, NULL, FILE_BEGIN );
- }*/
-
- unsigned ResourceFileWindows::read(void * data, unsigned count)
- {
- if( pimpl->hfile == INVALID_HANDLE_VALUE )
- return 0;
- DWORD read = 0;
- if( ReadFile( pimpl->hfile, data, count, &read, NULL ) == 0 )
- return 0;
- return read;
- }
-
- void ResourceFileWindows::skip(unsigned count)
- {
- if( pimpl->hfile == INVALID_HANDLE_VALUE )
- return;
- SetFilePointer( pimpl->hfile, count, NULL, FILE_CURRENT );
- }
-
- void ResourceFileWindows::reset(unsigned position)
- {
- if( pimpl->hfile == INVALID_HANDLE_VALUE )
- return;
- SetFilePointer( pimpl->hfile, position, NULL, FILE_BEGIN );
- }
-
- unsigned ResourceFileWindows::get_size()
- {
- if( pimpl->hfile == INVALID_HANDLE_VALUE )
- return 0;
- return GetFileSize( pimpl->hfile, NULL );
- }
-