/[svn]/linuxsampler/trunk/src/db/InstrumentsDb.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/db/InstrumentsDb.cpp

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

revision 1350 by iliev, Sun Sep 16 23:06:10 2007 UTC revision 1603 by iliev, Mon Dec 31 10:17:51 2007 UTC
# Line 20  Line 20 
20    
21  #include "InstrumentsDb.h"  #include "InstrumentsDb.h"
22    
23  #if HAVE_SQLITE3  #include "../common/global_private.h"
24    
25  #include <iostream>  #include <iostream>
26  #include <sstream>  #include <sstream>
# Line 127  namespace LinuxSampler { Line 127  namespace LinuxSampler {
127      sqlite3* InstrumentsDb::GetDb() {      sqlite3* InstrumentsDb::GetDb() {
128          if ( db != NULL) return db;          if ( db != NULL) return db;
129    
130          if (DbFile.empty()) DbFile = "/var/lib/linuxsampler/instruments.db";          if (DbFile.empty()) DbFile = CONFIG_DEFAULT_INSTRUMENTS_DB_LOCATION;
131          int rc = sqlite3_open(DbFile.c_str(), &db);          int rc = sqlite3_open(DbFile.c_str(), &db);
132          if (rc) {          if (rc) {
133              sqlite3_close(db);              sqlite3_close(db);
# Line 1168  namespace LinuxSampler { Line 1168  namespace LinuxSampler {
1168          try {          try {
1169              riff = new RIFF::File(File);              riff = new RIFF::File(File);
1170              gig::File* gig = new gig::File(riff);              gig::File* gig = new gig::File(riff);
1171                gig->SetAutoLoad(false); // avoid time consuming samples scanning
1172    
1173              std::stringstream sql;              std::stringstream sql;
1174              sql << "INSERT INTO instruments (dir_id,instr_name,instr_file,";              sql << "INSERT INTO instruments (dir_id,instr_name,instr_file,";
# Line 1623  namespace LinuxSampler { Line 1624  namespace LinuxSampler {
1624          return Dir.substr(0, i);          return Dir.substr(0, i);
1625      }      }
1626    
1627        void InstrumentsDb::Format() {
1628            DbInstrumentsMutex.Lock();
1629            if (db != NULL) {
1630                sqlite3_close(db);
1631                db = NULL;
1632            }
1633    
1634            if (DbFile.empty()) DbFile = CONFIG_DEFAULT_INSTRUMENTS_DB_LOCATION;
1635            String bkp = DbFile + ".bkp";
1636            remove(bkp.c_str());
1637            if (rename(DbFile.c_str(), bkp.c_str()) && errno != ENOENT) {
1638                DbInstrumentsMutex.Unlock();
1639                throw Exception(String("Failed to backup database: ") + strerror(errno));
1640            }
1641            
1642            String f = DbFile;
1643            DbFile = "";
1644            try { CreateInstrumentsDb(f); }
1645            catch(Exception e) {
1646                DbInstrumentsMutex.Unlock();
1647                throw e;
1648            }
1649            DbInstrumentsMutex.Unlock();
1650            
1651            FireDirectoryCountChanged("/");
1652            FireInstrumentCountChanged("/");
1653        }
1654    
1655      void InstrumentsDb::CheckFileName(String File) {      void InstrumentsDb::CheckFileName(String File) {
1656          if (File.empty()) throw Exception("Invalid file name: " + File);          if (File.empty()) throw Exception("Invalid file name: " + File);
1657      }      }
# Line 1727  namespace LinuxSampler { Line 1756  namespace LinuxSampler {
1756      }      }
1757    
1758  } // namespace LinuxSampler  } // namespace LinuxSampler
   
 #endif // HAVE_SQLITE3  

Legend:
Removed from v.1350  
changed lines
  Added in v.1603

  ViewVC Help
Powered by ViewVC