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