Bump version to 6.4-15
[LibreOffice.git] / desktop / win32 / source / loader.hxx
blobdfa8f0c971a0f22819169c1544fc32295c6b3421
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 #ifndef INCLUDED_DESKTOP_WIN32_SOURCE_LOADER_HXX
21 #define INCLUDED_DESKTOP_WIN32_SOURCE_LOADER_HXX
23 #include <cstddef>
24 #define WIN32_LEAN_AND_MEAN
25 #include <windows.h>
26 #include <string.h>
28 #define MY_LENGTH(s) (sizeof (s) / sizeof *(s) - 1)
29 #define MY_STRING(s) (s), MY_LENGTH(s)
31 namespace desktop_win32 {
33 inline WCHAR * commandLineAppend(
34 WCHAR * buffer, WCHAR const * text, std::size_t length)
36 wcsncpy(buffer, text, length + 1); // trailing null
37 return buffer + length;
40 inline WCHAR * commandLineAppend(WCHAR * buffer, WCHAR const * text) {
41 return commandLineAppend(buffer, text, wcslen(text));
44 inline WCHAR * commandLineAppendEncoded(WCHAR * buffer, WCHAR const * text) {
45 std::size_t n = 0;
46 for (;;) {
47 WCHAR c = *text++;
48 if (c == L'\0') {
49 break;
50 } else if (c == L'$') {
51 buffer = commandLineAppend(buffer, MY_STRING(L"\\$"));
52 n = 0;
53 } else if (c == L'\\') {
54 buffer = commandLineAppend(buffer, MY_STRING(L"\\\\"));
55 n += 2;
56 } else {
57 *buffer++ = c;
58 n = 0;
61 // The command line will continue with a double quote, so double any
62 // preceding backslashes as required by Windows:
63 for (std::size_t i = 0; i < n; ++i) {
64 *buffer++ = L'\\';
66 *buffer = L'\0';
67 return buffer;
70 // Set the PATH environment variable in the current (loader) process, so that a
71 // following CreateProcess has the necessary environment:
72 // @param binPath
73 // Must point to an array of size at least MAX_PATH. Is filled with the null
74 // terminated full path to the "bin" file corresponding to the current
75 // executable.
76 // @param iniDirectory
77 // Must point to an array of size at least MAX_PATH. Is filled with the null
78 // terminated full directory path (ending in "\") to the "ini" file
79 // corresponding to the current executable.
80 void extendLoaderEnvironment(WCHAR * binPath, WCHAR * iniDirectory);
82 // Implementation of the process guarding soffice.bin
83 int officeloader_impl(bool bAllowConsole);
87 #endif
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */