Fix crash when a subtitles file is not found

This commit is contained in:
Thomas Goyne 2013-11-09 15:56:09 -08:00
parent f0ff8c6179
commit 747e34b981

View file

@ -84,32 +84,32 @@ SubsController::SubsController(agi::Context *context)
void SubsController::Load(agi::fs::path const& filename, std::string charset) { void SubsController::Load(agi::fs::path const& filename, std::string charset) {
try { try {
if (charset.empty())
charset = CharSetDetect::GetEncoding(filename);
}
catch (agi::UserCancelException const&) {
return;
}
// Make sure that file isn't actually a timecode file
if (charset != "binary") {
try { try {
TextFileReader testSubs(filename, charset); if (charset.empty())
std::string cur = testSubs.ReadLineFromFile(); charset = CharSetDetect::GetEncoding(filename);
if (boost::starts_with(cur, "# timecode")) { }
context->videoController->LoadTimecodes(filename); catch (agi::UserCancelException const&) {
return; return;
}
// Make sure that file isn't actually a timecode file
if (charset != "binary") {
try {
TextFileReader testSubs(filename, charset);
std::string cur = testSubs.ReadLineFromFile();
if (boost::starts_with(cur, "# timecode")) {
context->videoController->LoadTimecodes(filename);
return;
}
}
catch (...) {
// if trying to load the file as timecodes fails it's fairly
// safe to assume that it is in fact not a timecode file
} }
} }
catch (...) {
// if trying to load the file as timecodes fails it's fairly
// safe to assume that it is in fact not a timecode file
}
}
const SubtitleFormat *reader = SubtitleFormat::GetReader(filename, charset); const SubtitleFormat *reader = SubtitleFormat::GetReader(filename, charset);
try {
AssFile temp; AssFile temp;
reader->ReadFile(&temp, filename, charset); reader->ReadFile(&temp, filename, charset);