aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin/msofficecomm/RegistryHandler.java
blob: 1cb11f6308fd5c61e1f94ebebca53cbc1653429b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Copyright @ 2015 Atlassian Pty Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.java.sip.communicator.plugin.msofficecomm;

import net.java.sip.communicator.util.Logger;

import com.sun.jna.platform.win32.*;

/**
 * Checks the registry keys used by 
 * Outlook.
 *
 * @author Hristo Terezov
 */
public class RegistryHandler
{
    /**
     * The logger.
     */
    private static Logger logger = Logger.getLogger(RegistryHandler.class);
    
    /**
     * The key under which the IM application is placed.
     */
    private static String REGISTRY_IM_APPLICATION_KEY 
        = "Software\\IM Providers";
    
    /**
     * The value under which the default IM application is placed.
     */
    private static String REGISTRY_DEFAULT_IM_APPLICATION_VALUE 
        = "DefaultIMApp";
    
    /**
     * The key for the outlook call integration.
     */
    private static String REGISTRY_CALL_INTEGRATION
        = "Software\\Microsoft\\Office\\Outlook\\Call Integration";
    
    /**
     * The value for the outlook call integration.
     */
    private static String REGISTRY_CALL_INTEGRATION_VALUE
        = "IMApplication";

    /**
     * The key for the outlook rtc application.
     */
    private static String REGISTRY_OFFICE11_RTC_APPLICATION
        = "Software\\Microsoft\\Office\\11.0\\Common\\PersonaMenu";
    
    /**
     * The key for the outlook rtc application.
     */
    private static String REGISTRY_OFFICE12_RTC_APPLICATION
    = "Software\\Microsoft\\Office\\12.0\\Common\\PersonaMenu";
    
    /**
     * The value for the rtc application.
     */
    private static String REGISTRY_RTC_APPLICATION_VALUE = "RTCApplication";
    
    /**
     * The key for Communicator IM App.
     */
    private static String REGISTRY_COMMUNICATOR_UP 
        = "Software\\IM Providers\\Communicator";
    
    /**
     * Up and running value.
     */
    private static String REGISTRY_UP_RUNNING_VALUE = "UpAndRunning";
    
    /**
     * Checks the existence of the registry keys for outlook call integration.
     */
    private static void checkCallIntegration()
    {
        if(!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, 
            REGISTRY_CALL_INTEGRATION)
            || !Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, 
            REGISTRY_CALL_INTEGRATION, 
            REGISTRY_CALL_INTEGRATION_VALUE))
        {
            logger.error(REGISTRY_CALL_INTEGRATION + 
                " doesn't exists in registry");
            return;
        }
        logger.info("Call integration: " +
            Advapi32Util.registryGetStringValue(
                WinReg.HKEY_LOCAL_MACHINE,
                REGISTRY_CALL_INTEGRATION,
                REGISTRY_CALL_INTEGRATION_VALUE));
    }
    
    /**
     * Checks the existence of the registry keys for outlook rtc application.
     */
    private static void checkRTCApplication()
    {
        if(!Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, 
            REGISTRY_OFFICE11_RTC_APPLICATION)
            || !Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, 
            REGISTRY_OFFICE11_RTC_APPLICATION, 
            REGISTRY_RTC_APPLICATION_VALUE))
        {
            logger.error(REGISTRY_OFFICE11_RTC_APPLICATION + 
                " doesn't exists in registry");
        }
        else
        {
            logger.info("RTC application: " +
                Advapi32Util.registryGetIntValue(
                    WinReg.HKEY_CURRENT_USER,
                    REGISTRY_OFFICE11_RTC_APPLICATION,
                    REGISTRY_RTC_APPLICATION_VALUE));
        }
        
        if(!Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, 
            REGISTRY_OFFICE12_RTC_APPLICATION)
            || !Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, 
            REGISTRY_OFFICE12_RTC_APPLICATION, 
            REGISTRY_RTC_APPLICATION_VALUE))
        {
            logger.error(REGISTRY_OFFICE12_RTC_APPLICATION + 
                " doesn't exists in registry");
        }
        else
        {
            logger.info("RTC application: " +
                Advapi32Util.registryGetIntValue(
                    WinReg.HKEY_CURRENT_USER,
                    REGISTRY_OFFICE12_RTC_APPLICATION,
                    REGISTRY_RTC_APPLICATION_VALUE));
        }
    }
    
    /**
     * Checks if the registry key for running Jitsi and Communicator.
     */
    private static void checkUpAndRunning()
    {
        if(!Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, 
            REGISTRY_COMMUNICATOR_UP)
            || !Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, 
            REGISTRY_COMMUNICATOR_UP, 
            REGISTRY_UP_RUNNING_VALUE))
        {
            logger.error(REGISTRY_COMMUNICATOR_UP + 
                " doesn't exists in registry");
        }
        else
        {
            logger.info("Communicator up and running value: " + 
                Advapi32Util.registryGetIntValue(
                    WinReg.HKEY_CURRENT_USER,
                    REGISTRY_COMMUNICATOR_UP,
                    REGISTRY_UP_RUNNING_VALUE));
        }
        
        if(!Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, 
            REGISTRY_IM_APPLICATION_KEY + "\\" + getApplicationName())
            || !Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, 
            REGISTRY_IM_APPLICATION_KEY + "\\" + getApplicationName(), 
            REGISTRY_UP_RUNNING_VALUE))
        {
            logger.error(REGISTRY_IM_APPLICATION_KEY + 
                " doesn't exists in registry");
        }
        else
        {
            logger.info("Up and running value: " + 
                Advapi32Util.registryGetIntValue(
                    WinReg.HKEY_CURRENT_USER,
                    REGISTRY_IM_APPLICATION_KEY + "\\" 
                        + getApplicationName(),
                    REGISTRY_UP_RUNNING_VALUE));
        }
    }
    
    /**
     * Logs registry information.
     */
    public static void checkRegistryKeys()
    {
        checkDefaultIMApp();
        checkRegisteredIMApp();
        checkCallIntegration();
        checkRTCApplication();
        checkUpAndRunning();
    }
    
    
    /**
     * Checks whether Jitsi is the default IM application.
     */
    private static void checkDefaultIMApp()
    {
        if(!Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, 
            REGISTRY_IM_APPLICATION_KEY) || 
            !Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, 
            REGISTRY_IM_APPLICATION_KEY, 
            REGISTRY_DEFAULT_IM_APPLICATION_VALUE))
        {
            logger.error(REGISTRY_IM_APPLICATION_KEY 
                + " doesn't extsts");
            return;
        }

        logger.info("Default IM App: " + Advapi32Util.registryGetStringValue(
                WinReg.HKEY_CURRENT_USER,
                REGISTRY_IM_APPLICATION_KEY,
                REGISTRY_DEFAULT_IM_APPLICATION_VALUE));
    }

    /**
     * Checks whether Jitsi is registered as IM provider.
     */
    private static void checkRegisteredIMApp()
    {
        if(!Advapi32Util.registryKeyExists(
            WinReg.HKEY_LOCAL_MACHINE,
            REGISTRY_IM_APPLICATION_KEY + "\\" + getApplicationName()))
        {
            logger.error(REGISTRY_IM_APPLICATION_KEY  + "\\" + 
                getApplicationName() + " doesn;t exsts");
            return;
        }
        
        logger.info("Registered IM App friendly name: " 
            + Advapi32Util.registryGetStringValue(
                WinReg.HKEY_LOCAL_MACHINE,
                REGISTRY_IM_APPLICATION_KEY + "\\" + 
                getApplicationName(),
                "FriendlyName"));
    }
    
    /**
     * Returns the application name.
     * @return the application name
     */
    private static String getApplicationName()
    {
        return MsOfficeCommActivator.getResources().getSettingsString(
            "service.gui.APPLICATION_NAME");
    }
}