Hello @lonk,
Your macro in the question does indeed list the name of registered Base files. It does not mean these are valid. The only way to tell if a registered item is valid is to check the URL against the URL of the Base file. The code you have in the question can get at a URL if it is a valid Base file. If not an error is thrown. So a different method to access these URL’s is needed. This is done with the ConfigurationProvider (or you may know this as the Expert Configuration in Options).
In addition, it is necessary to get the valid Base files from the directory. This is the macro in your comment. Not certain why you mention slow as the entire process is extremely quick.
The process needs to compare all Base files in the selected directory against all URLs registered. Using an array for the Base files, it contains the Base file name and its’ URL. If found in the list, the URL is wiped out. When finished, all items with a URL left are not registered & that is the list provided.
Macro:
Option Explicit
Sub CheckExistingFirebirdDatabase
Dim sFileName$, sPath$, t$
Dim x As Integer, y As Integer, z As Integer
sPath = Environ("HOME") & "/" & "Documents" & GetPathSeparator()
sFileName = Dir(sPath, 0)
Rem Build Array of Base files in directory
Rem Array has File name and a URL for comparison
Dim aFileArray(0,1) As String
Do While sFileName <> ""
If Right(sFileName,4) = ".odb" Then
ReDim Preserve aFileArray(x,1)
aFileArray(x,0) =sFileName
aFileArray(x,1) ="file://" & sPath & sFileName
x=x+1
End If
sFileName = Dir()
Loop
Rem Get access to Registered databases
Dim aProps(0) As New com.sun.star.beans.PropertyValue
aProps(0).Name = "nodepath"
aProps(0).Value = "/org.openoffice.Office.DataAccess/RegisteredNames/"
Dim oConfig As Object, oHistory As Object, oElementNames As Object
oConfig = createUnoService( "com.sun.star.configuration.ConfigurationProvider" )
oHistory = oConfig.createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess", aProps() )
Rem Element Names are needed to get access to the names needed
oElementNames = oHistory.getElementNames()
Dim sCkURL As String, sRegItems As String, iCount As Integer
iCount = UBound(oElementNames)
Dim aRegItems(iCount)
Rem Loop through Base files
for z = 0 to x-1
sCkURL = aFileArray(z,1)
Rem Loop through Registered files
For y = 0 to iCount
sRegItems = oHistory.getByName(oElementNames(y)).Location
Rem Clear Base file array URL if there is a match - already registered
If sRegItems = sCkURL Then aFileArray(z,1) = "" : Exit For
Next
Next
Rem Create a list of File array items where URL is NOT empty
for z = 0 to x-1
if aFileArray(z,1) <> "" Then t = t & aFileArray(z,0) & Chr(10)
Next
Rem Display list
MsgBox t,,sPath
End Sub