/[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 2154 by persson, Sun Aug 29 11:10:36 2010 UTC revision 2155 by persson, Thu Jan 6 11:33:40 2011 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-2009 by Christian Schoenebeck                      *   *   Copyright (C) 2003-2011 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 1425  namespace RIFF { Line 1425  namespace RIFF {
1425       *                         given RIFF file       *                         given RIFF file
1426       */       */
1427      File::File(const String& path) : List(this), Filename(path) {      File::File(const String& path) : List(this), Filename(path) {
1428        #if DEBUG         #if DEBUG
1429        std::cout << "File::File("<<path<<")" << std::endl;         std::cout << "File::File("<<path<<")" << std::endl;
1430        #endif // DEBUG         #endif // DEBUG
1431          bEndianNative = true;          try {
1432          //HACK: see _GET_RESIZED_CHUNKS() comment              bEndianNative = true;
1433          ResizedChunks.push_back(reinterpret_cast<Chunk*>(new std::set<Chunk*>));              //HACK: see _GET_RESIZED_CHUNKS() comment
1434          #if POSIX              ResizedChunks.push_back(reinterpret_cast<Chunk*>(new std::set<Chunk*>));
1435          hFileRead = hFileWrite = open(path.c_str(), O_RDONLY | O_NONBLOCK);              #if POSIX
1436          if (hFileRead <= 0) {              hFileRead = hFileWrite = open(path.c_str(), O_RDONLY | O_NONBLOCK);
1437              hFileRead = hFileWrite = 0;              if (hFileRead <= 0) {
1438              throw RIFF::Exception("Can't open \"" + path + "\"");                  hFileRead = hFileWrite = 0;
1439          }                  throw RIFF::Exception("Can't open \"" + path + "\"");
1440          #elif defined(WIN32)              }
1441          hFileRead = hFileWrite = CreateFile(              #elif defined(WIN32)
1442                                       path.c_str(), GENERIC_READ,              hFileRead = hFileWrite = CreateFile(
1443                                       FILE_SHARE_READ | FILE_SHARE_WRITE,                                           path.c_str(), GENERIC_READ,
1444                                       NULL, OPEN_EXISTING,                                           FILE_SHARE_READ | FILE_SHARE_WRITE,
1445                                       FILE_ATTRIBUTE_NORMAL |                                           NULL, OPEN_EXISTING,
1446                                       FILE_FLAG_RANDOM_ACCESS, NULL                                           FILE_ATTRIBUTE_NORMAL |
1447                                   );                                           FILE_FLAG_RANDOM_ACCESS, NULL
1448          if (hFileRead == INVALID_HANDLE_VALUE) {                                       );
1449              hFileRead = hFileWrite = INVALID_HANDLE_VALUE;              if (hFileRead == INVALID_HANDLE_VALUE) {
1450              throw RIFF::Exception("Can't open \"" + path + "\"");                  hFileRead = hFileWrite = INVALID_HANDLE_VALUE;
1451                    throw RIFF::Exception("Can't open \"" + path + "\"");
1452                }
1453                #else
1454                hFileRead = hFileWrite = fopen(path.c_str(), "rb");
1455                if (!hFileRead) throw RIFF::Exception("Can't open \"" + path + "\"");
1456                #endif // POSIX
1457                Mode = stream_mode_read;
1458                ulStartPos = RIFF_HEADER_SIZE;
1459                ReadHeader(0);
1460                if (ChunkID != CHUNK_ID_RIFF && ChunkID != CHUNK_ID_RIFX) {
1461                    throw RIFF::Exception("Not a RIFF file");
1462                }
1463          }          }
1464          #else          catch (...) {
1465          hFileRead = hFileWrite = fopen(path.c_str(), "rb");              Cleanup();
1466          if (!hFileRead) throw RIFF::Exception("Can't open \"" + path + "\"");              throw;
         #endif // POSIX  
         Mode = stream_mode_read;  
         ulStartPos = RIFF_HEADER_SIZE;  
         ReadHeader(0);  
         if (ChunkID != CHUNK_ID_RIFF && ChunkID != CHUNK_ID_RIFX) {  
             throw RIFF::Exception("Not a RIFF file");  
1467          }          }
1468      }      }
1469    
# Line 1766  namespace RIFF { Line 1772  namespace RIFF {
1772         #if DEBUG         #if DEBUG
1773         std::cout << "File::~File()" << std::endl;         std::cout << "File::~File()" << std::endl;
1774         #endif // DEBUG         #endif // DEBUG
1775            Cleanup();
1776        }
1777    
1778        void File::Cleanup() {
1779          #if POSIX          #if POSIX
1780          if (hFileRead) close(hFileRead);          if (hFileRead) close(hFileRead);
1781          #elif defined(WIN32)          #elif defined(WIN32)

Legend:
Removed from v.2154  
changed lines
  Added in v.2155

  ViewVC Help
Powered by ViewVC