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