MCPcopy Create free account
hub / github.com/TypesettingTools/Aegisub / OnInit

Method OnInit

src/main.cpp:109–316  ·  view source on GitHub ↗

@brief Gets called when application starts. @return bool

Source from the content-addressed store, hash-verified

107/// @brief Gets called when application starts.
108/// @return bool
109bool 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);

Callers

nothing calls this directly

Calls 15

InitLocaleFunction · 0.85
InitFunction · 0.85
OpenFunction · 0.85
CleanCacheFunction · 0.85
init_builtin_commandsFunction · 0.85
initFunction · 0.85
GetSVNRevisionFunction · 0.85
CacheFontsFunction · 0.85
PerformVersionCheckFunction · 0.85
BindMethod · 0.80
DecodeMethod · 0.80
SetTokenMethod · 0.80

Tested by

no test coverage detected