unit DemoFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TDemoForm =
class(TForm)
SkinButton: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
SkinPath:
string;
SkinList: TStrings;
SkinStream: TStream;
end;
var
DemoForm: TDemoForm;
implementation
{$R *.dfm}
uses
FileCtrl;
const
SKIN_EXTENSIONS = '
*.jpg;*.bmp';
type
TSkinItem =
class
FOffset: Int64;
FSize: Int64;
public
constructor Create(offset, size: Int64);
property Offset: Int64
read FOffSet;
property Size: Int64
read FSize;
end;
constructor TSkinItem.Create(offset, size: Int64);
begin
inherited Create;
FOffset := offset;
FSize := size;
end;
function GetFiles(
const dir, masks:
string; s: TStrings =
nil): Integer;
begin
with TFileListBox.CreateParented(HWND(HWND_MESSAGE))
do
try
Mask := masks;
Directory := dir;
FileType := [ftArchive];
Result := Items.Count;
if Assigned(s)
then
s.Assign(Items);
finally
Free;
end;
end;
procedure LoadSkins(
const SkinPath, Extensions:
string;
SkinList: TStrings; SkinStream: TStream);
var
i: Integer;
totalSize: Int64;
s: TStream;
begin
totalSize := 0;
with SkinList
do
for i := 0
to Pred(Count)
do
Objects[i].Free;
GetFiles(SkinPath, Extensions, SkinList);
with SkinList
do
for i := 0
to Pred(Count)
do
begin
s := TFileStream.Create(Strings[i], fmOpenRead
or fmShareDenyWrite);
try
Objects[i] := TSkinItem.Create(totalSize, s.Size);
SkinStream.CopyFrom(s, 0);
Inc(totalSize, s.Size);
finally
s.Free;
end;
end;
end;
procedure TDemoForm.FormCreate(Sender: TObject);
begin
if (ParamCount = 0)
or not FileExists(ParamStr(1))
then GetDir(0, SkinPath)
else SkinPath := ParamStr(1);
SkinPath := IncludeTrailingPathDelimiter(SkinPath);
SkinList := TStringList.Create;
SkinStream := TMemoryStream.Create;
LoadSkins(SkinPath, SKIN_EXTENSIONS, SkinList, SkinStream);
end;
procedure TDemoForm.SkinButtonClick(Sender: TObject);
begin
if SelectDirectory('
Select SkinPath', '
C:\', SkinPath)
then
LoadSkins(SkinPath, SKIN_EXTENSIONS, SkinList, SkinStream);
end;
end.