/[svn]/libgig/trunk/src/RIFF.cpp
ViewVC logotype

Diff of /libgig/trunk/src/RIFF.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2914 by schoenebeck, Tue May 17 19:04:56 2016 UTC revision 3048 by schoenebeck, Fri Nov 25 18:34:45 2016 UTC
# Line 125  namespace RIFF { Line 125  namespace RIFF {
125              read(pFile->hFileRead, &ChunkID, 4);              read(pFile->hFileRead, &ChunkID, 4);
126              read(pFile->hFileRead, &ullCurrentChunkSize, pFile->FileOffsetSize);              read(pFile->hFileRead, &ullCurrentChunkSize, pFile->FileOffsetSize);
127          #elif defined(WIN32)          #elif defined(WIN32)
128          const LARGE_INTEGER liFilePos = { .QuadPart = filePos };          LARGE_INTEGER liFilePos;
129            liFilePos.QuadPart = filePos;
130          if (SetFilePointerEx(pFile->hFileRead, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN)) {          if (SetFilePointerEx(pFile->hFileRead, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN)) {
131              DWORD dwBytesRead;              DWORD dwBytesRead;
132              ReadFile(pFile->hFileRead, &ChunkID, 4, &dwBytesRead, NULL);              ReadFile(pFile->hFileRead, &ChunkID, 4, &dwBytesRead, NULL);
# Line 185  namespace RIFF { Line 186  namespace RIFF {
186              write(pFile->hFileWrite, &ullNewChunkSize, pFile->FileOffsetSize);              write(pFile->hFileWrite, &ullNewChunkSize, pFile->FileOffsetSize);
187          }          }
188          #elif defined(WIN32)          #elif defined(WIN32)
189          const LARGE_INTEGER liFilePos = { .QuadPart = filePos };          LARGE_INTEGER liFilePos;
190            liFilePos.QuadPart = filePos;
191          if (SetFilePointerEx(pFile->hFileWrite, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN)) {          if (SetFilePointerEx(pFile->hFileWrite, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN)) {
192              DWORD dwBytesWritten;              DWORD dwBytesWritten;
193              WriteFile(pFile->hFileWrite, &uiNewChunkID, 4, &dwBytesWritten, NULL);              WriteFile(pFile->hFileWrite, &uiNewChunkID, 4, &dwBytesWritten, NULL);
# Line 311  namespace RIFF { Line 313  namespace RIFF {
313       *  @param WordCount  number of data words to read       *  @param WordCount  number of data words to read
314       *  @param WordSize   size of each data word to read       *  @param WordSize   size of each data word to read
315       *  @returns          number of successfully read data words or 0 if end       *  @returns          number of successfully read data words or 0 if end
316       *                    of file reached or error occured       *                    of file reached or error occurred
317       */       */
318      file_offset_t Chunk::Read(void* pData, file_offset_t WordCount, file_offset_t WordSize) {      file_offset_t Chunk::Read(void* pData, file_offset_t WordCount, file_offset_t WordSize) {
319          #if DEBUG          #if DEBUG
# Line 331  namespace RIFF { Line 333  namespace RIFF {
333          }          }
334          readWords /= WordSize;          readWords /= WordSize;
335          #elif defined(WIN32)          #elif defined(WIN32)
336          const LARGE_INTEGER liFilePos = { .QuadPart = ullStartPos + ullPos };          LARGE_INTEGER liFilePos;
337            liFilePos.QuadPart = ullStartPos + ullPos;
338          if (!SetFilePointerEx(pFile->hFileRead, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN))          if (!SetFilePointerEx(pFile->hFileRead, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN))
339              return 0;              return 0;
340          DWORD readWords;          DWORD readWords;
# Line 379  namespace RIFF { Line 382  namespace RIFF {
382       *  @param WordSize   size of each data word to write       *  @param WordSize   size of each data word to write
383       *  @returns          number of successfully written data words       *  @returns          number of successfully written data words
384       *  @throws RIFF::Exception  if write operation would exceed current       *  @throws RIFF::Exception  if write operation would exceed current
385       *                           chunk size or any IO error occured       *                           chunk size or any IO error occurred
386       *  @see Resize()       *  @see Resize()
387       */       */
388      file_offset_t Chunk::Write(void* pData, file_offset_t WordCount, file_offset_t WordSize) {      file_offset_t Chunk::Write(void* pData, file_offset_t WordCount, file_offset_t WordSize) {
# Line 416  namespace RIFF { Line 419  namespace RIFF {
419          if (writtenWords < 1) throw Exception("POSIX IO Error while trying to write chunk data");          if (writtenWords < 1) throw Exception("POSIX IO Error while trying to write chunk data");
420          writtenWords /= WordSize;          writtenWords /= WordSize;
421          #elif defined(WIN32)          #elif defined(WIN32)
422          const LARGE_INTEGER liFilePos = { .QuadPart = ullStartPos + ullPos };          LARGE_INTEGER liFilePos;
423            liFilePos.QuadPart = ullStartPos + ullPos;
424          if (!SetFilePointerEx(pFile->hFileWrite, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN)) {          if (!SetFilePointerEx(pFile->hFileWrite, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN)) {
425              throw Exception("Could not seek to position " + ToString(ullPos) +              throw Exception("Could not seek to position " + ToString(ullPos) +
426                              " in chunk (" + ToString(ullStartPos + ullPos) + " in file)");                              " in chunk (" + ToString(ullStartPos + ullPos) + " in file)");
# Line 451  namespace RIFF { Line 455  namespace RIFF {
455       * @param pData             destination buffer       * @param pData             destination buffer
456       * @param WordCount         number of 8 Bit signed integers to read       * @param WordCount         number of 8 Bit signed integers to read
457       * @returns                 number of read integers       * @returns                 number of read integers
458       * @throws RIFF::Exception  if an error occured or less than       * @throws RIFF::Exception  if an error occurred or less than
459       *                          \a WordCount integers could be read!       *                          \a WordCount integers could be read!
460       */       */
461      file_offset_t Chunk::ReadInt8(int8_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::ReadInt8(int8_t* pData, file_offset_t WordCount) {
# Line 472  namespace RIFF { Line 476  namespace RIFF {
476       * @param pData             source buffer (containing the data)       * @param pData             source buffer (containing the data)
477       * @param WordCount         number of 8 Bit signed integers to write       * @param WordCount         number of 8 Bit signed integers to write
478       * @returns                 number of written integers       * @returns                 number of written integers
479       * @throws RIFF::Exception  if an IO error occured       * @throws RIFF::Exception  if an IO error occurred
480       * @see Resize()       * @see Resize()
481       */       */
482      file_offset_t Chunk::WriteInt8(int8_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::WriteInt8(int8_t* pData, file_offset_t WordCount) {
# Line 488  namespace RIFF { Line 492  namespace RIFF {
492       * @param pData             destination buffer       * @param pData             destination buffer
493       * @param WordCount         number of 8 Bit unsigned integers to read       * @param WordCount         number of 8 Bit unsigned integers to read
494       * @returns                 number of read integers       * @returns                 number of read integers
495       * @throws RIFF::Exception  if an error occured or less than       * @throws RIFF::Exception  if an error occurred or less than
496       *                          \a WordCount integers could be read!       *                          \a WordCount integers could be read!
497       */       */
498      file_offset_t Chunk::ReadUint8(uint8_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::ReadUint8(uint8_t* pData, file_offset_t WordCount) {
# Line 509  namespace RIFF { Line 513  namespace RIFF {
513       * @param pData             source buffer (containing the data)       * @param pData             source buffer (containing the data)
514       * @param WordCount         number of 8 Bit unsigned integers to write       * @param WordCount         number of 8 Bit unsigned integers to write
515       * @returns                 number of written integers       * @returns                 number of written integers
516       * @throws RIFF::Exception  if an IO error occured       * @throws RIFF::Exception  if an IO error occurred
517       * @see Resize()       * @see Resize()
518       */       */
519      file_offset_t Chunk::WriteUint8(uint8_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::WriteUint8(uint8_t* pData, file_offset_t WordCount) {
# Line 525  namespace RIFF { Line 529  namespace RIFF {
529       * @param pData             destination buffer       * @param pData             destination buffer
530       * @param WordCount         number of 16 Bit signed integers to read       * @param WordCount         number of 16 Bit signed integers to read
531       * @returns                 number of read integers       * @returns                 number of read integers
532       * @throws RIFF::Exception  if an error occured or less than       * @throws RIFF::Exception  if an error occurred or less than
533       *                          \a WordCount integers could be read!       *                          \a WordCount integers could be read!
534       */       */
535      file_offset_t Chunk::ReadInt16(int16_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::ReadInt16(int16_t* pData, file_offset_t WordCount) {
# Line 546  namespace RIFF { Line 550  namespace RIFF {
550       * @param pData             source buffer (containing the data)       * @param pData             source buffer (containing the data)
551       * @param WordCount         number of 16 Bit signed integers to write       * @param WordCount         number of 16 Bit signed integers to write
552       * @returns                 number of written integers       * @returns                 number of written integers
553       * @throws RIFF::Exception  if an IO error occured       * @throws RIFF::Exception  if an IO error occurred
554       * @see Resize()       * @see Resize()
555       */       */
556      file_offset_t Chunk::WriteInt16(int16_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::WriteInt16(int16_t* pData, file_offset_t WordCount) {
# Line 562  namespace RIFF { Line 566  namespace RIFF {
566       * @param pData             destination buffer       * @param pData             destination buffer
567       * @param WordCount         number of 8 Bit unsigned integers to read       * @param WordCount         number of 8 Bit unsigned integers to read
568       * @returns                 number of read integers       * @returns                 number of read integers
569       * @throws RIFF::Exception  if an error occured or less than       * @throws RIFF::Exception  if an error occurred or less than
570       *                          \a WordCount integers could be read!       *                          \a WordCount integers could be read!
571       */       */
572      file_offset_t Chunk::ReadUint16(uint16_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::ReadUint16(uint16_t* pData, file_offset_t WordCount) {
# Line 583  namespace RIFF { Line 587  namespace RIFF {
587       * @param pData             source buffer (containing the data)       * @param pData             source buffer (containing the data)
588       * @param WordCount         number of 16 Bit unsigned integers to write       * @param WordCount         number of 16 Bit unsigned integers to write
589       * @returns                 number of written integers       * @returns                 number of written integers
590       * @throws RIFF::Exception  if an IO error occured       * @throws RIFF::Exception  if an IO error occurred
591       * @see Resize()       * @see Resize()
592       */       */
593      file_offset_t Chunk::WriteUint16(uint16_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::WriteUint16(uint16_t* pData, file_offset_t WordCount) {
# Line 599  namespace RIFF { Line 603  namespace RIFF {
603       * @param pData             destination buffer       * @param pData             destination buffer
604       * @param WordCount         number of 32 Bit signed integers to read       * @param WordCount         number of 32 Bit signed integers to read
605       * @returns                 number of read integers       * @returns                 number of read integers
606       * @throws RIFF::Exception  if an error occured or less than       * @throws RIFF::Exception  if an error occurred or less than
607       *                          \a WordCount integers could be read!       *                          \a WordCount integers could be read!
608       */       */
609      file_offset_t Chunk::ReadInt32(int32_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::ReadInt32(int32_t* pData, file_offset_t WordCount) {
# Line 620  namespace RIFF { Line 624  namespace RIFF {
624       * @param pData             source buffer (containing the data)       * @param pData             source buffer (containing the data)
625       * @param WordCount         number of 32 Bit signed integers to write       * @param WordCount         number of 32 Bit signed integers to write
626       * @returns                 number of written integers       * @returns                 number of written integers
627       * @throws RIFF::Exception  if an IO error occured       * @throws RIFF::Exception  if an IO error occurred
628       * @see Resize()       * @see Resize()
629       */       */
630      file_offset_t Chunk::WriteInt32(int32_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::WriteInt32(int32_t* pData, file_offset_t WordCount) {
# Line 636  namespace RIFF { Line 640  namespace RIFF {
640       * @param pData             destination buffer       * @param pData             destination buffer
641       * @param WordCount         number of 32 Bit unsigned integers to read       * @param WordCount         number of 32 Bit unsigned integers to read
642       * @returns                 number of read integers       * @returns                 number of read integers
643       * @throws RIFF::Exception  if an error occured or less than       * @throws RIFF::Exception  if an error occurred or less than
644       *                          \a WordCount integers could be read!       *                          \a WordCount integers could be read!
645       */       */
646      file_offset_t Chunk::ReadUint32(uint32_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::ReadUint32(uint32_t* pData, file_offset_t WordCount) {
# Line 653  namespace RIFF { Line 657  namespace RIFF {
657       *       *
658       * @param s                 destination string       * @param s                 destination string
659       * @param size              number of characters to read       * @param size              number of characters to read
660       * @throws RIFF::Exception  if an error occured or less than       * @throws RIFF::Exception  if an error occurred or less than
661       *                          \a size characters could be read!       *                          \a size characters could be read!
662       */       */
663      void Chunk::ReadString(String& s, int size) {      void Chunk::ReadString(String& s, int size) {
# Line 674  namespace RIFF { Line 678  namespace RIFF {
678       * @param pData             source buffer (containing the data)       * @param pData             source buffer (containing the data)
679       * @param WordCount         number of 32 Bit unsigned integers to write       * @param WordCount         number of 32 Bit unsigned integers to write
680       * @returns                 number of written integers       * @returns                 number of written integers
681       * @throws RIFF::Exception  if an IO error occured       * @throws RIFF::Exception  if an IO error occurred
682       * @see Resize()       * @see Resize()
683       */       */
684      file_offset_t Chunk::WriteUint32(uint32_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::WriteUint32(uint32_t* pData, file_offset_t WordCount) {
# Line 686  namespace RIFF { Line 690  namespace RIFF {
690       * the chunk.       * the chunk.
691       *       *
692       * @returns                 read integer word       * @returns                 read integer word
693       * @throws RIFF::Exception  if an error occured       * @throws RIFF::Exception  if an error occurred
694       */       */
695      int8_t Chunk::ReadInt8() {      int8_t Chunk::ReadInt8() {
696          #if DEBUG          #if DEBUG
# Line 702  namespace RIFF { Line 706  namespace RIFF {
706       * within the chunk.       * within the chunk.
707       *       *
708       * @returns                 read integer word       * @returns                 read integer word
709       * @throws RIFF::Exception  if an error occured       * @throws RIFF::Exception  if an error occurred
710       */       */
711      uint8_t Chunk::ReadUint8() {      uint8_t Chunk::ReadUint8() {
712          #if DEBUG          #if DEBUG
# Line 719  namespace RIFF { Line 723  namespace RIFF {
723       * needed.       * needed.
724       *       *
725       * @returns                 read integer word       * @returns                 read integer word
726       * @throws RIFF::Exception  if an error occured       * @throws RIFF::Exception  if an error occurred
727       */       */
728      int16_t Chunk::ReadInt16() {      int16_t Chunk::ReadInt16() {
729          #if DEBUG          #if DEBUG
# Line 736  namespace RIFF { Line 740  namespace RIFF {
740       * needed.       * needed.
741       *       *
742       * @returns                 read integer word       * @returns                 read integer word
743       * @throws RIFF::Exception  if an error occured       * @throws RIFF::Exception  if an error occurred
744       */       */
745      uint16_t Chunk::ReadUint16() {      uint16_t Chunk::ReadUint16() {
746          #if DEBUG          #if DEBUG
# Line 753  namespace RIFF { Line 757  namespace RIFF {
757       * needed.       * needed.
758       *       *
759       * @returns                 read integer word       * @returns                 read integer word
760       * @throws RIFF::Exception  if an error occured       * @throws RIFF::Exception  if an error occurred
761       */       */
762      int32_t Chunk::ReadInt32() {      int32_t Chunk::ReadInt32() {
763          #if DEBUG          #if DEBUG
# Line 770  namespace RIFF { Line 774  namespace RIFF {
774       * needed.       * needed.
775       *       *
776       * @returns                 read integer word       * @returns                 read integer word
777       * @throws RIFF::Exception  if an error occured       * @throws RIFF::Exception  if an error occurred
778       */       */
779      uint32_t Chunk::ReadUint32() {      uint32_t Chunk::ReadUint32() {
780          #if DEBUG          #if DEBUG
# Line 807  namespace RIFF { Line 811  namespace RIFF {
811              #if POSIX              #if POSIX
812              if (lseek(pFile->hFileRead, ullStartPos, SEEK_SET) == -1) return NULL;              if (lseek(pFile->hFileRead, ullStartPos, SEEK_SET) == -1) return NULL;
813              #elif defined(WIN32)              #elif defined(WIN32)
814              const LARGE_INTEGER liFilePos = { .QuadPart = ullStartPos };              LARGE_INTEGER liFilePos;
815                liFilePos.QuadPart = ullStartPos;
816              if (!SetFilePointerEx(pFile->hFileRead, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN)) return NULL;              if (!SetFilePointerEx(pFile->hFileRead, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN)) return NULL;
817              #else              #else
818              if (fseeko(pFile->hFileRead, ullStartPos, SEEK_SET)) return NULL;              if (fseeko(pFile->hFileRead, ullStartPos, SEEK_SET)) return NULL;
# Line 869  namespace RIFF { Line 874  namespace RIFF {
874       * boundary!       * boundary!
875       *       *
876       * @param NewSize - new chunk body size in bytes (must be greater than zero)       * @param NewSize - new chunk body size in bytes (must be greater than zero)
877       * @throws RIFF::Exception  if \a NewSize is less than 1 or Unrealistic large       * @throws RIFF::Exception  if \a NewSize is less than 1 or unrealistic large
878       * @see File::Save()       * @see File::Save()
879       */       */
880      void Chunk::Resize(file_offset_t NewSize) {      void Chunk::Resize(file_offset_t NewSize) {
# Line 912  namespace RIFF { Line 917  namespace RIFF {
917                  throw Exception("Writing Chunk data (from RAM) failed");                  throw Exception("Writing Chunk data (from RAM) failed");
918              }              }
919              #elif defined(WIN32)              #elif defined(WIN32)
920              const LARGE_INTEGER liFilePos = { .QuadPart = ullWritePos };              LARGE_INTEGER liFilePos;
921                liFilePos.QuadPart = ullWritePos;
922              SetFilePointerEx(pFile->hFileWrite, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN);              SetFilePointerEx(pFile->hFileWrite, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN);
923              DWORD dwBytesWritten;              DWORD dwBytesWritten;
924              WriteFile(pFile->hFileWrite, pChunkData, ullNewChunkSize, &dwBytesWritten, NULL); //FIXME: won't save chunks larger than 2GB !              WriteFile(pFile->hFileWrite, pChunkData, ullNewChunkSize, &dwBytesWritten, NULL); //FIXME: won't save chunks larger than 2GB !
# Line 942  namespace RIFF { Line 948  namespace RIFF {
948                  lseek(pFile->hFileWrite, ullWritePos + ullOffset, SEEK_SET);                  lseek(pFile->hFileWrite, ullWritePos + ullOffset, SEEK_SET);
949                  iBytesMoved = write(pFile->hFileWrite, pCopyBuffer, iBytesMoved);                  iBytesMoved = write(pFile->hFileWrite, pCopyBuffer, iBytesMoved);
950                  #elif defined(WIN32)                  #elif defined(WIN32)
951                  LARGE_INTEGER liFilePos = { .QuadPart = ullStartPos + ullCurrentDataOffset + ullOffset };                  LARGE_INTEGER liFilePos;
952                    liFilePos.QuadPart = ullStartPos + ullCurrentDataOffset + ullOffset;
953                  SetFilePointerEx(pFile->hFileRead, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN);                  SetFilePointerEx(pFile->hFileRead, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN);
954                  ReadFile(pFile->hFileRead, pCopyBuffer, iBytesMoved, &iBytesMoved, NULL);                  ReadFile(pFile->hFileRead, pCopyBuffer, iBytesMoved, &iBytesMoved, NULL);
955                  liFilePos.QuadPart = ullWritePos + ullOffset;                  liFilePos.QuadPart = ullWritePos + ullOffset;
# Line 976  namespace RIFF { Line 983  namespace RIFF {
983              lseek(pFile->hFileWrite, ullStartPos + ullNewChunkSize, SEEK_SET);              lseek(pFile->hFileWrite, ullStartPos + ullNewChunkSize, SEEK_SET);
984              write(pFile->hFileWrite, &cPadByte, 1);              write(pFile->hFileWrite, &cPadByte, 1);
985              #elif defined(WIN32)              #elif defined(WIN32)
986              const LARGE_INTEGER liFilePos = { .QuadPart = ullStartPos + ullNewChunkSize };              LARGE_INTEGER liFilePos;
987                liFilePos.QuadPart = ullStartPos + ullNewChunkSize;
988              SetFilePointerEx(pFile->hFileWrite, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN);              SetFilePointerEx(pFile->hFileWrite, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN);
989              DWORD dwBytesWritten;              DWORD dwBytesWritten;
990              WriteFile(pFile->hFileWrite, &cPadByte, 1, &dwBytesWritten, NULL);              WriteFile(pFile->hFileWrite, &cPadByte, 1, &dwBytesWritten, NULL);
# Line 1071  namespace RIFF { Line 1079  namespace RIFF {
1079      /**      /**
1080       *  Returns sublist chunk with list type <i>\a ListType</i> within this       *  Returns sublist chunk with list type <i>\a ListType</i> within this
1081       *  chunk list. Use this method if you expect only one sublist chunk of       *  chunk list. Use this method if you expect only one sublist chunk of
1082       *  that type in the list. It there are more than one, it's undetermined       *  that type in the list. If there are more than one, it's undetermined
1083       *  which one of them will be returned! If there are no sublists with       *  which one of them will be returned! If there are no sublists with
1084       *  that desired list type, NULL will be returned.       *  that desired list type, NULL will be returned.
1085       *       *
# Line 1097  namespace RIFF { Line 1105  namespace RIFF {
1105      }      }
1106    
1107      /**      /**
1108       *  Returns the first subchunk within the list. You have to call this       *  Returns the first subchunk within the list (which may be an ordinary
1109         *  chunk as well as a list chunk). You have to call this
1110       *  method before you can call GetNextSubChunk(). Recall it when you want       *  method before you can call GetNextSubChunk(). Recall it when you want
1111       *  to start from the beginning of the list again.       *  to start from the beginning of the list again.
1112       *       *
# Line 1114  namespace RIFF { Line 1123  namespace RIFF {
1123      }      }
1124    
1125      /**      /**
1126       *  Returns the next subchunk within the list. You have to call       *  Returns the next subchunk within the list (which may be an ordinary
1127         *  chunk as well as a list chunk). You have to call
1128       *  GetFirstSubChunk() before you can use this method!       *  GetFirstSubChunk() before you can use this method!
1129       *       *
1130       *  @returns  pointer to the next subchunk within the list or NULL if       *  @returns  pointer to the next subchunk within the list or NULL if
# Line 1176  namespace RIFF { Line 1186  namespace RIFF {
1186      }      }
1187    
1188      /**      /**
1189       *  Returns number of subchunks within the list.       *  Returns number of subchunks within the list (including list chunks).
1190       */       */
1191      unsigned int List::CountSubChunks() {      size_t List::CountSubChunks() {
1192          if (!pSubChunks) LoadSubChunks();          if (!pSubChunks) LoadSubChunks();
1193          return pSubChunks->size();          return pSubChunks->size();
1194      }      }
# Line 1187  namespace RIFF { Line 1197  namespace RIFF {
1197       *  Returns number of subchunks within the list with chunk ID       *  Returns number of subchunks within the list with chunk ID
1198       *  <i>\a ChunkId</i>.       *  <i>\a ChunkId</i>.
1199       */       */
1200      unsigned int List::CountSubChunks(uint32_t ChunkID) {      size_t List::CountSubChunks(uint32_t ChunkID) {
1201          unsigned int result = 0;          size_t result = 0;
1202          if (!pSubChunks) LoadSubChunks();          if (!pSubChunks) LoadSubChunks();
1203          ChunkList::iterator iter = pSubChunks->begin();          ChunkList::iterator iter = pSubChunks->begin();
1204          ChunkList::iterator end  = pSubChunks->end();          ChunkList::iterator end  = pSubChunks->end();
# Line 1204  namespace RIFF { Line 1214  namespace RIFF {
1214      /**      /**
1215       *  Returns number of sublists within the list.       *  Returns number of sublists within the list.
1216       */       */
1217      unsigned int List::CountSubLists() {      size_t List::CountSubLists() {
1218          return CountSubChunks(CHUNK_ID_LIST);          return CountSubChunks(CHUNK_ID_LIST);
1219      }      }
1220    
# Line 1212  namespace RIFF { Line 1222  namespace RIFF {
1222       *  Returns number of sublists within the list with list type       *  Returns number of sublists within the list with list type
1223       *  <i>\a ListType</i>       *  <i>\a ListType</i>
1224       */       */
1225      unsigned int List::CountSubLists(uint32_t ListType) {      size_t List::CountSubLists(uint32_t ListType) {
1226          unsigned int result = 0;          size_t result = 0;
1227          if (!pSubChunks) LoadSubChunks();          if (!pSubChunks) LoadSubChunks();
1228          ChunkList::iterator iter = pSubChunks->begin();          ChunkList::iterator iter = pSubChunks->begin();
1229          ChunkList::iterator end  = pSubChunks->end();          ChunkList::iterator end  = pSubChunks->end();
# Line 1375  namespace RIFF { Line 1385  namespace RIFF {
1385          lseek(pFile->hFileRead, filePos + CHUNK_HEADER_SIZE(pFile->FileOffsetSize), SEEK_SET);          lseek(pFile->hFileRead, filePos + CHUNK_HEADER_SIZE(pFile->FileOffsetSize), SEEK_SET);
1386          read(pFile->hFileRead, &ListType, 4);          read(pFile->hFileRead, &ListType, 4);
1387          #elif defined(WIN32)          #elif defined(WIN32)
1388          const LARGE_INTEGER liFilePos = { .QuadPart = filePos + CHUNK_HEADER_SIZE(pFile->FileOffsetSize) };          LARGE_INTEGER liFilePos;
1389            liFilePos.QuadPart = filePos + CHUNK_HEADER_SIZE(pFile->FileOffsetSize);
1390          SetFilePointerEx(pFile->hFileRead, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN);          SetFilePointerEx(pFile->hFileRead, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN);
1391          DWORD dwBytesRead;          DWORD dwBytesRead;
1392          ReadFile(pFile->hFileRead, &ListType, 4, &dwBytesRead, NULL);          ReadFile(pFile->hFileRead, &ListType, 4, &dwBytesRead, NULL);
# Line 1400  namespace RIFF { Line 1411  namespace RIFF {
1411          lseek(pFile->hFileWrite, filePos + CHUNK_HEADER_SIZE(pFile->FileOffsetSize), SEEK_SET);          lseek(pFile->hFileWrite, filePos + CHUNK_HEADER_SIZE(pFile->FileOffsetSize), SEEK_SET);
1412          write(pFile->hFileWrite, &ListType, 4);          write(pFile->hFileWrite, &ListType, 4);
1413          #elif defined(WIN32)          #elif defined(WIN32)
1414          const LARGE_INTEGER liFilePos = { .QuadPart = filePos + CHUNK_HEADER_SIZE(pFile->FileOffsetSize) };          LARGE_INTEGER liFilePos;
1415            liFilePos.QuadPart = filePos + CHUNK_HEADER_SIZE(pFile->FileOffsetSize);
1416          SetFilePointerEx(pFile->hFileWrite, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN);          SetFilePointerEx(pFile->hFileWrite, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN);
1417          DWORD dwBytesWritten;          DWORD dwBytesWritten;
1418          WriteFile(pFile->hFileWrite, &ListType, 4, &dwBytesWritten, NULL);          WriteFile(pFile->hFileWrite, &ListType, 4, &dwBytesWritten, NULL);
# Line 1485  namespace RIFF { Line 1497  namespace RIFF {
1497    
1498          // write all subchunks (including sub list chunks) recursively          // write all subchunks (including sub list chunks) recursively
1499          if (pSubChunks) {          if (pSubChunks) {
1500              int i = 0;              size_t i = 0;
1501              const int n = pSubChunks->size();              const size_t n = pSubChunks->size();
1502              for (ChunkList::iterator iter = pSubChunks->begin(), end = pSubChunks->end(); iter != end; ++iter, ++i) {              for (ChunkList::iterator iter = pSubChunks->begin(), end = pSubChunks->end(); iter != end; ++iter, ++i) {
1503                  // divide local progress into subprogress for loading current Instrument                  // divide local progress into subprogress for loading current Instrument
1504                  progress_t subprogress;                  progress_t subprogress;
# Line 1564  namespace RIFF { Line 1576  namespace RIFF {
1576       * Loads an existing RIFF file with all its chunks.       * Loads an existing RIFF file with all its chunks.
1577       *       *
1578       * @param path - path and file name of the RIFF file to open       * @param path - path and file name of the RIFF file to open
1579       * @throws RIFF::Exception if error occured while trying to load the       * @throws RIFF::Exception if error occurred while trying to load the
1580       *                         given RIFF file       *                         given RIFF file
1581       */       */
1582      File::File(const String& path)      File::File(const String& path)
# Line 1611  namespace RIFF { Line 1623  namespace RIFF {
1623       * @param Endian - whether the file uses little endian or big endian layout       * @param Endian - whether the file uses little endian or big endian layout
1624       * @param layout - general file structure type       * @param layout - general file structure type
1625       * @param fileOffsetSize - (optional) preference how to deal with large files       * @param fileOffsetSize - (optional) preference how to deal with large files
1626       * @throws RIFF::Exception if error occured while trying to load the       * @throws RIFF::Exception if error occurred while trying to load the
1627       *                         given RIFF-alike file       *                         given RIFF-alike file
1628       */       */
1629      File::File(const String& path, uint32_t FileType, endian_t Endian, layout_t layout, offset_size_t fileOffsetSize)      File::File(const String& path, uint32_t FileType, endian_t Endian, layout_t layout, offset_size_t fileOffsetSize)
# Line 1638  namespace RIFF { Line 1650  namespace RIFF {
1650       * @param path - path and file name of the RIFF file or RIFF-alike file to       * @param path - path and file name of the RIFF file or RIFF-alike file to
1651       *               be opened       *               be opened
1652       * @param FileType - (optional) expected chunk ID of first chunk in file       * @param FileType - (optional) expected chunk ID of first chunk in file
1653       * @throws RIFF::Exception if error occured while trying to load the       * @throws RIFF::Exception if error occurred while trying to load the
1654       *                         given RIFF file or RIFF-alike file       *                         given RIFF file or RIFF-alike file
1655       */       */
1656      void File::__openExistingFile(const String& path, uint32_t* FileType) {      void File::__openExistingFile(const String& path, uint32_t* FileType) {
# Line 1842  namespace RIFF { Line 1854  namespace RIFF {
1854       *       *
1855       * @param pProgress - optional: callback function for progress notification       * @param pProgress - optional: callback function for progress notification
1856       * @throws RIFF::Exception if there is an empty chunk or empty list       * @throws RIFF::Exception if there is an empty chunk or empty list
1857       *                         chunk or any kind of IO error occured       *                         chunk or any kind of IO error occurred
1858       */       */
1859      void File::Save(progress_t* pProgress) {      void File::Save(progress_t* pProgress) {
1860          //TODO: implementation for the case where first chunk is not a global container (List chunk) is not implemented yet (i.e. Korg files)          //TODO: implementation for the case where first chunk is not a global container (List chunk) is not implemented yet (i.e. Korg files)
# Line 1898  namespace RIFF { Line 1910  namespace RIFF {
1910              #if defined(WIN32)              #if defined(WIN32)
1911              DWORD iBytesMoved = 1; // we have to pass it via pointer to the Windows API, thus the correct size must be ensured              DWORD iBytesMoved = 1; // we have to pass it via pointer to the Windows API, thus the correct size must be ensured
1912              #else              #else
1913              int iBytesMoved = 1;              ssize_t iBytesMoved = 1;
1914              #endif              #endif
1915              for (file_offset_t ullPos = workingFileSize, iNotif = 0; iBytesMoved > 0; ++iNotif) {              for (file_offset_t ullPos = workingFileSize, iNotif = 0; iBytesMoved > 0; ++iNotif) {
1916                  iBytesMoved = (ullPos < 4096) ? ullPos : 4096;                  iBytesMoved = (ullPos < 4096) ? ullPos : 4096;
# Line 1909  namespace RIFF { Line 1921  namespace RIFF {
1921                  lseek(hFileWrite, ullPos + positiveSizeDiff, SEEK_SET);                  lseek(hFileWrite, ullPos + positiveSizeDiff, SEEK_SET);
1922                  iBytesMoved = write(hFileWrite, pCopyBuffer, iBytesMoved);                  iBytesMoved = write(hFileWrite, pCopyBuffer, iBytesMoved);
1923                  #elif defined(WIN32)                  #elif defined(WIN32)
1924                  LARGE_INTEGER liFilePos = { .QuadPart = ullPos };                  LARGE_INTEGER liFilePos;
1925                    liFilePos.QuadPart = ullPos;
1926                  SetFilePointerEx(hFileRead, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN);                  SetFilePointerEx(hFileRead, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN);
1927                  ReadFile(hFileRead, pCopyBuffer, iBytesMoved, &iBytesMoved, NULL);                  ReadFile(hFileRead, pCopyBuffer, iBytesMoved, &iBytesMoved, NULL);
1928                  liFilePos.QuadPart = ullPos + positiveSizeDiff;                  liFilePos.QuadPart = ullPos + positiveSizeDiff;
# Line 2053  namespace RIFF { Line 2066  namespace RIFF {
2066          if (ftruncate(hFileWrite, ullNewSize) < 0)          if (ftruncate(hFileWrite, ullNewSize) < 0)
2067              throw Exception("Could not resize file \"" + Filename + "\"");              throw Exception("Could not resize file \"" + Filename + "\"");
2068          #elif defined(WIN32)          #elif defined(WIN32)
2069          const LARGE_INTEGER liFilePos = { .QuadPart = ullNewSize };          LARGE_INTEGER liFilePos;
2070            liFilePos.QuadPart = ullNewSize;
2071          if (          if (
2072              !SetFilePointerEx(hFileWrite, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN) ||              !SetFilePointerEx(hFileWrite, liFilePos, NULL/*new pos pointer*/, FILE_BEGIN) ||
2073              !SetEndOfFile(hFileWrite)              !SetEndOfFile(hFileWrite)

Legend:
Removed from v.2914  
changed lines
  Added in v.3048

  ViewVC Help
Powered by ViewVC