issue-#181 fixing error handling of HostDialog.OpenExternal

issue-#181 fixing error handling of HostDialog.OpenExternal

Postby Josef Templ » Mon Nov 06, 2017 7:26 pm

Based on the discussion starting in https://forum.blackboxframework.org/viewtopic.php?f=50&t=385&start=80#p6578 I have created issue-#181 https://redmine.blackboxframework.org/issues/181.

An experimental version is committed in http://blackboxframework.org/unstable/issue-%23181/blackbox-1.7.1-rc1.985.zip.

See diffs at https://redmine.blackboxframework.org/projects/blackbox/repository/diff?utf8=%E2%9C%93&rev=297ef4056da81267ed90c6ca289feba6bdc37419&rev_to=e618a693f31551c13a49445d51835d39ecd38fe0.

I have done the following changes:
1. I added error messages in the form of a Windows message box for the most common types of errors.
Note: Everything inside HostDialog.OpenExternal runs in a separate thread. Care must be taken not to use the BlackBox runtime system, in particular the heap.

2. Under wine I first try the wine associations and if that fails with any kind of association error I retry with 'winebrowser ' prepended.
If that also fails, the error message refers to the original wine association.

3. I added Host/Rsrc/Strings resources for the error messages.

- Josef
User avatar
Josef Templ
 
Posts: 2038
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#181 fixing error handling of HostDialog.OpenExter

Postby Zinn » Mon Nov 06, 2017 11:37 pm

Error message as modal dialog is not a good idea. That stops the BlackBox program until OK is clicked. Better is to write the message into the Log windows and BlackBox continues.
- Helmut
Zinn
 
Posts: 472
Joined: Tue Mar 25, 2014 5:56 pm
Location: Frankfurt am Main

Re: issue-#181 fixing error handling of HostDialog.OpenExter

Postby Josef Templ » Tue Nov 07, 2017 1:36 am

Zinn wrote:Error message as modal dialog is not a good idea. That stops the BlackBox program until OK is clicked. Better is to write the message into the Log windows and BlackBox continues.
- Helmut


This is what I also expected. But what I have seen in my experiments is that a modal dialog does not stop BlackBox.
It only blocks the delivery of mouse and keyboard messages but actions continue to run.

Note: The special problem to consider here is that the error message is produced by a parallel thread.
Any interaction with the main thread must be avoided because BlackBox is single-threaded.

- Josef
User avatar
Josef Templ
 
Posts: 2038
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#181 fixing error handling of HostDialog.OpenExter

Postby Zinn » Tue Nov 07, 2017 8:43 am

I observe that my sample
(!)"Dialog.OpenExternal('Test/Docu/Buch2.pdf')"
reports the correct error message: File 'Test/Docu/Buch2.pdf' not found.
and the sample
(!)"Dialog.OpenExternal('Test/Docu/Buch.pdf')"
opens correctly the pdf file.
It is a big improvement.

That is the result in Wine.
In Windows the second sample produce the error message File 'Test/Docu/Buch.pdf' not found.
There I have to enter the absolut path otherwise file is not found.

A solution may be insert before the Wine test:

IF res = WinApi.SE_ERR_FNF THEN
(* Open failed use absolute filename and try again - Windows only *)
res := WinApi.GetFullPathNameW(fileName, LEN(wine_fileName), wine_fileName, np);
res := WinApi.ShellExecuteW(0, NIL, wine_fileName, NIL, NIL, WinApi.SW_SHOWNORMAL);
END;

- Helmut
Zinn
 
Posts: 472
Joined: Tue Mar 25, 2014 5:56 pm
Location: Frankfurt am Main

Re: issue-#181 fixing error handling of HostDialog.OpenExter

Postby Zinn » Tue Nov 07, 2017 2:48 pm

Now we have nice error reporting in Dialog.OpenExternal.

The same is missing in Dialog.RunExternal, e.g.

(!)"Dialog.RunExternal('notepad.exe')"
opens the notepad.

(!)"Dialog.RunExternal('notepad2.exe')"
nothing happens even no error messages.

- Helmut
Zinn
 
Posts: 472
Joined: Tue Mar 25, 2014 5:56 pm
Location: Frankfurt am Main

Re: issue-#181 fixing error handling of HostDialog.OpenExter

Postby Zinn » Tue Nov 07, 2017 3:00 pm

Occasionally we need in Dialog.OpenExternal
wine_fileName := "winebrowser " + fileName$;
instead of fileName only.

The same situation we have in Dialog.RunExternal. There we need occasionally
wine_exeName := "wineconsole " + exeName$;
instead of exeName only.

E.g. we need wineconsole
(!)"Dialog.RunExternal('cmd')"
(!)"Dialog.RunExternal('cmd /k dir')"

E.g. works without wineconsole
(!)"Dialog.RunExternal('cmd /k regedit')"
(!)"Dialog.RunExternal('cmd /c start /unix /usr/bin/gedit')"

- Helmut
Zinn
 
Posts: 472
Joined: Tue Mar 25, 2014 5:56 pm
Location: Frankfurt am Main

Re: issue-#181 fixing error handling of HostDialog.OpenExter

Postby Josef Templ » Tue Nov 07, 2017 5:03 pm

Zinn wrote:Occasionally we need in Dialog.OpenExternal
wine_fileName := "winebrowser " + fileName$;
instead of fileName only.

The same situation we have in Dialog.RunExternal. There we need occasionally
wine_exeName := "wineconsole " + exeName$;
instead of exeName only.

E.g. we need wineconsole
(!)"Dialog.RunExternal('cmd')"
(!)"Dialog.RunExternal('cmd /k dir')"

E.g. works without wineconsole
(!)"Dialog.RunExternal('cmd /k regedit')"
(!)"Dialog.RunExternal('cmd /c start /unix /usr/bin/gedit')"

- Helmut


>> (!)"Dialog.OpenExternal('Test/Docu/Buch.pdf')"
You have to use \ under Windows, I think.
Sometimes / is also supported but I don't know the rule behind it.
wine will probably support both.

RunExternal can of course also be improved but let us focus on OpenExternal first.

What do you mean by "Occasionally"? Can you give a rule?

- Josef
User avatar
Josef Templ
 
Posts: 2038
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#181 fixing error handling of HostDialog.OpenExter

Postby Josef Templ » Wed Nov 08, 2017 7:38 am

There seems to be a real wine bug with the implementation of "cmd".
Unfortunately there is no error code returned for the failing examples so it is not easily possible to
retry with wineconsole prepended.

The bug is not easy to see but I think I know it.

It is possible to prepend "wineconsole " explicitly in the RunExternal command.
If it is considered important to be portable, it is possible to detect the special command start "cmd " and prepend "wineconsole " only for that special pattern.
I don't know how important it is to be portable in this case.

- Josef
User avatar
Josef Templ
 
Posts: 2038
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#181 fixing error handling of HostDialog.OpenExter

Postby Josef Templ » Wed Nov 08, 2017 11:23 am

I have now added some error messages also for RunExternal.
In addition, I have added a work-around a bug in wine when calling 'cmd'.
In this case, 'wineconsole ' is prepended.

The diffs are https://redmine.blackboxframework.org/projects/blackbox/repository/diff?utf8=%E2%9C%93&rev=22608024f21a9f8f22d42208399b8263cce82514&rev_to=297ef4056da81267ed90c6ca289feba6bdc37419.

For testing please use http://blackboxframework.org/unstable/issue-%23181/blackbox-1.7.1-rc1.988.zip.

- Josef
User avatar
Josef Templ
 
Posts: 2038
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#181 fixing error handling of HostDialog.OpenExter

Postby Zinn » Thu Nov 09, 2017 7:02 am

Now the implementation of OpenExternal & RunExternal is much better.
Josef improved
- the error handling
- solved the winebrowser problem
- added wineconsole
But there are still some differences to the CPC edition. Would you like to know?

One differences is that windows need absolute path name for OpenExternal and does not open a file with relative path name (file not found).
This I already reported above. It doesn’t matter if you use ‘/’ or ‘\’ the behaviour is the same.

- Helmut
Zinn
 
Posts: 472
Joined: Tue Mar 25, 2014 5:56 pm
Location: Frankfurt am Main

Next

Return to Resolved (Bugs)

Who is online

Users browsing this forum: No registered users and 1 guest

cron