xref: /trunk/main/wizards/source/importwizard/API.xba (revision 3e02b54d)
1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*3e02b54dSAndrew Rist<!--***********************************************************
4*3e02b54dSAndrew Rist *
5*3e02b54dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
6*3e02b54dSAndrew Rist * or more contributor license agreements.  See the NOTICE file
7*3e02b54dSAndrew Rist * distributed with this work for additional information
8*3e02b54dSAndrew Rist * regarding copyright ownership.  The ASF licenses this file
9*3e02b54dSAndrew Rist * to you under the Apache License, Version 2.0 (the
10*3e02b54dSAndrew Rist * "License"); you may not use this file except in compliance
11*3e02b54dSAndrew Rist * with the License.  You may obtain a copy of the License at
12*3e02b54dSAndrew Rist *
13*3e02b54dSAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
14*3e02b54dSAndrew Rist *
15*3e02b54dSAndrew Rist * Unless required by applicable law or agreed to in writing,
16*3e02b54dSAndrew Rist * software distributed under the License is distributed on an
17*3e02b54dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*3e02b54dSAndrew Rist * KIND, either express or implied.  See the License for the
19*3e02b54dSAndrew Rist * specific language governing permissions and limitations
20*3e02b54dSAndrew Rist * under the License.
21*3e02b54dSAndrew Rist *
22*3e02b54dSAndrew Rist ***********************************************************-->
23cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="API" script:language="StarBasic">Declare Function RegOpenKeyEx Lib &quot;advapi32.dll&quot; Alias &quot;RegOpenKeyExA&quot; _
24cdf0e10cSrcweir (ByVal hKey As Long, _
25cdf0e10cSrcweir  ByVal lpSubKey As String, _
26cdf0e10cSrcweir  ByVal ulOptions As Long, _
27cdf0e10cSrcweir  ByVal samDesired As Long, _
28cdf0e10cSrcweir  phkResult As Long) As Long
29cdf0e10cSrcweir
30cdf0e10cSrcweirDeclare Function RegQueryValueExString Lib &quot;advapi32.dll&quot; Alias &quot;RegQueryValueExA&quot; _
31cdf0e10cSrcweir (ByVal hKey As Long, _
32cdf0e10cSrcweir  ByVal lpValueName As String, _
33cdf0e10cSrcweir  ByVal lpReserved As Long, _
34cdf0e10cSrcweir  lpType As Long, _
35cdf0e10cSrcweir  lpData As String, _
36cdf0e10cSrcweir  lpcbData As Long) As Long
37cdf0e10cSrcweir
38cdf0e10cSrcweirDeclare Function RegQueryValueExLong Lib &quot;advapi32.dll&quot; Alias &quot;RegQueryValueExA&quot; _
39cdf0e10cSrcweir (ByVal hKey As Long, _
40cdf0e10cSrcweir  ByVal lpValueName As String, _
41cdf0e10cSrcweir  ByVal lpReserved As Long, _
42cdf0e10cSrcweir  lpType As Long, _
43cdf0e10cSrcweir  lpData As Long, _
44cdf0e10cSrcweir  lpcbData As Long) As Long
45cdf0e10cSrcweir
46cdf0e10cSrcweirDeclare Function RegQueryValueExNULL Lib &quot;advapi32.dll&quot; Alias &quot;RegQueryValueExA&quot; _
47cdf0e10cSrcweir (ByVal hKey As Long, _
48cdf0e10cSrcweir  ByVal lpValueName As String, _
49cdf0e10cSrcweir  ByVal lpReserved As Long, _
50cdf0e10cSrcweir  lpType As Long, _
51cdf0e10cSrcweir  ByVal lpData As Long, _
52cdf0e10cSrcweir  lpcbData As Long) As Long
53cdf0e10cSrcweir
54cdf0e10cSrcweirDeclare Function RegCloseKeyA Lib &quot;advapi32.dll&quot; Alias &quot;RegCloseKey&quot; _
55cdf0e10cSrcweir (ByVal hKey As Long) As Long
56cdf0e10cSrcweir
57cdf0e10cSrcweir
58cdf0e10cSrcweirPublic Const HKEY_CLASSES_ROOT = &amp;H80000000
59cdf0e10cSrcweirPublic Const HKEY_CURRENT_USER = &amp;H80000001
60cdf0e10cSrcweirPublic Const HKEY_LOCAL_MACHINE = &amp;H80000002
61cdf0e10cSrcweirPublic Const HKEY_USERS = &amp;H80000003
62cdf0e10cSrcweirPublic Const KEY_ALL_ACCESS = &amp;H3F
63cdf0e10cSrcweirPublic Const REG_OPTION_NON_VOLATILE = 0
64cdf0e10cSrcweirPublic Const REG_SZ As Long = 1
65cdf0e10cSrcweirPublic Const REG_DWORD As Long = 4
66cdf0e10cSrcweirPublic Const ERROR_NONE = 0
67cdf0e10cSrcweirPublic Const ERROR_BADDB = 1
68cdf0e10cSrcweirPublic Const ERROR_BADKEY = 2
69cdf0e10cSrcweirPublic Const ERROR_CANTOPEN = 3
70cdf0e10cSrcweirPublic Const ERROR_CANTREAD = 4
71cdf0e10cSrcweirPublic Const ERROR_CANTWRITE = 5
72cdf0e10cSrcweirPublic Const ERROR_OUTOFMEMORY = 6
73cdf0e10cSrcweirPublic Const ERROR_INVALID_PARAMETER = 7
74cdf0e10cSrcweirPublic Const ERROR_ACCESS_DENIED = 8
75cdf0e10cSrcweirPublic Const ERROR_INVALID_PARAMETERS = 87
76cdf0e10cSrcweirPublic Const ERROR_NO_MORE_ITEMS = 259
77cdf0e10cSrcweir&apos;Public Const KEY_READ = &amp;H20019
78cdf0e10cSrcweir
79cdf0e10cSrcweir
80cdf0e10cSrcweirFunction OpenRegKey(lBaseKey As Long, sKeyName As String) As Variant
81cdf0e10cSrcweirDim LocKeyValue
82cdf0e10cSrcweirDim hKey as Long
83cdf0e10cSrcweirDim lRetValue as Long
84cdf0e10cSrcweir	lRetValue = RegOpenKeyEx(lBaseKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
85cdf0e10cSrcweir&apos;	lRetValue = QueryValue(HKEY_LOCAL_MACHINE, &quot;SOFTWARE\Microsoft\Outlook Express\5.0\Default Settings&quot;, &quot;Revocation Checking&quot;)
86cdf0e10cSrcweir	If hKey &lt;&gt; 0 Then
87cdf0e10cSrcweir	    RegCloseKeyA (hKey)
88cdf0e10cSrcweir	End If
89cdf0e10cSrcweir	OpenRegKey() = lRetValue
90cdf0e10cSrcweirEnd Function
91cdf0e10cSrcweir
92cdf0e10cSrcweir
93cdf0e10cSrcweirFunction GetDefaultPath(CurOffice as Integer) As String
94cdf0e10cSrcweirDim sPath as String
95cdf0e10cSrcweirDim Index as Integer
96cdf0e10cSrcweir	Select Case Wizardmode
97cdf0e10cSrcweir		Case SBMICROSOFTMODE
98cdf0e10cSrcweir			Index = Applications(CurOffice,SBAPPLKEY)
99cdf0e10cSrcweir			If GetGUIType = 1 Then &apos; Windows
100cdf0e10cSrcweir			    sPath = QueryValue(HKEY_LOCAL_MACHINE, sKeyName(Index), sValueName(Index))
101cdf0e10cSrcweir			Else
102cdf0e10cSrcweir				sPath = &quot;&quot;
103cdf0e10cSrcweir			End If
104cdf0e10cSrcweir			If sPath = &quot;&quot; Then
105cdf0e10cSrcweir				sPath = SOWorkPath
106cdf0e10cSrcweir			End If
107cdf0e10cSrcweir			GetDefaultPath = sPath
108cdf0e10cSrcweir		Case SBXMLMODE
109cdf0e10cSrcweir			GetDefaultPath = SOWorkPath
110cdf0e10cSrcweir	End Select
111cdf0e10cSrcweirEnd Function
112cdf0e10cSrcweir
113cdf0e10cSrcweir
114cdf0e10cSrcweirFunction GetTemplateDefaultPath(Index as Integer) As String
115cdf0e10cSrcweirDim sLocTemplatePath as String
116cdf0e10cSrcweirDim sLocProgrampath as String
117cdf0e10cSrcweirDim Progstring as String
118cdf0e10cSrcweirDim PathList()as String
119cdf0e10cSrcweirDim Maxindex as Integer
120cdf0e10cSrcweirDim OldsLocTemplatePath
121cdf0e10cSrcweirDim sTemplateKeyName as String
122cdf0e10cSrcweirDim sTemplateValueName as String
123cdf0e10cSrcweir	On Local Error Goto NOVAlIDSYSTEMPATH
124cdf0e10cSrcweir	Select Case WizardMode
125cdf0e10cSrcweir		Case SBMICROSOFTMODE
126cdf0e10cSrcweir			If GetGUIType = 1 Then &apos; Windows
127cdf0e10cSrcweir				&apos; Template directory of Office 97
128cdf0e10cSrcweir				sTemplateKeyName = &quot;Software\Microsoft\Office\8.0\Common\FileNew\LocalTemplates&quot;
129cdf0e10cSrcweir				sTemplateValueName = &quot;&quot;
130cdf0e10cSrcweir				sLocTemplatePath = QueryValue(HKEY_LOCAL_MACHINE, sTemplateKeyName, sTemplateValueName)
131cdf0e10cSrcweir
132cdf0e10cSrcweir				If sLocTemplatePath = &quot;&quot; Then
133cdf0e10cSrcweir					&apos; Retrieve the template directory of Office 2000
134cdf0e10cSrcweir					&apos; Unfortunately there is no existing note about the template directory in
135cdf0e10cSrcweir					&apos; the whole registry.
136cdf0e10cSrcweir
137cdf0e10cSrcweir					&apos; Programdirectory of Office 2000
138cdf0e10cSrcweir					sTemplateKeyName = &quot;Software\Microsoft\Office\9.0\Common\InstallRoot&quot;
139cdf0e10cSrcweir					sTemplateValueName = &quot;Path&quot;
140cdf0e10cSrcweir				    sLocProgrampath = QueryValue(HKEY_LOCAL_MACHINE, sTemplateKeyName, sTemplateValueName)
141cdf0e10cSrcweir					If sLocProgrampath &lt;&gt; &quot;&quot; Then
142cdf0e10cSrcweir					    If Right(sLocProgrampath, 1) &lt;&gt; &quot;\&quot; Then
143cdf0e10cSrcweir					    	sLocProgrampath = sLocProgrampath &amp; &quot;\&quot;
144cdf0e10cSrcweir			   			End If
145cdf0e10cSrcweir						PathList() = ArrayoutofString(sLocProgrampath,&quot;\&quot;,Maxindex)
146cdf0e10cSrcweir						Progstring = &quot;\&quot; &amp; PathList(Maxindex-1) &amp; &quot;\&quot;
147cdf0e10cSrcweir						OldsLocTemplatePath = DeleteStr(sLocProgramPath,Progstring)
148cdf0e10cSrcweir
149cdf0e10cSrcweir						sLocTemplatePath = OldsLocTemplatePath &amp; &quot;\&quot; &amp; &quot;Templates&quot;
150cdf0e10cSrcweir
151cdf0e10cSrcweir						&apos; Does this subdirectory &quot;templates&quot; exist at all
152cdf0e10cSrcweir            			If oUcb.Exists(sLocTemplatePath) Then
153cdf0e10cSrcweir							&apos; If Not the main directory of the office is the base
154cdf0e10cSrcweir							sLocTemplatePath = OldsLocTemplatePath
155cdf0e10cSrcweir						End If
156cdf0e10cSrcweir					Else
157cdf0e10cSrcweir						sLocTemplatePath = SOWorkPath
158cdf0e10cSrcweir					End If
159cdf0e10cSrcweir				End If
160cdf0e10cSrcweir				GetTemplateDefaultPath = ConvertToUrl(sLocTemplatePath)
161cdf0e10cSrcweir			Else
162cdf0e10cSrcweir				GetTemplateDefaultPath = SOWorkPath
163cdf0e10cSrcweir			End If
164cdf0e10cSrcweir		Case SBXMLMODE
165cdf0e10cSrcweir			If Index = 3 Then
166cdf0e10cSrcweir				&apos; Helper Application with no templates
167cdf0e10cSrcweir				GetTemplateDefaultPath = SOWorkPath
168cdf0e10cSrcweir			Else
169cdf0e10cSrcweir				GetTemplateDefaultPath = SOTemplatePath
170cdf0e10cSrcweir			End If
171cdf0e10cSrcweir	End Select
172cdf0e10cSrcweirNOVALIDSYSTEMPATH:
173cdf0e10cSrcweir	If Err &lt;&gt; 0 Then
174cdf0e10cSrcweir		GetTemplateDefaultPath() = SOWorkPath
175cdf0e10cSrcweir		Resume ONITGOES
176cdf0e10cSrcweir		ONITGOES:
177cdf0e10cSrcweir	End If
178cdf0e10cSrcweirEnd Function
179cdf0e10cSrcweir
180cdf0e10cSrcweir
181cdf0e10cSrcweirFunction QueryValueEx(ByVal lhKey, ByVal szValueName As String, vValue As String) As Long
182cdf0e10cSrcweirDim cch As Long
183cdf0e10cSrcweirDim lrc As Long
184cdf0e10cSrcweirDim lType As Long
185cdf0e10cSrcweirDim lValue As Long
186cdf0e10cSrcweirDim sValue As String
187cdf0e10cSrcweirDim Empty
188cdf0e10cSrcweir
189cdf0e10cSrcweir    On Error GoTo QueryValueExError
190cdf0e10cSrcweir
191cdf0e10cSrcweir    lrc = RegQueryValueExNULL(lhKey, szValueName, 0&amp;, lType, 0&amp;, cch)
192cdf0e10cSrcweir    If lrc &lt;&gt; ERROR_NONE Then Error 5
193cdf0e10cSrcweir    Select Case lType
194cdf0e10cSrcweir        Case REG_SZ:
195cdf0e10cSrcweir            sValue = String(cch, 0)
196cdf0e10cSrcweir            lrc = RegQueryValueExString(lhKey, szValueName, 0&amp;, lType, sValue, cch)
197cdf0e10cSrcweir            If lrc = ERROR_NONE Then
198cdf0e10cSrcweir                vValue = Left$(sValue, cch)
199cdf0e10cSrcweir            Else
200cdf0e10cSrcweir                vValue = Empty
201cdf0e10cSrcweir            End If
202cdf0e10cSrcweir        Case REG_DWORD:
203cdf0e10cSrcweir            lrc = RegQueryValueExLong(lhKey, szValueName, 0&amp;, lType, lValue, cch)
204cdf0e10cSrcweir            If lrc = ERROR_NONE Then
205cdf0e10cSrcweir                vValue = lValue
206cdf0e10cSrcweir            End If
207cdf0e10cSrcweir        Case Else
208cdf0e10cSrcweir            lrc = -1
209cdf0e10cSrcweir    End Select
210cdf0e10cSrcweirQueryValueExExit:
211cdf0e10cSrcweir    QueryValueEx = lrc
212cdf0e10cSrcweir    Exit Function
213cdf0e10cSrcweirQueryValueExError:
214cdf0e10cSrcweir    Resume QueryValueExExit
215cdf0e10cSrcweirEnd Function
216cdf0e10cSrcweir
217cdf0e10cSrcweir
218cdf0e10cSrcweirFunction QueryValue(BaseKey As Long, sKeyName As String, sValueName As String) As Variant
219cdf0e10cSrcweirDim lRetVal As Long         &apos; Returnvalue API-Call
220cdf0e10cSrcweirDim hKey As Long            &apos; Onen key handle
221cdf0e10cSrcweirDim vValue As String        &apos; Key value
222cdf0e10cSrcweir
223cdf0e10cSrcweir    lRetVal = RegOpenKeyEx(BaseKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
224cdf0e10cSrcweir    lRetVal = QueryValueEx(hKey, sValueName, vValue)
225cdf0e10cSrcweir    RegCloseKeyA (hKey)
226cdf0e10cSrcweir    QueryValue = vValue
227cdf0e10cSrcweirEnd Function
228*3e02b54dSAndrew Rist</script:module>
229