summaryrefslogtreecommitdiff
path: root/images/updatestdimgs.pas
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-07-01 14:01:13 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-07-01 14:01:13 +0000
commit7d92fe6198a7878f7eb5970912c12496eb0e7de6 (patch)
tree2f61a0c68161eae35944843582c723923719c22b /images/updatestdimgs.pas
parentd77c30bf2891857f9336b46b95a8739801bcb0e3 (diff)
downloadfpGUI-7d92fe6198a7878f7eb5970912c12496eb0e7de6.tar.xz
* Thanks to Michael van Canneyt for updating and improving the updatestdimgs tool.
Diffstat (limited to 'images/updatestdimgs.pas')
-rw-r--r--images/updatestdimgs.pas144
1 files changed, 121 insertions, 23 deletions
diff --git a/images/updatestdimgs.pas b/images/updatestdimgs.pas
index 2b3f9926..16180727 100644
--- a/images/updatestdimgs.pas
+++ b/images/updatestdimgs.pas
@@ -10,29 +10,127 @@ program updatestdimgs;
{$APPTYPE CONSOLE}
{$ENDIF}
-uses
- SysUtils
- {$ifdef Win32}
- ,Windows
- {$else}
- ,linux
- {$endif}
- ;
-
-var
- sr : TSearchRec;
- i,p : integer;
- s : string;
- cmdline : string;
-begin
- i := FindFirst('*.bmp',faAnyFile,sr);
- while i=0 do
+uses
+ SysUtils,
+ CustApp;
+
+const
+{$ifdef unix}
+ bin2obj = 'bin2obj';
+{$else}
+ bin2obj = 'bin2obj.exe';
+{$endif}
+
+type
+ TConvertApp = class(TCustomApplication)
+ private
+ FBeVerbose: Boolean;
+ FBinary: string;
+ FOutputFile: string;
+ FInputDir: string;
+ FPrefix: string;
+ public
+ procedure Usage;
+ procedure Verbose(Msg: string; Args: array of const);
+ procedure ConvertImage(FN: string);
+ procedure ConvertImages;
+ function ProcessCommandLine: Boolean;
+ procedure DoRun; override;
+ property BeVerbose: Boolean read FBeVerbose;
+ property InputDir: string read FInputDir;
+ property OutputFile: string read FOutputFile;
+ property Prefix: string read FPrefix;
+ end;
+
+
+ procedure TConvertApp.Usage;
+ begin
+ Writeln('Usage : ', ExtractFileName(ParamStr(0)));
+ Writeln(' -h --help This help screen');
+ Writeln(' -i --inputdir=NNN Search files in dir NNN');
+ Writeln(' -o --output=NNN Write output in file NNN');
+ Writeln(' -p --prefix=NNN Prefix constant names with NNN');
+ Writeln(' -v --verbose Be verbose');
+ end;
+
+ procedure TConvertApp.Verbose(Msg: string; Args: array of const);
+ begin
+ if BeVerbose then
+ Writeln(StdErr, Format(Msg, Args));
+ end;
+
+ procedure TConvertApp.ConvertImage(FN: string);
+ var
+ S: string;
+ begin
+ Verbose('Converting image : %s', [FN]);
+ S := FPrefix + ChangeFileExt(FN, '');
+ if (FOutputFile <> '') then
+ ExecuteProcess(FBinary, ['-o', FOutputFile, '-c', S, FN])
+ else
+ ExecuteProcess(FBinary, ['-c', S, FN]);
+ end;
+
+ function TConvertApp.ProcessCommandLine: Boolean;
+ const
+ Longopts: array[1..5] of string = (
+ 'help', 'verbose', 'inputdir', 'output:', 'prefix:');
+ var
+ S: string;
+ begin
+ S := CheckOptions('hvi:o:p:', Longopts);
+ Result := (S = '') and not HasOption('h', 'help');
+ if not Result then
+ begin
+ if (S <> '') then
+ Writeln(StdErr, 'Error in options: ', S);
+ Usage;
+ Exit;
+ end;
+ FBeVerbose := HasOption('v');
+ if HasOption('i', 'inputdir') then
+ FInputDir := GetOptionValue('i', 'inputdir');
+ if HasOption('o', 'output') then
+ FOutputFile := GetOptionValue('o', 'output');
+ if HasOption('p', 'prefix') then
+ FPrefix := GetOptionValue('p', 'prefix')
+ else
+ FPrefix := 'stdimg_';
+ end;
+
+ procedure TConvertApp.DoRun;
+ begin
+ StopOnException := True;
+ if ProcessCommandLine then
+ ConvertImages;
+ Terminate;
+ end;
+
+ procedure TConvertApp.ConvertImages;
+ var
+ Info: TSearchRec;
begin
- s := sr.Name;
- p := pos('.bmp',s);
- if p > 0 then s := copy(s,1,p-1);
- cmdline := 'bin2obj -c stdimg_'+s+' '+sr.Name;
- WinExec(PChar(cmdline),0);
- i := FindNext(sr);
+ if (FBinary = '') then
+ FBinary := FileSearch('bin2obj', GetEnvironmentVariable('PATH'));
+ if (FInputDir <> '') then
+ FInputDir := IncludeTrailingPathDelimiter(FInputDir);
+ if FindFirst(FInputDir + '*.bmp', faAnyFile, Info) = 0 then
+ try
+ repeat
+ ConvertImage(FInputDir + Info.Name);
+ until FindNext(Info) <> 0;
+ finally
+ FindClose(Info);
+ end;
end;
+
+begin
+ with TConvertApp.Create(nil) do
+ try
+ Run
+ finally
+ Free;
+ end;
end.
+
+