1623 |
return Dir.substr(0, i); |
return Dir.substr(0, i); |
1624 |
} |
} |
1625 |
|
|
1626 |
|
void InstrumentsDb::Format() { |
1627 |
|
DbInstrumentsMutex.Lock(); |
1628 |
|
if (db != NULL) { |
1629 |
|
sqlite3_close(db); |
1630 |
|
db = NULL; |
1631 |
|
} |
1632 |
|
|
1633 |
|
if (DbFile.empty()) DbFile = "/var/lib/linuxsampler/instruments.db"; |
1634 |
|
String bkp = DbFile + ".bkp"; |
1635 |
|
remove(bkp.c_str()); |
1636 |
|
if (rename(DbFile.c_str(), bkp.c_str()) && errno != ENOENT) { |
1637 |
|
DbInstrumentsMutex.Unlock(); |
1638 |
|
throw Exception(String("Failed to backup database: ") + strerror(errno)); |
1639 |
|
} |
1640 |
|
|
1641 |
|
String f = DbFile; |
1642 |
|
DbFile = ""; |
1643 |
|
try { CreateInstrumentsDb(f); } |
1644 |
|
catch(Exception e) { |
1645 |
|
DbInstrumentsMutex.Unlock(); |
1646 |
|
throw e; |
1647 |
|
} |
1648 |
|
DbInstrumentsMutex.Unlock(); |
1649 |
|
|
1650 |
|
FireDirectoryCountChanged("/"); |
1651 |
|
FireInstrumentCountChanged("/"); |
1652 |
|
} |
1653 |
|
|
1654 |
void InstrumentsDb::CheckFileName(String File) { |
void InstrumentsDb::CheckFileName(String File) { |
1655 |
if (File.empty()) throw Exception("Invalid file name: " + File); |
if (File.empty()) throw Exception("Invalid file name: " + File); |
1656 |
} |
} |