EWriter file issue

Please post all questions and comments regarding Help & Manual 7 here.

Moderators: Alexander Halser, Tim Green

Post Reply
User avatar
Martin Wynne
Posts: 2656
Joined: Mon May 12, 2003 3:21 pm
Location: West of the Severn, UK

EWriter file issue

Unread post by Martin Wynne »

When EWriter is used with a separate data package file, it keeps the data file open. For no obvious reason, because it should never need to write to it.

Users of my application may start EWriter (with a data package file), and then close my application leaving EWriter running. If they then try to re-start my application they get a file access violation. That's because during startup my application tests for the existence of the data package and updates it from the server if necessary. It can't do that if the file is still open in EWriter.

I have added an exception trap to catch that and warn the user to close EWriter before re-starting my application.

But it would be much better if EWriter simply closed the file after loading it. Is that possible please?

regards,

Martin.
User avatar
Tim Green
Site Admin
Posts: 23155
Joined: Mon Jun 24, 2002 9:11 am
Location: Bruehl, Germany
Contact:

Re: EWriter file issue

Unread post by Tim Green »

Hi Martin,

Interesting, I've asked Alex to look into it. In the meantime, you could just call my_book.exe close from your application when the user closes it. That would then be the same functionality as programs linked to CHM files, which also automatically close the CHM viewer when they close.
Regards,
Tim (EC Software Documentation & User Support)

Private support:
Please do not email or PM me with private support requests -- post to the forum directly.
User avatar
Alexander Halser
EC-Software Support
Posts: 4098
Joined: Mon Jun 24, 2002 7:24 pm
Location: Salzburg, Austria
Contact:

Re: EWriter file issue

Unread post by Alexander Halser »

The external ebook files are kept in non-exclusive read-only access. They need to be kept open, because the viewer needs to access the data. If the file gets closed, it needs to re-open it, re-initialize the internal content and the configuration. So, it's normal that the data file is in kept open with read access and you cannot replace it while it is being viewed.
But it would be much better if EWriter simply closed the file after loading it. Is that possible please?
No. Those data files could be way to big and the viewer is not designed to keep the entire stuff in memory.
Alexander Halser
Senior Software Architect, EC Software GmbH
User avatar
Martin Wynne
Posts: 2656
Joined: Mon May 12, 2003 3:21 pm
Location: West of the Severn, UK

Re: EWriter file issue

Unread post by Martin Wynne »

Tim Green wrote:In the meantime, you could just call my_book.exe close from your application when the user closes it. That would then be the same functionality as programs linked to CHM files, which also automatically close the CHM viewer when they close.
Hi Tim, Alex,

Thanks for your replies. Is it documented anywhere that EWriter honours the 'close' parameter? I have been trying to use the Windows API DestroyWindow function, without much success.

But I have now tested 'close' and it works fine, so many thanks for that. :)

However I don't want to close EWriter when my application closes, because it is quite possible that a user wants it to remain open. For the links to videos and interactive tutorials for example. Also the Keyword Index is a lot easier to use in the V2 skins than the online responsive V3 index.

But I will now close it, if found open, when my application starts, and re-open it once up and running. I didn't expect that to work from a fresh application instance, but it does! Many thanks.

Are there any other undocumented parameters which the EWriter executable honours? For example it might be useful to Minimize/Restore it from my application.

I have already discovered that once it is open, EWriter will display a topic without the navigation frame if called simply with the topic URL (topic_file.html), and ignores the Webhelp option setting to force open the navigation frame. This could potentially be very useful to replace various alert messages and warnings within my application (i.e. not in the TOC or Index), which could then be updated at will.

regards,

Martin.
Simon Dismore
Posts: 454
Joined: Thu Nov 16, 2006 1:29 pm
Location: London, UK

Re: EWriter file issue

Unread post by Simon Dismore »

Alexander Halser wrote:the data file is in kept open with read access and you cannot replace it while it is being viewed
@Alexander, would this work?
  1. Assume my viewer program is already displaying the old data file.
  2. My application program (app) successfully downloads the new data file (either to temp location or using temp filename in final location), verifies checksum etc.
  3. My app temporarily selects one of the viewer's built-in topics, e.g. my_viewer.exe "updating.html"
    Question is: does the viewer close the old data file when that happens?
  4. My app then deletes the old data file and moves/renames the newly downloaded file.
  5. My app now tells the viewer to load the new file, e.g. my_viewer.exe "<path>\mybook.ebk" "index.html"
If this technique is supported in the current version, it could be enhanced in future so that the viewer (or a separate updater tool) does all the work* to keep its title(s) updated, without needing any changes to the application(s). That might be a significant advantage compared with CHM and PDF documentation.

*Could include background polling and/or "push" notifications to detect version changes, plus local storage to keep track of versions and current topic. Some sort of "code signing" for ebooks and viewers would be advisable too, otherwise the Links to executable files could be a major security hole.
Last edited by Simon Dismore on Mon Jul 18, 2016 11:36 am, edited 3 times in total.
Simon Dismore
Posts: 454
Joined: Thu Nov 16, 2006 1:29 pm
Location: London, UK

Re: EWriter file issue

Unread post by Simon Dismore »

Martin Wynne wrote:Is it documented anywhere that EWriter honours the 'close' parameter
http://help.ec-software.com/hm_application_links_to_ewriter.htm?zoom_highlightsub=close
User avatar
Martin Wynne
Posts: 2656
Joined: Mon May 12, 2003 3:21 pm
Location: West of the Severn, UK

Re: EWriter file issue

Unread post by Martin Wynne »

Many thanks Simon.

I have not much of a leg to stand on, when telling my users to RTFM. :)

Martin.
User avatar
Alexander Halser
EC-Software Support
Posts: 4098
Joined: Mon Jun 24, 2002 7:24 pm
Location: Salzburg, Austria
Contact:

Re: EWriter file issue

Unread post by Alexander Halser »

Martin,
Your program should close the viewer / data file before it updates the help data. The /close parameter was introduced for exactly this reason - to be able to deliberately close the help viewer/file from your code.

I suggest to implement a "help close" function in your application, that does the following steps:

a) Test the help file(s) if they are in use by attempting to open the file read-only but exclusively.
b) If that fails, the help file is in use -> run the viewer for this data file with the /close parameter

This function should be called by code when your application closes, to make sure that the help does not stay open (this will result in a similar behaviour as CHM files). Before you update the content, call the function as well (attempt to close the file), then double-test with (a).

I would actually go a different way for help content updates: If the target help file cannot be accessed because it is in use, ask in a loop to close the help file in order to update it. If the action gets canceled by the user, exit. If not, repeat the loop until you have access to the data file. This is the safest, politest and most transparent way for the end user to handle it, I'd say.
Alexander Halser
Senior Software Architect, EC Software GmbH
User avatar
Martin Wynne
Posts: 2656
Joined: Mon May 12, 2003 3:21 pm
Location: West of the Severn, UK

Re: EWriter file issue

Unread post by Martin Wynne »

Thanks Alexander.

I don't want to close EWriter when my program closes because I think some users (me included) may want to leave it running (if only for the Keyword Index to the online responsive Webhelp).

Instead I'm testing for it on program startup, and closing it if found running, like this:

Code: Select all

function close_ewriter:integer;

var
  viewer_str,content_str,app_name_str:string;
  window_handle:integer;

begin
  app_name_str:='My Help Project';    // H&M project title
  
  window_handle:=FindWindow(nil,PChar(app_name_str));
  
  if window_handle<>0    // ewriter running
     then begin
            viewer_str:=ExtractFilePath(Application.ExeName)+'ewriter_viewer.exe';
            content_str:='close';

            if ShellExecute(0,'open',PChar(viewer_str),PChar(content_str),nil,SW_SHOWNORMAL)<=32
               then ShowMessage('Error - unable to close the integrated Help viewer.');
          end;

  RESULT:=window_handle;
end;
Before updating the data files I'm checking again that this function returns 0. Then only after the files have been updated from the server the various Help menu items and Help buttons are enabled. The files are updated only during startup.

The file updater is additionally trapping any exceptions and warning the user of an error and to close EWriter.

This all seems to be working fine.

regards,

Martin.
Last edited by Martin Wynne on Mon Jul 18, 2016 9:43 pm, edited 2 times in total.
User avatar
Alexander Halser
EC-Software Support
Posts: 4098
Joined: Mon Jun 24, 2002 7:24 pm
Location: Salzburg, Austria
Contact:

Re: EWriter file issue

Unread post by Alexander Halser »

2.My app temporarily selects one of the viewer's built-in topics, e.g. my_viewer.exe "updating.html"
Question is: does the viewer close the old data file when that happens?
The data file stays open in that case. The viewer has a built-in function to not open the same data file twice. If you happen to make a secondary call to "my_viewer.exe" (without a data file parameter), the viewer will bring the first instance into foreground and the second instance (that is inevitably launched by Windows) will silently close without showing up. This feature is essential to do context-senstive help calls with eBooks.

When you use the viewer with a data file parameter (e.g. "my_viewer.exe mydatafile.help"), the function checks the data file, not for executable itself. In other words, it is possible to launch 2 or more instances of "my_viewer.exe" with different data files. But it is not possible to launch "my_viewer.exe" with the same data file twice. This, again, is essential to make context-sensitive help calls.

Your context-sensitive help call with "updating.html" is not relevant in both cases. You can do consecutive help calls like this without creating two instances of the viewer:

my_viewer.exe "updating.html"
my_viewer.exe "index.html"

With a separate data file, it looks like this:

my_viewer.exe "mydatafile.help" "updating.html"
my_viewer.exe "mydatafile.help" "index.html"

Result: still just 1 instance of the same eBook executable.

To close it, run:
my_viewer.exe "mydatafile.help" close
Alexander Halser
Senior Software Architect, EC Software GmbH
Simon Dismore
Posts: 454
Joined: Thu Nov 16, 2006 1:29 pm
Location: London, UK

Re: EWriter file issue

Unread post by Simon Dismore »

Alexander Halser wrote:it is possible to launch 2 or more instances of "my_viewer.exe" with different data files
That's not working for me, I'm afraid. These are the steps I did
  1. Environment was H&M 7.1.0 build 3925, WIndows 8.1 Pro 64-bit, 24GB RAM, Xeon, Nvidia K2000.
  2. Compile Get Me Started Example to ewriter Get_Me_Started_Help.exe
  3. Copy Get_Me_Started_Help.exe and rename the copy as viewer.exe
  4. Compile Interactive Media example to ewriter InteractiveMedia_Help.ebk
  5. Compile Conditional Output example to ewriter CondOutput_Help.ebk
  6. Copy all four files (two .exes, two .ebks) to network share W:\hm\eWriter_tests
  7. Create shortcuts:
    W:\hm\eWriter_tests\viewer.exe close
    W:\hm\eWriter_tests\viewer.exe CondOutput_Help.ebk
    W:\hm\eWriter_tests\viewer.exe CondOutput_Help.ebk close
    W:\hm\eWriter_tests\viewer.exe InteractiveMedia_Help.ebk
    W:\hm\eWriter_tests\viewer.exe InteractiveMedia_Help.ebk close
  8. Launch viewer.exe
  9. Launch viewer.exe CondOutput_Help.ebk
    second viewer instance is not launched, instead existing viewer content is replaced
  10. Launch viewer.exe InteractiveMedia_Help.ebk close
    viewer instance is closed, even though that's not the open data file
This happens whether I use shortcuts or command window or combinations mixing both, "run as administrator" etc. The only way I can get two simultaneous instances is to run Get_Me_Started_Help.exe and viewer.exe. Have I misunderstood something?
User avatar
Alexander Halser
EC-Software Support
Posts: 4098
Joined: Mon Jun 24, 2002 7:24 pm
Location: Salzburg, Austria
Contact:

Re: EWriter file issue

Unread post by Alexander Halser »

Hi Simon,

You are correct, the ebook viewer must take the data file into account and open a second instance. The problem has been fixed with build 3971 (7.2 beta), which is already available from this link:

http://download.ec-software.com/help-an ... 0-beta.exe
Alexander Halser
Senior Software Architect, EC Software GmbH
Simon Dismore
Posts: 454
Joined: Thu Nov 16, 2006 1:29 pm
Location: London, UK

Re: EWriter file issue

Unread post by Simon Dismore »

Alexander Halser wrote:The problem has been fixed with build 3971 (7.2 beta)
I've repeated my test using build 3971 on the same platform, and steps 8 and 9 now behave as expected. Bug closed :)
Post Reply