From ce97d995b4ef3ee955c7997f1f86fe9e52bf4d23 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 2 Aug 2010 08:18:53 +0000 Subject: [PATCH] Also remove timecodes and keyframes from the MRU lists when they cannot be found. Updates #717. Originally committed to SVN as r4721. --- aegisub/src/keyframe.cpp | 32 +++++++++++--------------------- aegisub/src/video_context.cpp | 19 ++++++++++++++++--- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/aegisub/src/keyframe.cpp b/aegisub/src/keyframe.cpp index b26898cfd..c2a3d6268 100644 --- a/aegisub/src/keyframe.cpp +++ b/aegisub/src/keyframe.cpp @@ -48,29 +48,19 @@ #include "video_context.h" std::vector KeyFrameFile::Load(wxString filename) { - try { - std::vector keyFrames; - TextFileReader file(filename,_T("ASCII")); + std::vector keyFrames; + TextFileReader file(filename,_T("ASCII")); - wxString cur = file.ReadLineFromFile(); - // Detect type (Only Xvid, DivX, x264 and Aegisub's keyframe files are currently supported) - if (cur == _T("# keyframe format v1")) { OpenAegiKeyFrames(file, keyFrames); } - else if (cur.StartsWith(_T("# XviD 2pass stat file"))) { OpenXviDKeyFrames(file, keyFrames); } - else if (cur.StartsWith(_T("##map version"))) { OpenDivXKeyFrames(file, keyFrames); } - else if (cur.StartsWith(_T("#options:"))) { Openx264KeyFrames(file, keyFrames); } - else { throw(_T("Invalid or unsupported keyframes file.")); } + wxString cur = file.ReadLineFromFile(); + // Detect type (Only Xvid, DivX, x264 and Aegisub's keyframe files are currently supported) + if (cur == _T("# keyframe format v1")) { OpenAegiKeyFrames(file, keyFrames); } + else if (cur.StartsWith(_T("# XviD 2pass stat file"))) { OpenXviDKeyFrames(file, keyFrames); } + else if (cur.StartsWith(_T("##map version"))) { OpenDivXKeyFrames(file, keyFrames); } + else if (cur.StartsWith(_T("#options:"))) { Openx264KeyFrames(file, keyFrames); } + else { throw(_T("Invalid or unsupported keyframes file.")); } - config::mru->Add("Keyframes", STD_STR(filename)); - return keyFrames; - } - // Fail - catch (const wchar_t *error) { - wxMessageBox(error, _T("Error opening keyframes file"), wxOK | wxICON_ERROR, NULL); - } - catch (...) { - wxMessageBox(_T("Unknown error"), _T("Error opening keyframes file"), wxOK | wxICON_ERROR, NULL); - } - return std::vector(); + config::mru->Add("Keyframes", STD_STR(filename)); + return keyFrames; } void KeyFrameFile::Save(wxString filename, std::vector const& keyFrames) { diff --git a/aegisub/src/video_context.cpp b/aegisub/src/video_context.cpp index 5c340c606..230259bf1 100644 --- a/aegisub/src/video_context.cpp +++ b/aegisub/src/video_context.cpp @@ -471,9 +471,21 @@ void VideoContext::SetAspectRatio(int type, double value) { void VideoContext::LoadKeyframes(wxString filename) { if (filename == keyFramesFilename || filename.empty()) return; - keyFrames = KeyFrameFile::Load(filename); - keyFramesFilename = filename; - Refresh(); + try { + keyFrames = KeyFrameFile::Load(filename); + keyFramesFilename = filename; + Refresh(); + } + catch (const wchar_t *error) { + wxMessageBox(error, _T("Error opening keyframes file"), wxOK | wxICON_ERROR, NULL); + } + catch (agi::acs::AcsNotFound const&) { + wxLogError(L"Could not open file " + filename); + config::mru->Remove("Keyframes", STD_STR(filename)); + } + catch (...) { + wxMessageBox(_T("Unknown error"), _T("Error opening keyframes file"), wxOK | wxICON_ERROR, NULL); + } } void VideoContext::SaveKeyframes(wxString filename) { @@ -501,6 +513,7 @@ void VideoContext::LoadTimecodes(wxString filename) { } catch (const agi::acs::AcsError&) { wxLogError(L"Could not open file " + filename); + config::mru->Remove("Timecodes", STD_STR(filename)); } catch (const agi::vfr::Error& e) { wxLogError(L"Timecode file parse error: %s", e.GetMessage().c_str());