@brief Gets called when application starts. @return bool
| 107 | /// @brief Gets called when application starts. |
| 108 | /// @return bool |
| 109 | bool AegisubApp::OnInit() { |
| 110 | // App name (yeah, this is a little weird to get rid of an odd warning) |
| 111 | #if defined(__WXMSW__) || defined(__WXMAC__) |
| 112 | SetAppName("Aegisub"); |
| 113 | #else |
| 114 | SetAppName("aegisub"); |
| 115 | #endif |
| 116 | |
| 117 | // The logger isn't created on demand on background threads, so force it to |
| 118 | // be created now |
| 119 | (void)wxLog::GetActiveTarget(); |
| 120 | |
| 121 | agi::util::InitLocale(); |
| 122 | |
| 123 | agi::dispatch::Init([](agi::dispatch::Thunk f) { |
| 124 | auto evt = new ValueEvent<agi::dispatch::Thunk>(EVT_CALL_THUNK, -1, std::move(f)); |
| 125 | wxTheApp->QueueEvent(evt); |
| 126 | }); |
| 127 | |
| 128 | wxTheApp->Bind(EVT_CALL_THUNK, [this](ValueEvent<agi::dispatch::Thunk>& evt) { |
| 129 | try { |
| 130 | evt.Get()(); |
| 131 | } |
| 132 | catch (...) { |
| 133 | OnExceptionInMainLoop(); |
| 134 | } |
| 135 | }); |
| 136 | |
| 137 | config::path = new agi::Path; |
| 138 | crash_writer::Initialize(config::path->Decode("?user")); |
| 139 | |
| 140 | agi::log::log = new agi::log::LogSink; |
| 141 | #ifdef _DEBUG |
| 142 | agi::log::log->Subscribe(std::make_unique<agi::log::EmitSTDOUT>()); |
| 143 | #endif |
| 144 | |
| 145 | // Set config file |
| 146 | StartupLog("Load local configuration"); |
| 147 | #ifdef __WXMSW__ |
| 148 | // Try loading configuration from the install dir if one exists there |
| 149 | try { |
| 150 | auto conf_local(config::path->Decode("?data/config.json")); |
| 151 | std::unique_ptr<std::istream> localConfig(agi::io::Open(conf_local)); |
| 152 | config::opt = new agi::Options(conf_local, GET_DEFAULT_CONFIG(default_config)); |
| 153 | |
| 154 | // Local config, make ?user mean ?data so all user settings are placed in install dir |
| 155 | config::path->SetToken("?user", config::path->Decode("?data")); |
| 156 | config::path->SetToken("?local", config::path->Decode("?data")); |
| 157 | crash_writer::Initialize(config::path->Decode("?user")); |
| 158 | } catch (agi::fs::FileSystemError const&) { |
| 159 | // File doesn't exist or we can't read it |
| 160 | // Might be worth displaying an error in the second case |
| 161 | } |
| 162 | #endif |
| 163 | |
| 164 | StartupLog("Create log writer"); |
| 165 | auto path_log = config::path->Decode("?user/log/"); |
| 166 | agi::fs::CreateDirectory(path_log); |
nothing calls this directly
no test coverage detected