diff --git a/aegisub/src/ass_file.cpp b/aegisub/src/ass_file.cpp index ec0058bd2..148f76c2f 100644 --- a/aegisub/src/ass_file.cpp +++ b/aegisub/src/ass_file.cpp @@ -80,71 +80,54 @@ AssFile::~AssFile() { } /// @brief Load generic subs -void AssFile::Load (const wxString &_filename,wxString charset,bool addToRecent) { - bool ok = false; - Clear(); - +void AssFile::Load(const wxString &_filename,wxString charset,bool addToRecent) { try { - // Try to open file - FILE *file; -#ifdef WIN32 - file = _tfopen(_filename.c_str(), _T("r")); -#else - file = fopen(_filename.mb_str(*wxConvFileName), "r"); -#endif - if (!file) { - throw _T("Unable to open file \"") + _filename + _T("\". Check if it exists and if you have permissions to read it."); - } - fclose(file); - - // Find file encoding if (charset.empty()) { charset = CharSetDetect::GetEncoding(_filename); } - // Generic preparation - Clear(); - // Get proper format reader SubtitleFormat *reader = SubtitleFormat::GetReader(_filename); - // Read file - if (reader) { - AssFile temp; - reader->SetTarget(&temp); - reader->ReadFile(_filename,charset); - swap(temp); - ok = true; + if (!reader) { + wxMessageBox(L"Unknown file type","Error loading file",wxICON_ERROR | wxOK); + return; } - // Couldn't find a type - else throw _T("Unknown file type."); + // Read file + AssFile temp; + reader->SetTarget(&temp); + reader->ReadFile(_filename,charset); + swap(temp); + } + catch (agi::UserCancelException const&) { + return; } - catch (agi::UserCancelException const&) { } catch (const wchar_t *except) { wxMessageBox(except,_T("Error loading file"),wxICON_ERROR | wxOK); + return; } - catch (wxString except) { + catch (wxString &except) { wxMessageBox(except,_T("Error loading file"),wxICON_ERROR | wxOK); + return; } // Real exception catch (agi::Exception &e) { wxMessageBox(wxString(e.GetChainedMessage().c_str(), wxConvUTF8), L"Error loading file", wxICON_ERROR|wxOK); + return; } // Other error catch (...) { wxMessageBox(_T("Unknown error"),_T("Error loading file"),wxICON_ERROR | wxOK); + return; } - // Verify loading - if (ok) filename = _filename; - else LoadDefault(); - // Set general data loaded = true; + filename = _filename; // Add comments and set vars AddComment(_T("Script generated by Aegisub ") + GetAegisubLongVersionString()); @@ -152,11 +135,15 @@ void AssFile::Load (const wxString &_filename,wxString charset,bool addToRecent) SetScriptInfo(_T("ScriptType"),_T("v4.00+")); // Push the initial state of the file onto the undo stack - Commit("", commitId); - savedCommitId = commitId; + UndoStack.clear(); + RedoStack.clear(); + undoDescription.clear(); + commitId = -1; + savedCommitId = 0; + Commit(""); // Add to recent - if (addToRecent && ok) AddToRecent(_filename); + if (addToRecent) AddToRecent(_filename); } void AssFile::Save(wxString _filename,bool setfilename,bool addToRecent,const wxString encoding) { @@ -771,8 +758,8 @@ wxString AssFile::GetWildcardList(int mode) { int AssFile::Commit(wxString desc, int amendId) { ++commitId; // Allow coalescing only if it's the last change and the file has not been - // saved since the last change and the undo stack isn't empty - if (commitId == amendId+1 && RedoStack.empty() && savedCommitId != commitId && !UndoStack.empty()) { + // saved since the last change + if (commitId == amendId+1 && RedoStack.empty() && savedCommitId != commitId) { UndoStack.back() = *this; return commitId; }