1 |
/*************************************************************************** |
/*************************************************************************** |
2 |
* * |
* * |
3 |
* Copyright (C) 2007, 2008 Grigor Iliev * |
* Copyright (C) 2007-2009 Grigor Iliev * |
4 |
* * |
* * |
5 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
6 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
1177 |
throw Exception(ss.str()); |
throw Exception(ss.str()); |
1178 |
} |
} |
1179 |
|
|
1180 |
|
bool unlocked = false; |
1181 |
RIFF::File* riff = NULL; |
RIFF::File* riff = NULL; |
1182 |
gig::File* gig = NULL; |
gig::File* gig = NULL; |
1183 |
try { |
try { |
1206 |
|
|
1207 |
if (Index == -1) { |
if (Index == -1) { |
1208 |
int instrIndex = 0; |
int instrIndex = 0; |
1209 |
|
// Assume that it's locked and should be unlocked at this point |
1210 |
|
// to be able to use the database from another threads |
1211 |
|
if (!InTransaction) { |
1212 |
|
DbInstrumentsMutex.Unlock(); |
1213 |
|
unlocked = true; |
1214 |
|
} else { |
1215 |
|
std::cerr << "Shouldn't be in transaction when adding instruments." << std::endl; |
1216 |
|
} |
1217 |
|
|
1218 |
if (pProgress != NULL) gig->GetInstrument(0, &(pProgress->GigFileProgress)); // TODO: this workaround should be fixed |
if (pProgress != NULL) gig->GetInstrument(0, &(pProgress->GigFileProgress)); // TODO: this workaround should be fixed |
1219 |
gig::Instrument* pInstrument = gig->GetFirstInstrument(); |
gig::Instrument* pInstrument = gig->GetFirstInstrument(); |
1220 |
|
|
1221 |
|
if (!InTransaction) DbInstrumentsMutex.Lock(); |
1222 |
while (pInstrument) { |
while (pInstrument) { |
1223 |
BindTextParam(pStmt, 7, gig->pInfo->Product); |
BindTextParam(pStmt, 7, gig->pInfo->Product); |
1224 |
BindTextParam(pStmt, 8, gig->pInfo->Artists); |
BindTextParam(pStmt, 8, gig->pInfo->Artists); |
1246 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
1247 |
if (gig != NULL) delete gig; |
if (gig != NULL) delete gig; |
1248 |
if (riff != NULL) delete riff; |
if (riff != NULL) delete riff; |
1249 |
|
if (unlocked) DbInstrumentsMutex.Lock(); |
1250 |
std::stringstream ss; |
std::stringstream ss; |
1251 |
ss << "Failed to scan `" << FilePath << "`: " << e.Message; |
ss << "Failed to scan `" << FilePath << "`: " << e.Message; |
1252 |
|
|
1254 |
} catch (Exception e) { |
} catch (Exception e) { |
1255 |
if (gig != NULL) delete gig; |
if (gig != NULL) delete gig; |
1256 |
if (riff != NULL) delete riff; |
if (riff != NULL) delete riff; |
1257 |
|
if (unlocked) DbInstrumentsMutex.Lock(); |
1258 |
throw e; |
throw e; |
1259 |
} catch (...) { |
} catch (...) { |
1260 |
if (gig != NULL) delete gig; |
if (gig != NULL) delete gig; |
1261 |
if (riff != NULL) delete riff; |
if (riff != NULL) delete riff; |
1262 |
|
if (unlocked) DbInstrumentsMutex.Lock(); |
1263 |
throw Exception("Failed to scan `" + FilePath + "`"); |
throw Exception("Failed to scan `" + FilePath + "`"); |
1264 |
} |
} |
1265 |
} |
} |