173 |
throw e; |
throw e; |
174 |
} |
} |
175 |
EndTransaction(); |
EndTransaction(); |
176 |
if (i == -1) throw Exception("Unkown DB directory: " + Dir); |
if (i == -1) throw Exception("Unkown DB directory: " + toEscapedPath(Dir)); |
177 |
|
|
178 |
return i; |
return i; |
179 |
} |
} |
192 |
BeginTransaction(); |
BeginTransaction(); |
193 |
try { |
try { |
194 |
int dirId = GetDirectoryId(Dir); |
int dirId = GetDirectoryId(Dir); |
195 |
if(dirId == -1) throw Exception("Unknown DB directory: " + Dir); |
if(dirId == -1) throw Exception("Unknown DB directory: " + toEscapedPath(Dir)); |
196 |
|
|
197 |
StringListPtr pDirs; |
StringListPtr pDirs; |
198 |
if (Recursive) { |
if (Recursive) { |
215 |
std::stringstream sql; |
std::stringstream sql; |
216 |
sql << "SELECT dir_name FROM instr_dirs "; |
sql << "SELECT dir_name FROM instr_dirs "; |
217 |
sql << "WHERE parent_dir_id=" << DirId << " AND dir_id!=0"; |
sql << "WHERE parent_dir_id=" << DirId << " AND dir_id!=0"; |
218 |
return ExecSqlStringList(sql.str()); |
StringListPtr dirs = ExecSqlStringList(sql.str()); |
219 |
|
|
220 |
|
for (int i = 0; i < dirs->size(); i++) { |
221 |
|
for (int j = 0; j < dirs->at(i).length(); j++) { |
222 |
|
if (dirs->at(i).at(j) == '/') dirs->at(i).at(j) = '\0'; |
223 |
|
} |
224 |
|
} |
225 |
|
|
226 |
|
return dirs; |
227 |
} |
} |
228 |
|
|
229 |
int InstrumentsDb::GetDirectoryId(String Dir) { |
int InstrumentsDb::GetDirectoryId(String Dir) { |
252 |
|
|
253 |
int InstrumentsDb::GetDirectoryId(int ParentDirId, String DirName) { |
int InstrumentsDb::GetDirectoryId(int ParentDirId, String DirName) { |
254 |
dmsg(2,("InstrumentsDb: GetDirectoryId(ParentDirId=%d, DirName=%s)\n", ParentDirId, DirName.c_str())); |
dmsg(2,("InstrumentsDb: GetDirectoryId(ParentDirId=%d, DirName=%s)\n", ParentDirId, DirName.c_str())); |
255 |
|
DirName = toDbName(DirName); |
256 |
std::stringstream sql; |
std::stringstream sql; |
257 |
sql << "SELECT dir_id FROM instr_dirs WHERE parent_dir_id="; |
sql << "SELECT dir_id FROM instr_dirs WHERE parent_dir_id="; |
258 |
sql << ParentDirId << " AND dir_name=?"; |
sql << ParentDirId << " AND dir_name=?"; |
305 |
|
|
306 |
String dirName = GetFileName(Dir); |
String dirName = GetFileName(Dir); |
307 |
if(ParentDir.empty() || dirName.empty()) { |
if(ParentDir.empty() || dirName.empty()) { |
308 |
throw Exception("Failed to add DB directory: " + Dir); |
throw Exception("Failed to add DB directory: " + toEscapedPath(Dir)); |
309 |
} |
} |
310 |
|
|
311 |
int id = GetDirectoryId(ParentDir); |
int id = GetDirectoryId(ParentDir); |
312 |
if (id == -1) throw Exception("DB directory doesn't exist: " + ParentDir); |
if (id == -1) throw Exception("DB directory doesn't exist: " + toEscapedPath(ParentDir)); |
313 |
int id2 = GetDirectoryId(id, dirName); |
int id2 = GetDirectoryId(id, dirName); |
314 |
if (id2 != -1) throw Exception("DB directory already exist: " + Dir); |
if (id2 != -1) throw Exception("DB directory already exist: " + toEscapedPath(Dir)); |
315 |
id2 = GetInstrumentId(id, dirName); |
id2 = GetInstrumentId(id, dirName); |
316 |
if (id2 != -1) throw Exception("Instrument with that name exist: " + Dir); |
if (id2 != -1) throw Exception("Instrument with that name exist: " + toEscapedPath(Dir)); |
317 |
|
|
318 |
std::stringstream sql; |
std::stringstream sql; |
319 |
sql << "INSERT INTO instr_dirs (parent_dir_id, dir_name) VALUES ("; |
sql << "INSERT INTO instr_dirs (parent_dir_id, dir_name) VALUES ("; |
320 |
sql << id << ", ?)"; |
sql << id << ", ?)"; |
321 |
|
|
322 |
ExecSql(sql.str(), dirName); |
ExecSql(sql.str(), toDbName(dirName)); |
323 |
} catch (Exception e) { |
} catch (Exception e) { |
324 |
EndTransaction(); |
EndTransaction(); |
325 |
throw e; |
throw e; |
338 |
BeginTransaction(); |
BeginTransaction(); |
339 |
try { |
try { |
340 |
int dirId = GetDirectoryId(Dir); |
int dirId = GetDirectoryId(Dir); |
341 |
if (dirId == -1) throw Exception("Unknown DB directory: " + Dir); |
if (dirId == -1) throw Exception("Unknown DB directory: " + toEscapedPath(Dir)); |
342 |
if (dirId == 0) throw Exception("Cannot delete the root directory: " + Dir); |
if (dirId == 0) throw Exception("Cannot delete the root directory: " + Dir); |
343 |
if(ParentDir.empty()) throw Exception("Unknown parent directory"); |
if(ParentDir.empty()) throw Exception("Unknown parent directory"); |
344 |
if (Force) RemoveDirectoryContent(dirId); |
if (Force) RemoveDirectoryContent(dirId); |
425 |
|
|
426 |
try { |
try { |
427 |
int id = GetDirectoryId(Dir); |
int id = GetDirectoryId(Dir); |
428 |
if(id == -1) throw Exception("Unknown DB directory: " + Dir); |
if(id == -1) throw Exception("Unknown DB directory: " + toEscapedPath(Dir)); |
429 |
|
|
430 |
sqlite3_stmt *pStmt = NULL; |
sqlite3_stmt *pStmt = NULL; |
431 |
std::stringstream sql; |
std::stringstream sql; |
448 |
if (res != SQLITE_DONE) { |
if (res != SQLITE_DONE) { |
449 |
throw Exception("DB error: " + ToString(sqlite3_errmsg(db))); |
throw Exception("DB error: " + ToString(sqlite3_errmsg(db))); |
450 |
} else { |
} else { |
451 |
throw Exception("Unknown DB directory: " + Dir); |
throw Exception("Unknown DB directory: " + toEscapedPath(Dir)); |
452 |
} |
} |
453 |
} |
} |
454 |
|
|
465 |
void InstrumentsDb::RenameDirectory(String Dir, String Name) { |
void InstrumentsDb::RenameDirectory(String Dir, String Name) { |
466 |
dmsg(2,("InstrumentsDb: RenameDirectory(Dir=%s,Name=%s)\n", Dir.c_str(), Name.c_str())); |
dmsg(2,("InstrumentsDb: RenameDirectory(Dir=%s,Name=%s)\n", Dir.c_str(), Name.c_str())); |
467 |
CheckFileName(Name); |
CheckFileName(Name); |
468 |
|
String dbName = toDbName(Name); |
469 |
|
|
470 |
BeginTransaction(); |
BeginTransaction(); |
471 |
try { |
try { |
472 |
int dirId = GetDirectoryId(Dir); |
int dirId = GetDirectoryId(Dir); |
473 |
if (dirId == -1) throw Exception("Unknown DB directory: " + Dir); |
if (dirId == -1) throw Exception("Unknown DB directory: " + toEscapedText(Dir)); |
474 |
|
|
475 |
std::stringstream sql; |
std::stringstream sql; |
476 |
sql << "SELECT parent_dir_id FROM instr_dirs WHERE dir_id=" << dirId; |
sql << "SELECT parent_dir_id FROM instr_dirs WHERE dir_id=" << dirId; |
477 |
|
|
478 |
int parent = ExecSqlInt(sql.str()); |
int parent = ExecSqlInt(sql.str()); |
479 |
if (parent == -1) throw Exception("Unknown parent directory: " + Dir); |
if (parent == -1) throw Exception("Unknown parent directory: " + toEscapedPath(Dir)); |
480 |
if (GetDirectoryId(parent, Name) != -1) { |
|
481 |
throw Exception("Cannot rename. Directory with that name already exists: " + Name); |
if (GetDirectoryId(parent, dbName) != -1) { |
482 |
|
String s = toEscapedPath(Name); |
483 |
|
throw Exception("Cannot rename. Directory with that name already exists: " + s); |
484 |
} |
} |
485 |
|
|
486 |
if (GetInstrumentId(parent, Name) != -1) { |
if (GetInstrumentId(parent, dbName) != -1) { |
487 |
throw Exception("Cannot rename. Instrument with that name exist: " + Dir); |
throw Exception("Cannot rename. Instrument with that name exist: " + toEscapedPath(Dir)); |
488 |
} |
} |
489 |
|
|
490 |
sql.str(""); |
sql.str(""); |
491 |
sql << "UPDATE instr_dirs SET dir_name=? WHERE dir_id=" << dirId; |
sql << "UPDATE instr_dirs SET dir_name=? WHERE dir_id=" << dirId; |
492 |
ExecSql(sql.str(), Name); |
ExecSql(sql.str(), dbName); |
493 |
} catch (Exception e) { |
} catch (Exception e) { |
494 |
EndTransaction(); |
EndTransaction(); |
495 |
throw e; |
throw e; |
509 |
BeginTransaction(); |
BeginTransaction(); |
510 |
try { |
try { |
511 |
int dirId = GetDirectoryId(Dir); |
int dirId = GetDirectoryId(Dir); |
512 |
if (dirId == -1) throw Exception("Unknown DB directory: " + Dir); |
if (dirId == -1) throw Exception("Unknown DB directory: " + toEscapedPath(Dir)); |
513 |
int dstId = GetDirectoryId(Dst); |
int dstId = GetDirectoryId(Dst); |
514 |
if (dstId == -1) throw Exception("Unknown DB directory: " + Dst); |
if (dstId == -1) throw Exception("Unknown DB directory: " + toEscapedPath(Dst)); |
515 |
if (dirId == dstId) { |
if (dirId == dstId) { |
516 |
throw Exception("Cannot move directory to itself"); |
throw Exception("Cannot move directory to itself"); |
517 |
} |
} |
527 |
String dirName = GetFileName(Dir); |
String dirName = GetFileName(Dir); |
528 |
|
|
529 |
int id2 = GetDirectoryId(dstId, dirName); |
int id2 = GetDirectoryId(dstId, dirName); |
530 |
if (id2 != -1) throw Exception("DB directory already exist: " + dirName); |
if (id2 != -1) throw Exception("DB directory already exist: " + toEscapedPath(dirName)); |
531 |
id2 = GetInstrumentId(dstId, dirName); |
id2 = GetInstrumentId(dstId, dirName); |
532 |
if (id2 != -1) throw Exception("Instrument with that name exist: " + dirName); |
if (id2 != -1) throw Exception("Instrument with that name exist: " + toEscapedPath(dirName)); |
533 |
|
|
534 |
std::stringstream sql; |
std::stringstream sql; |
535 |
sql << "UPDATE instr_dirs SET parent_dir_id=" << dstId; |
sql << "UPDATE instr_dirs SET parent_dir_id=" << dstId; |
555 |
BeginTransaction(); |
BeginTransaction(); |
556 |
try { |
try { |
557 |
int dirId = GetDirectoryId(Dir); |
int dirId = GetDirectoryId(Dir); |
558 |
if (dirId == -1) throw Exception("Unknown DB directory: " + Dir); |
if (dirId == -1) throw Exception("Unknown DB directory: " + toEscapedPath(Dir)); |
559 |
int dstId = GetDirectoryId(Dst); |
int dstId = GetDirectoryId(Dst); |
560 |
if (dstId == -1) throw Exception("Unknown DB directory: " + Dst); |
if (dstId == -1) throw Exception("Unknown DB directory: " + toEscapedPath(Dst)); |
561 |
if (dirId == dstId) { |
if (dirId == dstId) { |
562 |
throw Exception("Cannot copy directory to itself"); |
throw Exception("Cannot copy directory to itself"); |
563 |
} |
} |
573 |
String dirName = GetFileName(Dir); |
String dirName = GetFileName(Dir); |
574 |
|
|
575 |
int id2 = GetDirectoryId(dstId, dirName); |
int id2 = GetDirectoryId(dstId, dirName); |
576 |
if (id2 != -1) throw Exception("DB directory already exist: " + dirName); |
if (id2 != -1) throw Exception("DB directory already exist: " + toEscapedPath(dirName)); |
577 |
id2 = GetInstrumentId(dstId, dirName); |
id2 = GetInstrumentId(dstId, dirName); |
578 |
if (id2 != -1) throw Exception("Instrument with that name exist: " + dirName); |
if (id2 != -1) throw Exception("Instrument with that name exist: " + toEscapedPath(dirName)); |
579 |
|
|
580 |
DirectoryCopier directoryCopier(ParentDir, Dst); |
DirectoryCopier directoryCopier(ParentDir, Dst); |
581 |
DirectoryTreeWalk(Dir, &directoryCopier); |
DirectoryTreeWalk(Dir, &directoryCopier); |
593 |
BeginTransaction(); |
BeginTransaction(); |
594 |
try { |
try { |
595 |
int id = GetDirectoryId(Dir); |
int id = GetDirectoryId(Dir); |
596 |
if(id == -1) throw Exception("Unknown DB directory: " + Dir); |
if(id == -1) throw Exception("Unknown DB directory: " + toEscapedPath(Dir)); |
597 |
|
|
598 |
std::stringstream sql; |
std::stringstream sql; |
599 |
sql << "UPDATE instr_dirs SET description=?,modified=CURRENT_TIMESTAMP "; |
sql << "UPDATE instr_dirs SET description=?,modified=CURRENT_TIMESTAMP "; |
657 |
DbInstrumentsMutex.Lock(); |
DbInstrumentsMutex.Lock(); |
658 |
try { |
try { |
659 |
int dirId = GetDirectoryId(DbDir); |
int dirId = GetDirectoryId(DbDir); |
660 |
if (dirId == -1) throw Exception("Invalid DB directory: " + DbDir); |
if (dirId == -1) throw Exception("Invalid DB directory: " + toEscapedText(DbDir)); |
661 |
|
|
662 |
struct stat statBuf; |
struct stat statBuf; |
663 |
int res = stat(FilePath.c_str(), &statBuf); |
int res = stat(FilePath.c_str(), &statBuf); |
689 |
DbInstrumentsMutex.Lock(); |
DbInstrumentsMutex.Lock(); |
690 |
try { |
try { |
691 |
int dirId = GetDirectoryId(DbDir); |
int dirId = GetDirectoryId(DbDir); |
692 |
if (dirId == -1) throw Exception("Invalid DB directory: " + DbDir); |
if (dirId == -1) throw Exception("Invalid DB directory: " + toEscapedPath(DbDir)); |
693 |
|
|
694 |
struct stat statBuf; |
struct stat statBuf; |
695 |
int res = stat(FsDir.c_str(), &statBuf); |
int res = stat(FsDir.c_str(), &statBuf); |
778 |
} |
} |
779 |
EndTransaction(); |
EndTransaction(); |
780 |
|
|
781 |
if (i == -1) throw Exception("Unknown Db directory: " + Dir); |
if (i == -1) throw Exception("Unknown Db directory: " + toEscapedPath(Dir)); |
782 |
return i; |
return i; |
783 |
} |
} |
784 |
|
|
794 |
BeginTransaction(); |
BeginTransaction(); |
795 |
try { |
try { |
796 |
int dirId = GetDirectoryId(Dir); |
int dirId = GetDirectoryId(Dir); |
797 |
if(dirId == -1) throw Exception("Unknown DB directory: " + Dir); |
if(dirId == -1) throw Exception("Unknown DB directory: " + toEscapedPath(Dir)); |
798 |
|
|
799 |
StringListPtr pInstrs; |
StringListPtr pInstrs; |
800 |
|
|
832 |
std::stringstream sql; |
std::stringstream sql; |
833 |
sql << "SELECT instr_id FROM instruments WHERE dir_id="; |
sql << "SELECT instr_id FROM instruments WHERE dir_id="; |
834 |
sql << DirId << " AND instr_name=?"; |
sql << DirId << " AND instr_name=?"; |
835 |
return ExecSqlInt(sql.str(), InstrName); |
return ExecSqlInt(sql.str(), toDbName(InstrName)); |
836 |
} |
} |
837 |
|
|
838 |
String InstrumentsDb::GetInstrumentName(int InstrId) { |
String InstrumentsDb::GetInstrumentName(int InstrId) { |
839 |
dmsg(2,("InstrumentsDb: GetInstrumentName(InstrId=%d)\n", InstrId)); |
dmsg(2,("InstrumentsDb: GetInstrumentName(InstrId=%d)\n", InstrId)); |
840 |
std::stringstream sql; |
std::stringstream sql; |
841 |
sql << "SELECT instr_name FROM instruments WHERE instr_id=" << InstrId; |
sql << "SELECT instr_name FROM instruments WHERE instr_id=" << InstrId; |
842 |
return ExecSqlString(sql.str()); |
return toAbstractName(ExecSqlString(sql.str())); |
843 |
} |
} |
844 |
|
|
845 |
void InstrumentsDb::RemoveInstrument(String Instr) { |
void InstrumentsDb::RemoveInstrument(String Instr) { |
851 |
try { |
try { |
852 |
int instrId = GetInstrumentId(Instr); |
int instrId = GetInstrumentId(Instr); |
853 |
if(instrId == -1) { |
if(instrId == -1) { |
854 |
throw Exception("The specified instrument does not exist: " + Instr); |
throw Exception("The specified instrument does not exist: " + toEscapedPath(Instr)); |
855 |
} |
} |
856 |
RemoveInstrument(instrId); |
RemoveInstrument(instrId); |
857 |
} catch (Exception e) { |
} catch (Exception e) { |
886 |
BeginTransaction(); |
BeginTransaction(); |
887 |
try { |
try { |
888 |
int id = GetInstrumentId(Instr); |
int id = GetInstrumentId(Instr); |
889 |
if(id == -1) throw Exception("Unknown DB instrument: " + Instr); |
if(id == -1) throw Exception("Unknown DB instrument: " + toEscapedPath(Instr)); |
890 |
i = GetInstrumentInfo(id); |
i = GetInstrumentInfo(id); |
891 |
} catch (Exception e) { |
} catch (Exception e) { |
892 |
EndTransaction(); |
EndTransaction(); |
945 |
BeginTransaction(); |
BeginTransaction(); |
946 |
try { |
try { |
947 |
int dirId = GetDirectoryId(GetDirectoryPath(Instr)); |
int dirId = GetDirectoryId(GetDirectoryPath(Instr)); |
948 |
if (dirId == -1) throw Exception("Unknown DB instrument: " + Instr); |
if (dirId == -1) throw Exception("Unknown DB instrument: " + toEscapedPath(Instr)); |
949 |
|
|
950 |
int instrId = GetInstrumentId(dirId, GetFileName(Instr)); |
int instrId = GetInstrumentId(dirId, GetFileName(Instr)); |
951 |
if (instrId == -1) throw Exception("Unknown DB instrument: " + Instr); |
if (instrId == -1) throw Exception("Unknown DB instrument: " + toEscapedPath(Instr)); |
952 |
|
|
953 |
if (GetInstrumentId(dirId, Name) != -1) { |
if (GetInstrumentId(dirId, Name) != -1) { |
954 |
throw Exception("Cannot rename. Instrument with that name already exists: " + Name); |
String s = toEscapedPath(Name); |
955 |
|
throw Exception("Cannot rename. Instrument with that name already exists: " + s); |
956 |
} |
} |
957 |
|
|
958 |
if (GetDirectoryId(dirId, Name) != -1) { |
if (GetDirectoryId(dirId, Name) != -1) { |
959 |
throw Exception("Cannot rename. Directory with that name already exists: " + Name); |
String s = toEscapedPath(Name); |
960 |
|
throw Exception("Cannot rename. Directory with that name already exists: " + s); |
961 |
} |
} |
962 |
|
|
963 |
std::stringstream sql; |
std::stringstream sql; |
964 |
sql << "UPDATE instruments SET instr_name=? WHERE instr_id=" << instrId; |
sql << "UPDATE instruments SET instr_name=? WHERE instr_id=" << instrId; |
965 |
ExecSql(sql.str(), Name); |
ExecSql(sql.str(), toDbName(Name)); |
966 |
} catch (Exception e) { |
} catch (Exception e) { |
967 |
EndTransaction(); |
EndTransaction(); |
968 |
throw e; |
throw e; |
978 |
|
|
979 |
BeginTransaction(); |
BeginTransaction(); |
980 |
try { |
try { |
981 |
int dirId = GetDirectoryId(GetDirectoryPath(Instr)); |
int dirId = GetDirectoryId(ParentDir); |
982 |
if (dirId == -1) throw Exception("Unknown DB instrument: " + Instr); |
if (dirId == -1) throw Exception("Unknown DB instrument: " + toEscapedPath(Instr)); |
983 |
|
|
984 |
String instrName = GetFileName(Instr); |
String instrName = GetFileName(Instr); |
985 |
int instrId = GetInstrumentId(dirId, instrName); |
int instrId = GetInstrumentId(dirId, instrName); |
986 |
if (instrId == -1) throw Exception("Unknown DB instrument: " + Instr); |
if (instrId == -1) throw Exception("Unknown DB instrument: " + toEscapedPath(Instr)); |
987 |
|
|
988 |
int dstId = GetDirectoryId(Dst); |
int dstId = GetDirectoryId(Dst); |
989 |
if (dstId == -1) throw Exception("Unknown DB directory: " + Dst); |
if (dstId == -1) throw Exception("Unknown DB directory: " + toEscapedPath(Dst)); |
990 |
if (dirId == dstId) { |
if (dirId == dstId) { |
991 |
EndTransaction(); |
EndTransaction(); |
992 |
return; |
return; |
993 |
} |
} |
994 |
|
|
995 |
if (GetInstrumentId(dstId, instrName) != -1) { |
if (GetInstrumentId(dstId, instrName) != -1) { |
996 |
throw Exception("Cannot move. Instrument with that name already exists: " + instrName); |
String s = toEscapedPath(instrName); |
997 |
|
throw Exception("Cannot move. Instrument with that name already exists: " + s); |
998 |
} |
} |
999 |
|
|
1000 |
if (GetDirectoryId(dstId, instrName) != -1) { |
if (GetDirectoryId(dstId, instrName) != -1) { |
1001 |
throw Exception("Cannot move. Directory with that name already exists: " + instrName); |
String s = toEscapedPath(instrName); |
1002 |
|
throw Exception("Cannot move. Directory with that name already exists: " + s); |
1003 |
} |
} |
1004 |
|
|
1005 |
std::stringstream sql; |
std::stringstream sql; |
1023 |
BeginTransaction(); |
BeginTransaction(); |
1024 |
try { |
try { |
1025 |
int dirId = GetDirectoryId(GetDirectoryPath(Instr)); |
int dirId = GetDirectoryId(GetDirectoryPath(Instr)); |
1026 |
if (dirId == -1) throw Exception("Unknown DB instrument: " + Instr); |
if (dirId == -1) throw Exception("Unknown DB instrument: " + toEscapedPath(Instr)); |
1027 |
|
|
1028 |
String instrName = GetFileName(Instr); |
String instrName = GetFileName(Instr); |
1029 |
int instrId = GetInstrumentId(dirId, instrName); |
int instrId = GetInstrumentId(dirId, instrName); |
1030 |
if (instrId == -1) throw Exception("Unknown DB instrument: " + Instr); |
if (instrId == -1) throw Exception("Unknown DB instrument: " + toEscapedPath(Instr)); |
1031 |
|
|
1032 |
int dstId = GetDirectoryId(Dst); |
int dstId = GetDirectoryId(Dst); |
1033 |
if (dstId == -1) throw Exception("Unknown DB directory: " + Dst); |
if (dstId == -1) throw Exception("Unknown DB directory: " + toEscapedPath(Dst)); |
1034 |
if (dirId == dstId) { |
if (dirId == dstId) { |
1035 |
EndTransaction(); |
EndTransaction(); |
1036 |
return; |
return; |
1037 |
} |
} |
1038 |
|
|
1039 |
if (GetInstrumentId(dstId, instrName) != -1) { |
if (GetInstrumentId(dstId, instrName) != -1) { |
1040 |
throw Exception("Cannot copy. Instrument with that name already exists: " + instrName); |
String s = toEscapedPath(instrName); |
1041 |
|
throw Exception("Cannot copy. Instrument with that name already exists: " + s); |
1042 |
} |
} |
1043 |
|
|
1044 |
if (GetDirectoryId(dstId, instrName) != -1) { |
if (GetDirectoryId(dstId, instrName) != -1) { |
1045 |
throw Exception("Cannot copy. Directory with that name already exists: " + instrName); |
String s = toEscapedPath(instrName); |
1046 |
|
throw Exception("Cannot copy. Directory with that name already exists: " + s); |
1047 |
} |
} |
1048 |
|
|
1049 |
CopyInstrument(instrId, instrName, dstId, Dst); |
CopyInstrument(instrId, instrName, dstId, Dst); |
1069 |
throw Exception("DB error: " + ToString(sqlite3_errmsg(db))); |
throw Exception("DB error: " + ToString(sqlite3_errmsg(db))); |
1070 |
} |
} |
1071 |
|
|
1072 |
BindTextParam(pStmt, 1, InstrName); |
BindTextParam(pStmt, 1, toDbName(InstrName)); |
1073 |
BindTextParam(pStmt, 2, i.InstrFile); |
BindTextParam(pStmt, 2, i.InstrFile); |
1074 |
BindTextParam(pStmt, 3, i.FormatFamily); |
BindTextParam(pStmt, 3, i.FormatFamily); |
1075 |
BindTextParam(pStmt, 4, i.FormatVersion); |
BindTextParam(pStmt, 4, i.FormatVersion); |
1094 |
BeginTransaction(); |
BeginTransaction(); |
1095 |
try { |
try { |
1096 |
int id = GetInstrumentId(Instr); |
int id = GetInstrumentId(Instr); |
1097 |
if(id == -1) throw Exception("Unknown DB instrument: " + Instr); |
if(id == -1) throw Exception("Unknown DB instrument: " + toEscapedPath(Instr)); |
1098 |
|
|
1099 |
std::stringstream sql; |
std::stringstream sql; |
1100 |
sql << "UPDATE instruments SET description=?,modified=CURRENT_TIMESTAMP "; |
sql << "UPDATE instruments SET description=?,modified=CURRENT_TIMESTAMP "; |
1135 |
void InstrumentsDb::AddGigInstruments(String DbDir, String File, int Index, ScanProgress* pProgress) { |
void InstrumentsDb::AddGigInstruments(String DbDir, String File, int Index, ScanProgress* pProgress) { |
1136 |
dmsg(2,("InstrumentsDb: AddGigInstruments(DbDir=%s,File=%s,Index=%d)\n", DbDir.c_str(), File.c_str(), Index)); |
dmsg(2,("InstrumentsDb: AddGigInstruments(DbDir=%s,File=%s,Index=%d)\n", DbDir.c_str(), File.c_str(), Index)); |
1137 |
int dirId = GetDirectoryId(DbDir); |
int dirId = GetDirectoryId(DbDir); |
1138 |
if (dirId == -1) throw Exception("Invalid DB directory: " + DbDir); |
if (dirId == -1) throw Exception("Invalid DB directory: " + toEscapedPath(DbDir)); |
1139 |
|
|
1140 |
struct stat statBuf; |
struct stat statBuf; |
1141 |
int res = stat(File.c_str(), &statBuf); |
int res = stat(File.c_str(), &statBuf); |
1258 |
FireInstrumentCountChanged(DbDir); |
FireInstrumentCountChanged(DbDir); |
1259 |
} |
} |
1260 |
|
|
1261 |
void InstrumentsDb::DirectoryTreeWalk(String Path, DirectoryHandler* pHandler) { |
void InstrumentsDb::DirectoryTreeWalk(String AbstractPath, DirectoryHandler* pHandler) { |
1262 |
int DirId = GetDirectoryId(Path); |
int DirId = GetDirectoryId(AbstractPath); |
1263 |
if(DirId == -1) throw Exception("Unknown DB directory: " + Path); |
if(DirId == -1) throw Exception("Unknown DB directory: " + toEscapedPath(AbstractPath)); |
1264 |
DirectoryTreeWalk(pHandler, Path, DirId, 0); |
DirectoryTreeWalk(pHandler, AbstractPath, DirId, 0); |
1265 |
} |
} |
1266 |
|
|
1267 |
void InstrumentsDb::DirectoryTreeWalk(DirectoryHandler* pHandler, String Path, int DirId, int Level) { |
void InstrumentsDb::DirectoryTreeWalk(DirectoryHandler* pHandler, String AbstractPath, int DirId, int Level) { |
1268 |
if(Level == 1000) throw Exception("Possible infinite loop detected"); |
if(Level == 1000) throw Exception("Possible infinite loop detected"); |
1269 |
pHandler->ProcessDirectory(Path, DirId); |
pHandler->ProcessDirectory(AbstractPath, DirId); |
1270 |
|
|
1271 |
String s; |
String s; |
1272 |
StringListPtr pDirs = GetDirectories(DirId); |
StringListPtr pDirs = GetDirectories(DirId); |
1273 |
for(int i = 0; i < pDirs->size(); i++) { |
for(int i = 0; i < pDirs->size(); i++) { |
1274 |
if (Path.length() == 1 && Path.at(0) == '/') s = "/" + pDirs->at(i); |
if (AbstractPath.length() == 1 && AbstractPath.at(0) == '/') { |
1275 |
else s = Path + "/" + pDirs->at(i); |
s = "/" + pDirs->at(i); |
1276 |
|
} else { |
1277 |
|
s = AbstractPath + "/" + pDirs->at(i); |
1278 |
|
} |
1279 |
DirectoryTreeWalk(pHandler, s, GetDirectoryId(DirId, pDirs->at(i)), Level + 1); |
DirectoryTreeWalk(pHandler, s, GetDirectoryId(DirId, pDirs->at(i)), Level + 1); |
1280 |
} |
} |
1281 |
} |
} |
1287 |
BeginTransaction(); |
BeginTransaction(); |
1288 |
try { |
try { |
1289 |
int DirId = GetDirectoryId(Dir); |
int DirId = GetDirectoryId(Dir); |
1290 |
if(DirId == -1) throw Exception("Unknown DB directory: " + Dir); |
if(DirId == -1) throw Exception("Unknown DB directory: " + toEscapedPath(Dir)); |
1291 |
|
|
1292 |
if (Recursive) DirectoryTreeWalk(Dir, &directoryFinder); |
if (Recursive) DirectoryTreeWalk(Dir, &directoryFinder); |
1293 |
else directoryFinder.ProcessDirectory(Dir, DirId); |
else directoryFinder.ProcessDirectory(Dir, DirId); |
1307 |
BeginTransaction(); |
BeginTransaction(); |
1308 |
try { |
try { |
1309 |
int DirId = GetDirectoryId(Dir); |
int DirId = GetDirectoryId(Dir); |
1310 |
if(DirId == -1) throw Exception("Unknown DB directory: " + Dir); |
if(DirId == -1) throw Exception("Unknown DB directory: " + toEscapedPath(Dir)); |
1311 |
|
|
1312 |
if (Recursive) DirectoryTreeWalk(Dir, &instrumentFinder); |
if (Recursive) DirectoryTreeWalk(Dir, &instrumentFinder); |
1313 |
else instrumentFinder.ProcessDirectory(Dir, DirId); |
else instrumentFinder.ProcessDirectory(Dir, DirId); |
1611 |
|
|
1612 |
void InstrumentsDb::CheckFileName(String File) { |
void InstrumentsDb::CheckFileName(String File) { |
1613 |
if (File.empty()) throw Exception("Invalid file name: " + File); |
if (File.empty()) throw Exception("Invalid file name: " + File); |
|
if (File.find('/') != std::string::npos) { |
|
|
throw Exception("Invalid file name: " + File); |
|
|
} |
|
1614 |
} |
} |
1615 |
|
|
1616 |
String InstrumentsDb::GetUniqueInstrumentName(int DirId, String Name) { |
String InstrumentsDb::GetUniqueInstrumentName(int DirId, String Name) { |
1629 |
throw Exception("Unable to find an unique name: " + Name); |
throw Exception("Unable to find an unique name: " + Name); |
1630 |
} |
} |
1631 |
|
|
1632 |
|
String InstrumentsDb::toDbName(String AbstractName) { |
1633 |
|
for (int i = 0; i < AbstractName.length(); i++) { |
1634 |
|
if (AbstractName.at(i) == '\0') AbstractName.at(i) = '/'; |
1635 |
|
} |
1636 |
|
return AbstractName; |
1637 |
|
} |
1638 |
|
|
1639 |
|
String InstrumentsDb::toEscapedPath(String AbstractName) { |
1640 |
|
for (int i = 0; i < AbstractName.length(); i++) { |
1641 |
|
if (AbstractName.at(i) == '\0') AbstractName.replace(i++, 1, "\\/"); |
1642 |
|
else if (AbstractName.at(i) == '\\') AbstractName.replace(i++, 1, "\\\\"); |
1643 |
|
else if (AbstractName.at(i) == '\'') AbstractName.replace(i++, 1, "\\'"); |
1644 |
|
else if (AbstractName.at(i) == '"') AbstractName.replace(i++, 1, "\\\""); |
1645 |
|
else if (AbstractName.at(i) == '\r') AbstractName.replace(i++, 1, "\\r"); |
1646 |
|
else if (AbstractName.at(i) == '\n') AbstractName.replace(i++, 1, "\\n"); |
1647 |
|
} |
1648 |
|
return AbstractName; |
1649 |
|
} |
1650 |
|
|
1651 |
|
String InstrumentsDb::toEscapedText(String text) { |
1652 |
|
for (int i = 0; i < text.length(); i++) { |
1653 |
|
if (text.at(i) == '\\') text.replace(i++, 1, "\\\\"); |
1654 |
|
else if (text.at(i) == '\'') text.replace(i++, 1, "\\'"); |
1655 |
|
else if (text.at(i) == '"') text.replace(i++, 1, "\\\""); |
1656 |
|
else if (text.at(i) == '\r') text.replace(i++, 1, "\\r"); |
1657 |
|
else if (text.at(i) == '\n') text.replace(i++, 1, "\\n"); |
1658 |
|
} |
1659 |
|
return text; |
1660 |
|
} |
1661 |
|
|
1662 |
|
String InstrumentsDb::toEscapedName(String AbstractName) { |
1663 |
|
for (int i = 0; i < AbstractName.length(); i++) { |
1664 |
|
if (AbstractName.at(i) == '\0') AbstractName.at(i) = '/'; |
1665 |
|
else if (AbstractName.at(i) == '\\') AbstractName.replace(i++, 1, "\\\\"); |
1666 |
|
else if (AbstractName.at(i) == '\'') AbstractName.replace(i++, 1, "\\'"); |
1667 |
|
else if (AbstractName.at(i) == '"') AbstractName.replace(i++, 1, "\\\""); |
1668 |
|
else if (AbstractName.at(i) == '\r') AbstractName.replace(i++, 1, "\\r"); |
1669 |
|
else if (AbstractName.at(i) == '\n') AbstractName.replace(i++, 1, "\\n"); |
1670 |
|
} |
1671 |
|
return AbstractName; |
1672 |
|
} |
1673 |
|
|
1674 |
|
String InstrumentsDb::toAbstractName(String DbName) { |
1675 |
|
for (int i = 0; i < DbName.length(); i++) { |
1676 |
|
if (DbName.at(i) == '/') DbName.at(i) = '\0'; |
1677 |
|
} |
1678 |
|
return DbName; |
1679 |
|
} |
1680 |
|
|
1681 |
void InstrumentsDb::FireDirectoryCountChanged(String Dir) { |
void InstrumentsDb::FireDirectoryCountChanged(String Dir) { |
1682 |
for (int i = 0; i < llInstrumentsDbListeners.GetListenerCount(); i++) { |
for (int i = 0; i < llInstrumentsDbListeners.GetListenerCount(); i++) { |
1683 |
llInstrumentsDbListeners.GetListener(i)->DirectoryCountChanged(Dir); |
llInstrumentsDbListeners.GetListener(i)->DirectoryCountChanged(Dir); |