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> |
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); |
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,"; |
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 |
} |
} |
1756 |
} |
} |
1757 |
|
|
1758 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |
|
|
|
|
#endif // HAVE_SQLITE3 |
|