Cut down on the ifdefs in main.cpp

Shuffle some stuff around to reduces the number of ifdefs and always
define MacOpenFile since there's no reason not to.
This commit is contained in:
Thomas Goyne 2013-01-06 17:33:18 -08:00
parent 9b24ab38a4
commit bd9a81372d
2 changed files with 54 additions and 62 deletions

View file

@ -80,9 +80,6 @@ namespace config {
agi::MRUManager *mru = 0;
}
///////////////////
// wxWidgets macro
IMPLEMENT_APP(AegisubApp)
static const char *LastStartupState = nullptr;
@ -119,6 +116,9 @@ void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName) {
}
__except (EXCEPTION_CONTINUE_EXECUTION) {}
}
#else
void SetThreadName(int dwThreadID, const char *szThreadName) {
}
#endif
void AegisubApp::OnAssertFailure(const wxChar *file, int line, const wxChar *func, const wxChar *cond, const wxChar *msg) {
@ -205,9 +205,7 @@ bool AegisubApp::OnInit() {
StartupLog("Load MRU");
config::mru = new agi::MRUManager(from_wx(StandardPaths::DecodePath("?user/mru.json")), GET_DEFAULT_CONFIG(default_mru), config::opt);
#ifdef __VISUALC__
SetThreadName((DWORD) -1,"AegiMain");
#endif
SetThreadName(-1, "AegiMain");
StartupLog("Inside OnInit");
frame = nullptr;
@ -315,6 +313,55 @@ int AegisubApp::OnExit() {
return wxApp::OnExit();
}
#if wxUSE_STACKWALKER == 1
class StackWalker: public wxStackWalker {
wxFile *crash_text; // FP to the crash text file.
public:
StackWalker(wxString cause);
~StackWalker();
void OnStackFrame(const wxStackFrame& frame);
};
/// @brief Called at the start of walking the stack.
/// @param cause cause of the crash.
///
StackWalker::StackWalker(wxString cause) {
crash_text = new wxFile(StandardPaths::DecodePath("?user/crashlog.txt"), wxFile::write_append);
if (crash_text->IsOpened()) {
wxDateTime time = wxDateTime::Now();
crash_text->Write(wxString::Format("--- %s ------------------\n", time.FormatISOCombined()));
crash_text->Write(wxString::Format("VER - %s\n", GetAegisubLongVersionString()));
crash_text->Write(wxString::Format("FTL - Beginning stack dump for \"%s\":\n", cause));
}
}
/// @brief Callback to format a single frame
/// @param frame frame to parse.
///
void StackWalker::OnStackFrame(const wxStackFrame &frame) {
if (crash_text->IsOpened()) {
wxString dst = wxString::Format("%03u - %p: ", (unsigned)frame.GetLevel(),frame.GetAddress()) + frame.GetName();
if (frame.HasSourceLocation())
dst = wxString::Format("%s on %s:%u", dst, frame.GetFileName(), (unsigned)frame.GetLine());
crash_text->Write(wxString::Format("%s\n", dst));
}
}
/// @brief Called at the end of walking the stack.
StackWalker::~StackWalker() {
if (crash_text->IsOpened()) {
crash_text->Write("End of stack dump.\n");
crash_text->Write("----------------------------------------\n\n");
crash_text->Close();
}
}
#endif
/// 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.");
@ -385,46 +432,6 @@ void AegisubApp::HandleEvent(wxEvtHandler *handler, wxEventFunction func, wxEven
#undef SHOW_EXCEPTION
}
#if wxUSE_STACKWALKER == 1
/// @brief Called at the start of walking the stack.
/// @param cause cause of the crash.
///
StackWalker::StackWalker(wxString cause) {
crash_text = new wxFile(StandardPaths::DecodePath("?user/crashlog.txt"), wxFile::write_append);
if (crash_text->IsOpened()) {
wxDateTime time = wxDateTime::Now();
crash_text->Write(wxString::Format("--- %s ------------------\n", time.FormatISOCombined()));
crash_text->Write(wxString::Format("VER - %s\n", GetAegisubLongVersionString()));
crash_text->Write(wxString::Format("FTL - Beginning stack dump for \"%s\":\n", cause));
}
}
/// @brief Callback to format a single frame
/// @param frame frame to parse.
///
void StackWalker::OnStackFrame(const wxStackFrame &frame) {
if (crash_text->IsOpened()) {
wxString dst = wxString::Format("%03u - %p: ", (unsigned)frame.GetLevel(),frame.GetAddress()) + frame.GetName();
if (frame.HasSourceLocation())
dst = wxString::Format("%s on %s:%u", dst, frame.GetFileName(), (unsigned)frame.GetLine());
crash_text->Write(wxString::Format("%s\n", dst));
}
}
/// @brief Called at the end of walking the stack.
StackWalker::~StackWalker() {
if (crash_text->IsOpened()) {
crash_text->Write("End of stack dump.\n");
crash_text->Write("----------------------------------------\n\n");
crash_text->Close();
}
}
#endif
int AegisubApp::OnRun() {
wxString error;
@ -463,7 +470,6 @@ int AegisubApp::OnRun() {
return 1;
}
#ifdef __WXMAC__
void AegisubApp::MacOpenFile(const wxString &filename) {
if (frame != nullptr && !filename.empty()) {
frame->LoadSubtitles(filename);
@ -471,4 +477,3 @@ void AegisubApp::MacOpenFile(const wxString &filename) {
OPT_SET("Path/Last/Subtitles")->SetString(from_wx(filepath.GetPath()));
}
}
#endif

View file

@ -93,21 +93,8 @@ public:
FrameMain *frame;
Automation4::AutoloadScriptManager *global_scripts;
#ifdef __WXMAC__
// Apple events
virtual void MacOpenFile(const wxString &filename);
#endif
void MacOpenFile(const wxString &filename);
};
wxDECLARE_APP(AegisubApp);
#if wxUSE_STACKWALKER == 1
class StackWalker: public wxStackWalker {
wxFile *crash_text; // FP to the crash text file.
public:
StackWalker(wxString cause);
~StackWalker();
void OnStackFrame(const wxStackFrame& frame);
};
#endif // wxUSE_STACKWALKER