1e28571a5SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3e28571a5SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4e28571a5SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5e28571a5SAndrew Rist  * distributed with this work for additional information
6e28571a5SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7e28571a5SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8e28571a5SAndrew Rist  * "License"); you may not use this file except in compliance
9e28571a5SAndrew Rist  * with the License.  You may obtain a copy of the License at
10e28571a5SAndrew Rist  *
11e28571a5SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12e28571a5SAndrew Rist  *
13e28571a5SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14e28571a5SAndrew Rist  * software distributed under the License is distributed on an
15e28571a5SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16e28571a5SAndrew Rist  * KIND, either express or implied.  See the License for the
17e28571a5SAndrew Rist  * specific language governing permissions and limitations
18e28571a5SAndrew Rist  * under the License.
19e28571a5SAndrew Rist  *
20e28571a5SAndrew Rist  *************************************************************/
21e28571a5SAndrew Rist 
22*75f04985Sdamjan // MARKER(update_precomp.py): autogen include statement, do not remove
23*75f04985Sdamjan #include "precompiled_cui.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #if defined _MSC_VER
26cdf0e10cSrcweir #pragma warning(push, 1)
27cdf0e10cSrcweir #endif
28cdf0e10cSrcweir #include <windows.h>
29cdf0e10cSrcweir #if defined _MSC_VER
30cdf0e10cSrcweir #pragma warning(pop)
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #include <Winreg.h>
33cdf0e10cSrcweir #include <Shlwapi.h>
34cdf0e10cSrcweir #include <stdio.h>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #define SO_PATH_SIZE		4096
38cdf0e10cSrcweir #define MOZ_PLUGIN_DLL_NAME "npsopluginmi.dll"
39cdf0e10cSrcweir extern "C" {
lc_isInstalled(const char * realFilePath)40cdf0e10cSrcweir int lc_isInstalled(const  char* realFilePath)
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 	HKEY hKeySoftware;
43cdf0e10cSrcweir 	HKEY hMozillaPlugins;
44cdf0e10cSrcweir 	HKEY hStarOffice;
45cdf0e10cSrcweir 	char sSoPath[SO_PATH_SIZE];
46cdf0e10cSrcweir 	char sPluginPath[SO_PATH_SIZE];
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 	LONG ret;
49cdf0e10cSrcweir 	ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,  "SOFTWARE",  0,  KEY_READ, &hKeySoftware);
50cdf0e10cSrcweir 	if(ret != ERROR_SUCCESS){
51cdf0e10cSrcweir 		ret = RegOpenKeyEx(HKEY_CURRENT_USER,  "SOFTWARE",  0,  KEY_READ, &hKeySoftware);
52cdf0e10cSrcweir 		if(ret != ERROR_SUCCESS){
53cdf0e10cSrcweir 			return -1;
54cdf0e10cSrcweir 		}
55cdf0e10cSrcweir 	}
56cdf0e10cSrcweir 	ret = RegOpenKeyEx(hKeySoftware,  "MozillaPlugins",  0,  KEY_READ, &hMozillaPlugins);
57cdf0e10cSrcweir 	if(ret != ERROR_SUCCESS){
58cdf0e10cSrcweir 		RegCloseKey(hKeySoftware);
59cdf0e10cSrcweir 		if( ret == ERROR_FILE_NOT_FOUND)
60cdf0e10cSrcweir 			return 1;
61cdf0e10cSrcweir 		else
62cdf0e10cSrcweir 			return -1;
63cdf0e10cSrcweir 	}
64cdf0e10cSrcweir 	ret = RegOpenKeyEx(hMozillaPlugins,  "@sun.com/npsopluginmi;version=1.0",  0,  KEY_READ, &hStarOffice);
65cdf0e10cSrcweir 	if(ret != ERROR_SUCCESS){
66cdf0e10cSrcweir 		RegCloseKey(hKeySoftware);
67cdf0e10cSrcweir 		RegCloseKey(hMozillaPlugins);
68cdf0e10cSrcweir 		if( ret == ERROR_FILE_NOT_FOUND)
69cdf0e10cSrcweir 			return 1;
70cdf0e10cSrcweir 		else
71cdf0e10cSrcweir 			return -1;
72cdf0e10cSrcweir 	}
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	if((realFilePath == NULL) || (strlen(realFilePath) == 0) || (strlen(realFilePath) >= SO_PATH_SIZE))
75cdf0e10cSrcweir 	    ret = -1;
76cdf0e10cSrcweir 	else{
77cdf0e10cSrcweir 	    sprintf(sSoPath,"%s", realFilePath);
78cdf0e10cSrcweir 	    ret = 0;
79cdf0e10cSrcweir 	}
80cdf0e10cSrcweir 	//ret =  GetCurrentDirectory( SO_PATH_SIZE, sSoPath);
81cdf0e10cSrcweir 	//ret = GetEnvironmentVariable("prog", sSoPath, SO_PATH_SIZE);
82cdf0e10cSrcweir 	// GetCurrentDirectory return the char number of the string
83cdf0e10cSrcweir 	if(ret == 0){
84cdf0e10cSrcweir 		DWORD  dType = REG_SZ;
85cdf0e10cSrcweir 		DWORD  dSize = SO_PATH_SIZE;
86cdf0e10cSrcweir 		ret = RegQueryValueEx (hStarOffice, "Path", NULL,  &dType , (LPBYTE) sPluginPath, &dSize);
87cdf0e10cSrcweir 		if(ret == ERROR_SUCCESS){
88cdf0e10cSrcweir 			if(strcmp(sPluginPath, sSoPath) == 0)
89cdf0e10cSrcweir 				ret = 0;
90cdf0e10cSrcweir 			else
91cdf0e10cSrcweir 				ret = 1;
92cdf0e10cSrcweir 		}
93cdf0e10cSrcweir 		else
94cdf0e10cSrcweir 			ret = -1;
95cdf0e10cSrcweir 	}
96cdf0e10cSrcweir 	else
97cdf0e10cSrcweir 		ret = -1;
98cdf0e10cSrcweir 	RegCloseKey(hStarOffice);
99cdf0e10cSrcweir 	RegCloseKey(hMozillaPlugins);
100cdf0e10cSrcweir 	RegCloseKey(hKeySoftware);
101cdf0e10cSrcweir 	return ret;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
lc_uninstallPlugin(const char *)104cdf0e10cSrcweir int lc_uninstallPlugin(const  char*)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir 	HKEY hKeySoftware;
107cdf0e10cSrcweir 	HKEY hMozillaPlugins;
108cdf0e10cSrcweir 	HKEY hStarOffice;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	LONG ret;
111cdf0e10cSrcweir 	ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,  "SOFTWARE",  0,  KEY_READ|KEY_WRITE, &hKeySoftware);
112cdf0e10cSrcweir 	if(ret != ERROR_SUCCESS){
113cdf0e10cSrcweir 		ret = RegOpenKeyEx(HKEY_CURRENT_USER,  "SOFTWARE",  0,  KEY_READ|KEY_WRITE, &hKeySoftware);
114cdf0e10cSrcweir 		if(ret != ERROR_SUCCESS){
115cdf0e10cSrcweir 			return -1;
116cdf0e10cSrcweir 		}
117cdf0e10cSrcweir 	}
118cdf0e10cSrcweir 	ret = RegOpenKeyEx(hKeySoftware,  "MozillaPlugins",  0,  KEY_READ|KEY_WRITE, &hMozillaPlugins);
119cdf0e10cSrcweir 	if(ret != ERROR_SUCCESS){
120cdf0e10cSrcweir 		RegCloseKey(hKeySoftware);
121cdf0e10cSrcweir 		if( ret == ERROR_FILE_NOT_FOUND)
122cdf0e10cSrcweir 			return 0;
123cdf0e10cSrcweir 		else
124cdf0e10cSrcweir 			return -1;
125cdf0e10cSrcweir 	}
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	ret = RegOpenKeyEx(hMozillaPlugins,  "@sun.com/npsopluginmi;version=1.0",  0,  KEY_READ|KEY_WRITE, &hStarOffice);
128cdf0e10cSrcweir 	if(ret != ERROR_SUCCESS){
129cdf0e10cSrcweir 		RegCloseKey(hKeySoftware);
130cdf0e10cSrcweir 		RegCloseKey(hMozillaPlugins);
131cdf0e10cSrcweir 		if( ret == ERROR_FILE_NOT_FOUND)
132cdf0e10cSrcweir 			return 0;
133cdf0e10cSrcweir 		else
134cdf0e10cSrcweir 			return -1;
135cdf0e10cSrcweir 	}
136cdf0e10cSrcweir 	RegCloseKey(hStarOffice);
137cdf0e10cSrcweir 	ret = SHDeleteKey(hMozillaPlugins,  "@sun.com/npsopluginmi;version=1.0");
138cdf0e10cSrcweir 	if(ret != ERROR_SUCCESS){
139cdf0e10cSrcweir 		ret = -1;
140cdf0e10cSrcweir 	}
141cdf0e10cSrcweir 	RegFlushKey(hMozillaPlugins);
142cdf0e10cSrcweir 	RegCloseKey(hMozillaPlugins);
143cdf0e10cSrcweir 	RegCloseKey(hKeySoftware);
144cdf0e10cSrcweir 	return ret;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
lc_installPlugin(const char * realFilePath)147cdf0e10cSrcweir int lc_installPlugin(const  char* realFilePath)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir 	HKEY hKeySoftware;
150cdf0e10cSrcweir 	HKEY hMozillaPlugins;
151cdf0e10cSrcweir 	HKEY hStarOffice;
152cdf0e10cSrcweir 	char sSoPath[SO_PATH_SIZE];
153cdf0e10cSrcweir 	DWORD  sState;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 	LONG ret;
157cdf0e10cSrcweir 	ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,  "SOFTWARE",  0,  KEY_READ|KEY_WRITE, &hKeySoftware);
158cdf0e10cSrcweir 	if(ret != ERROR_SUCCESS){
159cdf0e10cSrcweir 		ret = RegOpenKeyEx(HKEY_CURRENT_USER,  "SOFTWARE",  0,  KEY_READ|KEY_WRITE, &hKeySoftware);
160cdf0e10cSrcweir 		if(ret != ERROR_SUCCESS){
161cdf0e10cSrcweir 			return -1;
162cdf0e10cSrcweir 		}
163cdf0e10cSrcweir 	}
164cdf0e10cSrcweir 	ret = RegOpenKeyEx(hKeySoftware,  "MozillaPlugins",  0,  KEY_READ|KEY_WRITE, &hMozillaPlugins);
165cdf0e10cSrcweir 	if(ret != ERROR_SUCCESS){
166cdf0e10cSrcweir 		RegCreateKeyEx(hKeySoftware,
167cdf0e10cSrcweir 			"MozillaPlugins",
168cdf0e10cSrcweir 			0,
169cdf0e10cSrcweir 			NULL,
170cdf0e10cSrcweir 			REG_OPTION_NON_VOLATILE,
171cdf0e10cSrcweir 			KEY_READ|KEY_WRITE,
172cdf0e10cSrcweir 			NULL,
173cdf0e10cSrcweir 			&hMozillaPlugins,
174cdf0e10cSrcweir 			&sState);
175cdf0e10cSrcweir 	}
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 	ret = RegCreateKeyEx(hMozillaPlugins,
178cdf0e10cSrcweir 		"@sun.com/npsopluginmi;version=1.0",
179cdf0e10cSrcweir 		0,
180cdf0e10cSrcweir 		NULL,
181cdf0e10cSrcweir 		REG_OPTION_NON_VOLATILE,
182cdf0e10cSrcweir 		KEY_READ|KEY_WRITE,
183cdf0e10cSrcweir 		NULL,
184cdf0e10cSrcweir         &hStarOffice,
185cdf0e10cSrcweir 		&sState);
186cdf0e10cSrcweir 	if(ret != ERROR_SUCCESS){
187cdf0e10cSrcweir 		RegCloseKey(hKeySoftware);
188cdf0e10cSrcweir 		RegCloseKey(hMozillaPlugins);
189cdf0e10cSrcweir 		return -1;
190cdf0e10cSrcweir 	}
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 	RegFlushKey(hStarOffice);
193cdf0e10cSrcweir     RegFlushKey(hMozillaPlugins);
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 	if((realFilePath == NULL) || (strlen(realFilePath) == 0) || (strlen(realFilePath) >= SO_PATH_SIZE))
197cdf0e10cSrcweir 	    ret = -1;
198cdf0e10cSrcweir 	else{
199cdf0e10cSrcweir 	    sprintf(sSoPath,"%s", realFilePath);
200cdf0e10cSrcweir 	    ret = 0;
201cdf0e10cSrcweir 	}
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 	//ret =  GetCurrentDirectory( SO_PATH_SIZE, sSoPath);
204cdf0e10cSrcweir 	// GetCurrentDirectory return the char number of the string
205cdf0e10cSrcweir 	if(ret == 0){
206cdf0e10cSrcweir 		ret = RegSetValueEx( hStarOffice, "Path", 0, REG_SZ,  (LPBYTE) sSoPath, strlen(sSoPath) + 1);
207cdf0e10cSrcweir 		if(ret == ERROR_SUCCESS)
208cdf0e10cSrcweir 			ret = 0;
209cdf0e10cSrcweir 		else
210cdf0e10cSrcweir 			ret = -1;
211cdf0e10cSrcweir 	}
212cdf0e10cSrcweir 	else
213cdf0e10cSrcweir 		ret = -1;
214cdf0e10cSrcweir     RegFlushKey(hStarOffice);
215cdf0e10cSrcweir     RegFlushKey(hMozillaPlugins);
216cdf0e10cSrcweir     RegCloseKey(hStarOffice);
217cdf0e10cSrcweir     RegCloseKey(hMozillaPlugins);
218cdf0e10cSrcweir 	RegCloseKey(hKeySoftware);
219cdf0e10cSrcweir 	RegFlushKey(HKEY_LOCAL_MACHINE);
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 	return ret;
222cdf0e10cSrcweir }
223cdf0e10cSrcweir }
224