/[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 1102 by persson, Sun Mar 18 07:13:06 2007 UTC revision 1885 by persson, Thu Apr 16 18:25:31 2009 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   libgig - C++ cross-platform Gigasampler format file access library    *   *   libgig - C++ cross-platform Gigasampler format file access library    *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003-2007 by Christian Schoenebeck                      *   *   Copyright (C) 2003-2009 by Christian Schoenebeck                      *
6   *                              <cuse@users.sourceforge.net>               *   *                              <cuse@users.sourceforge.net>               *
7   *                                                                         *   *                                                                         *
8   *   This library is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
# Line 21  Line 21 
21   *   MA  02111-1307  USA                                                   *   *   MA  02111-1307  USA                                                   *
22   ***************************************************************************/   ***************************************************************************/
23    
24    #include <algorithm>
25  #include <string.h>  #include <string.h>
26    
27  #include "RIFF.h"  #include "RIFF.h"
# Line 29  Line 30 
30    
31  namespace RIFF {  namespace RIFF {
32    
33    // *************** Internal functions **************
34    // *
35    
36        /// Returns a human readable path of the given chunk.
37        static String __resolveChunkPath(Chunk* pCk) {
38            String sPath;
39            for (Chunk* pChunk = pCk; pChunk; pChunk = pChunk->GetParent()) {
40                if (pChunk->GetChunkID() == CHUNK_ID_LIST) {
41                    List* pList = (List*) pChunk;
42                    sPath = "->'" + pList->GetListTypeString() + "'" + sPath;
43                } else {
44                    sPath = "->'" + pChunk->GetChunkIDString() + "'" + sPath;
45                }
46            }
47            return sPath;
48        }
49    
50    
51    
52  // *************** Chunk **************  // *************** Chunk **************
53  // *  // *
54    
# Line 39  namespace RIFF { Line 59  namespace RIFF {
59          ulPos      = 0;          ulPos      = 0;
60          pParent    = NULL;          pParent    = NULL;
61          pChunkData = NULL;          pChunkData = NULL;
62            CurrentChunkSize = 0;
63            NewChunkSize = 0;
64          ulChunkDataSize = 0;          ulChunkDataSize = 0;
65          ChunkID    = CHUNK_ID_RIFF;          ChunkID    = CHUNK_ID_RIFF;
66          this->pFile = pFile;          this->pFile = pFile;
# Line 53  namespace RIFF { Line 75  namespace RIFF {
75          pParent       = Parent;          pParent       = Parent;
76          ulPos         = 0;          ulPos         = 0;
77          pChunkData    = NULL;          pChunkData    = NULL;
78            CurrentChunkSize = 0;
79            NewChunkSize = 0;
80          ulChunkDataSize = 0;          ulChunkDataSize = 0;
81          ReadHeader(StartPos);          ReadHeader(StartPos);
82      }      }
# Line 63  namespace RIFF { Line 87  namespace RIFF {
87          this->pParent    = pParent;          this->pParent    = pParent;
88          ulPos            = 0;          ulPos            = 0;
89          pChunkData       = NULL;          pChunkData       = NULL;
         ulChunkDataSize  = 0;  
90          ChunkID          = uiChunkID;          ChunkID          = uiChunkID;
91            ulChunkDataSize  = 0;
92          CurrentChunkSize = 0;          CurrentChunkSize = 0;
93          NewChunkSize     = uiBodySize;          NewChunkSize     = uiBodySize;
94      }      }
95    
96      Chunk::~Chunk() {      Chunk::~Chunk() {
97          if (CurrentChunkSize != NewChunkSize) pFile->UnlogResized(this);          if (pFile) pFile->UnlogResized(this);
98          if (pChunkData) delete[] pChunkData;          if (pChunkData) delete[] pChunkData;
99      }      }
100    
# Line 78  namespace RIFF { Line 102  namespace RIFF {
102          #if DEBUG          #if DEBUG
103          std::cout << "Chunk::Readheader(" << fPos << ") ";          std::cout << "Chunk::Readheader(" << fPos << ") ";
104          #endif // DEBUG          #endif // DEBUG
105            ChunkID = 0;
106            NewChunkSize = CurrentChunkSize = 0;
107          #if POSIX          #if POSIX
108          if (lseek(pFile->hFileRead, fPos, SEEK_SET) != -1) {          if (lseek(pFile->hFileRead, fPos, SEEK_SET) != -1) {
109              read(pFile->hFileRead, &ChunkID, 4);              read(pFile->hFileRead, &ChunkID, 4);
# Line 108  namespace RIFF { Line 134  namespace RIFF {
134              }              }
135              #if DEBUG              #if DEBUG
136              std::cout << "ckID=" << convertToString(ChunkID) << " ";              std::cout << "ckID=" << convertToString(ChunkID) << " ";
137              std::cout << "ckSize=" << ChunkSize << " ";              std::cout << "ckSize=" << CurrentChunkSize << " ";
138              std::cout << "bEndianNative=" << bEndianNative << std::endl;              std::cout << "bEndianNative=" << pFile->bEndianNative << std::endl;
139              #endif // DEBUG              #endif // DEBUG
140              NewChunkSize = CurrentChunkSize;              NewChunkSize = CurrentChunkSize;
141          }          }
# Line 205  namespace RIFF { Line 231  namespace RIFF {
231         #if DEBUG         #if DEBUG
232         std::cout << "Chunk::Remainingbytes()=" << CurrentChunkSize - ulPos << std::endl;         std::cout << "Chunk::Remainingbytes()=" << CurrentChunkSize - ulPos << std::endl;
233         #endif // DEBUG         #endif // DEBUG
234          return CurrentChunkSize - ulPos;          return (CurrentChunkSize > ulPos) ? CurrentChunkSize - ulPos : 0;
235      }      }
236    
237      /**      /**
# Line 216  namespace RIFF { Line 242  namespace RIFF {
242       *  - RIFF::stream_closed :       *  - RIFF::stream_closed :
243       *    the data stream was closed somehow, no more reading possible       *    the data stream was closed somehow, no more reading possible
244       *  - RIFF::stream_end_reached :       *  - RIFF::stream_end_reached :
245       *    alreaady reached the end of the chunk data, no more reading       *    already reached the end of the chunk data, no more reading
246       *    possible without SetPos()       *    possible without SetPos()
247       */       */
248      stream_state_t Chunk::GetState() {      stream_state_t Chunk::GetState() {
# Line 254  namespace RIFF { Line 280  namespace RIFF {
280         #if DEBUG         #if DEBUG
281         std::cout << "Chunk::Read(void*,ulong,ulong)" << std::endl;         std::cout << "Chunk::Read(void*,ulong,ulong)" << std::endl;
282         #endif // DEBUG         #endif // DEBUG
283            if (ulStartPos == 0) return 0; // is only 0 if this is a new chunk, so nothing to read (yet)
284          if (ulPos >= CurrentChunkSize) return 0;          if (ulPos >= CurrentChunkSize) return 0;
285          if (ulPos + WordCount * WordSize >= CurrentChunkSize) WordCount = (CurrentChunkSize - ulPos) / WordSize;          if (ulPos + WordCount * WordSize >= CurrentChunkSize) WordCount = (CurrentChunkSize - ulPos) / WordSize;
286          #if POSIX          #if POSIX
# Line 339  namespace RIFF { Line 366  namespace RIFF {
366          #elif defined(WIN32)          #elif defined(WIN32)
367          if (SetFilePointer(pFile->hFileWrite, ulStartPos + ulPos, NULL/*32 bit*/, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {          if (SetFilePointer(pFile->hFileWrite, ulStartPos + ulPos, NULL/*32 bit*/, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
368              throw Exception("Could not seek to position " + ToString(ulPos) +              throw Exception("Could not seek to position " + ToString(ulPos) +
369                              " in chunk (" + ToString(ulStartPos + ulPos) + " in file)");                                          " in chunk (" + ToString(ulStartPos + ulPos) + " in file)");
370          }          }
371          DWORD writtenWords;          DWORD writtenWords;
372          WriteFile(pFile->hFileWrite, pData, WordCount * WordSize, &writtenWords, NULL);          WriteFile(pFile->hFileWrite, pData, WordCount * WordSize, &writtenWords, NULL);
# Line 706  namespace RIFF { Line 733  namespace RIFF {
733       * @see ReleaseChunkData()       * @see ReleaseChunkData()
734       */       */
735      void* Chunk::LoadChunkData() {      void* Chunk::LoadChunkData() {
736          if (!pChunkData && pFile->Filename != "") {          if (!pChunkData && pFile->Filename != "" && ulStartPos != 0) {
737              #if POSIX              #if POSIX
738              if (lseek(pFile->hFileRead, ulStartPos, SEEK_SET) == -1) return NULL;              if (lseek(pFile->hFileRead, ulStartPos, SEEK_SET) == -1) return NULL;
739              #elif defined(WIN32)              #elif defined(WIN32)
# Line 775  namespace RIFF { Line 802  namespace RIFF {
802       * @see File::Save()       * @see File::Save()
803       */       */
804      void Chunk::Resize(int iNewSize) {      void Chunk::Resize(int iNewSize) {
805          if (iNewSize <= 0) throw Exception("Chunk size must be at least one byte");          if (iNewSize <= 0)
806                throw Exception("There is at least one empty chunk (zero size): " + __resolveChunkPath(this));
807          if (NewChunkSize == iNewSize) return;          if (NewChunkSize == iNewSize) return;
808          NewChunkSize = iNewSize;          NewChunkSize = iNewSize;
809          pFile->LogAsResized(this);          pFile->LogAsResized(this);
# Line 922  namespace RIFF { Line 950  namespace RIFF {
950        #if DEBUG        #if DEBUG
951        std::cout << "List::~List()" << std::endl;        std::cout << "List::~List()" << std::endl;
952        #endif // DEBUG        #endif // DEBUG
953            DeleteChunkList();
954        }
955    
956        void List::DeleteChunkList() {
957          if (pSubChunks) {          if (pSubChunks) {
958              ChunkList::iterator iter = pSubChunks->begin();              ChunkList::iterator iter = pSubChunks->begin();
959              ChunkList::iterator end  = pSubChunks->end();              ChunkList::iterator end  = pSubChunks->end();
# Line 930  namespace RIFF { Line 962  namespace RIFF {
962                  iter++;                  iter++;
963              }              }
964              delete pSubChunks;              delete pSubChunks;
965                pSubChunks = NULL;
966            }
967            if (pSubChunksMap) {
968                delete pSubChunksMap;
969                pSubChunksMap = NULL;
970          }          }
         if (pSubChunksMap) delete pSubChunksMap;  
971      }      }
972    
973      /**      /**
# Line 1132  namespace RIFF { Line 1168  namespace RIFF {
1168          pSubChunks->push_back(pNewChunk);          pSubChunks->push_back(pNewChunk);
1169          (*pSubChunksMap)[uiChunkID] = pNewChunk;          (*pSubChunksMap)[uiChunkID] = pNewChunk;
1170          pNewChunk->Resize(uiBodySize);          pNewChunk->Resize(uiBodySize);
1171            NewChunkSize += CHUNK_HEADER_SIZE;
1172            pFile->LogAsResized(this);
1173          return pNewChunk;          return pNewChunk;
1174      }      }
1175    
# Line 1167  namespace RIFF { Line 1205  namespace RIFF {
1205          List* pNewListChunk = new List(pFile, this, uiListType);          List* pNewListChunk = new List(pFile, this, uiListType);
1206          pSubChunks->push_back(pNewListChunk);          pSubChunks->push_back(pNewListChunk);
1207          (*pSubChunksMap)[CHUNK_ID_LIST] = pNewListChunk;          (*pSubChunksMap)[CHUNK_ID_LIST] = pNewListChunk;
1208            NewChunkSize += LIST_HEADER_SIZE;
1209            pFile->LogAsResized(this);
1210          return pNewListChunk;          return pNewListChunk;
1211      }      }
1212    
# Line 1203  namespace RIFF { Line 1243  namespace RIFF {
1243        std::cout << "List::Readheader(ulong) ";        std::cout << "List::Readheader(ulong) ";
1244        #endif // DEBUG        #endif // DEBUG
1245          Chunk::ReadHeader(fPos);          Chunk::ReadHeader(fPos);
1246            if (CurrentChunkSize < 4) return;
1247          NewChunkSize = CurrentChunkSize -= 4;          NewChunkSize = CurrentChunkSize -= 4;
1248          #if POSIX          #if POSIX
1249          lseek(pFile->hFileRead, fPos + CHUNK_HEADER_SIZE, SEEK_SET);          lseek(pFile->hFileRead, fPos + CHUNK_HEADER_SIZE, SEEK_SET);
# Line 1248  namespace RIFF { Line 1289  namespace RIFF {
1289          if (!pSubChunks) {          if (!pSubChunks) {
1290              pSubChunks    = new ChunkList();              pSubChunks    = new ChunkList();
1291              pSubChunksMap = new ChunkMap();              pSubChunksMap = new ChunkMap();
1292                #if defined(WIN32)
1293                if (pFile->hFileRead == INVALID_HANDLE_VALUE) return;
1294                #else
1295              if (!pFile->hFileRead) return;              if (!pFile->hFileRead) return;
1296                #endif
1297              unsigned long uiOriginalPos = GetPos();              unsigned long uiOriginalPos = GetPos();
1298              SetPos(0); // jump to beginning of list chunk body              SetPos(0); // jump to beginning of list chunk body
1299              while (RemainingBytes() >= CHUNK_HEADER_SIZE) {              while (RemainingBytes() >= CHUNK_HEADER_SIZE) {
# Line 1344  namespace RIFF { Line 1389  namespace RIFF {
1389       * "from scratch". Note: there must be no empty chunks or empty list       * "from scratch". Note: there must be no empty chunks or empty list
1390       * chunks when trying to make the new RIFF file persistent with Save()!       * chunks when trying to make the new RIFF file persistent with Save()!
1391       *       *
1392         * Note: by default, the RIFF file will be saved in native endian
1393         * format; that is, as a RIFF file on little-endian machines and
1394         * as a RIFX file on big-endian. To change this behaviour, call
1395         * SetByteOrder() before calling Save().
1396         *
1397       * @param FileType - four-byte identifier of the RIFF file type       * @param FileType - four-byte identifier of the RIFF file type
1398       * @see AddSubChunk(), AddSubList()       * @see AddSubChunk(), AddSubList(), SetByteOrder()
1399       */       */
1400      File::File(uint32_t FileType) : List(this) {      File::File(uint32_t FileType) : List(this) {
1401          #if defined(WIN32)          #if defined(WIN32)
# Line 1383  namespace RIFF { Line 1433  namespace RIFF {
1433                                       path.c_str(), GENERIC_READ,                                       path.c_str(), GENERIC_READ,
1434                                       FILE_SHARE_READ | FILE_SHARE_WRITE,                                       FILE_SHARE_READ | FILE_SHARE_WRITE,
1435                                       NULL, OPEN_EXISTING,                                       NULL, OPEN_EXISTING,
1436                                       FILE_ATTRIBUTE_NORMAL, NULL                                       FILE_ATTRIBUTE_NORMAL |
1437                                         FILE_FLAG_RANDOM_ACCESS, NULL
1438                                   );                                   );
1439          if (hFileRead == INVALID_HANDLE_VALUE) {          if (hFileRead == INVALID_HANDLE_VALUE) {
1440              hFileRead = hFileWrite = INVALID_HANDLE_VALUE;              hFileRead = hFileWrite = INVALID_HANDLE_VALUE;
# Line 1396  namespace RIFF { Line 1447  namespace RIFF {
1447          Mode = stream_mode_read;          Mode = stream_mode_read;
1448          ulStartPos = RIFF_HEADER_SIZE;          ulStartPos = RIFF_HEADER_SIZE;
1449          ReadHeader(0);          ReadHeader(0);
1450          if (ChunkID != CHUNK_ID_RIFF) {          if (ChunkID != CHUNK_ID_RIFF && ChunkID != CHUNK_ID_RIFX) {
1451              throw RIFF::Exception("Not a RIFF file");              throw RIFF::Exception("Not a RIFF file");
1452          }          }
1453      }      }
# Line 1436  namespace RIFF { Line 1487  namespace RIFF {
1487                                                   Filename.c_str(), GENERIC_READ,                                                   Filename.c_str(), GENERIC_READ,
1488                                                   FILE_SHARE_READ | FILE_SHARE_WRITE,                                                   FILE_SHARE_READ | FILE_SHARE_WRITE,
1489                                                   NULL, OPEN_EXISTING,                                                   NULL, OPEN_EXISTING,
1490                                                   FILE_ATTRIBUTE_NORMAL, NULL                                                   FILE_ATTRIBUTE_NORMAL |
1491                                                     FILE_FLAG_RANDOM_ACCESS,
1492                                                     NULL
1493                                               );                                               );
1494                      if (hFileRead == INVALID_HANDLE_VALUE) {                      if (hFileRead == INVALID_HANDLE_VALUE) {
1495                          hFileRead = hFileWrite = INVALID_HANDLE_VALUE;                          hFileRead = hFileWrite = INVALID_HANDLE_VALUE;
# Line 1464  namespace RIFF { Line 1517  namespace RIFF {
1517                                                   GENERIC_READ | GENERIC_WRITE,                                                   GENERIC_READ | GENERIC_WRITE,
1518                                                   FILE_SHARE_READ,                                                   FILE_SHARE_READ,
1519                                                   NULL, OPEN_ALWAYS,                                                   NULL, OPEN_ALWAYS,
1520                                                   FILE_ATTRIBUTE_NORMAL, NULL                                                   FILE_ATTRIBUTE_NORMAL |
1521                                                     FILE_FLAG_RANDOM_ACCESS,
1522                                                     NULL
1523                                               );                                               );
1524                      if (hFileRead == INVALID_HANDLE_VALUE) {                      if (hFileRead == INVALID_HANDLE_VALUE) {
1525                          hFileRead = hFileWrite = CreateFile(                          hFileRead = hFileWrite = CreateFile(
1526                                                       Filename.c_str(), GENERIC_READ,                                                       Filename.c_str(), GENERIC_READ,
1527                                                       FILE_SHARE_READ | FILE_SHARE_WRITE,                                                       FILE_SHARE_READ | FILE_SHARE_WRITE,
1528                                                       NULL, OPEN_EXISTING,                                                       NULL, OPEN_EXISTING,
1529                                                       FILE_ATTRIBUTE_NORMAL, NULL                                                       FILE_ATTRIBUTE_NORMAL |
1530                                                         FILE_FLAG_RANDOM_ACCESS,
1531                                                         NULL
1532                                                   );                                                   );
1533                          throw Exception("Could not (re)open file \"" + Filename + "\" in read mode");                          throw Exception("Could not (re)open file \"" + Filename + "\" in read+write mode");
1534                      }                      }
1535                      #else                      #else
1536                      if (hFileRead) fclose(hFileRead);                      if (hFileRead) fclose(hFileRead);
# Line 1507  namespace RIFF { Line 1564  namespace RIFF {
1564          return false;          return false;
1565      }      }
1566    
1567        /** @brief Set the byte order to be used when saving.
1568         *
1569         * Set the byte order to be used in the file. A value of
1570         * endian_little will create a RIFF file, endian_big a RIFX file
1571         * and endian_native will create a RIFF file on little-endian
1572         * machines and RIFX on big-endian machines.
1573         *
1574         * @param Endian - endianess to use when file is saved.
1575         */
1576        void File::SetByteOrder(endian_t Endian) {
1577            #if WORDS_BIGENDIAN
1578            bEndianNative = Endian != endian_little;
1579            #else
1580            bEndianNative = Endian != endian_big;
1581            #endif
1582        }
1583    
1584      /** @brief Save changes to same file.      /** @brief Save changes to same file.
1585       *       *
1586       * Make all changes of all chunks persistent by writing them to the       * Make all changes of all chunks persistent by writing them to the
# Line 1533  namespace RIFF { Line 1607  namespace RIFF {
1607    
1608          // first we sum up all positive chunk size changes (and skip all negative ones)          // first we sum up all positive chunk size changes (and skip all negative ones)
1609          unsigned long ulPositiveSizeDiff = 0;          unsigned long ulPositiveSizeDiff = 0;
1610          for (ChunkList::iterator iter = ResizedChunks.begin(), end = ResizedChunks.end(); iter != end; ++iter) {          for (std::set<Chunk*>::const_iterator iter = ResizedChunks.begin(), end = ResizedChunks.end(); iter != end; ++iter) {
1611              if ((*iter)->GetNewSize() == 0) {              if ((*iter)->GetNewSize() == 0) {
1612                  // just to make the exception message a bit more verbose: resolve the chunk's path                  throw Exception("There is at least one empty chunk (zero size): " + __resolveChunkPath(*iter));
                 String sChunkPath;  
                 for (Chunk* pChunk = *iter; pChunk; pChunk = pChunk->GetParent()) {  
                     if (pChunk->GetChunkID() == CHUNK_ID_LIST) {  
                         List* pList = (List*) pChunk;  
                         sChunkPath = "->'" + pList->GetListTypeString() + "'" + sChunkPath;  
                     } else {  
                         sChunkPath = "->'" + pChunk->GetChunkIDString() + "'" + sChunkPath;  
                     }  
                 }  
                 throw Exception("There is at least one empty chunk (zero size): " + sChunkPath);  
             }  
             if ((*iter)->GetNewSize() + 1L > (*iter)->GetSize()) {  
                 unsigned long ulDiff = (*iter)->GetNewSize() - (*iter)->GetSize() + 1L; // +1 in case we have to add a pad byte  
                 ulPositiveSizeDiff += ulDiff;  
1613              }              }
1614                unsigned long newSizePadded = (*iter)->GetNewSize() + (*iter)->GetNewSize() % 2;
1615                unsigned long oldSizePadded = (*iter)->GetSize() + (*iter)->GetSize() % 2;
1616                if (newSizePadded > oldSizePadded) ulPositiveSizeDiff += newSizePadded - oldSizePadded;
1617          }          }
1618    
1619          unsigned long ulWorkingFileSize = GetFileSize();          unsigned long ulWorkingFileSize = GetFileSize();
# Line 1566  namespace RIFF { Line 1629  namespace RIFF {
1629              #if defined(WIN32)              #if defined(WIN32)
1630              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
1631              #else              #else
1632              int iBytesMoved = 1;              int iBytesMoved = 1;
1633              #endif              #endif
1634              for (unsigned long ulPos = 0; iBytesMoved > 0; ulPos += iBytesMoved) {              for (unsigned long ulPos = ulFileSize; iBytesMoved > 0; ) {
1635                  const unsigned long ulToMove = ulFileSize - ulPos;                  iBytesMoved = (ulPos < 4096) ? ulPos : 4096;
1636                  iBytesMoved = (ulToMove < 4096) ? ulToMove : 4096;                  ulPos -= iBytesMoved;
1637                  #if POSIX                  #if POSIX
1638                  lseek(hFileRead, ulPos, SEEK_SET);                  lseek(hFileRead, ulPos, SEEK_SET);
1639                  iBytesMoved = read(hFileRead, pCopyBuffer, iBytesMoved);                  iBytesMoved = read(hFileRead, pCopyBuffer, iBytesMoved);
# Line 1633  namespace RIFF { Line 1696  namespace RIFF {
1696          #elif defined(WIN32)          #elif defined(WIN32)
1697          hFileWrite = CreateFile(          hFileWrite = CreateFile(
1698                           path.c_str(), GENERIC_WRITE, FILE_SHARE_READ,                           path.c_str(), GENERIC_WRITE, FILE_SHARE_READ,
1699                           NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL                           NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL |
1700                             FILE_FLAG_RANDOM_ACCESS, NULL
1701                       );                       );
1702          if (hFileWrite == INVALID_HANDLE_VALUE) {          if (hFileWrite == INVALID_HANDLE_VALUE) {
1703              hFileWrite = hFileRead;              hFileWrite = hFileRead;
# Line 1658  namespace RIFF { Line 1722  namespace RIFF {
1722          // forget all resized chunks          // forget all resized chunks
1723          ResizedChunks.clear();          ResizedChunks.clear();
1724    
1725          if (Filename.length() > 0) {          #if POSIX
1726              #if POSIX          if (hFileWrite) close(hFileWrite);
1727              close(hFileWrite);          #elif defined(WIN32)
1728              #elif defined(WIN32)          if (hFileWrite != INVALID_HANDLE_VALUE) CloseHandle(hFileWrite);
1729              CloseHandle(hFileWrite);          #else
1730              #else          if (hFileWrite) fclose(hFileWrite);
1731              fclose(hFileWrite);          #endif
1732              #endif          hFileWrite = hFileRead;
             hFileWrite = hFileRead;  
         }  
1733    
1734          // associate new file with this File object from now on          // associate new file with this File object from now on
1735          Filename = path;          Filename = path;
# Line 1701  namespace RIFF { Line 1763  namespace RIFF {
1763          #else          #else
1764          if (hFileRead) fclose(hFileRead);          if (hFileRead) fclose(hFileRead);
1765          #endif // POSIX          #endif // POSIX
1766            DeleteChunkList();
1767            pFile = NULL;
1768      }      }
1769    
1770      void File::LogAsResized(Chunk* pResizedChunk) {      void File::LogAsResized(Chunk* pResizedChunk) {
1771          ResizedChunks.push_back(pResizedChunk);          ResizedChunks.insert(pResizedChunk);
1772      }      }
1773    
1774      void File::UnlogResized(Chunk* pResizedChunk) {      void File::UnlogResized(Chunk* pResizedChunk) {
1775          ResizedChunks.remove(pResizedChunk);          ResizedChunks.erase(pResizedChunk);
1776      }      }
1777    
1778      unsigned long File::GetFileSize() {      unsigned long File::GetFileSize() {

Legend:
Removed from v.1102  
changed lines
  Added in v.1885

  ViewVC Help
Powered by ViewVC