1 'encoding UTF-8 Do not remove or change this line!
2 '**************************************************************************
3 '* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 '* Copyright 2008 by Sun Microsystems, Inc.
7 '* OpenOffice.org - a multi-platform office productivity suite
9 '* $RCSfile: t_extension_manager_tools.inc,v $
13 '* last change: $Author: jsk $ $Date: 2008-06-20 07:57:57 $
15 '* This file is part of OpenOffice.org.
17 '* OpenOffice.org is free software: you can redistribute it and/or modify
18 '* it under the terms of the GNU Lesser General Public License version 3
19 '* only, as published by the Free Software Foundation.
21 '* OpenOffice.org is distributed in the hope that it will be useful,
22 '* but WITHOUT ANY WARRANTY; without even the implied warranty of
23 '* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 '* GNU Lesser General Public License version 3 for more details
25 '* (a copy is included in the LICENSE file that accompanied this code).
27 '* You should have received a copy of the GNU Lesser General Public License
28 '* version 3 along with OpenOffice.org. If not, see
29 '* <http://www.openoffice.org/license.html>
30 '* for a copy of the LGPLv3 License.
32 '/******************************************************************************
34 '* owner : joerg.skottke@sun.com
36 '* short description : Tools to ease working with the extension manager
38 '\******************************************************************************
40 function hExtensionAddGUI( _path as string, _flags as string ) as integer
42 '///<h3>Install an extension using the OpenOffice.org Extension Manager UI</h3>
43 '///<p>This function is intended for use with the new Extension Manager UI
44 '///+ and replaces an older function with the same name. Please note that
45 '///+ the interface has changed significantly. <br>This has become necessary
46 '///+ because the Extension Manager can turn up with a really huge number
47 '///+ of different dialogs, warnings, errormessages etc. <br>
48 '///+ As this function is designed to handle the most common installation
49 '///+ scenarios it needs quite a number of differnt options.<br>
50 '///+ Please have a look at the usage sample:<br><br></p>
51 '///+ <p align="center"><i>hExtensionAddGUI( sMyExtension,
52 '///+ "InstallForAll,BrokenDeps,DenyUpdate" )</i<p><br>
57 '///+<li>Path to extension (String)</li>
59 '///+<li>The path has to be fully qualified</li>
60 '///+<li>The path may be platform specific</li>
63 '///+<li>Flags (String), defaults underlined</li>
65 '///+<li>The string is non optional but may be empty. Allowed flags are:</li>
67 '///+<li>InstallForAll | <u>InstallForUser</u><br>Used when running office with administrator rights</li>
68 '///+<li>AllowUpdate | DenyUpdate | <u>NoUpdate</u><br>Reinstall already installed extension/update</li>
69 '///+<li>AcceptLicense | DenyLicense | <u>NoLicense</u><br>How to handle possible license dialog</li>
70 '///+<li>BrokenDeps<br>Close exactly one broken dependencies warning</li>
71 '///+<li>UseSlot<br>Use the File Open slot to load the extension (faster)</li>
73 '///+<li>It is recommended to use the comma as delimiter between flags</li>
77 '///<u>Return Value:</u><br>
79 '///+<li>Installation status (Integer)</li>
81 '///+<li>> 0 = Installation completed with no errors, number of installed extensions</li>
82 '///+<li>-1 = The requested extension does not exist</li>
83 '///+<li>-2 = The Add-button could not be accessed</li>
84 '///+<li>-3 = The Extension Manager did not open</li>
85 '///+<li>-4 = Unknown messagebox before the file Open dialog exists</li>
86 '///+<li>-5 = Broken dependency warning displayed</li>
87 '///+<li>-6 = The File Open dialog did not pop up</li>
91 dim flags as string : flags = lcase( _flags )
92 dim path as string : path = convertpath( _path )
93 dim bLogs as boolean : bLogs = FALSE
95 const CFN = "hExtensionAddGUI()::"
97 '///<u>Description</u>
100 ' set defaults if string is empty
101 if ( flags = "" ) then flags = "installforuser,noupdate,nolicense"
102 if ( instr( flags , "verbose" ) <> 0 ) then bLogs = TRUE
104 if ( bLogs ) then printlog( CFN & "Flags: " & flags )
106 '///+<li>Verify that the requested extension exists (filesystem level)</li>
107 if ( not FileExists( path ) ) then
108 printlog( CFN & "Requested extension does not exist" )
109 hExtensionAddGUI() = -1
116 printlog( "********** Installing extension begin **********" )
119 '///+<li>Open the Extension Manager - optionally using the slot (CWS oxtsysint01)</li>
120 if ( instr( flags , "useslot" ) <> 0 ) then
124 kontext "PackageManager"
126 if ( PackageManager.exists( 2 ) ) then
128 '///+<li>Verify that the "Add.." button is available</li>
129 if ( add.exists() and add.isEnabled() ) then
131 '///+<li>Click the "Add..." button</li>
134 printlog( CFN & "Add button is missing or disabled" )
135 hExtensionAddGUI() = -2
139 '///+<li>Test for the dreaded "The office workdirectory does not exist" warning, close it</li>
141 if ( Active.exists( 1 ) ) then
142 if ( Active.getButtonCount() = 1 ) then
143 if ( bLogs ) then printlog( Active.getText() )
146 printlog( CFN & "Unexpected/unknown messagebox" )
147 printlog( Active.getText() )
148 hExtensionAddGUI() = -4
153 '///+<li>Enter the extension name into the file picker, open the file</lI>
155 if ( OeffnenDlg.exists( 2 ) ) then
156 DateiName.setText( path )
159 printlog( CFN & "The File Open dialog did not open" )
160 hExtensionAddGUI() = -6
165 printlog( CFN & "Extension Manager is not open" )
166 hExtensionAddGUI() = -3
171 '///+<li>Test for the installation target dialog that comes up as soon as the
172 '///+ user has administrator rights or works on a userspace installation.
173 '///+ Handle the dialog as specified by the function flags</li>
174 if ( instr( flags, "installfor" ) <> 0 ) then
176 if ( Active.exists( 1 ) ) then
177 if ( Active.getButtonCount() = 3 ) then
180 printlog( CFN & "Installation target dialog found" )
181 printlog( Active.getText() )
184 if ( instr( flags , "installforall" ) <> 0 ) then
185 printlog( CFN & "Installing for all users" )
188 printlog( CFN & "Installing for user only" )
193 printlog( CFN & "Unexpected/unknown dialog" )
194 printlog( Active.getText() )
198 if ( bLogs ) then printlog( CFN & "Skipping handling of installation target" )
201 if ( bLogs ) then printlog( CFN & "Not handling userspace installations" )
204 '///+<li>Test for the broken dependencies exception, close it with ok.</li>
205 if ( instr( flags , "brokendeps" ) <> 0 ) then
206 if ( bLogs ) then printlog( CFN & "Testing for dependencies messagebox" )
207 kontext "UnsatisfiedDependencies"
208 if ( UnsatisfiedDependencies.exists( 1 ) ) then
209 printlog( CFN & "Closing Unsatisfied Dependencies dialog." )
210 UnsatisfiedDependencies.ok()
211 hExtensionAddGUI() = -5
213 printlog( CFN & "No unsatisfied dependencies dialog" )
216 if ( bLogs ) then printlog( CFN & "Skipping handling of broken dependencies dialog" )
219 '///+<li>Test for the extension update dialog which pops up if an extension
220 '///+ is already installed. Handle as specified by flags</li>
221 if ( instr( flags, "update" ) ) then
222 if ( bLogs ) then printlog( CFN & "Testing for version message/update" )
224 if ( Active.exists( 1 ) ) then
227 printlog( CFN & "Found update dialog" )
228 printlog( Active.getText() )
231 if ( Active.getButtonCount() = 2 ) then
232 if ( instr( flags, "denyupdate" ) <> 0 ) then
233 printlog( CFN & "Denying update" )
236 printlog( CFN & "Allowing update" )
240 printlog( CFN & "Unexpected/unknown dialog displayed" )
241 printlog( Active.getText() )
244 if ( instr( flags , "noupdate" ) <> 0 ) then
245 printlog( CFN & "No update dialog present. Good" )
247 printlog( CFN & "Update messagebox is missing" )
251 if ( bLogs ) then printlog( CFN & "Skipping handling of update dialog" )
254 '///+<li>Test for the Software License Agreement dialog. Handle as specified by
256 if ( instr( flags, "license" ) <> 0 ) then
257 if ( bLogs ) then printlog( CFN & "Testing software license dialog" )
258 kontext "ExtensionSoftwareLicenseAgreement"
259 if ( ExtensionSoftwareLicenseAgreement.exists( 5 ) ) then
260 if ( bLogs ) then printlog( CFN & "Software license dialog found" )
261 if ( instr( flags , "denylicense" ) <> 0 ) then
262 printlog( CFN & "Cancelling software license dialog" )
263 ExtensionSoftwareLicenseAgreement.cancel()
265 printlog( CFN & "Accepting software license" )
266 do while ( not accept.isEnabled() )
273 if ( instr( flags , "nolicense" ) <> 0 ) then
274 printlog( CFN & "No license dialog displayed. Good." )
276 warnlog( CFN & "Expected license dialog is missing" )
280 if ( bLogs ) then printlog( CFN & "Skipping handling of license dialog" )
283 '///+<li>Retrieve the number of installed extensions</li>
284 kontext "PackageManager"
286 hExtensionAddGUI() = BrowsePackages.getItemCount()
288 '///+<li>Close the Extension Manager</li>
289 PackageManager.close()
292 printlog( "********** Installing extension end **********" )
300 '*******************************************************************************
302 function hExtensionRemoveGUI( cExtensionName as string ) as integer
305 '///<h3>Remove an extension via Extension Manager </h3>
307 '///<u>Input value(s):</u><br>
309 '///+<li>UI Name of the extension (string)</li>
313 '///<u>Return Value:</u><br>
316 '///+<li>Errorcode (integer)</li>
318 '///+<li>0 = No errors, extension was removed</li>
319 '///+<li>1 = Failure to open Extension Manager (fatal)</li>
320 '///+<li>2 = Cannot delete found extension, remove-button is disabled (fatal)</li>
321 '///+<li>3 = The extension was not found (non-fatal)</li>
325 const CFN = "hExtensionRemoveGUI(): "
327 printlog( "Removing extension by name: " & cExtensionName )
330 kontext "PackageManager"
331 if ( PackageManager.exists( 2 ) ) then
333 BrowsePackages.select( cExtensionName )
334 if ( Remove.exists() ) then
335 if ( Remove.isEnabled() ) then
339 if ( Active.exists( 3 ) ) then
340 printlog( Active.getText() )
344 warnlog( CFN & "Expected confirmation dialog is missing" )
346 hExtensionRemoveGUI() = 0
348 hExtensionRemoveGUI() = 2
351 hExtensionRemoveGUI() = 4
354 hExtensionRemoveGUI() = 3
357 kontext "PackageManager"
358 PackageManager.close()
360 hExtensionRemoveGUI() = 1
365 '*******************************************************************************
367 function sExtensionCLI(sCommand as string, sExtensionName as string, optional sExtensionPath as string) as string
368 '/// Add/remove an extension with the command line tool 'unopkg'///'
369 '/// INPUT: sCommand: string of command from "add remove list reinstall" ///'
370 '/// INPUT: sExtensionName: name of the extension ///'
371 '/// INPUT: optional sExtensionPath: path to the extension ///'
372 '/// RETURN: currently nothing ///'
373 dim sLokalExtensionPath as string
374 dim sCommands as string
375 dim sUnoPkg as string
376 dim i, a, b as integer
380 Dim sContent(5) as string
381 Dim sPlatformProgramPath as string
383 if isMissing(sExtensionPath) then
384 sLokalExtensionPath = ""
386 sLokalExtensionPath = sExtensionPath
389 sCommands = "add remove list reinstall"
393 b = inStr(a-12, sAppExe, "soffice")
394 sUnoPkg = left(sAppExe, b-1) + "unopkg" + mid(sAppExe, b+len("soffice"))
396 'sUnoPkg = convertToUrl(sUnoPkg)
398 qaErrorLog ("Need to think about another solution..." + sAppExe)
400 args = sCommand+" "+sLokalExtensionPath + sExtensionName
401 printlog "Executing: "+sUnopkg+" "+args
402 if gPlatGroup <> "unx" then
403 shell(sUnoPkg,2,args)
405 sFile = ConvertPath (gOfficePath + "user/work/uno.sh")
406 if gPlatform = lcase("osx") then
407 sPlatformProgramPath = "MacOS"
409 sPlatformProgramPath = "program"
411 sEnv = convertToURL(convertPath(gNetzOfficePath + sPlatformProgramPath + "/fundamentalrc")
412 listAppend(sContent(), "export URE_BOOTSTRAP=" + sEnv)
413 listAppend(sContent(), sUnoPkg + " " + args)
414 listWrite(sContent(), sFile)
415 shell("bash",1,sFile)
419 '*******************************************************************************
421 function hExtensionGetItemList( cItemList() as string ) as integer
423 '///<h3>Get the list of all items in the extensions list</h3>
424 '///<i>The array contains the list of all items in the extension manager GUI,
425 '///+ including all components of the extensions. Consider this when defining
426 '///+ the size of the array to be passed to this function as problems here are
427 '///+ hard to debug.<br>
428 '///+ Starting point is any document, the function will return to the
429 '///+ calling document on completion</i><br><br>
433 '///+<li>Array for the list items (string)</li>
437 '///<u>Return Value:</u><br>
439 '///+<li>Number of items (integer)</li>
441 '///+<li>0 on any error</li>
442 '///+<li>2 if no extensions exist (My Macros/OpenOffice.org macros nodes present</li>
443 '///+<li>> 2 if any changes to the default exist</li>
447 dim iItemCount as integer
448 dim iCurrentExtension as integer
450 printlog( "Retrieving extension list" )
453 kontext "PackageManager"
454 if ( PackageManager.exists( 2 ) ) then
456 iItemCount = BrowsePackages.getItemCount()
458 for iCurrentExtension = 1 to iItemCount
459 cItemList( iCurrentExtension ) = BrowsePackages.getItemText( iCurrentExtension , 1 )
460 printlog( " * " & cItemList( iCurrentExtension )
461 next iCurrentExtension
463 hExtensionGetItemList() = iItemCount
464 cItemList( 0 ) = iItemCount
465 PackageManager.close()
469 hExtensionGetItemList() = 0
475 '*******************************************************************************
477 function hSelectExtensionID( iPos as integer ) as string
479 '///<h3>Select an item by index in the list of available extensions</h3>
480 '///<i>This function needs the Extension Manager to be open. It will only
481 '///+ select extensions but not their components.</i><br><br>
485 '///+<li>Absolute position of the extension to be selected (Integer)</li>
488 '///<u>Return Value:</u><br>
490 '///+<li>Name of the selected extension (String)</li>
491 '///+<li>Empty string on index out of range or Extension Manager not open</li>
494 printlog( "Selecting extension at pos. " & iPos )
497 kontext "PackageManager"
498 if ( PackageManager.exists( 2 ) ) then
500 BrowsePackages.select( iPos )
501 hSelectExtensionID() = BrowsePackages.getItemText( iPos , 1 )
503 hSelectExtensionID() = ""
505 PackageManager.close()
507 hSelectExtensionID() = ""
513 '*******************************************************************************
515 function hSelectExtensionName( cName as string ) as integer
517 '///<h3>Select an item by name in the list of available extensions</h3>
518 '///<i>This function needs the Extension Manager to be open. It will only
519 '///+ select extensions but not their components.</i><br><br>
523 '///+<li>Name of the extension (String)</li>
525 '///+<li>Name of any item in the treelist, even those of top nodes</li>
529 '///<u>Return Value:</u><br>
531 '///+<li>Absolute position of the selected extension (Integer)</li>
533 '///+<li>0 = Extension was not found</li>
534 '///+<li>> 0 = Absolute position of the extension/node</li>
535 '///+<li>-1 = Extension Manager did not open</li>
539 printlog( "Selecting extension by display name: " & cName )
542 kontext "PackageManager"
543 if ( PackageManager.exists( 2 ) ) then
545 BrowsePackages.select( cName )
546 hSelectExtensionName() = BrowsePackages.getSelIndex()
548 hSelectExtensionName() = 0
550 PackageManager.close()
552 hSelectExtensionName() = -1
559 '*******************************************************************************
561 function hSelectOptionsItem( cName as string, iIndex as integer ) as integer
563 '///<h3>Select an item in Tools/Options and verify</h3>
564 '///<i>You need to open the Tools/Options dialog before using this function,
565 '///+ it will not close the dialog either. No warnlogs are printed so evaluation
566 '///+ of the return value is mandatory</i><br><br>
568 '///<u>Parameter(s):</u><br>
571 '///+<li>Name of the extension node (string)</li>
573 '///+<li>Name of the module</li>
574 '///+<li>Name of the leaf</li>
575 '///+<li>Node must be valid</li>
578 '///+<li>Position of the node (absolute) (integer)</li>
580 '///+<li>All nodes are expanded</li>
581 '///+<li>Position must be valid (> 0 and ≤ number of nodes in list)</li>
587 '///<u>Returns:</u><br>
589 '///+<li>Errorcondition (integer)</li>
591 '///+<li>0 = Success</li>
592 '///+<li>1 = Partial success - node is at wrong position</li>
593 '///+<li>2 = Node does not exist</li>
594 '///+<li>3 = Dialog not open</li>
595 '///+<li>4 = Index out of range (incorrect call to function)</li>
599 const CFN = "hSelectOptionsItem::"
600 printlog( CFN & "Enter with option (Name).: " & cName )
601 printlog( CFN & "Enter with option (Index): " & iIndex )
603 dim brc as boolean ' a multi purpose boolean returnvalue
604 dim irc as integer ' a multi purpose integer returnvalue
605 dim crc as string ' a multi purpose string returnvalue
607 '///<u>Description:</u>
609 '///+<li>Make sure we are on the Tools/Options dialog</li>
610 kontext "OptionenDlg"
611 if ( not OptionenDlg.exists( 2 ) ) then
612 warnlog( CFN & "Tools/Options is not open, aborting" )
613 hSelectOptionsItem() = 3
617 '///+<li>Expand all nodes on "OptionsListe"</li>
618 irc = hExpandAllNodes( OptionsListe )
619 if ( irc < iIndex ) then
620 warnlog( CFN & "Index out of range, quitting" )
621 hSelectOptionsItem() = 4
625 '///+<li>Search for the node at the given index, handle errors, exit function</li>
626 crc = hSelectNode( OptionsListe , iIndex )
628 ' if the name of the node at given position is ok ...
629 if ( crc = cName ) then
630 printlog( CFN & "Exit: The node was found: " & crc )
631 hSelectOptionsItem() = 0
634 ' if the name is not ok, try to find the node by name
636 printlog( CFN & "Node not found at expected position, retrying" )
637 irc = hSelectNodeByName( OptionsListe , cName )
639 ' if the node is found it is just at the wrong position - bad but not deadly
641 qaerrorlog( CFN & "Exit: Node <" & cName & "> found at pos: " & irc )
642 hSelectOptionsItem() = 1
645 ' if the node was not found at all this is really bad.
647 warnlog( CFN & "Exit: Node does not exist: " & cName )
648 hSelectOptionsItem() = 3
658 '*******************************************************************************
660 function hIsExtensionAlreadyInstalled( cName as string ) as boolean
662 '///<h3>Check if an extension is already installed</h3>
663 '///<i>The function opents the Extension Manager, finds (or not) the extension
664 '///+ and returns an appropriate return value. The Extension Manager is
665 '///+ closed again at the end.</i><br><br>
669 '///+<li>Name of the extension (String)</li>
672 '///<u>Return Value:</u><br>
674 '///+<li>is the extension allredy installed (boolean)</li>
676 '///+<li>FALSE = Extension is not installed</li>
677 '///+<li>FALSE = Extension Manager did not open</li>
678 '///+<li>TRUE = Extension is installed</li>
682 printlog( "Checking if extension is already installed: " & cname )
684 dim iCountExtensions as integer
687 hIsExtensionAlreadyInstalled() = FALSE
690 kontext "PackageManager"
692 iCountExtensions = BrowsePackages.getItemCount()
694 for i = 1 to iCountExtensions
695 if(Instr(BrowsePackages.getItemText(i,1),cname) <> 0) then
696 hIsExtensionAlreadyInstalled() = TRUE
700 PackageManager.close()
705 '*******************************************************************************
707 function hDisableUserExtensionGUI( extension_name as string ) as integer
709 '///<h3>Disable a userspace extension by name via GUI</h3>
710 '///<i>This function tries to disable an Extension specified by name. There
711 '///+ are several reasons why this might fail so it is required to evaluate the
712 '///+ returnvalue as the function will not print any warnings. If the function
713 '///+ fails this is most likely caused by a) the extension already being
714 '///+ disabled or b) the extension belonging to the shared layer.<br>
715 '///+ The Extension Manager needs to be open when function is called.</i><br><br>
717 '///<u>Parameter(s):</u><br>
720 '///+<li>Name of the extension to be disabled (string)</li>
722 '///+<li>Only extensions from the user layer can be disabled</li>
728 '///<u>Returns:</u><br>
730 '///+<li>Errorcondition (integer)</li>
732 '///+<li>0 = Extension was found and disabled</li>
733 '///+<li>1 = Extension does not exist</li>
734 '///+<li>2 = Extension could not be disabled</li>
735 '///+<li>3 = Extension Manager did not open</li>
738 printlog( "Disabling user extension" )
741 kontext "PackageManager"
742 if ( PackageManager.exists( 2 ) ) then
744 BrowsePackages.select( extension_name )
745 if ( Disable.exists() and Disable.isEnabled() ) then
746 hDisableUserExtensionGUI() = 0
748 hDisableUserExtensionGUI() = 2
750 PackageManager.close()
752 hDisableUserExtensionGUI() = 1
755 hDisableUserExtensionGUI() = 3
760 '*******************************************************************************
762 function hGetExtensionCount() as integer
764 printlog( "Getting number of installed extensions." )
767 kontext "PackageManager"
768 if ( PackageManager.exists( 2 ) ) then
770 hGetExtensionCount() = BrowsePackages.getItemCount()
771 PackageManager.close()
773 hGetExtensionCount() = -2
776 hGetExtensionCount() = -1