From f09572174af0cd3e1f22cb1445ea33cbc946df41 Mon Sep 17 00:00:00 2001 From: "rosenfield.albert" Date: Thu, 12 Feb 2009 16:40:20 +0000 Subject: [PATCH] Bugfix binary readout in HTML view function. Also, rename it to 'image view' in the GUI, because that's what it is. --- source/main.dfm | 4 ++-- source/main.pas | 41 +++++++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/source/main.dfm b/source/main.dfm index 9da3e570..fa6be283 100644 --- a/source/main.dfm +++ b/source/main.dfm @@ -1940,8 +1940,8 @@ object MainForm: TMainForm end object actHTMLview: TAction Category = 'Export/Import' - Caption = 'HTML-view' - Hint = 'View contents as HTML-file' + Caption = 'Image view' + Hint = 'View image contents' ImageIndex = 32 OnExecute = actHTMLviewExecute end diff --git a/source/main.pas b/source/main.pas index 91fe914a..561d42b5 100644 --- a/source/main.pas +++ b/source/main.pas @@ -2241,44 +2241,53 @@ end; // view HTML procedure TMainForm.actHTMLviewExecute(Sender: TObject); +const + msgNotBinary = 'Non-binary field selected. Only binary fields containing JPEG, PNG, GIF and BMP images are supported.'; + msgNotImage = 'Unrecognized image format. Only JPEG, PNG, GIF and BMP are supported.'; var - g : TVirtualStringTree; - filename : String; - f : Textfile; - Content : WideString; - IsBinary : Boolean; - SaveBinary : Boolean; + g : TVirtualStringTree; + filename : String; + f : Textfile; + Header, Content : String; + IsBinary : Boolean; + SaveBinary : Boolean; begin g := ActiveGrid; if g = nil then begin messagebeep(MB_ICONASTERISK); exit; end; Screen.Cursor := crHourGlass; showstatus('Saving contents to file...'); - if not EnsureFullWidth(g, g.FocusedColumn, g.FocusedNode) then - Exit; IsBinary := ActiveData.Columns[g.FocusedColumn].IsBinary; - Content := g.Text[g.FocusedNode, g.FocusedColumn]; + Header := WideHexToBin(Copy(g.Text[g.FocusedNode, g.FocusedColumn], 3, 20)); SaveBinary := false; filename := GetTempDir+'\'+APPNAME+'-preview.'; - if IsBinary and (pos('JFIF', copy(Content, 0, 20)) <> 0) then begin + if IsBinary and (Copy(Header, 7, 4) = 'JFIF') then begin SaveBinary := true; filename := filename + 'jpeg'; - end else if IsBinary and StrCmpBegin('GIF', Content) then begin + end else if IsBinary and (Copy(Header, 2, 3) = 'PNG') then begin + SaveBinary := true; + filename := filename + 'png'; + end else if IsBinary and StrCmpBegin('GIF', Header) then begin SaveBinary := true; filename := filename + 'gif'; - end else if IsBinary and StrCmpBegin('BM', Content) then begin + end else if IsBinary and StrCmpBegin('BM', Header) then begin SaveBinary := true; filename := filename + 'bmp'; - end else if Isbinary then filename := filename + 'txt' - else filename := filename + 'html'; + end; + + if not IsBinary then begin + MessageDlg(msgNotBinary, mtWarning, [mbOk], 0); + end else if not SaveBinary then begin + MessageDlg(msgNotImage, mtWarning, [mbOk], 0); + end; if SaveBinary then begin + if not EnsureFullWidth(g, g.FocusedColumn, g.FocusedNode) then Exit; + Content := WideHexToBin(Copy(g.Text[g.FocusedNode, g.FocusedColumn], 3, High(Integer))); AssignFile(f, filename); Rewrite(f); Write(f, Content); CloseFile(f); - end else begin - SaveUnicodeFile(filename, Content); end; ShowStatus( STATUS_MSG_READY ); Screen.Cursor := crDefault;