1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: md5.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_desktop.hxx"
37 # define WIN32_LEAN_AND_MEAN
39 #pragma warning(push, 1)
42 # include <shellapi.h>
51 #include "sal/config.h"
52 #include "tools/pathutils.hxx"
54 const DWORD PE_Signature
= 0x00004550;
56 #define MY_LENGTH(s) (sizeof (s) / sizeof *(s) - 1)
57 #define MY_STRING(s) (s), MY_LENGTH(s)
58 #define MAX_STR_CAPTION 256
59 #define MAX_TEXT_LENGTH 1024
61 static void failPath(wchar_t* pszAppTitle
, wchar_t* pszMsg
)
63 MessageBoxW(NULL
, pszMsg
, pszAppTitle
, MB_OK
| MB_ICONERROR
);
64 TerminateProcess(GetCurrentProcess(), 255);
71 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
, NULL
,
72 GetLastError(), 0, reinterpret_cast< LPWSTR
>(&buf
), 0, NULL
);
73 MessageBoxW(NULL
, buf
, NULL
, MB_OK
| MB_ICONERROR
);
75 TerminateProcess(GetCurrentProcess(), 255);
78 static LPVOID
getVirtualBaseAddress( wchar_t* pszFilePath
)
82 LPVOID lpFileBase
= 0;
83 PIMAGE_DOS_HEADER lpDosHeader
;
84 PIMAGE_NT_HEADERS lpNTHeader
;
86 hFile
= CreateFile(pszFilePath
,
87 GENERIC_READ
, FILE_SHARE_READ
, NULL
,
88 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
,
91 if ( hFile
== INVALID_HANDLE_VALUE
)
96 hFileMapping
= CreateFileMapping(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
97 if ( hFileMapping
== 0 )
103 lpFileBase
= MapViewOfFile(hFileMapping
, FILE_MAP_READ
, 0, 0, 0);
104 if ( lpFileBase
== 0 )
106 CloseHandle(hFileMapping
);
111 lpDosHeader
= (PIMAGE_DOS_HEADER
)lpFileBase
;
112 if ( lpDosHeader
->e_magic
== IMAGE_DOS_SIGNATURE
)
114 lpNTHeader
= (PIMAGE_NT_HEADERS
)((char*)lpDosHeader
+ lpDosHeader
->e_lfanew
);
115 if (lpNTHeader
->Signature
== PE_Signature
)
116 lpFileBase
= reinterpret_cast<LPVOID
>( lpNTHeader
->OptionalHeader
.ImageBase
);
119 UnmapViewOfFile(lpFileBase
);
120 CloseHandle(hFileMapping
);
126 static bool checkImageVirtualBaseAddress(wchar_t* pszFilePath
, LPVOID lpVBA
)
128 LPVOID lpImageVBA
= getVirtualBaseAddress(pszFilePath
);
129 if ( lpImageVBA
== lpVBA
)
135 static wchar_t* getBrandPath(wchar_t * pszPath
)
137 DWORD n
= GetModuleFileNameW(NULL
, pszPath
, MAX_PATH
);
138 if (n
== 0 || n
>= MAX_PATH
) {
141 return tools::filename(pszPath
);
144 extern "C" int APIENTRY
WinMain( HINSTANCE hInst
, HINSTANCE
, LPSTR
, int )
146 wchar_t* pAppTitle
= new wchar_t[ MAX_STR_CAPTION
];
148 LoadString( hInst
, IDS_APP_TITLE
, pAppTitle
, MAX_STR_CAPTION
);
150 wchar_t* pTextServer
= new wchar_t[ MAX_TEXT_LENGTH
];
151 pTextServer
[0] = '\0';
152 LoadString( hInst
, IDS_MSG_OPTIMIZED_FOR_SERVER
, pTextServer
, MAX_TEXT_LENGTH
);
154 wchar_t* pTextClient
= new wchar_t[ MAX_TEXT_LENGTH
];
155 pTextClient
[0] = '\0';
156 LoadString( hInst
, IDS_MSG_OPTIMIZED_FOR_CLIENT
, pTextClient
, MAX_TEXT_LENGTH
);
158 wchar_t* pTextNoInstallation
= new wchar_t[ MAX_TEXT_LENGTH
];
159 pTextNoInstallation
[0] = '\0';
160 LoadString( hInst
, IDS_MSG_NO_INSTALLATION_FOUND
, pTextNoInstallation
, MAX_TEXT_LENGTH
);
162 LPVOID VBA
= (void*)0x10000000;
163 wchar_t path
[MAX_PATH
];
165 wchar_t * pathEnd
= getBrandPath(path
);
167 if (tools::buildPath(path
, path
, pathEnd
, MY_STRING(L
"libxml2.dll")) == NULL
)
169 bool bFast
= checkImageVirtualBaseAddress(path
, VBA
);
171 if (tools::buildPath(path
, path
, pathEnd
, MY_STRING(L
"..\\basis-link")) == NULL
)
173 pathEnd
= tools::resolveLink(path
);
176 failPath(pAppTitle
, pTextNoInstallation
);
178 if (tools::buildPath(path
, path
, pathEnd
, MY_STRING(L
"\\program\\vclmi.dll")) == NULL
)
180 bFast
&= checkImageVirtualBaseAddress(path
, VBA
);
182 if (tools::buildPath(path
, path
, pathEnd
, MY_STRING(L
"\\ure-link")) == NULL
)
184 pathEnd
= tools::resolveLink(path
);
187 failPath(pAppTitle
, pTextNoInstallation
);
189 if (tools::buildPath(path
, path
, pathEnd
, MY_STRING(L
"\\bin\\sal3.dll")) == NULL
)
191 bFast
&= checkImageVirtualBaseAddress(path
, VBA
);
193 const wchar_t* pOutput
= pTextClient
;
195 pOutput
= pTextServer
;
197 MessageBoxW( NULL
, pOutput
, pAppTitle
, MB_OK
);