mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-21 05:09:31 +02:00
* Small output improvement
This commit is contained in:
parent
9cc08d9124
commit
67a614e48d
@ -5,7 +5,7 @@ program restool;
|
|||||||
uses
|
uses
|
||||||
custapp, sysutils, classes, resource, elfreader, resreader, coffreader, machoreader, dfmreader,
|
custapp, sysutils, classes, resource, elfreader, resreader, coffreader, machoreader, dfmreader,
|
||||||
bitmapresource, stringtableresource, versionresource, groupiconresource, groupcursorresource,
|
bitmapresource, stringtableresource, versionresource, groupiconresource, groupcursorresource,
|
||||||
acceleratorsresource;
|
acceleratorsresource, groupresource;
|
||||||
|
|
||||||
Type
|
Type
|
||||||
TRunMode = (rmList,rmExtract);
|
TRunMode = (rmList,rmExtract);
|
||||||
@ -20,8 +20,12 @@ Type
|
|||||||
FDestFile : String;
|
FDestFile : String;
|
||||||
FResName,FResType : String;
|
FResName,FResType : String;
|
||||||
FResIndex : integer;
|
FResIndex : integer;
|
||||||
|
FStructured : Boolean;
|
||||||
|
procedure DumpAllResources(var aDest: Text);
|
||||||
|
procedure DumpResource(var aDest: Text; Res: TAbstractResource; Idx: integer; const Prefix: String='');
|
||||||
function ProcessOptions: Boolean;
|
function ProcessOptions: Boolean;
|
||||||
procedure Usage(const aErr: String);
|
procedure Usage(const aErr: String);
|
||||||
|
procedure DumpOwnedResource(var aDest: Text; aOwner: TAbstractResource; const Prefix: String);
|
||||||
procedure WriteResource(Res: TAbstractResource; const aDestFile: String);
|
procedure WriteResource(Res: TAbstractResource; const aDestFile: String);
|
||||||
Protected
|
Protected
|
||||||
procedure doRun; override;
|
procedure doRun; override;
|
||||||
@ -112,25 +116,65 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TRestool.dumpresourcefile(const aFileName: String; var aDest : Text);
|
|
||||||
|
procedure TRestool.DumpResource(var aDest : Text; Res : TAbstractResource; Idx : integer; const Prefix : String = '');
|
||||||
|
|
||||||
|
var
|
||||||
|
aType,aName : string;
|
||||||
|
|
||||||
|
|
||||||
|
begin
|
||||||
|
aName:=Res.Name.Name;
|
||||||
|
if res.name.DescType=dtID then
|
||||||
|
aName:='#'+aName;
|
||||||
|
aType:=ResTypeName(res._Type.ID,True);
|
||||||
|
Writeln(aDest,Prefix,Idx:3,' : Type: ',aType,' name: ',aName);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TRestool.DumpOwnedResource(var aDest : Text; aOwner : TAbstractResource; const Prefix : String);
|
||||||
|
|
||||||
Var
|
Var
|
||||||
res : TAbstractResource;
|
res : TAbstractResource;
|
||||||
aType,aName : string;
|
|
||||||
i : Integer;
|
i : Integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
For I:=0 to FResFile.Count-1 do
|
||||||
|
begin
|
||||||
|
Res:=FResFile.Items[i];
|
||||||
|
if Res.Owner=aOwner then
|
||||||
|
begin
|
||||||
|
DumpResource(aDest,Res,I,Prefix);
|
||||||
|
if Res is TGroupResource then
|
||||||
|
DumpOwnedResource(aDest,Res,' '+Prefix);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TRestool.DumpAllResources(var aDest : Text);
|
||||||
|
|
||||||
|
Var
|
||||||
|
res : TAbstractResource;
|
||||||
|
i : Integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
For I:=0 to FResFile.Count-1 do
|
||||||
|
begin
|
||||||
|
Res:=FResFile.Items[i];
|
||||||
|
DumpResource(aDest,Res,I);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TRestool.dumpresourcefile(const aFileName: String; var aDest : Text);
|
||||||
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
FResFile.LoadFromFile(aFileName);
|
FResFile.LoadFromFile(aFileName);
|
||||||
Writeln(aDest,'File ',aFileName,' contains ',FResFile.Count,' resources:');
|
Writeln(aDest,'File ',aFileName,' contains ',FResFile.Count,' resources:');
|
||||||
For I:=0 to FResFile.Count-1 do
|
if FStructured then
|
||||||
begin
|
DumpOwnedResource(aDest,Nil,'')
|
||||||
Res:=FResFile.Items[i];
|
else
|
||||||
aName:=Res.Name.Name;
|
DumpAllResources(aDest);
|
||||||
if res.name.DescType=dtID then
|
|
||||||
aName:='#'+aName;
|
|
||||||
aType:=ResTypeName(res._Type.ID,True);
|
|
||||||
Writeln(aDest,I:3,' : Type: ',aType,' name: ',aName);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TRestool.WriteResource(Res : TAbstractResource; const aDestFile : String);
|
procedure TRestool.WriteResource(Res : TAbstractResource; const aDestFile : String);
|
||||||
@ -159,8 +203,8 @@ end;
|
|||||||
function TRestool.ProcessOptions: Boolean;
|
function TRestool.ProcessOptions: Boolean;
|
||||||
|
|
||||||
const
|
const
|
||||||
Short = 'h:i:n:t:m:xlo:';
|
Short = 'h:i:n:t:m:xlo:s';
|
||||||
Long : Array of string = ('help','index:','name:','type:','mode:','extract','output:','list');
|
Long : Array of string = ('help','index:','name:','type:','mode:','extract','output:','list','structured');
|
||||||
|
|
||||||
var
|
var
|
||||||
RM,Idx,Err : String;
|
RM,Idx,Err : String;
|
||||||
@ -176,6 +220,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
S:=GetNonOptions(Short,long);
|
S:=GetNonOptions(Short,long);
|
||||||
FDestFile:=GetOptionValue('o','output');
|
FDestFile:=GetOptionValue('o','output');
|
||||||
|
FStructured:=HasOption('s','structured');
|
||||||
if Length(S)>0 then
|
if Length(S)>0 then
|
||||||
FinputFile:=S[0]
|
FinputFile:=S[0]
|
||||||
else if Length(S)>1 then
|
else if Length(S)>1 then
|
||||||
@ -243,16 +288,12 @@ begin
|
|||||||
Writeln('-i --index=IDX Index of resource to extract.');
|
Writeln('-i --index=IDX Index of resource to extract.');
|
||||||
Writeln('-n --name=NAME Name of resource to extract');
|
Writeln('-n --name=NAME Name of resource to extract');
|
||||||
Writeln('-t --type=TYPE Type of resource to extract. Known type names (RT_RCDATA etc.) can be used.');
|
Writeln('-t --type=TYPE Type of resource to extract. Known type names (RT_RCDATA etc.) can be used.');
|
||||||
Writeln('-l --list List resources in file.');
|
Writeln('-l --list List resources in file (equivalent to -m list).');
|
||||||
Writeln('-x --extract Extract a resource from file. Specify -i or -n and -t options');
|
Writeln('-x --extract Extract a resource from file. Specify -i or -n and -t options. (equivalent to -m extract)');
|
||||||
|
Writeln('-m --mode=MODE set mode to extract or list.');
|
||||||
Writeln('-o --output=FILE Filename to extract a resource to (or specify the name as the second non-option argument.');
|
Writeln('-o --output=FILE Filename to extract a resource to (or specify the name as the second non-option argument.');
|
||||||
Writeln(' If no filename is given, a default name is constructed from either index or Filename to extract a resource to (or specify the name as the second non-option argument.');
|
Writeln(' If no filename is given, a default name is constructed from either index or Filename to extract a resource to (or specify the name as the second non-option argument.');
|
||||||
|
Writeln('-s --structured List resources in structured form: resources are listed under their group.');
|
||||||
(*
|
|
||||||
Short = 'h:i:n:t:m:xlo:';
|
|
||||||
Long : Array of string = ('help','index:','name:','type:','mode:','extract','output:','list');
|
|
||||||
|
|
||||||
*)
|
|
||||||
ExitCode:=Ord(aErr<>'');
|
ExitCode:=Ord(aErr<>'');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user