Update ooo320-m1
[ooovba.git] / desktop / win32 / source / rebase / rebasegui.cxx
blob3cb36cb49b3c36f64207b02ab5997ed0552559c9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: md5.cxx,v $
10 * $Revision: 1.8 $
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"
33 #define UNICODE 1
34 #define _UNICODE 1
36 #ifndef _WINDOWS_
37 # define WIN32_LEAN_AND_MEAN
38 #if defined _MSC_VER
39 #pragma warning(push, 1)
40 #endif
41 # include <windows.h>
42 # include <shellapi.h>
43 # include <wchar.h>
44 #if defined _MSC_VER
45 #pragma warning(pop)
46 #endif
47 #endif
49 #include "Resource.h"
50 #include <time.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);
67 static void fail()
69 LPWSTR buf = NULL;
70 FormatMessageW(
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);
74 LocalFree(buf);
75 TerminateProcess(GetCurrentProcess(), 255);
78 static LPVOID getVirtualBaseAddress( wchar_t* pszFilePath )
80 HANDLE hFile;
81 HANDLE hFileMapping;
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,
89 0);
91 if ( hFile == INVALID_HANDLE_VALUE )
93 return NULL;
96 hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
97 if ( hFileMapping == 0 )
99 CloseHandle(hFile);
100 return NULL;
103 lpFileBase = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
104 if ( lpFileBase == 0 )
106 CloseHandle(hFileMapping);
107 CloseHandle(hFile);
108 return NULL;
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);
121 CloseHandle(hFile);
123 return lpFileBase;
126 static bool checkImageVirtualBaseAddress(wchar_t* pszFilePath, LPVOID lpVBA)
128 LPVOID lpImageVBA = getVirtualBaseAddress(pszFilePath);
129 if ( lpImageVBA == lpVBA )
130 return true;
131 else
132 return false;
135 static wchar_t* getBrandPath(wchar_t * pszPath)
137 DWORD n = GetModuleFileNameW(NULL, pszPath, MAX_PATH);
138 if (n == 0 || n >= MAX_PATH) {
139 exit(EXIT_FAILURE);
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 ];
147 pAppTitle[0] = '\0';
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)
168 fail();
169 bool bFast = checkImageVirtualBaseAddress(path, VBA);
171 if (tools::buildPath(path, path, pathEnd, MY_STRING(L"..\\basis-link")) == NULL)
172 fail();
173 pathEnd = tools::resolveLink(path);
175 if (pathEnd == NULL)
176 failPath(pAppTitle, pTextNoInstallation);
178 if (tools::buildPath(path, path, pathEnd, MY_STRING(L"\\program\\vclmi.dll")) == NULL)
179 fail();
180 bFast &= checkImageVirtualBaseAddress(path, VBA);
182 if (tools::buildPath(path, path, pathEnd, MY_STRING(L"\\ure-link")) == NULL)
183 fail();
184 pathEnd = tools::resolveLink(path);
186 if (pathEnd == NULL)
187 failPath(pAppTitle, pTextNoInstallation);
189 if (tools::buildPath(path, path, pathEnd, MY_STRING(L"\\bin\\sal3.dll")) == NULL)
190 fail();
191 bFast &= checkImageVirtualBaseAddress(path, VBA);
193 const wchar_t* pOutput = pTextClient;
194 if (!bFast)
195 pOutput = pTextServer;
197 MessageBoxW( NULL, pOutput, pAppTitle, MB_OK );
199 return 0;