Page 1 of 1

Problem saving as HTML on UNC with pictures

Posted: Thu Jun 11, 2015 7:53 am
by Hillebrandt
Hi,

if i use

Code: Select all

...
var
  ...
  rveMail : TRichViewEdit;
  sPath1, sPath2 : String;
...
begin
  ...
  sPath1 := 'C:\MyApp\Data\';
  sPath2 := '\\server\MyApp\Data\';
  ...
  rveMail.SaveHtml(
    sPath1 + 'temp.html',
    'EMailEditorRv-Design',
    sPath1,
    [rvsoOverrideImages, rvsoUTF8]
  );
  ...
end;
it worked fine, with saving images. Bur if I use sPath2 instead it
doesn't work.

When I change CRVData TCustomRVData.GetNextFileName
from

Code: Select all

function TCustomRVData.GetNextFileName(const ImagesPrefix, Path, Ext: String;
  var imgSaveNo: Integer; OverrideFiles: Boolean): String;
var FullPath: String;
begin
  if {$IFDEF RICHVIEWCBDEF3}AnsiPos{$ELSE}Pos{$ENDIF}(':',ImagesPrefix)>0 then
    FullPath := ImagesPrefix
  else
    FullPath := Path+ImagesPrefix;
  while True do begin
    inc(imgSaveNo);
    Result := FullPath+IntToStr(imgSaveNo)+Ext;
    if not FileExists(Result) then
      exit;
    {$WARNINGS OFF}
    if OverrideFiles and ((FileGetAttr(Result) and faReadOnly)=0) then
      exit;
    {$WARNINGS ON}
  end;
end;
to

Code: Select all

function TCustomRVData.GetNextFileName(const ImagesPrefix, Path, Ext: String;
  var imgSaveNo: Integer; OverrideFiles: Boolean): String;
var FullPath: String;
begin
  if ({$IFDEF RICHVIEWCBDEF3}AnsiPos{$ELSE}Pos{$ENDIF}(':',ImagesPrefix)>0) OR
     (copy(ImagesPrefix, 1, 2) = '\\') then
    FullPath := ImagesPrefix
  else
    FullPath := Path+ImagesPrefix;
  while True do begin
    inc(imgSaveNo);
    Result := FullPath+IntToStr(imgSaveNo)+Ext;
    if not FileExists(Result) then
      exit;
    {$WARNINGS OFF}
    if OverrideFiles and ((FileGetAttr(Result) and faReadOnly)=0) then
      exit;
    {$WARNINGS ON}
  end;
end;
it do what I need it to do.
Is there a other way to do saving so that the complete Path for the
embedded images would be written in the HTML, or can you do
the change I do for everyone? Or in another way,
so that I can use "SaveHTML" for an UNC-Path correctly?
I hope the change I do is a good idea and
can be found his way into the next update! :-)

Greetings from Germany
Hillebrandt

Posted: Mon Jul 06, 2015 7:43 am
by Hillebrandt
[[Push]]

What about this "problem"?
We doesn't like to do changes on source of third-party-software,
so please insert this or find a better (righter) way to resolve
the described error.

Greetings from Germany
Hillebrandt

Posted: Tue Jul 07, 2015 10:03 am
by Sergey Tkachenko
Sorry for the delay.

You can use OnHTMLSaveImage2 event.
In this event, you can save the picture yourself where you need, a provide a string that will be inserted in <img src>.

Posted: Tue Jul 07, 2015 10:46 am
by Hillebrandt
Hi Mr. Sergey Tkachenko,
Sergey Tkachenko wrote:Sorry for the delay. ...
I was in vacation, too! ;-)
Sergey Tkachenko wrote:You can use OnHTMLSaveImage2 event.
In this event, you can save the picture yourself where you need,
a provide a string that will be inserted in <img src>.
Ok, for now, I have problem rebuilding the problem,
when I undo my changees I'm not able to reproduce the error. :oops:
I come back and report, If I found out what to do.
I'm sure it happens on loading and not on saving, but whatever.

Greetings from Germany
Hillebrandt

Re: Problem saving as HTML on UNC with pictures

Posted: Fri Apr 07, 2017 9:52 am
by Hillebrandt
Hi Mr. Sergey Tkachenko,

I've forgot about the problem, but it still occurs (in Version 15.3.2).
I load an html-text with image tags. It shows everything fine.
With OnSaveImage2:

Code: Select all

  Sender.GetItemExtraStrProperty(
    Sender.Style.ItemNo,
    rvespImageFileName,
    Location
  );

  DoDefault := (Location = '') OR (NOT RVIsURL(Location)); // <- here break-point
and the modification in "TCustomRVData.GetNextFileName" it saves the images as needed.
But when I follow the debug-tracing (I hope you know what I mean) throught "TRichViewRVData.SaveImage2"
and "TCustomRVData.DoSavePicture", it runs into "TRVGraphicItemInfo.SaveToHTML".
The last lines here where

Code: Select all

  if Location<>'' then
    RVWrite(
      Stream,
      {$IFDEF RVUNICODESTR}AnsiStrings.{$ENDIF}Format(
        '<img%s%ssrc="%s"%s%s>',
        [
          GetHTMLImageAlign(VAlign, SaveOptions, UseCSS), 
          GetExtraIMGStr,
          StringToHTMLString(
            RV_GetHTMLPath(Location), // <---------------- here
            SaveOptions, 
            TCustomRVData(RVData).GetRVStyle
          ),
          StringToHTMLString(
            GetMoreImgAttributes(RVData, ItemNo, Path, SaveOptions, UseCSS),
            SaveOptions,
            TCustomRVData(RVData).GetRVStyle
          ),
          RV_HTMLGetEndingSlash(SaveOptions)
        ]
      )
    );
I have marked the "line" where my problem is. "Location" is filled fine with an UNC-Path,
but with RV_GetHTMLPath it changes the "\" to "/". After that the img-Tag has a "wrong"
source.
What can I do to change this behavior?

Thanks for reading this far and a nice weekend.

Greetings from Papenburg, Germany
Hillebrandt

Re: Problem saving as HTML on UNC with pictures

Posted: Fri Apr 07, 2017 4:15 pm
by Sergey Tkachenko
Well, I can see two possible solutions:
1) The component should not change slashes if the path starts from '\\'
2) Adding an option for SaveHTML options to save paths as they are.

What do you think?

Re: Problem saving as HTML on UNC with pictures

Posted: Tue Apr 11, 2017 10:15 am
by Hillebrandt
Hi Mr. Sergey Tkachenko,

my first idea was something like this:

Code: Select all

  if Location<>'' then
  Begin
    if (RVIsURL(RV_GetHTMLPath(Location))) then // <---------------- changed here
    Begin // <---------------- changed here
      sRealLocation := RV_GetHTMLPath(Location); // <---------------- changed here
    End Else // <---------------- changed here
    Begin // <---------------- changed here
      sRealLocation := Location; // <---------------- changed here
    End; // <---------------- changed here
    RVWrite(
      Stream,
      {$IFDEF RVUNICODESTR}AnsiStrings.{$ENDIF}Format(
        '<img%s%ssrc="%s"%s%s>',
        [
          GetHTMLImageAlign(VAlign, SaveOptions, UseCSS), 
          GetExtraIMGStr,
          StringToHTMLString(
            sRealLocation, // <---------------- changed here
            SaveOptions, 
            TCustomRVData(RVData).GetRVStyle
          ),
          StringToHTMLString(
            GetMoreImgAttributes(RVData, ItemNo, Path, SaveOptions, UseCSS),
            SaveOptions,
            TCustomRVData(RVData).GetRVStyle
          ),
          RV_HTMLGetEndingSlash(SaveOptions)
        ]
      )
    );
  End;
this should help in any needed way.
Now, the question is: What do you think? Does this work for others as well?
It would be really sad when this breaks other things.

Thanks for reading this far and a nice week.

Greetings from Papenburg, Germany
Hillebrandt

Re: Problem saving as HTML on UNC with pictures

Posted: Wed Apr 12, 2017 8:21 am
by Sergey Tkachenko
This solution does not convert related parts, such as "images\image1.png".

Re: Problem saving as HTML on UNC with pictures

Posted: Tue Apr 18, 2017 8:29 am
by Hillebrandt
Hi Mr. Sergey Tkachenko,

ok but that's no big problem ...
Change IsUrl to:

Code: Select all

function RVIsURL(const s: String; const bHtmlLink : Boolean = False): Boolean;
var str: String;
    {....................................}
    function CheckPrefix(const Prefix: String): Boolean;
    begin
      Result := (Length(str)>Length(Prefix)) and
        (Copy(str, 1, Length(Prefix))=Prefix);
    end;
    {....................................}
begin
  if (Assigned(RVIsCustomURL)) then
  Begin
    Result := RVIsCustomURL(s);
  End else
  Begin
    Result := False;
  End;
  if (not Result) then
  begin
    str := AnsiLowerCase(s);
    Result :=
      CheckPrefix('http://') or
      CheckPrefix('ftp://') or
      CheckPrefix('file://') or
      CheckPrefix('gopher://') or
      CheckPrefix('mailto:') or
      CheckPrefix('https://') or
      CheckPrefix('news:') or
      CheckPrefix('telnet:') or
      CheckPrefix('wais:') or
      CheckPrefix('www.') or
      CheckPrefix('ftp.');
    if (bHtmlLink) AND (NOT Result) then
    Begin
      // For Links like: "images\image.jpg"
      Result :=
       (NOT (CheckPrefix('\\'))) AND
       (NOT (CheckPrefix('//'))) AND
       (Pos(':', str) = 0);
    End;
  end;
end;
and in TRVGraphicItemInfo.SaveToHTML change it to

Code: Select all

    if (RVIsURL(RV_GetHTMLPath(Location), True)) then
    Begin
      sRealLocation := RV_GetHTMLPath(Location);
    End Else
    Begin
      sRealLocation := Location;
    End;
finally you get

Code: Select all

  if Location<>'' then
  Begin
    if (RVIsURL(RV_GetHTMLPath(Location), True)) then
    Begin
      sRealLocation := RV_GetHTMLPath(Location);
    End Else
    Begin
      sRealLocation := Location;
    End;
    RVWrite(
      Stream,
      {$IFDEF RVUNICODESTR}AnsiStrings.{$ENDIF}Format(
        '<img%s%ssrc="%s"%s%s>',
        [
          GetHTMLImageAlign(VAlign, SaveOptions, UseCSS), 
          GetExtraIMGStr,
          StringToHTMLString(
            sRealLocation,
            SaveOptions, 
            TCustomRVData(RVData).GetRVStyle
          ),
          StringToHTMLString(
            GetMoreImgAttributes(RVData, ItemNo, Path, SaveOptions, UseCSS),
            SaveOptions,
            TCustomRVData(RVData).GetRVStyle
          ),
          RV_HTMLGetEndingSlash(SaveOptions)
        ]
      )
    );
  End;
This way it should change "images\image.jpg" to "images/image.jpg".
I hope it's good and fast enougth to implement it in your source, otherwise I had to change it
anytime I make an update and maybe this helps others with the same problem.

Thanks for reading this far and a nice week.

Greetings from Papenburg, Germany
Hillebrandt

Re: Problem saving as HTML on UNC with pictures

Posted: Tue Apr 18, 2017 3:53 pm
by Sergey Tkachenko
What if, instead, I make the following changes:

Code: Select all

// new function
function RVIsUNCPath(const s: String): Boolean;
begin
  Result := (Length(s) >= 2) and (s[1] = '\') and (s[2] = '\');
end;

Code: Select all

// modified function
function RV_GetHTMLPath(const Path: String): String;
var
  i: Integer;
begin
  Result := Path;
  if not RVIsUNCPath(Path) then
    for i := 1 to Length(Result) do
      if Result[i] = '\' then
        Result[i] := '/';
end;

Re: Problem saving as HTML on UNC with pictures

Posted: Wed Apr 19, 2017 7:10 am
by Hillebrandt
Hi Mr. Sergey Tkachenko,

this doesn't work for me, because I have some path look like "C:\MainDB\Signatures\Logo.jpg".
Sorry.

Greetings from Papenburg, Germany
Hillebrandt

Re: Problem saving as HTML on UNC with pictures

Posted: Wed Apr 19, 2017 10:52 am
by Sergey Tkachenko
Ok, if

Code: Select all

function RVIsUNCPath(const s: String): Boolean;
begin
  Result := (Length(s) >= 2) and ((s[1] = '\') and (s[2] = '\')) or (s[2] = ':');
end;
?

Re: Problem saving as HTML on UNC with pictures

Posted: Mon Apr 24, 2017 10:00 am
by Hillebrandt
Hi Mr. Sergey Tkachenko,

1) it should have another name ... something like "RVIsUncOrLocalPath"
otherwise your source is no longer so "beautiful"! :wink:
2) Can you please add this "request" in the RVIsURL-Function? I use it in several places in my source.

Greetings from Papenburg, Germany
Hillebrandt

Re: Problem saving as HTML on UNC with pictures

Posted: Mon Apr 24, 2017 11:08 am
by Sergey Tkachenko
May be you can create your own function, calling RVIsURL inside? The main goal of this function is detecting URL in text, and this new parameter will be against this goal, and will not be used in our code...