{******************************************************************************}
{* *}
{* Project: CrashPoint *}
{* Unit: uCP_MapFile *}
{* Version: 1.0 *}
{* *}
{* Description: *}
{* Klasse um eine Liste von Streams in eine Datei zu *}
{* speichern und zu lesen *}
{* *}
{* Log: *}
{* # First Version *}
{* *}
{* *}
{* Author: Björn R. Salgert (bjoern@bsnx.net) *}
{* URL: N/A - [url]http://bsnx.net[/url] *}
{* *}
{******************************************************************************}
unit uCP_MapFile;
interface
uses SysUtils, Classes, JvSimpleXml, Dialogs;
type
TMapFile =
class (TJvSimpleXML)
protected
public
procedure AddStream(
Name:
String; Stream: TStringStream);
procedure GetStream(
Name:
String; Stream: TStream);
procedure AddString(
Name, Text:
String);
function GetString(
Name:
String):
String;
procedure AddInt(
Name:
String; I: Integer);
function GetInt(
Name:
String): Integer;
constructor Create(AOwner: TComponent);
override;
end;
implementation
function streamtostr(S: TStream):
string;
var
str:
string;
lStringStream: TStringStream;
begin
lStringStream := TStringStream.Create;
Try
lStringStream.CopyFrom(S, 0);
Result := lStringStream.DataString;
Finally
lStringStream.Free;
End;
end;
function strtohex(Text:
String):
String;
var
i: integer;
s:
string;
begin
for i:=1
to length(Text)
do begin
s:= s+IntToHex(Byte(Text[i]), 2);
end;
result:=s
end;
{ TMapFile }
procedure TMapFile.AddInt(
Name:
String; I: Integer);
begin
Self.Root.Items.Add(
Name, i);
end;
procedure TMapFile.AddStream(
Name:
String; Stream: TStringStream);
begin
// Self.Root.Items.Add(Name, strtohex(Stream.DataString));
Stream.Position:=0;
Self.Root.Items.Add(
Name, Stream);
end;
procedure TMapFile.AddString(
Name, Text:
String);
begin
Self.Root.Items.Add(
Name, Text);
end;
constructor TMapFile.Create(AOwner: TComponent);
begin
inherited;
Self.Root.
Name:= '
map';
end;
function TMapFile.GetInt(
Name:
String): Integer;
begin
if Self.Root.Items.ItemNamed[
Name]<>
nil then begin
result:=Self.Root.Items.ItemNamed[
Name].IntValue;
end;
end;
procedure TMapFile.GetStream(
Name:
String; Stream: TStream);
var
b: Byte;
i: integer;
begin
if Self.Root.Items.ItemNamed[
Name]<>
nil then begin
Stream.Position:=0;
Self.Root.Items.ItemNamed[
Name].GetBinaryValue(Stream);
{
for i:=1 to Length(Self.Root.Items.ItemNamed[Name].Value) do begin
B:= Byte(Self.Root.Items.ItemNamed[Name].Value[i]);
Stream.Write(B, sizeof(B));
end; }
end;
end;
function TMapFile.GetString(
Name:
String):
String;
begin
if Self.Root.Items.ItemNamed[
Name]<>
nil then begin
result:= Self.Root.Items.ItemNamed[
Name].Value;
end;
end;
end.