update dev300-m58
[ooovba.git] / svx / source / cui / winpluginlib.cpp
blob17928c161b46bd7ea0f55aeed27928a2f1e3ae39
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: winpluginlib.cpp,v $
10 * $Revision: 1.6 $
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
33 #endif
35 #if defined _MSC_VER
36 #pragma warning(push, 1)
37 #endif
38 #include <windows.h>
39 #if defined _MSC_VER
40 #pragma warning(pop)
41 #endif
42 #include <Winreg.h>
43 #include <Shlwapi.h>
44 #include <stdio.h>
47 #define SO_PATH_SIZE 4096
48 #define MOZ_PLUGIN_DLL_NAME "npsopluginmi.dll"
49 extern "C" {
50 int lc_isInstalled(const char* realFilePath)
52 HKEY hKeySoftware;
53 HKEY hMozillaPlugins;
54 HKEY hStarOffice;
55 char sSoPath[SO_PATH_SIZE];
56 char sPluginPath[SO_PATH_SIZE];
58 LONG ret;
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){
63 return -1;
66 ret = RegOpenKeyEx(hKeySoftware, "MozillaPlugins", 0, KEY_READ, &hMozillaPlugins);
67 if(ret != ERROR_SUCCESS){
68 RegCloseKey(hKeySoftware);
69 if( ret == ERROR_FILE_NOT_FOUND)
70 return 1;
71 else
72 return -1;
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)
79 return 1;
80 else
81 return -1;
84 if((realFilePath == NULL) || (strlen(realFilePath) == 0) || (strlen(realFilePath) >= SO_PATH_SIZE))
85 ret = -1;
86 else{
87 sprintf(sSoPath,"%s", realFilePath);
88 ret = 0;
90 //ret = GetCurrentDirectory( SO_PATH_SIZE, sSoPath);
91 //ret = GetEnvironmentVariable("prog", sSoPath, SO_PATH_SIZE);
92 // GetCurrentDirectory return the char number of the string
93 if(ret == 0){
94 DWORD dType = REG_SZ;
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)
99 ret = 0;
100 else
101 ret = 1;
103 else
104 ret = -1;
106 else
107 ret = -1;
108 RegCloseKey(hStarOffice);
109 RegCloseKey(hMozillaPlugins);
110 RegCloseKey(hKeySoftware);
111 return ret;
114 int lc_uninstallPlugin(const char*)
116 HKEY hKeySoftware;
117 HKEY hMozillaPlugins;
118 HKEY hStarOffice;
120 LONG ret;
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){
125 return -1;
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)
132 return 0;
133 else
134 return -1;
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)
142 return 0;
143 else
144 return -1;
146 RegCloseKey(hStarOffice);
147 ret = SHDeleteKey(hMozillaPlugins, "@sun.com/npsopluginmi;version=1.0");
148 if(ret != ERROR_SUCCESS){
149 ret = -1;
151 RegFlushKey(hMozillaPlugins);
152 RegCloseKey(hMozillaPlugins);
153 RegCloseKey(hKeySoftware);
154 return ret;
157 int lc_installPlugin(const char* realFilePath)
159 HKEY hKeySoftware;
160 HKEY hMozillaPlugins;
161 HKEY hStarOffice;
162 char sSoPath[SO_PATH_SIZE];
163 DWORD sState;
166 LONG ret;
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){
171 return -1;
174 ret = RegOpenKeyEx(hKeySoftware, "MozillaPlugins", 0, KEY_READ|KEY_WRITE, &hMozillaPlugins);
175 if(ret != ERROR_SUCCESS){
176 RegCreateKeyEx(hKeySoftware,
177 "MozillaPlugins",
179 NULL,
180 REG_OPTION_NON_VOLATILE,
181 KEY_READ|KEY_WRITE,
182 NULL,
183 &hMozillaPlugins,
184 &sState);
187 ret = RegCreateKeyEx(hMozillaPlugins,
188 "@sun.com/npsopluginmi;version=1.0",
190 NULL,
191 REG_OPTION_NON_VOLATILE,
192 KEY_READ|KEY_WRITE,
193 NULL,
194 &hStarOffice,
195 &sState);
196 if(ret != ERROR_SUCCESS){
197 RegCloseKey(hKeySoftware);
198 RegCloseKey(hMozillaPlugins);
199 return -1;
202 RegFlushKey(hStarOffice);
203 RegFlushKey(hMozillaPlugins);
206 if((realFilePath == NULL) || (strlen(realFilePath) == 0) || (strlen(realFilePath) >= SO_PATH_SIZE))
207 ret = -1;
208 else{
209 sprintf(sSoPath,"%s", realFilePath);
210 ret = 0;
213 //ret = GetCurrentDirectory( SO_PATH_SIZE, sSoPath);
214 // GetCurrentDirectory return the char number of the string
215 if(ret == 0){
216 ret = RegSetValueEx( hStarOffice, "Path", 0, REG_SZ, (LPBYTE) sSoPath, strlen(sSoPath) + 1);
217 if(ret == ERROR_SUCCESS)
218 ret = 0;
219 else
220 ret = -1;
222 else
223 ret = -1;
224 RegFlushKey(hStarOffice);
225 RegFlushKey(hMozillaPlugins);
226 RegCloseKey(hStarOffice);
227 RegCloseKey(hMozillaPlugins);
228 RegCloseKey(hKeySoftware);
229 RegFlushKey(HKEY_LOCAL_MACHINE);
231 return ret;