Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.6 KiB

  1. #pragma once
  2. #include "windows.h"
  3. #include <string>
  4. using std::wstring;
  5. enum FileContentType {
  6. FileContentsUnicode,
  7. FileContentsUnicodeBigEndian,
  8. FileContentsUTF8
  9. };
  10. FileContentType DetermineFileTypeFromBuffer( unsigned char *, int );
  11. int DetermineFileTypeSigSize( FileContentType );
  12. CByteVector ConvertWstringToDestination( wstring str, FileContentType fct );
  13. wstring ConvertToWstring( const CByteVector &bytes, FileContentType fct );
  14. const static unsigned char UNICODE_SIGNATURE[] = { 0xFF, 0xFE };
  15. const static unsigned char UNICODE_BIG_ENDIAN_SIGNATURE[] = { 0xFE, 0xFF };
  16. const static unsigned char UTF8_SIGNATURE[] = { 0x0 };
  17. class Win32File
  18. {
  19. FileContentType _type;
  20. wstring _wsName;
  21. HANDLE _hFile;
  22. bool _bOpenForRead, _bEof;
  23. public:
  24. void openForRead( wstring wstname );
  25. void openForWrite( wstring wstname, FileContentType bCreateFileType, bool bCanOverwrite = true );
  26. bool eof();
  27. void snarfFullFile( wstring& );
  28. void writeLine( const wstring& );
  29. int filepointer() { return SetFilePointer( _hFile, 0, NULL, FILE_CURRENT ); }
  30. int filesize() { return GetFileSize( _hFile, NULL ); }
  31. FileContentType gettype() { return _type; }
  32. Win32File();
  33. ~Win32File();
  34. class AlreadyOpened { };
  35. class OpeningError { public: DWORD error; OpeningError( DWORD d ) : error( d ) { } };
  36. class ReadWriteError { public: bool isReading; DWORD error; ReadWriteError( bool m, DWORD e ) : isReading( m ), error( e ) { } };
  37. private:
  38. Win32File( const Win32File& );
  39. };