summaryrefslogtreecommitdiff
path: root/wizards
diff options
context:
space:
mode:
authorJean-Pierre Ledure <jp@ledure.be>2024-03-23 17:41:49 +0100
committerJean-Pierre Ledure <jp@ledure.be>2024-03-24 17:35:49 +0100
commite110974bc1c2a0b253d27cf3ad2643aa5208e2cd (patch)
treef302c8f732340f8c61ccae26966a203a276dd16b /wizards
parentee2afff68ed5b22b2bf635d536584e8cba4ae2a4 (diff)
ScriptForge (session).RunApplication() redesign
The RunApplication() method uses - either the Shell() Basic built-in function (only in asynchronous mode) - or the com.sun.star.system.SystemShellExecute() service in this order. The second is tried in case of failure of the first one. Benefits: - the method can start batch files or scripts - broader than Shell(): giving a user file as argument opens its application first based on the file suffix - more robust error handling Read discussion in tdf#160222. This change could require a light revisit of the sf_session help page. Change-Id: I1fb4717db4b971bd62885ad0e38b7c08a8e6f434 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165218 Reviewed-by: Jean-Pierre Ledure <jp@ledure.be> Tested-by: Jenkins
Diffstat (limited to 'wizards')
-rw-r--r--wizards/source/scriptforge/SF_Session.xba26
1 files changed, 23 insertions, 3 deletions
diff --git a/wizards/source/scriptforge/SF_Session.xba b/wizards/source/scriptforge/SF_Session.xba
index 307fb7a8f4bf..cc6e576e1c5f 100644
--- a/wizards/source/scriptforge/SF_Session.xba
+++ b/wizards/source/scriptforge/SF_Session.xba
@@ -563,9 +563,12 @@ Public Function RunApplication(Optional ByVal Command As Variant _
&apos;&apos;&apos; The method does not validate the given parameters, but only passes them to the specified command
&apos;&apos;&apos; Returns:
&apos;&apos;&apos; True if success
+&apos;&apos;&apos; Exceptions:
+&apos;&apos;&apos; UNKNOWNFILEERROR Command could not be identified as a valid file
&apos;&apos;&apos; Examples:
&apos;&apos;&apos; session.RunApplication(&quot;Notepad.exe&quot;)
&apos;&apos;&apos; session.RunApplication(&quot;C:\myFolder\myDocument.odt&quot;)
+&apos;&apos;&apos; session.RunApplication(&quot;kate&quot;) &apos; (Linux)
&apos;&apos;&apos; session.RunApplication(&quot;kate&quot;, &quot;/home/me/install.txt&quot;) &apos; (Linux)
Dim bReturn As Boolean &apos; Returned value
@@ -585,9 +588,23 @@ Check:
End If
Try:
- Set oShell = SF_Utils._GetUNOService(&quot;SystemShellExecute&quot;)
- sCommand = SF_FileSystem._ConvertToUrl(Command)
- oShell.execute(sCommand, Parameters, com.sun.star.system.SystemShellExecuteFlags.DEFAULTS)
+ &apos; Cfr. discussion tdf#160222
+ &apos; 1) Try Shell(), always in not synchronized mode
+ &apos; 2) If failure - check command existence as a valid file
+ &apos; - try com.sun.star.system.SystemShellExecute
+ sCommand = SF_FileSystem._ConvertFromUrl(Command)
+ On Local Error GoTo Step2
+ Shell(sCommand, , Parameters, False)
+ Step2:
+ If Err &gt; 0 Then
+ On Error GoTo 0 &apos; Reset error status
+ If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
+ If Not SF_FileSystem.FileExists(Command) Then GoTo CatchNotExists
+ Set oShell = SF_Utils._GetUNOService(&quot;SystemShellExecute&quot;)
+ sCommand = SF_FileSystem._ConvertToUrl(Command)
+ oShell.execute(sCommand, Parameters, com.sun.star.system.SystemShellExecuteFlags.DEFAULTS)
+ End If
+
bReturn = True
Finally:
@@ -596,6 +613,9 @@ Finally:
Exit Function
Catch:
GoTo Finally
+CatchNotExists:
+ SF_Exception.RaiseFatal(UNKNOWNFILEERROR, &quot;Command&quot;, Command)
+ GoTo Finally
End Function &apos; ScriptForge.SF_Session.RunApplication
REM -----------------------------------------------------------------------------