Bump version to 6.0-36
[LibreOffice.git] / desktop / source / app / sofficemain.cxx
blob67c1efe4a799653d0b3fb2ec90fc1365b406178d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
21 #include <config_features.h>
22 #include <config_version.h>
23 #include <config_folders.h>
25 #include <desktop/dllapi.h>
27 #include <app.hxx>
28 #include "cmdlineargs.hxx"
29 #include "cmdlinehelp.hxx"
31 #include <desktop/exithelper.h>
32 #include <osl/file.hxx>
33 #include <rtl/bootstrap.hxx>
34 #include <sal/log.hxx>
35 #include <tools/extendapplicationenvironment.hxx>
36 #include <vcl/svmain.hxx>
38 #include <com/sun/star/beans/NamedValue.hpp>
39 #include <comphelper/storagehelper.hxx>
40 #include <cppuhelper/bootstrap.hxx>
41 #include <unotools/mediadescriptor.hxx>
43 #if HAVE_FEATURE_BREAKPAD
44 #include <fstream>
45 #include <desktop/crashreport.hxx>
47 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
48 #include <client/linux/handler/exception_handler.h>
49 #elif defined WNT
50 #if defined __clang__
51 #pragma clang diagnostic push
52 #pragma clang diagnostic ignored "-Wmicrosoft-enum-value"
53 #endif
54 #include <client/windows/handler/exception_handler.h>
55 #if defined __clang__
56 #pragma clang diagnostic pop
57 #endif
58 #include <locale>
59 #include <codecvt>
60 #endif
62 #endif
65 #ifdef ANDROID
66 # include <jni.h>
67 # include <android/log.h>
68 # include <salhelper/thread.hxx>
70 # define LOGTAG "LibreOffice/sofficemain"
71 # define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOGTAG, __VA_ARGS__))
72 #endif
74 #if HAVE_FEATURE_BREAKPAD
76 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
77 static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void* /*context*/, bool succeeded)
79 std::string ini_path = CrashReporter::getIniFileName();
80 std::ofstream minidump_file(ini_path, std::ios_base::app);
81 minidump_file << "DumpFile=" << descriptor.path() << "\n";
82 minidump_file.close();
83 SAL_WARN("desktop", "minidump generated: " << descriptor.path());
84 return succeeded;
86 #elif defined WNT
87 static bool dumpCallback(const wchar_t* path, const wchar_t* id,
88 void* /*context*/, EXCEPTION_POINTERS* /*exinfo*/,
89 MDRawAssertionInfo* /*assertion*/,
90 bool succeeded)
92 std::string ini_path = CrashReporter::getIniFileName();
93 std::ofstream minidump_file(ini_path, std::ios_base::app);
94 // TODO: moggi: can we avoid this conversion
95 std::wstring_convert<std::codecvt_utf8<wchar_t>> conv1;
96 std::string aPath = conv1.to_bytes(std::wstring(path)) + conv1.to_bytes(std::wstring(id)) + ".dmp";
97 minidump_file << "DumpFile=" << aPath << "\n";
98 minidump_file << "GDIHandles=" << ::GetGuiResources (::GetCurrentProcess(), GR_GDIOBJECTS) << "\n";
99 minidump_file.close();
100 SAL_WARN("desktop", "minidump generated: " << aPath);
101 return succeeded;
103 #endif
105 #endif
106 extern "C" int DESKTOP_DLLPUBLIC soffice_main()
108 #if HAVE_FEATURE_BREAKPAD
110 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
111 google_breakpad::MinidumpDescriptor descriptor("/tmp");
112 google_breakpad::ExceptionHandler eh(descriptor, nullptr, dumpCallback, nullptr, true, -1);
114 CrashReporter::storeExceptionHandler(&eh);
115 #elif defined WNT
116 google_breakpad::ExceptionHandler eh(L".", nullptr, dumpCallback, nullptr, google_breakpad::ExceptionHandler::HANDLER_ALL);
118 CrashReporter::storeExceptionHandler(&eh);
119 #endif
120 #endif
122 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID && !defined(LIBO_HEADLESS) && HAVE_FEATURE_OPENGL
123 /* Run test for OpenGL support in own process to avoid crash with broken
124 * OpenGL drivers. Start process as early as possible.
125 * In non-headless mode, the process will be reaped in X11OpenGLDeviceInfo::GetData
126 * (vcl/opengl/x11/X11DeviceInfo.cxx). In headless mode, the process will be reaped late in
127 * Desktop::Main (desktop/source/app/app.cxx), in a code block that needs to be covered by the
128 * same #if condition as this code block.
130 bool bSuccess = fire_glxtest_process();
131 SAL_WARN_IF(!bSuccess, "desktop.opengl", "problems with glxtest");
132 #endif
134 #if defined ANDROID
135 try {
136 rtl::Bootstrap::setIniFilename("file:///assets/program/lofficerc");
137 #endif
138 tools::extendApplicationEnvironment();
140 desktop::Desktop aDesktop;
141 // This string is used during initialization of the Gtk+ VCL module
142 Application::SetAppName( "soffice" );
143 #ifdef UNX
144 // handle --version and --help already here, otherwise they would be handled
145 // after VCL initialization that might fail if $DISPLAY is not set
146 const desktop::CommandLineArgs& rCmdLineArgs = desktop::Desktop::GetCommandLineArgs();
147 const OUString& aUnknown( rCmdLineArgs.GetUnknown() );
148 if ( !aUnknown.isEmpty() )
150 desktop::Desktop::InitApplicationServiceManager();
151 desktop::displayCmdlineHelp( aUnknown );
152 return EXIT_FAILURE;
154 if ( rCmdLineArgs.IsHelp() )
156 desktop::Desktop::InitApplicationServiceManager();
157 desktop::displayCmdlineHelp( OUString() );
158 return EXIT_SUCCESS;
160 if ( rCmdLineArgs.IsVersion() )
162 desktop::Desktop::InitApplicationServiceManager();
163 desktop::displayVersion();
164 return EXIT_SUCCESS;
166 #endif
167 return SVMain();
168 #if defined ANDROID
169 } catch (const css::uno::Exception &e) {
170 LOGI("Unhandled UNO exception: '%s'",
171 OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
172 throw; // to get exception type printed
174 #endif
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */