Check-in [c4b54c40b6]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Started on a hex viewer.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | develop
Files: files | file ages | folders
SHA1:c4b54c40b6ba36ba69820b31f59264f481e95848
User & Date: tinus 2015-02-18 14:20:48
Context
2015-02-25
09:42
Hex viewer background color. check-in: b26e4249b9 user: tinus tags: develop
08:43
ZPreview: added some comments for future development of the hex viewer. Leaf check-in: 5ecb7152bb user: tinus tags: feature/hex-viewer
2015-02-18
14:20
Started on a hex viewer. check-in: c4b54c40b6 user: tinus tags: develop
2015-02-17
16:32
Enable changing order of renderers (changes are not stored yet). check-in: c4b41ad964 user: tinus tags: develop
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added ZPreview/src/Delphi/F_PE_Hex.dfm.

























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
object frmPEHex: TfrmPEHex
  Left = 0
  Top = 0
  Caption = 'Hex viewer'
  ClientHeight = 282
  ClientWidth = 418
  Color = clBtnFace
  DoubleBuffered = True
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object pbxPreview: TPaintBox
    Left = 0
    Top = 0
    Width = 401
    Height = 282
    Align = alClient
    ParentColor = False
    OnPaint = pbxPreviewPaint
    ExplicitLeft = 120
    ExplicitTop = 56
    ExplicitWidth = 105
    ExplicitHeight = 105
  end
  object scbVertical: TScrollBar
    Left = 401
    Top = 0
    Width = 17
    Height = 282
    Align = alRight
    Kind = sbVertical
    PageSize = 0
    Position = 3
    TabOrder = 0
    ExplicitLeft = 360
    ExplicitTop = 120
    ExplicitHeight = 121
  end
end

Added ZPreview/src/Delphi/F_PE_Hex.pas.



































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
unit F_PE_Hex;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  U_PreviewEngine, Vcl.ExtCtrls, Vcl.StdCtrls;

type
  TLayoutInfo = record
    FileSize: Int64;
    FirstIndex: Int64;
    Width: integer;
    Height: integer;
    CharWidth: integer;
    LineHeight: integer;
  end;

type
  TfrmPEHex = class(TCustomPreviewEngineForm)
    scbVertical: TScrollBar;
    pbxPreview: TPaintBox;
    procedure pbxPreviewPaint(Sender: TObject);
  private
    { Private declarations }
    FBitmap: TBitmap;
    FCurrLayout: TLayoutInfo;
    FPrevLayout: TLayoutInfo;
  protected
    function GetRenderers: TRendererList; override;
  public
    { Public declarations }
    procedure Clear; override;
  end;

var
  frmPEHex: TfrmPEHex;

implementation

{$R *.dfm}

type
  THexRenderer = class(TRenderer)
  public
    function  CouldShowFile(const FileName: string): boolean; override;
    function  TryShowFile(const FileName: string): boolean; override;
    function  SummarizeInfo: string; override;
    procedure PopulateInfo(const Lines: IInfoLineDisplayer); override;
  end {TGraphicRenderer};


{ ================================================================================================ }
{ TfrmPEHex }

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmPEHex.Clear;
begin
  inherited;
  FFileName := '';
  pbxPreview.Invalidate;
end {TfrmPEHex.Clear};

{ ------------------------------------------------------------------------------------------------ }
function TfrmPEHex.GetRenderers: TRendererList;
begin
  Result := inherited;
  if Result.Count = 0 then begin
    Result.Add(THexRenderer.Create(Self));
  end;
end {TfrmPEHex.GetRenderers};

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmPEHex.pbxPreviewPaint(Sender: TObject);
var
  Canvas: TCanvas;
begin
  {$MESSAGE WARN 'TODO: TfrmPEHex.pbxPreviewPaint  MCO 18-02-2015'}
  // TODO: check whether anything has changed since last time?
  if not Assigned(FBitmap)
    or (pbxPreview.ClientWidth <> FBitmap.Width)
    or (pbxPreview.ClientHeight <> FBitmap.Height)
    or CompareMem(@FCurrLayout, @FPrevLayout, SizeOf(TLayoutInfo))
  then begin
    // if things have changed (or there is no old bitmap), then draw a new one
    FreeAndNil(FBitmap);
    FBitmap := TBitmap.Create;
    FBitmap.SetSize(pbxPreview.ClientWidth, pbxPreview.ClientHeight);
    Canvas := FBitmap.Canvas;
    Canvas.Assign(pbxPreview.Canvas);

    // TODO: on initialization and change of font
    // TODO: get the (average) character width and line height
    // TODO: calculate the width in characters
    // TODO: calculate the height in characters
    // TODO: calculate the length, in characters, of the maximum offset
    // TODO: calculate the number of bytes that can be represented on a single line (bytes per line)
    // TODO: calculate the number of rows that fit on a single screen (rows per screen)
    // TODO: calculate the number of bytes per screen
    scbVertical.Max := 0; // number of rows
    scbVertical.SmallChange := 1; // 1 row
    scbVertical.PageSize := 0; // TODO: rows per screen
    scbVertical.LargeChange := scbVertical.PageSize - 1; // rows per screen - 1

  end;
  // copy the in-memory bitmap onto the canvas
  pbxPreview.Canvas.Draw(0, 0, FBitmap);
  FPrevLayout := FCurrLayout;
end {TfrmPEHex.pbxPreviewPaint};


{ ================================================================================================ }
{ THexRenderer }

{ ------------------------------------------------------------------------------------------------ }
function THexRenderer.CouldShowFile(const FileName: string): boolean;
begin
  Result := True;
end {THexRenderer.CouldShowFile};

{ ------------------------------------------------------------------------------------------------ }
function THexRenderer.TryShowFile(const FileName: string): boolean;
var
  FS: TFileStream;
begin
  // try opening the file for reading (deny none)
  FS := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
  try
//    FFileSize := FS.Size;
  finally
    FS.Free;
  end;
  // reset the navigation info
  Form.Clear;
  {$MESSAGE WARN 'TODO: TfrmPEHex.SetFileName  MCO 18-02-2015'}
  TfrmPEHex(Form).FFileName := FileName;
  Result := True;
end {THexRenderer.TryShowFile};

{ ------------------------------------------------------------------------------------------------ }
procedure THexRenderer.PopulateInfo(const Lines: IInfoLineDisplayer);
begin
  inherited;
end {THexRenderer.PopulateInfo};

{ ------------------------------------------------------------------------------------------------ }
function THexRenderer.SummarizeInfo: string;
begin
  Result := ''; // (nothing to show)
end {THexRenderer.SummarizeInfo};





////////////////////////////////////////////////////////////////////////////////////////////////////
initialization
  TCustomPreviewEngineForm.RegisterForm(TfrmPEHex);

end.

Changes to ZPreview/src/Delphi/M_Main.pas.

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
implementation
{%CLASSGROUP 'Vcl.Controls.TControl'}
{$R *.dfm}

uses
  F_Main,
  F_PE_Graphics, {$IFDEF WIN32}F_PE_FreeImage,{$ENDIF} F_PE_PreviewHandlers, F_PE_WlxPlugins,
  F_PE_Text, F_PE_ShellItemImages;

{ ------------------------------------------------------------------------------------------------ }
procedure TmodMain.tmrStartTimer(Sender: TObject);
begin
  tmrStart.Enabled := False;
  frmMain.ActionManager.FindItemByAction(frmMain.actAutorefresh).Action.Execute;
end {TmodMain.tmrStartTimer};

end.







|









24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
implementation
{%CLASSGROUP 'Vcl.Controls.TControl'}
{$R *.dfm}

uses
  F_Main,
  F_PE_Graphics, {$IFDEF WIN32}F_PE_FreeImage,{$ENDIF} F_PE_PreviewHandlers, F_PE_WlxPlugins,
  F_PE_Text, F_PE_ShellItemImages, F_PE_Hex;

{ ------------------------------------------------------------------------------------------------ }
procedure TmodMain.tmrStartTimer(Sender: TObject);
begin
  tmrStart.Enabled := False;
  frmMain.ActionManager.FindItemByAction(frmMain.actAutorefresh).Action.Execute;
end {TmodMain.tmrStartTimer};

end.

Changes to ZPreview/src/Delphi/ZPreview.dproj.

182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
                    <VersionInfoKeys Name="restoreAnyVersion"/>
                    <VersionInfoKeys Name="installLocation"/>
                    <VersionInfoKeys Name="largeHeap"/>
                    <VersionInfoKeys Name="theme"/>
                </VersionInfoKeys>
            </Delphi.Personality>
            <Deployment>
                <DeployFile LocalName="Win32\Debug\ZPreview.32.exe" Configuration="Debug" Class="ProjectOutput">
                    <Platform Name="Win32">
                        <RemoteName>ZPreview.exe</RemoteName>
                        <Overwrite>true</Overwrite>
                    </Platform>
                </DeployFile>
                <DeployFile LocalName="..\..\out\Debug\ZPreview.32.exe" Configuration="Debug" Class="ProjectOutput">
                    <Platform Name="Win32">
                        <RemoteName>ZPreview.exe</RemoteName>
                        <Overwrite>true</Overwrite>
                    </Platform>
                </DeployFile>
                <DeployFile LocalName="Win32\Debug\ZPreview.exe" Configuration="Debug" Class="ProjectOutput">
                    <Platform Name="Win32">
                        <RemoteName>ZPreview.exe</RemoteName>
                        <Overwrite>true</Overwrite>
                    </Platform>
                </DeployFile>
                <DeployClass Required="true" Name="DependencyPackage">
                    <Platform Name="iOSDevice">







|











|







182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
                    <VersionInfoKeys Name="restoreAnyVersion"/>
                    <VersionInfoKeys Name="installLocation"/>
                    <VersionInfoKeys Name="largeHeap"/>
                    <VersionInfoKeys Name="theme"/>
                </VersionInfoKeys>
            </Delphi.Personality>
            <Deployment>
                <DeployFile LocalName="Win32\Debug\ZPreview.exe" Configuration="Debug" Class="ProjectOutput">
                    <Platform Name="Win32">
                        <RemoteName>ZPreview.exe</RemoteName>
                        <Overwrite>true</Overwrite>
                    </Platform>
                </DeployFile>
                <DeployFile LocalName="..\..\out\Debug\ZPreview.32.exe" Configuration="Debug" Class="ProjectOutput">
                    <Platform Name="Win32">
                        <RemoteName>ZPreview.exe</RemoteName>
                        <Overwrite>true</Overwrite>
                    </Platform>
                </DeployFile>
                <DeployFile LocalName="Win32\Debug\ZPreview.32.exe" Configuration="Debug" Class="ProjectOutput">
                    <Platform Name="Win32">
                        <RemoteName>ZPreview.exe</RemoteName>
                        <Overwrite>true</Overwrite>
                    </Platform>
                </DeployFile>
                <DeployClass Required="true" Name="DependencyPackage">
                    <Platform Name="iOSDevice">