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: winpluginlib.cpp,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 #ifdef SVX_DLLIMPLEMENTATION
32 #undef SVX_DLLIMPLEMENTATION
36 #pragma warning(push, 1)
47 #define SO_PATH_SIZE 4096
48 #define MOZ_PLUGIN_DLL_NAME "npsopluginmi.dll"
50 int lc_isInstalled(const char* realFilePath
)
55 char sSoPath
[SO_PATH_SIZE
];
56 char sPluginPath
[SO_PATH_SIZE
];
59 ret
= RegOpenKeyEx(HKEY_LOCAL_MACHINE
, "SOFTWARE", 0, KEY_READ
, &hKeySoftware
);
60 if(ret
!= ERROR_SUCCESS
){
61 ret
= RegOpenKeyEx(HKEY_CURRENT_USER
, "SOFTWARE", 0, KEY_READ
, &hKeySoftware
);
62 if(ret
!= ERROR_SUCCESS
){
66 ret
= RegOpenKeyEx(hKeySoftware
, "MozillaPlugins", 0, KEY_READ
, &hMozillaPlugins
);
67 if(ret
!= ERROR_SUCCESS
){
68 RegCloseKey(hKeySoftware
);
69 if( ret
== ERROR_FILE_NOT_FOUND
)
74 ret
= RegOpenKeyEx(hMozillaPlugins
, "@sun.com/npsopluginmi;version=1.0", 0, KEY_READ
, &hStarOffice
);
75 if(ret
!= ERROR_SUCCESS
){
76 RegCloseKey(hKeySoftware
);
77 RegCloseKey(hMozillaPlugins
);
78 if( ret
== ERROR_FILE_NOT_FOUND
)
84 if((realFilePath
== NULL
) || (strlen(realFilePath
) == 0) || (strlen(realFilePath
) >= SO_PATH_SIZE
))
87 sprintf(sSoPath
,"%s", realFilePath
);
90 //ret = GetCurrentDirectory( SO_PATH_SIZE, sSoPath);
91 //ret = GetEnvironmentVariable("prog", sSoPath, SO_PATH_SIZE);
92 // GetCurrentDirectory return the char number of the string
95 DWORD dSize
= SO_PATH_SIZE
;
96 ret
= RegQueryValueEx (hStarOffice
, "Path", NULL
, &dType
, (LPBYTE
) sPluginPath
, &dSize
);
97 if(ret
== ERROR_SUCCESS
){
98 if(strcmp(sPluginPath
, sSoPath
) == 0)
108 RegCloseKey(hStarOffice
);
109 RegCloseKey(hMozillaPlugins
);
110 RegCloseKey(hKeySoftware
);
114 int lc_uninstallPlugin(const char*)
117 HKEY hMozillaPlugins
;
121 ret
= RegOpenKeyEx(HKEY_LOCAL_MACHINE
, "SOFTWARE", 0, KEY_READ
|KEY_WRITE
, &hKeySoftware
);
122 if(ret
!= ERROR_SUCCESS
){
123 ret
= RegOpenKeyEx(HKEY_CURRENT_USER
, "SOFTWARE", 0, KEY_READ
|KEY_WRITE
, &hKeySoftware
);
124 if(ret
!= ERROR_SUCCESS
){
128 ret
= RegOpenKeyEx(hKeySoftware
, "MozillaPlugins", 0, KEY_READ
|KEY_WRITE
, &hMozillaPlugins
);
129 if(ret
!= ERROR_SUCCESS
){
130 RegCloseKey(hKeySoftware
);
131 if( ret
== ERROR_FILE_NOT_FOUND
)
137 ret
= RegOpenKeyEx(hMozillaPlugins
, "@sun.com/npsopluginmi;version=1.0", 0, KEY_READ
|KEY_WRITE
, &hStarOffice
);
138 if(ret
!= ERROR_SUCCESS
){
139 RegCloseKey(hKeySoftware
);
140 RegCloseKey(hMozillaPlugins
);
141 if( ret
== ERROR_FILE_NOT_FOUND
)
146 RegCloseKey(hStarOffice
);
147 ret
= SHDeleteKey(hMozillaPlugins
, "@sun.com/npsopluginmi;version=1.0");
148 if(ret
!= ERROR_SUCCESS
){
151 RegFlushKey(hMozillaPlugins
);
152 RegCloseKey(hMozillaPlugins
);
153 RegCloseKey(hKeySoftware
);
157 int lc_installPlugin(const char* realFilePath
)
160 HKEY hMozillaPlugins
;
162 char sSoPath
[SO_PATH_SIZE
];
167 ret
= RegOpenKeyEx(HKEY_LOCAL_MACHINE
, "SOFTWARE", 0, KEY_READ
|KEY_WRITE
, &hKeySoftware
);
168 if(ret
!= ERROR_SUCCESS
){
169 ret
= RegOpenKeyEx(HKEY_CURRENT_USER
, "SOFTWARE", 0, KEY_READ
|KEY_WRITE
, &hKeySoftware
);
170 if(ret
!= ERROR_SUCCESS
){
174 ret
= RegOpenKeyEx(hKeySoftware
, "MozillaPlugins", 0, KEY_READ
|KEY_WRITE
, &hMozillaPlugins
);
175 if(ret
!= ERROR_SUCCESS
){
176 RegCreateKeyEx(hKeySoftware
,
180 REG_OPTION_NON_VOLATILE
,
187 ret
= RegCreateKeyEx(hMozillaPlugins
,
188 "@sun.com/npsopluginmi;version=1.0",
191 REG_OPTION_NON_VOLATILE
,
196 if(ret
!= ERROR_SUCCESS
){
197 RegCloseKey(hKeySoftware
);
198 RegCloseKey(hMozillaPlugins
);
202 RegFlushKey(hStarOffice
);
203 RegFlushKey(hMozillaPlugins
);
206 if((realFilePath
== NULL
) || (strlen(realFilePath
) == 0) || (strlen(realFilePath
) >= SO_PATH_SIZE
))
209 sprintf(sSoPath
,"%s", realFilePath
);
213 //ret = GetCurrentDirectory( SO_PATH_SIZE, sSoPath);
214 // GetCurrentDirectory return the char number of the string
216 ret
= RegSetValueEx( hStarOffice
, "Path", 0, REG_SZ
, (LPBYTE
) sSoPath
, strlen(sSoPath
) + 1);
217 if(ret
== ERROR_SUCCESS
)
224 RegFlushKey(hStarOffice
);
225 RegFlushKey(hMozillaPlugins
);
226 RegCloseKey(hStarOffice
);
227 RegCloseKey(hMozillaPlugins
);
228 RegCloseKey(hKeySoftware
);
229 RegFlushKey(HKEY_LOCAL_MACHINE
);