| 201 | } |
| 202 | |
| 203 | Application::Application(int &argc, char **argv) : QApplication(argc, argv) |
| 204 | { |
| 205 | #if defined Q_OS_WIN32 |
| 206 | // attach the parent console |
| 207 | if(AttachConsole(ATTACH_PARENT_PROCESS)) |
| 208 | { |
| 209 | // if attach succeeds, reopen and sync all the i/o |
| 210 | if(freopen("CON", "w", stdout)) |
| 211 | { |
| 212 | std::cout.sync_with_stdio(); |
| 213 | } |
| 214 | if(freopen("CON", "w", stderr)) |
| 215 | { |
| 216 | std::cerr.sync_with_stdio(); |
| 217 | } |
| 218 | if(freopen("CON", "r", stdin)) |
| 219 | { |
| 220 | std::cin.sync_with_stdio(); |
| 221 | } |
| 222 | auto out = GetStdHandle (STD_OUTPUT_HANDLE); |
| 223 | DWORD written; |
| 224 | const char * endline = "\n"; |
| 225 | WriteConsole(out, endline, strlen(endline), &written, NULL); |
| 226 | consoleAttached = true; |
| 227 | } |
| 228 | #endif |
| 229 | setOrganizationName(BuildConfig.LAUNCHER_NAME); |
| 230 | setOrganizationDomain(BuildConfig.LAUNCHER_DOMAIN); |
| 231 | setApplicationName(BuildConfig.LAUNCHER_NAME); |
| 232 | setApplicationDisplayName(QString("%1 %2").arg(BuildConfig.LAUNCHER_DISPLAYNAME, BuildConfig.printableVersionString())); |
| 233 | setApplicationVersion(BuildConfig.printableVersionString()); |
| 234 | setDesktopFileName(BuildConfig.LAUNCHER_DESKTOPFILENAME); |
| 235 | startTime = QDateTime::currentDateTime(); |
| 236 | |
| 237 | // Don't quit on hiding the last window |
| 238 | this->setQuitOnLastWindowClosed(false); |
| 239 | |
| 240 | // Commandline parsing |
| 241 | QCommandLineParser parser; |
| 242 | parser.setApplicationDescription(BuildConfig.LAUNCHER_NAME); |
| 243 | |
| 244 | parser.addOptions({ |
| 245 | {{"d", "dir"}, "Use a custom path as application root (use '.' for current directory)", "directory"}, |
| 246 | {{"l", "launch"}, "Launch the specified instance (by instance ID)", "instance"}, |
| 247 | {{"s", "server"}, "Join the specified server on launch (only valid in combination with --launch)", "address"}, |
| 248 | {{"a", "profile"}, "Use the account specified by its profile name (only valid in combination with --launch)", "profile"}, |
| 249 | {"alive", "Write a small '" + liveCheckFile + "' file after the launcher starts"}, |
| 250 | {{"I", "import"}, "Import instance from specified zip (local path or URL)", "file"} |
| 251 | }); |
| 252 | parser.addHelpOption(); |
| 253 | parser.addVersionOption(); |
| 254 | |
| 255 | parser.process(arguments()); |
| 256 | |
| 257 | m_instanceIdToLaunch = parser.value("launch"); |
| 258 | m_serverToJoin = parser.value("server"); |
| 259 | m_profileToUse = parser.value("profile"); |
| 260 | m_liveCheck = parser.isSet("alive"); |
nothing calls this directly
no test coverage detected