Save /back up Basic Libraries with macro, rename Libraries

Creating Extension - Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This forum is not for asking questions about writing your own macros.

Save /back up Basic Libraries with macro, rename Libraries

Postby JeJe » Mon Nov 12, 2018 12:31 am

Attached extension makes it easy to back up libraries. Someone recommended starting all your libraries with a couple of letters so they can be distinguished from other peoples - hence the feature of selecting libraries this way.
Second dialog to edit exported libraries
-rename them
-rename modules - includes replacing calls to the module eg in dialog controls
-replace text in files eg to change location=document to location = application
-open files in Writer

Use with caution - don't work on your only copy of a library
See module AAUser


Simple script to export/back up your Basic Libraries. (I've noticed that information in libraries can sometimes be lost when using the organiser and backing them up individually via the dialog is tedious)

Code: Select all   Expand viewCollapse view

sub test()
SaveBasicLibraries ConvertToUrl("C:\tmp\libraries" & "2" ' format(date,"ddmmyy"))
end sub
Sub SaveBasicLibraries(URL as string)

   dim i as long,libnames,Blibs,Dlibs,Dlibnames

   Blibs = GlobalScope.BasicLibraries

   libnames= Blibs.getelementnames

   for i = 0 to ubound(libnames)
         Blibs.ExportLibrary libnames(i),URL,nothing
   next


   Dlibs = GlobalScope.DialogLibraries
   Dlibnames= Dlibs.getelementnames

  for i = 0 to ubound(Dlibnames)
         Dlibs.ExportLibrary Dlibnames(i),URL,nothing
   next


   Msgbox "Libraries Exported"


End Sub




EDIT: MY ORIGINAL POST DIDN'T EXPORT DIALOGS - AMENDED.
EDIT2: Rename library code posted further on in thread
EDIT3: Added a dialog to the extension to Edit exported libraries
Attachments
JeIDE.oxt
(12.46 KiB) Downloaded 3 times
Last edited by JeJe on Tue Dec 04, 2018 1:25 am, edited 7 times in total.
Openoffice 4.1.2
Windows 8
JeJe
 
Posts: 300
Joined: Wed Mar 09, 2016 2:40 pm

Re: Save /back up Basic Libraries with macro

Postby JeJe » Tue Nov 20, 2018 5:37 pm

UPDATED THREAD AS ORIGINAL VERSION JUST SAVED MODULES NOT DIALOGS.

Think okay now - but don't rely on for anything critical (eg creating your only copy of a library)
Openoffice 4.1.2
Windows 8
JeJe
 
Posts: 300
Joined: Wed Mar 09, 2016 2:40 pm

Re: Save /back up Basic Libraries with macro

Postby Zizi64 » Tue Nov 20, 2018 8:35 pm

Tibor Kovacs, Hungary; LO4.4.7, LO6.1.1 on Win7x64Prof.
PortableApps, winPenPack: LO3.3.0-LO6.1.2 and AOO4.1.5
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 7470
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Save /back up Basic Libraries with macro

Postby JeJe » Tue Nov 20, 2018 10:56 pm

Thanks, yeah. Another approach would be to save the User Profile.

This document from 2006 discusses implementing multiple library export:

... allowing multiple library export would cause considerable work as currently the library listbox at the “Organizer dialog/Libraries” tabpage does not support multi selection and none of the other functionality provided there (Edit, Password, Delete) supports it either. So the corresponding buttons would always have to be disabled in case of a multi selection. The bottom line is that the small advantage of multi library export does not seem to justify the additional work. So it will not be realised for now.


https://www.openoffice.org/specs/ide/Ba ... rtSpec.odt

The thing I like about OO is even though it doesn't have this feature - it allows access to the things necessary to implement it yourself if you want it - just with OOBasic. I don't know anything about the effort needed to code the above in the main program... but in Basic that dialog I wrote took very little time.
Openoffice 4.1.2
Windows 8
JeJe
 
Posts: 300
Joined: Wed Mar 09, 2016 2:40 pm

Re: Save /back up Basic Libraries with macro

Postby RoryOF » Tue Nov 20, 2018 11:07 pm

The problem with saving the User Profile is that, on occasions, it is necessary to delete the User Profile; the ability to restore one's selection of macros to a new (uncorrupted) User Profile could be very useful.
Apache OpenOffice 4.1.6 on Xubuntu 18.04 (mostly 64 bit version) and infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 27677
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Save /back up Basic Libraries with macro

Postby JeJe » Sat Nov 24, 2018 8:53 pm

Here is my rename code.

It exports a library, renames the folder,
then loads each document and does a find/replace for instances of the library name.
(NB: there may be some I've missed)
You can then import the modified library.

This is all tedious doing it manually. The code could also be modified to do a find/replace for location=document vs location=application

Again, take care if you use this code, examine the results and keep a backup of the original library just in case.


Code: Select all   Expand viewCollapse view
sub test

   dim URL as string,pth as string, STS() AS STRING,libname as string,newlibname as string

   libname="JePickers"
   newlibname="JePickers2"

   oPathSettings = CreateUnoService( "com.sun.star.util.PathSettings" )
   URL= oPathSettings.UserConfig
   pth=convertfromURL( URL)

   CreateRenamedLibrary pth, libname,newlibname

   redim sts(5)
   sts(0) = "quot;" & libname
   sts(1) = "quot;" & newlibname
   sts(2) =  ":" & libname & "."
   sts(3) = ":" & newlibname & "."
   sts(4) = "library:name=" & chr(34) & libname
   sts(5) = "library:name=" & chr(34) & newlibname


   openFolderAndReplaceStrings pth,sts()
   Msgbox "Done"

end sub

sub CreateRenamedLibrary(pth as string, libname as string,newlibname as string)
   dim i as long,Blibs,Dlibs,URL as string

   URL = convertToURL(pth)
   Blibs = GlobalScope.BasicLibraries
   if Blibs.hasbyname(libname) then
      Blibs.ExportLibrary libname,URL,nothing
      gotlib = true
   end if
   Dlibs = GlobalScope.DialogLibraries

   if Dlibs.hasbyname(libname) then
      Dlibs.ExportLibrary libname,URL,nothing
      gotlib= true
   end if

   if gotlib = true then

      Name (pth & GetPathSeparator() & libname) as  (pth & GetPathSeparator() & newlibname)

      pth = (pth & GetPathSeparator() & newlibname &  GetPathSeparator())

   end if
end sub


sub openFolderAndReplaceStrings(pth as string,sts() as string)
   Dim NextFile As String,fpth as string

   NextFile = Dir(pth, 0)

   While NextFile  <> ""
      fpth = pth &  nextfile
      OpendocAndreplaceString pth & nextfile,STS()
      NextFile = Dir
      Wend
end sub


Sub OpendocAndreplaceString(pth as string,sts())

      Dim oDoc
      Dim oVal(2) As New com.sun.star.beans.PropertyValue
      dim URL as string
      Dim oRD as Object

      oVal(0).Name = "Hidden"
      oVal(0).Value = true
      oVal(1).Name = "FilterName"
      oVal(1).Value = "Text (encoded)"
      oVal(2).Name = "FilterOptions"
      oVal(2).Value = "UTF8,LF"

      oDoc = StarDesktop.loadComponentFromURL(convertToURL(pth), "_blank", 0, oVal())

      oRD = ODoc.createReplaceDescriptor
      oRD.SearchCaseSensitive = True

      for i = 0 to ubound(sts) step 2
         oRD.SearchString = sts(i)
         oRD.ReplaceString =sts(i+1)
         oDoc.replaceAll(oRD)
      next

      oDoc.store
      oDoc.close(TRUE)

End Sub
Openoffice 4.1.2
Windows 8
JeJe
 
Posts: 300
Joined: Wed Mar 09, 2016 2:40 pm

Re: Save /back up Basic Libraries with macro, rename Librari

Postby JeJe » Tue Dec 04, 2018 1:16 am

Added dialog to extension to edit exported dialogs.
Openoffice 4.1.2
Windows 8
JeJe
 
Posts: 300
Joined: Wed Mar 09, 2016 2:40 pm


Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest