Vastly simplify saving of backup .ass files when crashing.

* Remove "Autorecovery path" option, this should not be user configurable.
 * Crashes are now saved as recovered/YYYY-MM-DD-HHMMSS_<name>.ass (no pruning)

Originally committed to SVN as r3472.
This commit is contained in:
Amar Takhar 2009-09-03 05:27:11 +00:00
parent 01df6ba169
commit 78b0765608
3 changed files with 31 additions and 46 deletions

View file

@ -194,14 +194,6 @@ DialogOptions::DialogOptions(wxWindow *parent)
browse = new BrowseButton(filePage,-1,_T(""),BROWSE_FOLDER);
browse->Bind(edit);
fileSizer4->Add(browse,0,wxEXPAND);
fileSizer4->Add(new wxStaticText(filePage,-1,_("Crash recovery path:")),0,wxRIGHT | wxALIGN_CENTRE_VERTICAL,5);
edit = new wxTextCtrl(filePage,-1);
Bind(edit,_T("Auto recovery path"));
fileSizer4->Add(edit,1,wxEXPAND);
browse = new BrowseButton(filePage,-1,_T(""),BROWSE_FOLDER);
browse->Bind(edit);
fileSizer4->Add(browse,0,wxEXPAND);
fileSizer4->AddGrowableCol(1,1);
// Third static box

View file

@ -282,40 +282,36 @@ int AegisubApp::OnExit() {
/// Message displayed when an exception has occurred.
const static wxString exception_message = _("Oops, Aegisub has crashed!\n\nAn attempt has been made to save a copy of your file to:\n\n%s\n\nAegisub will now close.");
/// @brief Unhandled exception
///
/// @brief Called during an unhandled exception
void AegisubApp::OnUnhandledException() {
// Attempt to recover file
wxFileName origfile(AssFile::top->filename);
wxString path = Options.AsText(_T("Auto recovery path"));
if (path.IsEmpty()) path = StandardPaths::DecodePath(_T("?user/"));
wxFileName dstpath(path);
if (!dstpath.IsAbsolute()) path = StandardPaths::DecodePathMaybeRelative(path, _T("?user/"));
path += _T("/");
dstpath.Assign(path);
if (!dstpath.DirExists()) wxMkdir(path);
wxString filename = path + origfile.GetName() + _T(".RECOVER.ass");
// Current filename if any.
wxFileName file(AssFile::top->filename);
if (!file.HasName()) file.SetName(_T("untitled"));
// Set path and create if it doesn't exist.
file.SetPath(StandardPaths::DecodePath(_T("?user/recovered")));
if (!file.DirExists()) file.Mkdir();
// Save file
wxString filename = wxString::Format("%s/%s_%s.ass", file.GetPath(), wxDateTime::Now().Format("%Y-%m-%d-%H%M%S"), file.GetName());
AssFile::top->Save(filename,false,false);
// Inform user of crash
// Inform user of crash.
wxMessageBox(wxString::Format(exception_message, filename.c_str()), _("Program error"), wxOK | wxICON_ERROR, NULL);
}
/// @brief Fatal exception
///
/// @brief Called during a fatal exception.
void AegisubApp::OnFatalException() {
// Attempt to recover file
wxFileName origfile(AssFile::top->filename);
wxString path = Options.AsText(_T("Auto recovery path"));
if (path.IsEmpty()) path = StandardPaths::DecodePath(_T("?user/"));
wxFileName dstpath(path);
if (!dstpath.IsAbsolute()) path = StandardPaths::DecodePathMaybeRelative(path, _T("?user/"));
path += _T("/");
dstpath.Assign(path);
if (!dstpath.DirExists()) wxMkdir(path);
wxString filename = path + origfile.GetName() + _T(".RECOVER.ass");
// Current filename if any.
wxFileName file(AssFile::top->filename);
if (!file.HasName()) file.SetName(_T("untitled"));
// Set path and create if it doesn't exist.
file.SetPath(StandardPaths::DecodePath(_T("?user/recovered")));
if (!file.DirExists()) file.Mkdir();
// Save file
wxString filename = wxString::Format("%s/%s_%s.ass", file.GetPath(), wxDateTime::Now().Format("%Y-%m-%d-%H%M%S"), file.GetName());
AssFile::top->Save(filename,false,false);
#if wxUSE_STACKWALKER == 1
@ -323,18 +319,17 @@ void AegisubApp::OnFatalException() {
StackWalker walker(_T("Fatal exception"));
walker.WalkFromException();
#endif
// Inform user of crash
wxMessageBox(wxString::Format(exception_message, filename.c_str()), _("Program error"), wxOK | wxICON_ERROR, NULL);
wxMessageBox(wxString::Format(exception_message, filename.c_str()), _("Program error"), wxOK | wxICON_ERROR | wxSTAY_ON_TOP, NULL);
}
#endif
////////////////
// Stack walker
#if wxUSE_STACKWALKER == 1
#ifdef wxUSE_STACKWALKER
/// @brief DOCME
/// @param frame
/// @brief Callback to format a single frame
/// @param frame frame to parse.
///
void StackWalker::OnStackFrame(const wxStackFrame &frame) {
wxString dst = wxString::Format(_T("%03i - 0x%08X: "),frame.GetLevel(),frame.GetAddress()) + frame.GetName();
@ -346,8 +341,8 @@ void StackWalker::OnStackFrame(const wxStackFrame &frame) {
}
/// @brief DOCME
/// @param cause
/// @brief Called at the start of walking the stack.
/// @param cause cause of the crash.
///
StackWalker::StackWalker(wxString cause) {
file.open(wxString(StandardPaths::DecodePath(_T("?user/crashlog.txt"))).mb_str(),std::ios::out | std::ios::app);
@ -362,8 +357,7 @@ StackWalker::StackWalker(wxString cause) {
}
/// @brief DOCME
///
/// @brief Called at the end of walking the stack.
StackWalker::~StackWalker() {
if (file.is_open()) {
char dashes[1024];

View file

@ -116,7 +116,6 @@ void OptionsManager::LoadDefaults(bool onlyDefaults,bool doOverride) {
SetText(_T("Auto save path"),_T("?user/autosave"));
SetBool(_T("Auto backup"),true);
SetText(_T("Auto backup path"),_T("?user/autoback"));
SetText(_T("Auto recovery path"),_T("?user/recovered"));
SetInt(_T("Autoload linked files"),2);
SetText(_T("Text actor separator"),_T(":"));
SetText(_T("Text comment starter"),_T("#"));