1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
23 #define WIN32_LEAN_AND_MEAN
25 #pragma warning(push, 1)
38 #include <systools/win32/uwinapi.h>
40 #include <tools/pathutils.hxx>
41 #include "../loader.hxx"
45 static int GenericMain()
47 TCHAR szTargetFileName
[MAX_PATH
];
48 TCHAR szIniDirectory
[MAX_PATH
];
49 STARTUPINFO aStartupInfo
;
51 desktop_win32::getPaths(szTargetFileName
, szIniDirectory
);
53 ZeroMemory( &aStartupInfo
, sizeof(aStartupInfo
) );
54 aStartupInfo
.cb
= sizeof(aStartupInfo
);
56 GetStartupInfo( &aStartupInfo
);
58 DWORD dwExitCode
= (DWORD
)-1;
60 PROCESS_INFORMATION aProcessInfo
;
62 size_t iniDirLen
= wcslen(szIniDirectory
);
64 DWORD cwdLen
= GetCurrentDirectoryW(MAX_PATH
, cwd
);
65 if (cwdLen
>= MAX_PATH
) {
68 WCHAR redirect
[MAX_PATH
];
72 redirect
, szIniDirectory
, szIniDirectory
+ iniDirLen
,
73 MY_STRING(L
"redirect.ini")) != NULL
&&
74 (GetBinaryType(redirect
, &dummy
) || // cheaper check for file existence?
75 GetLastError() != ERROR_FILE_NOT_FOUND
);
76 LPTSTR cl1
= GetCommandLine();
77 WCHAR
* cl2
= new WCHAR
[
80 ? (MY_LENGTH(L
" \"-env:INIFILENAME=vnd.sun.star.pathname:") +
81 iniDirLen
+ MY_LENGTH(L
"redirect.ini\""))
83 MY_LENGTH(L
" \"-env:OOO_CWD=2") + 4 * cwdLen
+ MY_LENGTH(L
"\"") + 1];
84 // 4 * cwdLen: each char preceded by backslash, each trailing backslash
86 WCHAR
* p
= desktop_win32::commandLineAppend(cl2
, cl1
);
88 p
= desktop_win32::commandLineAppend(
89 p
, MY_STRING(L
" \"-env:INIFILENAME=vnd.sun.star.pathname:"));
90 p
= desktop_win32::commandLineAppend(p
, szIniDirectory
);
91 p
= desktop_win32::commandLineAppend(p
, MY_STRING(L
"redirect.ini\""));
93 p
= desktop_win32::commandLineAppend(p
, MY_STRING(L
" \"-env:OOO_CWD="));
95 p
= desktop_win32::commandLineAppend(p
, MY_STRING(L
"0"));
97 p
= desktop_win32::commandLineAppend(p
, MY_STRING(L
"2"));
98 p
= desktop_win32::commandLineAppendEncoded(p
, cwd
);
100 desktop_win32::commandLineAppend(p
, MY_STRING(L
"\""));
102 BOOL fSuccess
= CreateProcess(
122 // On Windows XP it seems as the desktop calls WaitForInputIdle after "OpenWidth" so we have to do so
123 // as if we where processing any messages
125 dwWaitResult
= MsgWaitForMultipleObjects( 1, &aProcessInfo
.hProcess
, FALSE
, INFINITE
, QS_ALLEVENTS
);
127 if ( WAIT_OBJECT_0
+ 1 == dwWaitResult
)
131 PeekMessage( &msg
, NULL
, 0, 0, PM_REMOVE
);
133 } while ( WAIT_OBJECT_0
+ 1 == dwWaitResult
);
136 GetExitCodeProcess( aProcessInfo
.hProcess
, &dwExitCode
);
138 CloseHandle( aProcessInfo
.hProcess
);
139 CloseHandle( aProcessInfo
.hThread
);
148 int WINAPI
WinMain( HINSTANCE
, HINSTANCE
, LPSTR
, int )
150 int WINAPI
_tWinMain( HINSTANCE
, HINSTANCE
, LPTSTR
, int )
153 return GenericMain();
164 return GenericMain();
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */