home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2002 May / Game.EXE_05_2002.iso / Alawar / Lib / Resource / ResourceFileWindows.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-27  |  1.6 KB  |  68 lines

  1. #include <win32/windows.h>
  2. #include <String.hpp>
  3. #include "ResourceFileWindows.h"
  4. #include <safe_new.h>
  5.  
  6. struct ResourceFileWindows::Impl
  7. {
  8.     HANDLE hfile;
  9. };
  10.  
  11. ResourceFileWindows::ResourceFileWindows(const String & name)
  12. :    pimpl( new Impl() )
  13. {
  14.     pimpl->hfile = CreateFile( name.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL );
  15. }
  16.  
  17. ResourceFileWindows::~ResourceFileWindows()
  18. {
  19.     if( pimpl->hfile != INVALID_HANDLE_VALUE )
  20.     {
  21.         CloseHandle( pimpl->hfile ); pimpl->hfile = INVALID_HANDLE_VALUE;
  22.     }
  23.     delete pimpl; pimpl = NULL;
  24. }
  25.  
  26. bool ResourceFileWindows::operator!()const
  27. {
  28.     return pimpl->hfile == INVALID_HANDLE_VALUE;
  29. }
  30.  
  31. /*void ResourceFileWindows::reset()
  32. {
  33.     if( pimpl->hfile == INVALID_HANDLE_VALUE )
  34.         return;
  35.     SetFilePointer( pimpl->hfile, 0, NULL, FILE_BEGIN );
  36. }*/
  37.  
  38. unsigned ResourceFileWindows::read(void * data, unsigned count)
  39. {
  40.     if( pimpl->hfile == INVALID_HANDLE_VALUE )
  41.         return 0;
  42.     DWORD read = 0;
  43.     if( ReadFile( pimpl->hfile, data, count, &read, NULL ) == 0 )
  44.         return 0;
  45.     return read;
  46. }
  47.  
  48. void ResourceFileWindows::skip(unsigned count)
  49. {
  50.     if( pimpl->hfile == INVALID_HANDLE_VALUE )
  51.         return;
  52.     SetFilePointer( pimpl->hfile, count, NULL, FILE_CURRENT );
  53. }
  54.  
  55. void ResourceFileWindows::reset(unsigned position)
  56. {
  57.     if( pimpl->hfile == INVALID_HANDLE_VALUE )
  58.         return;
  59.     SetFilePointer( pimpl->hfile, position, NULL, FILE_BEGIN );
  60. }
  61.  
  62. unsigned ResourceFileWindows::get_size()
  63. {
  64.     if( pimpl->hfile == INVALID_HANDLE_VALUE )
  65.         return 0;
  66.     return GetFileSize( pimpl->hfile, NULL );
  67. }
  68.