1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #if defined _MSC_VER 29*cdf0e10cSrcweir #pragma warning(push, 1) 30*cdf0e10cSrcweir #endif 31*cdf0e10cSrcweir #include <windows.h> 32*cdf0e10cSrcweir #if defined _MSC_VER 33*cdf0e10cSrcweir #pragma warning(pop) 34*cdf0e10cSrcweir #endif 35*cdf0e10cSrcweir #include <Winreg.h> 36*cdf0e10cSrcweir #include <Shlwapi.h> 37*cdf0e10cSrcweir #include <stdio.h> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #define SO_PATH_SIZE 4096 41*cdf0e10cSrcweir #define MOZ_PLUGIN_DLL_NAME "npsopluginmi.dll" 42*cdf0e10cSrcweir extern "C" { 43*cdf0e10cSrcweir int lc_isInstalled(const char* realFilePath) 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir HKEY hKeySoftware; 46*cdf0e10cSrcweir HKEY hMozillaPlugins; 47*cdf0e10cSrcweir HKEY hStarOffice; 48*cdf0e10cSrcweir char sSoPath[SO_PATH_SIZE]; 49*cdf0e10cSrcweir char sPluginPath[SO_PATH_SIZE]; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir LONG ret; 52*cdf0e10cSrcweir ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ, &hKeySoftware); 53*cdf0e10cSrcweir if(ret != ERROR_SUCCESS){ 54*cdf0e10cSrcweir ret = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE", 0, KEY_READ, &hKeySoftware); 55*cdf0e10cSrcweir if(ret != ERROR_SUCCESS){ 56*cdf0e10cSrcweir return -1; 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir ret = RegOpenKeyEx(hKeySoftware, "MozillaPlugins", 0, KEY_READ, &hMozillaPlugins); 60*cdf0e10cSrcweir if(ret != ERROR_SUCCESS){ 61*cdf0e10cSrcweir RegCloseKey(hKeySoftware); 62*cdf0e10cSrcweir if( ret == ERROR_FILE_NOT_FOUND) 63*cdf0e10cSrcweir return 1; 64*cdf0e10cSrcweir else 65*cdf0e10cSrcweir return -1; 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir ret = RegOpenKeyEx(hMozillaPlugins, "@sun.com/npsopluginmi;version=1.0", 0, KEY_READ, &hStarOffice); 68*cdf0e10cSrcweir if(ret != ERROR_SUCCESS){ 69*cdf0e10cSrcweir RegCloseKey(hKeySoftware); 70*cdf0e10cSrcweir RegCloseKey(hMozillaPlugins); 71*cdf0e10cSrcweir if( ret == ERROR_FILE_NOT_FOUND) 72*cdf0e10cSrcweir return 1; 73*cdf0e10cSrcweir else 74*cdf0e10cSrcweir return -1; 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir if((realFilePath == NULL) || (strlen(realFilePath) == 0) || (strlen(realFilePath) >= SO_PATH_SIZE)) 78*cdf0e10cSrcweir ret = -1; 79*cdf0e10cSrcweir else{ 80*cdf0e10cSrcweir sprintf(sSoPath,"%s", realFilePath); 81*cdf0e10cSrcweir ret = 0; 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir //ret = GetCurrentDirectory( SO_PATH_SIZE, sSoPath); 84*cdf0e10cSrcweir //ret = GetEnvironmentVariable("prog", sSoPath, SO_PATH_SIZE); 85*cdf0e10cSrcweir // GetCurrentDirectory return the char number of the string 86*cdf0e10cSrcweir if(ret == 0){ 87*cdf0e10cSrcweir DWORD dType = REG_SZ; 88*cdf0e10cSrcweir DWORD dSize = SO_PATH_SIZE; 89*cdf0e10cSrcweir ret = RegQueryValueEx (hStarOffice, "Path", NULL, &dType , (LPBYTE) sPluginPath, &dSize); 90*cdf0e10cSrcweir if(ret == ERROR_SUCCESS){ 91*cdf0e10cSrcweir if(strcmp(sPluginPath, sSoPath) == 0) 92*cdf0e10cSrcweir ret = 0; 93*cdf0e10cSrcweir else 94*cdf0e10cSrcweir ret = 1; 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir else 97*cdf0e10cSrcweir ret = -1; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir else 100*cdf0e10cSrcweir ret = -1; 101*cdf0e10cSrcweir RegCloseKey(hStarOffice); 102*cdf0e10cSrcweir RegCloseKey(hMozillaPlugins); 103*cdf0e10cSrcweir RegCloseKey(hKeySoftware); 104*cdf0e10cSrcweir return ret; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir int lc_uninstallPlugin(const char*) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir HKEY hKeySoftware; 110*cdf0e10cSrcweir HKEY hMozillaPlugins; 111*cdf0e10cSrcweir HKEY hStarOffice; 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir LONG ret; 114*cdf0e10cSrcweir ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ|KEY_WRITE, &hKeySoftware); 115*cdf0e10cSrcweir if(ret != ERROR_SUCCESS){ 116*cdf0e10cSrcweir ret = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE", 0, KEY_READ|KEY_WRITE, &hKeySoftware); 117*cdf0e10cSrcweir if(ret != ERROR_SUCCESS){ 118*cdf0e10cSrcweir return -1; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir ret = RegOpenKeyEx(hKeySoftware, "MozillaPlugins", 0, KEY_READ|KEY_WRITE, &hMozillaPlugins); 122*cdf0e10cSrcweir if(ret != ERROR_SUCCESS){ 123*cdf0e10cSrcweir RegCloseKey(hKeySoftware); 124*cdf0e10cSrcweir if( ret == ERROR_FILE_NOT_FOUND) 125*cdf0e10cSrcweir return 0; 126*cdf0e10cSrcweir else 127*cdf0e10cSrcweir return -1; 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir ret = RegOpenKeyEx(hMozillaPlugins, "@sun.com/npsopluginmi;version=1.0", 0, KEY_READ|KEY_WRITE, &hStarOffice); 131*cdf0e10cSrcweir if(ret != ERROR_SUCCESS){ 132*cdf0e10cSrcweir RegCloseKey(hKeySoftware); 133*cdf0e10cSrcweir RegCloseKey(hMozillaPlugins); 134*cdf0e10cSrcweir if( ret == ERROR_FILE_NOT_FOUND) 135*cdf0e10cSrcweir return 0; 136*cdf0e10cSrcweir else 137*cdf0e10cSrcweir return -1; 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir RegCloseKey(hStarOffice); 140*cdf0e10cSrcweir ret = SHDeleteKey(hMozillaPlugins, "@sun.com/npsopluginmi;version=1.0"); 141*cdf0e10cSrcweir if(ret != ERROR_SUCCESS){ 142*cdf0e10cSrcweir ret = -1; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir RegFlushKey(hMozillaPlugins); 145*cdf0e10cSrcweir RegCloseKey(hMozillaPlugins); 146*cdf0e10cSrcweir RegCloseKey(hKeySoftware); 147*cdf0e10cSrcweir return ret; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir int lc_installPlugin(const char* realFilePath) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir HKEY hKeySoftware; 153*cdf0e10cSrcweir HKEY hMozillaPlugins; 154*cdf0e10cSrcweir HKEY hStarOffice; 155*cdf0e10cSrcweir char sSoPath[SO_PATH_SIZE]; 156*cdf0e10cSrcweir DWORD sState; 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir LONG ret; 160*cdf0e10cSrcweir ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ|KEY_WRITE, &hKeySoftware); 161*cdf0e10cSrcweir if(ret != ERROR_SUCCESS){ 162*cdf0e10cSrcweir ret = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE", 0, KEY_READ|KEY_WRITE, &hKeySoftware); 163*cdf0e10cSrcweir if(ret != ERROR_SUCCESS){ 164*cdf0e10cSrcweir return -1; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir ret = RegOpenKeyEx(hKeySoftware, "MozillaPlugins", 0, KEY_READ|KEY_WRITE, &hMozillaPlugins); 168*cdf0e10cSrcweir if(ret != ERROR_SUCCESS){ 169*cdf0e10cSrcweir RegCreateKeyEx(hKeySoftware, 170*cdf0e10cSrcweir "MozillaPlugins", 171*cdf0e10cSrcweir 0, 172*cdf0e10cSrcweir NULL, 173*cdf0e10cSrcweir REG_OPTION_NON_VOLATILE, 174*cdf0e10cSrcweir KEY_READ|KEY_WRITE, 175*cdf0e10cSrcweir NULL, 176*cdf0e10cSrcweir &hMozillaPlugins, 177*cdf0e10cSrcweir &sState); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir ret = RegCreateKeyEx(hMozillaPlugins, 181*cdf0e10cSrcweir "@sun.com/npsopluginmi;version=1.0", 182*cdf0e10cSrcweir 0, 183*cdf0e10cSrcweir NULL, 184*cdf0e10cSrcweir REG_OPTION_NON_VOLATILE, 185*cdf0e10cSrcweir KEY_READ|KEY_WRITE, 186*cdf0e10cSrcweir NULL, 187*cdf0e10cSrcweir &hStarOffice, 188*cdf0e10cSrcweir &sState); 189*cdf0e10cSrcweir if(ret != ERROR_SUCCESS){ 190*cdf0e10cSrcweir RegCloseKey(hKeySoftware); 191*cdf0e10cSrcweir RegCloseKey(hMozillaPlugins); 192*cdf0e10cSrcweir return -1; 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir RegFlushKey(hStarOffice); 196*cdf0e10cSrcweir RegFlushKey(hMozillaPlugins); 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir if((realFilePath == NULL) || (strlen(realFilePath) == 0) || (strlen(realFilePath) >= SO_PATH_SIZE)) 200*cdf0e10cSrcweir ret = -1; 201*cdf0e10cSrcweir else{ 202*cdf0e10cSrcweir sprintf(sSoPath,"%s", realFilePath); 203*cdf0e10cSrcweir ret = 0; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir //ret = GetCurrentDirectory( SO_PATH_SIZE, sSoPath); 207*cdf0e10cSrcweir // GetCurrentDirectory return the char number of the string 208*cdf0e10cSrcweir if(ret == 0){ 209*cdf0e10cSrcweir ret = RegSetValueEx( hStarOffice, "Path", 0, REG_SZ, (LPBYTE) sSoPath, strlen(sSoPath) + 1); 210*cdf0e10cSrcweir if(ret == ERROR_SUCCESS) 211*cdf0e10cSrcweir ret = 0; 212*cdf0e10cSrcweir else 213*cdf0e10cSrcweir ret = -1; 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir else 216*cdf0e10cSrcweir ret = -1; 217*cdf0e10cSrcweir RegFlushKey(hStarOffice); 218*cdf0e10cSrcweir RegFlushKey(hMozillaPlugins); 219*cdf0e10cSrcweir RegCloseKey(hStarOffice); 220*cdf0e10cSrcweir RegCloseKey(hMozillaPlugins); 221*cdf0e10cSrcweir RegCloseKey(hKeySoftware); 222*cdf0e10cSrcweir RegFlushKey(HKEY_LOCAL_MACHINE); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir return ret; 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir } 227