21 |
#include "InstrumentsDb.h" |
#include "InstrumentsDb.h" |
22 |
|
|
23 |
#include "../common/File.h" |
#include "../common/File.h" |
24 |
|
#include "../common/Path.h" |
25 |
#include "../common/global_private.h" |
#include "../common/global_private.h" |
26 |
|
|
27 |
#include <iostream> |
#include <iostream> |
705 |
throw Exception(ss.str()); |
throw Exception(ss.str()); |
706 |
} |
} |
707 |
|
|
708 |
if(insDir) { |
String dir = insDir ? PrepareSubdirectory(DbDir, FilePath) : DbDir; |
709 |
std::string tmp = f.basename(FilePath, "."); |
AddInstrumentsFromFile(dir, FilePath, Index, pProgress); |
|
String gigDir; |
|
|
if(DbDir.length() == 1 && DbDir.at(0) == '/') //DbDir is / |
|
|
gigDir = DbDir + (String)tmp + "/"; |
|
|
else |
|
|
gigDir = DbDir +"/"+ (String)tmp + "/"; |
|
|
dmsg(2,("InstrumentsDb: AddInstrumentsNonrecursive(Dir from file mode=%d, Created SubDir=%s)\n",insDir, gigDir.c_str())); |
|
|
DbInstrumentsMutex.Unlock(); |
|
|
AddDirectory(gigDir);//TODO: Add some error checking here to make sure the dir is created |
|
|
DbInstrumentsMutex.Lock(); |
|
|
AddInstrumentsFromFile(gigDir, FilePath, Index, pProgress); |
|
|
} else { |
|
|
AddInstrumentsFromFile(DbDir, FilePath, Index, pProgress); |
|
|
} |
|
710 |
} catch (Exception e) { |
} catch (Exception e) { |
711 |
DbInstrumentsMutex.Unlock(); |
DbInstrumentsMutex.Unlock(); |
712 |
throw e; |
throw e; |
742 |
try { |
try { |
743 |
FileListPtr fileList = File::GetFiles(FsDir); |
FileListPtr fileList = File::GetFiles(FsDir); |
744 |
for (int i = 0; i < fileList->size(); i++) { |
for (int i = 0; i < fileList->size(); i++) { |
745 |
if(insDir) |
String dir = insDir ? PrepareSubdirectory(DbDir, fileList->at(i)) : DbDir; |
746 |
{ |
AddInstrumentsFromFile(dir, FsDir + fileList->at(i), -1, pProgress); |
|
//File gFile = File(fileList->at(i)); |
|
|
String gigDir; |
|
|
if(DbDir.length() == 1 && DbDir.at(0) == '/') //DbDir is / |
|
|
gigDir = DbDir + f.basename(fileList->at(i),".") + "/"; |
|
|
else |
|
|
gigDir = DbDir +"/"+ f.basename(fileList->at(i),".") + "/"; |
|
|
dmsg(2,("InstrumentsDb: AddInstrumentsNonrecursive(Dir from file mode=%d, Created SubDir=%s)\n",insDir, gigDir.c_str())); |
|
|
DbInstrumentsMutex.Unlock(); // UnLock the db so we can add our extra directory |
|
|
AddDirectory(gigDir);//TODO: Add some error checking here to make sure the dir is created |
|
|
DbInstrumentsMutex.Lock(); //Lock and carry on |
|
|
AddInstrumentsFromFile(gigDir, FsDir + fileList->at(i), -1, pProgress); |
|
|
} |
|
|
else |
|
|
{ |
|
|
AddInstrumentsFromFile(DbDir, FsDir + fileList->at(i), -1, pProgress); |
|
|
} |
|
747 |
} |
} |
748 |
} catch(Exception e) { |
} catch(Exception e) { |
749 |
e.PrintMessage(); |
e.PrintMessage(); |
1253 |
dmsg(2,("InstrumentsDb: AddGigInstrument(DbDir=%s,DirId=%d,File=%s,Index=%d)\n", DbDir.c_str(), DirId, File.c_str(), Index)); |
dmsg(2,("InstrumentsDb: AddGigInstrument(DbDir=%s,DirId=%d,File=%s,Index=%d)\n", DbDir.c_str(), DirId, File.c_str(), Index)); |
1254 |
String name = pInstrument->pInfo->Name; |
String name = pInstrument->pInfo->Name; |
1255 |
if (name == "") return; |
if (name == "") return; |
1256 |
name = GetUniqueInstrumentName(DirId, name); |
name = GetUniqueName(DirId, name); |
1257 |
|
|
1258 |
std::stringstream sql2; |
std::stringstream sql2; |
1259 |
sql2 << "SELECT COUNT(*) FROM instruments WHERE instr_file=? AND "; |
sql2 << "SELECT COUNT(*) FROM instruments WHERE instr_file=? AND "; |
1727 |
if (File.empty()) throw Exception("Invalid file name: " + File); |
if (File.empty()) throw Exception("Invalid file name: " + File); |
1728 |
} |
} |
1729 |
|
|
1730 |
String InstrumentsDb::GetUniqueInstrumentName(int DirId, String Name) { |
String InstrumentsDb::GetUniqueName(int DirId, String Name) { |
1731 |
dmsg(2,("InstrumentsDb: GetUniqueInstrumentName(DirId=%d,Name=%s)\n", DirId, Name.c_str())); |
dmsg(2,("InstrumentsDb: GetUniqueInstrumentName(DirId=%d,Name=%s)\n", DirId, Name.c_str())); |
1732 |
|
|
1733 |
if (GetInstrumentId(DirId, Name) == -1 && GetDirectoryId(DirId, Name) == -1) return Name; |
if (GetInstrumentId(DirId, Name) == -1 && GetDirectoryId(DirId, Name) == -1) return Name; |
1742 |
|
|
1743 |
throw Exception("Unable to find an unique name: " + Name); |
throw Exception("Unable to find an unique name: " + Name); |
1744 |
} |
} |
1745 |
|
|
1746 |
|
String InstrumentsDb::PrepareSubdirectory(String DbDir, String FsPath) { |
1747 |
|
std::string dir = Path::getBaseName(FsPath); |
1748 |
|
dir = toAbstractName(dir); |
1749 |
|
if(dir.empty()) dir = "New Directory"; |
1750 |
|
dir = GetUniqueName(GetDirectoryId(DbDir), dir); |
1751 |
|
dir = AppendNode(DbDir, dir); |
1752 |
|
AddDirectory(dir); |
1753 |
|
return dir; |
1754 |
|
} |
1755 |
|
|
1756 |
|
String InstrumentsDb::AppendNode(String DbDir, String Node) { |
1757 |
|
if(DbDir.length() == 1 && DbDir.at(0) == '/') return DbDir + Node + "/"; |
1758 |
|
return DbDir + "/" + Node + "/"; |
1759 |
|
} |
1760 |
|
|
1761 |
String InstrumentsDb::toDbName(String AbstractName) { |
String InstrumentsDb::toDbName(String AbstractName) { |
1762 |
for (int i = 0; i < AbstractName.length(); i++) { |
for (int i = 0; i < AbstractName.length(); i++) { |