|
| 1 | +/**************************************************************************** |
| 2 | + * |
| 3 | + * (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org> |
| 4 | + * |
| 5 | + * QGroundControl is licensed according to the terms in the file |
| 6 | + * COPYING.md in the root of the source code directory. |
| 7 | + * |
| 8 | + ****************************************************************************/ |
| 9 | + |
1 | 10 | #include "Platform.h"
|
2 | 11 |
|
| 12 | +#include <QtCore/QCoreApplication> |
| 13 | + |
3 | 14 | #ifdef Q_OS_MAC
|
| 15 | + |
4 | 16 | #include <CoreFoundation/CoreFoundation.h>
|
5 | 17 |
|
6 | 18 | void Platform::disableAppNapViaInfoDict()
|
7 | 19 | {
|
8 | 20 | CFBundleRef bundle = CFBundleGetMainBundle();
|
9 |
| - if (!bundle) return; |
| 21 | + if (!bundle) { |
| 22 | + return; |
| 23 | + } |
10 | 24 |
|
11 |
| - // CFBundleGetInfoDictionary returns the dictionary the OS already |
12 |
| - // parsed from Info.plist. Cast it to mutable so we can tweak it. |
13 | 25 | CFMutableDictionaryRef infoDict = (CFMutableDictionaryRef) CFBundleGetInfoDictionary(bundle);
|
14 |
| - |
15 |
| - // Inject the key → true |
16 | 26 | if (infoDict) {
|
17 |
| - CFDictionarySetValue(infoDict, |
18 |
| - CFSTR("NSAppSleepDisabled"), |
19 |
| - kCFBooleanTrue); |
| 27 | + CFDictionarySetValue(infoDict, CFSTR("NSAppSleepDisabled"), kCFBooleanTrue); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +#elif defined(Q_OS_WIN) |
| 32 | + |
| 33 | +#include <qt_windows.h> |
| 34 | + |
| 35 | +#ifdef Q_CC_MSVC |
| 36 | +#include <crtdbg.h> |
| 37 | + |
| 38 | +static int __cdecl WindowsCrtReportHook(int reportType, char *message, int *returnValue) |
| 39 | +{ |
| 40 | + Q_UNUSED(message); |
| 41 | + |
| 42 | + // For asserts, suppress any interactive break/GUI. Keep process running. |
| 43 | + if (reportType == _CRT_ASSERT) { |
| 44 | + if (returnValue) { |
| 45 | + *returnValue = 0; // continue execution |
| 46 | + } |
| 47 | + return TRUE; // handled: no further CRT processing |
20 | 48 | }
|
| 49 | + |
| 50 | + // For warnings/errors, let CRT continue with our non-GUI report mode. |
| 51 | + return FALSE; |
21 | 52 | }
|
| 53 | + |
| 54 | +#endif |
| 55 | + |
| 56 | +static void WindowsInvalidParameterHandler(const wchar_t *expression, |
| 57 | + const wchar_t *function, |
| 58 | + const wchar_t *file, |
| 59 | + unsigned int line, |
| 60 | + uintptr_t pReserved) |
| 61 | +{ |
| 62 | + Q_UNUSED(expression); |
| 63 | + Q_UNUSED(function); |
| 64 | + Q_UNUSED(file); |
| 65 | + Q_UNUSED(line); |
| 66 | + Q_UNUSED(pReserved); |
| 67 | + // Do nothing |
| 68 | +} |
| 69 | + |
| 70 | +static void WindowsSigIntHandler() |
| 71 | +{ |
| 72 | + qDebug() << "Ctrl-C received."; |
| 73 | + QCoreApplication::quit(); |
| 74 | +} |
| 75 | + |
| 76 | +static BOOL WINAPI WindowsConsoleCtrlHandler(DWORD CEvent) |
| 77 | +{ |
| 78 | + switch (CEvent) { |
| 79 | + case CTRL_C_EVENT: |
| 80 | + WindowsSigIntHandler(); |
| 81 | + return TRUE; |
| 82 | + default: |
| 83 | + break; |
| 84 | + } |
| 85 | + |
| 86 | + return FALSE; |
| 87 | +} |
| 88 | + |
| 89 | +void Platform::setWindowsNativeFunctions(bool quietWindowsAsserts) |
| 90 | +{ |
| 91 | + if (quietWindowsAsserts) { |
| 92 | + (void) _set_invalid_parameter_handler(WindowsInvalidParameterHandler); |
| 93 | + (void) SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); |
| 94 | +#ifdef Q_CC_MSVC |
| 95 | + (void) _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG); |
| 96 | + (void) _CrtSetReportHook2(_CRT_RPTHOOK_INSTALL, WindowsCrtReportHook); |
| 97 | +#endif |
| 98 | + } |
| 99 | + |
| 100 | + (void) SetConsoleCtrlHandler((PHANDLER_ROUTINE) WindowsConsoleCtrlHandler, TRUE); |
| 101 | + |
| 102 | + // TODO: Consider SetUnhandledExceptionFilter(windowsFaultHandler), _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT), etc. |
| 103 | + // (void) _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); |
| 104 | + // (void) _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); |
| 105 | + // (void) _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); |
| 106 | + // (void) _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); |
| 107 | + // (void) _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG); |
| 108 | + // (void) _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); |
| 109 | + // (void) _CrtSetReportHook2(_CRT_RPTHOOK_REMOVE, WindowsCrtReportHook); |
| 110 | +} |
| 111 | + |
22 | 112 | #endif
|
0 commit comments