* code simplified

git-svn-id: trunk@1167 -
This commit is contained in:
florian 2005-09-23 16:35:46 +00:00
parent cde3b119ef
commit 6863cb00df

View File

@ -1,5 +1,5 @@
const const
fpcres2elf_version=1; fpcres2elf_version=1;
type type
@ -31,11 +31,11 @@ type
PFPCResourceInfo = ^TFPCResourceInfo; PFPCResourceInfo = ^TFPCResourceInfo;
TFPCRuntimeResourceInfo = packed record TFPCRuntimeResourceInfo = packed record
reshash: longint; // always 32bit, contains an ELF hash of the resource entries name reshash: longint; // always 32bit, contains an ELF hash of the resource entries name
restype: longint; // always 32bit, contains the resource type ID compatible with Windows RES IDs restype: longint; // always 32bit, contains the resource type ID compatible with Windows RES IDs
ptr: pointer; // Memory pointer to the reosource ptr: pointer; // Memory pointer to the reosource
name: string; // String containing the name of the resource name: ansistring; // String containing the name of the resource
size: longint; // The size of the resource entry - 32/64 Bit, depending on platform size: longint; // The size of the resource entry - 32/64 Bit, depending on platform
end; end;
PFPCRuntimeResourceInfo = ^TFPCRuntimeResourceInfo; PFPCRuntimeResourceInfo = ^TFPCRuntimeResourceInfo;
@ -66,31 +66,32 @@ begin
Result := Result and (not G); Result := Result and (not G);
end; end;
end; end;
procedure InitializeResources; procedure InitializeResources;
var var
i:longint; i:longint;
CurrentResource:pFPCResourceInfo; CurrentResource:pFPCResourceInfo;
begin begin
If (FPCResourceSectionLocation=Nil) then If (FPCResourceSectionLocation=Nil) then
ResInfoCount:=0 ResInfoCount:=0
else else
ResInfoCount:=FPCResourceSectionLocation^.resentries; ResInfoCount:=FPCResourceSectionLocation^.resentries;
If (ResInfoCount<>0) then If (ResInfoCount<>0) then
begin begin
FPCRuntimeResourceInfoArray:=GetMem(SizeOf(TFPCRuntimeResourceInfo)*ResInfoCount); FPCRuntimeResourceInfoArray:=GetMem(SizeOf(TFPCRuntimeResourceInfo)*ResInfoCount);
for i:=0 to ResInfoCount-1 do for i:=0 to ResInfoCount-1 do
begin begin
CurrentResource:=pFPCResourceInfo(pointer(longint(FPCResourceSectionLocation^.reshash.ptr)+i*sizeof(TFPCResourceInfo))); CurrentResource:=pFPCResourceInfo(pointer(FPCResourceSectionLocation^.reshash.ptr+i*sizeof(TFPCResourceInfo)));
FPCRuntimeResourceInfoArray[i].reshash:=CurrentResource^.reshash; FPCRuntimeResourceInfoArray[i].reshash:=CurrentResource^.reshash;
FPCRuntimeResourceInfoArray[i].restype:=CurrentResource^.restype; FPCRuntimeResourceInfoArray[i].restype:=CurrentResource^.restype;
FPCRuntimeResourceInfoArray[i].ptr:=pointer(longint(CurrentResource^.ptr)+longint(FPCResourceSectionLocation^.resdata.ptr)); FPCRuntimeResourceInfoArray[i].ptr:=pointer(CurrentResource^.ptr)+PtrInt(FPCResourceSectionLocation^.resdata.ptr);
FPCRuntimeResourceInfoArray[i].name:=pchar(pointer(longint(CurrentResource^.name)+longint(FPCResourceSectionLocation^.ressym.ptr))); FPCRuntimeResourceInfoArray[i].name:=pchar(CurrentResource^.name)+PtrInt(FPCResourceSectionLocation^.ressym.ptr);
writeln(FPCRuntimeResourceInfoArray[i].name);
FPCRuntimeResourceInfoArray[i].size:=CurrentResource^.size; FPCRuntimeResourceInfoArray[i].size:=CurrentResource^.size;
end; end;
end; end;
InitRes:=true; InitRes:=true;
end; end;
@ -102,16 +103,16 @@ end;
function FindResource(ModuleHandle: HMODULE; ResourceName: PChar; ResourceType: PChar): TResourceHandle; function FindResource(ModuleHandle: HMODULE; ResourceName: PChar; ResourceType: PChar): TResourceHandle;
var var
i:longint; i:longint;
searchhash:longint; searchhash:longint;
n : string; n : string;
begin begin
Result:=0; Result:=0;
if (ResourceName=nil) then if (ResourceName=nil) then
Exit; Exit;
If Not InitRes then If Not InitRes then
InitializeResources; InitializeResources;
searchhash:=HashELF(ResourceName); searchhash:=HashELF(ResourceName);
n:=strpas(resourcename); n:=strpas(resourcename);
@ -120,13 +121,13 @@ begin
begin begin
if (FPCRuntimeResourceInfoArray[i].reshash=searchhash) and (FPCRuntimeResourceInfoArray[i].name=n) then if (FPCRuntimeResourceInfoArray[i].reshash=searchhash) and (FPCRuntimeResourceInfoArray[i].name=n) then
result:=i+1; result:=i+1;
Inc(I); Inc(I);
end; end;
end; end;
function LoadResource(ModuleHandle: HMODULE; ResHandle: TResourceHandle): HGLOBAL; function LoadResource(ModuleHandle: HMODULE; ResHandle: TResourceHandle): HGLOBAL;
begin begin
If Not InitRes then If Not InitRes then
InitializeResources; InitializeResources;
if (ResHandle>0) and (ResHandle-1<=ResInfoCount) then if (ResHandle>0) and (ResHandle-1<=ResInfoCount) then
result:=HGLOBAL(FPCRuntimeResourceInfoArray[ResHandle-1].ptr) result:=HGLOBAL(FPCRuntimeResourceInfoArray[ResHandle-1].ptr)
@ -136,7 +137,7 @@ end;
function SizeofResource(ModuleHandle: HMODULE; ResHandle: TResourceHandle): Integer; function SizeofResource(ModuleHandle: HMODULE; ResHandle: TResourceHandle): Integer;
begin begin
If Not InitRes then If Not InitRes then
InitializeResources; InitializeResources;
if (ResHandle>0) and (ResHandle-1<=ResInfoCount) then if (ResHandle>0) and (ResHandle-1<=ResInfoCount) then
result:=FPCRuntimeResourceInfoArray[ResHandle-1].size result:=FPCRuntimeResourceInfoArray[ResHandle-1].size