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 // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_odk.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #if defined _MSC_VER
32*cdf0e10cSrcweir #pragma warning(push, 1)
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir #include <windows.h>
35*cdf0e10cSrcweir #if defined _MSC_VER
36*cdf0e10cSrcweir #pragma warning(pop)
37*cdf0e10cSrcweir #endif
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <jni.h>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir extern "C" BOOL __stdcall _DllMainCRTStartup(HINSTANCE, DWORD, LPVOID)
42*cdf0e10cSrcweir {
43*cdf0e10cSrcweir     return TRUE;
44*cdf0e10cSrcweir }
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir extern "C" JNIEXPORT jboolean JNICALL
47*cdf0e10cSrcweir     Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenClassesRoot(
48*cdf0e10cSrcweir     JNIEnv *env, jclass, jlongArray hkresult)
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir     jboolean ret = JNI_FALSE;
51*cdf0e10cSrcweir     PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
52*cdf0e10cSrcweir     if (RegOpenKeyEx(HKEY_CLASSES_ROOT, NULL, 0, KEY_READ, phkey)
53*cdf0e10cSrcweir         == ERROR_SUCCESS)
54*cdf0e10cSrcweir         ret = JNI_TRUE;
55*cdf0e10cSrcweir     env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
56*cdf0e10cSrcweir     return ret;
57*cdf0e10cSrcweir }
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir extern "C" JNIEXPORT jboolean JNICALL
60*cdf0e10cSrcweir     Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenCurrentConfig(
61*cdf0e10cSrcweir     JNIEnv *env, jclass, jlongArray hkresult)
62*cdf0e10cSrcweir {
63*cdf0e10cSrcweir     jboolean ret = JNI_FALSE;
64*cdf0e10cSrcweir     PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
65*cdf0e10cSrcweir     if (RegOpenKeyEx(HKEY_CURRENT_CONFIG, NULL, 0, KEY_READ, phkey)
66*cdf0e10cSrcweir         == ERROR_SUCCESS)
67*cdf0e10cSrcweir         ret = JNI_TRUE;
68*cdf0e10cSrcweir     env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
69*cdf0e10cSrcweir     return ret;
70*cdf0e10cSrcweir }
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir extern "C" JNIEXPORT jboolean JNICALL
73*cdf0e10cSrcweir     Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenCurrentUser(
74*cdf0e10cSrcweir     JNIEnv *env, jclass, jlongArray hkresult)
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir     jboolean ret = JNI_FALSE;
77*cdf0e10cSrcweir     PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
78*cdf0e10cSrcweir     if (RegOpenKeyEx(HKEY_CURRENT_USER, NULL, 0, KEY_READ, phkey)
79*cdf0e10cSrcweir         == ERROR_SUCCESS)
80*cdf0e10cSrcweir         ret = JNI_TRUE;
81*cdf0e10cSrcweir     env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
82*cdf0e10cSrcweir     return ret;
83*cdf0e10cSrcweir }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir extern "C" JNIEXPORT jboolean JNICALL
86*cdf0e10cSrcweir     Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenLocalMachine(
87*cdf0e10cSrcweir     JNIEnv *env, jclass, jlongArray hkresult)
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir     jboolean ret = JNI_FALSE;
90*cdf0e10cSrcweir     PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
91*cdf0e10cSrcweir     if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, NULL, 0, KEY_READ, phkey)
92*cdf0e10cSrcweir         == ERROR_SUCCESS)
93*cdf0e10cSrcweir         ret = JNI_TRUE;
94*cdf0e10cSrcweir     env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
95*cdf0e10cSrcweir     return ret;
96*cdf0e10cSrcweir }
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir extern "C" JNIEXPORT jboolean JNICALL
99*cdf0e10cSrcweir     Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenUsers(
100*cdf0e10cSrcweir     JNIEnv *env, jclass, jlongArray hkresult)
101*cdf0e10cSrcweir {
102*cdf0e10cSrcweir     jboolean ret = JNI_FALSE;
103*cdf0e10cSrcweir     PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
104*cdf0e10cSrcweir     if (RegOpenKeyEx(HKEY_USERS, NULL, 0, KEY_READ, phkey) == ERROR_SUCCESS)
105*cdf0e10cSrcweir         ret = JNI_TRUE;
106*cdf0e10cSrcweir     env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
107*cdf0e10cSrcweir     return ret;
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir extern "C" JNIEXPORT jboolean JNICALL
111*cdf0e10cSrcweir     Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenKeyEx(
112*cdf0e10cSrcweir     JNIEnv *env, jclass, jlong parent, jstring name, jlongArray hkresult)
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir     jboolean ret = JNI_FALSE;
115*cdf0e10cSrcweir     const char *namestr = env->GetStringUTFChars(name, 0);
116*cdf0e10cSrcweir     PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
117*cdf0e10cSrcweir     if (RegOpenKeyEx((HKEY)parent, namestr, 0, KEY_READ, phkey)
118*cdf0e10cSrcweir         == ERROR_SUCCESS)
119*cdf0e10cSrcweir         ret = JNI_TRUE;
120*cdf0e10cSrcweir     env->ReleaseStringUTFChars(name, namestr);
121*cdf0e10cSrcweir     env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
122*cdf0e10cSrcweir     return ret;
123*cdf0e10cSrcweir }
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir extern "C" JNIEXPORT jboolean JNICALL
127*cdf0e10cSrcweir     Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegCloseKey(
128*cdf0e10cSrcweir     JNIEnv *, jclass, jlong hkey)
129*cdf0e10cSrcweir {
130*cdf0e10cSrcweir     jboolean ret = JNI_FALSE;
131*cdf0e10cSrcweir     if (RegCloseKey((HKEY)hkey) == ERROR_SUCCESS)
132*cdf0e10cSrcweir         ret = JNI_TRUE;
133*cdf0e10cSrcweir     return ret;
134*cdf0e10cSrcweir }
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir extern "C" JNIEXPORT jboolean
137*cdf0e10cSrcweir     JNICALL Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegQueryValueEx(
138*cdf0e10cSrcweir     JNIEnv *env, jclass, jlong hkey, jstring value, jlongArray type,
139*cdf0e10cSrcweir     jbyteArray data, jlongArray size)
140*cdf0e10cSrcweir {
141*cdf0e10cSrcweir     jboolean ret = JNI_FALSE;
142*cdf0e10cSrcweir     const char* valuestr = env->GetStringUTFChars(value, 0);
143*cdf0e10cSrcweir     LPDWORD ptype = (LPDWORD)env->GetLongArrayElements(type, 0);
144*cdf0e10cSrcweir     LPBYTE  pdata = (LPBYTE)env->GetByteArrayElements(data, 0);
145*cdf0e10cSrcweir     LPDWORD psize = (LPDWORD)env->GetLongArrayElements(size, 0);
146*cdf0e10cSrcweir     if (RegQueryValueEx((HKEY)hkey, valuestr, NULL, ptype, pdata, psize)
147*cdf0e10cSrcweir         == ERROR_SUCCESS)
148*cdf0e10cSrcweir         ret = JNI_TRUE;
149*cdf0e10cSrcweir     env->ReleaseStringUTFChars(value, valuestr);
150*cdf0e10cSrcweir     env->ReleaseLongArrayElements(type, (jlong *)ptype, 0);
151*cdf0e10cSrcweir     env->ReleaseByteArrayElements(data, (jbyte *)pdata, 0);
152*cdf0e10cSrcweir     env->ReleaseLongArrayElements(size, (jlong *)psize, 0);
153*cdf0e10cSrcweir     return ret;
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir extern "C" JNIEXPORT jboolean JNICALL
157*cdf0e10cSrcweir     Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegQueryInfoKey(
158*cdf0e10cSrcweir     JNIEnv *env, jclass, jlong hkey, jlongArray subkeys,
159*cdf0e10cSrcweir     jlongArray maxSubkeyLen, jlongArray values, jlongArray maxValueNameLen,
160*cdf0e10cSrcweir     jlongArray maxValueLen, jlongArray secDescriptor)
161*cdf0e10cSrcweir {
162*cdf0e10cSrcweir     jboolean ret = JNI_FALSE;
163*cdf0e10cSrcweir     LPDWORD psubkeys = (LPDWORD)env->GetLongArrayElements(subkeys, 0);
164*cdf0e10cSrcweir     LPDWORD pmaxSubkeyLen =
165*cdf0e10cSrcweir         (LPDWORD)env->GetLongArrayElements(maxSubkeyLen, 0);
166*cdf0e10cSrcweir     LPDWORD pvalues = (LPDWORD)env->GetLongArrayElements(values, 0);
167*cdf0e10cSrcweir     LPDWORD pmaxValueNameLen =
168*cdf0e10cSrcweir         (LPDWORD)env->GetLongArrayElements(maxValueNameLen, 0);
169*cdf0e10cSrcweir     LPDWORD pmaxValueLen =
170*cdf0e10cSrcweir         (LPDWORD)env->GetLongArrayElements(maxValueLen, 0);
171*cdf0e10cSrcweir     LPDWORD psecDescriptor =
172*cdf0e10cSrcweir         (LPDWORD)env->GetLongArrayElements(secDescriptor, 0);
173*cdf0e10cSrcweir     FILETIME ft;
174*cdf0e10cSrcweir     if (RegQueryInfoKey((HKEY)hkey, NULL, NULL, NULL, psubkeys, pmaxSubkeyLen,
175*cdf0e10cSrcweir                         NULL, pvalues, pmaxValueNameLen, pmaxValueLen,
176*cdf0e10cSrcweir                         psecDescriptor, &ft) == ERROR_SUCCESS)
177*cdf0e10cSrcweir         ret = JNI_TRUE;
178*cdf0e10cSrcweir     env->ReleaseLongArrayElements(subkeys, (jlong*)psubkeys, 0);
179*cdf0e10cSrcweir     env->ReleaseLongArrayElements(maxSubkeyLen, (jlong*)pmaxSubkeyLen, 0);
180*cdf0e10cSrcweir     env->ReleaseLongArrayElements(values, (jlong*)pvalues, 0);
181*cdf0e10cSrcweir     env->ReleaseLongArrayElements(maxValueNameLen, (jlong*)pmaxValueNameLen, 0);
182*cdf0e10cSrcweir     env->ReleaseLongArrayElements(maxValueLen, (jlong*)pmaxValueLen, 0);
183*cdf0e10cSrcweir     env->ReleaseLongArrayElements(secDescriptor, (jlong*)psecDescriptor, 0);
184*cdf0e10cSrcweir     return ret;
185*cdf0e10cSrcweir }
186