From c316180c74e144a5faecfe30ab38c8e4e0ef9e91 Mon Sep 17 00:00:00 2001 From: tobigun Date: Mon, 7 Apr 2008 08:50:43 +0000 Subject: - Removed lrs resource usage in linux. Resources are copied to /usr/share/resources now. - Unified resource handling: call GetResourceStream (UCommon) to retrieve a resource. - Removed the lazarus dependency in the Makefile (it will also use the main .dpr-file now) - Now that the lazarus dependency is gone, the MacOSX and Linux version might use a shared codebase. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1013 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Tools/ResourceExtractor/ResourceExtractor.lpi | 106 +++++++++++++++++ Tools/ResourceExtractor/ResourceExtractor.pas | 152 ++++++++++++++++++++++++ Tools/USDXResCompiler.lpi | 78 ------------- Tools/USDXResCompiler.lpr | 159 -------------------------- Tools/USDXResCompiler/USDXResCompiler.lpi | 78 +++++++++++++ Tools/USDXResCompiler/USDXResCompiler.lpr | 159 ++++++++++++++++++++++++++ Tools/USDXResCompiler/linux-build.sh | 3 + Tools/linux-build.sh | 3 - 8 files changed, 498 insertions(+), 240 deletions(-) create mode 100644 Tools/ResourceExtractor/ResourceExtractor.lpi create mode 100644 Tools/ResourceExtractor/ResourceExtractor.pas delete mode 100644 Tools/USDXResCompiler.lpi delete mode 100644 Tools/USDXResCompiler.lpr create mode 100644 Tools/USDXResCompiler/USDXResCompiler.lpi create mode 100644 Tools/USDXResCompiler/USDXResCompiler.lpr create mode 100755 Tools/USDXResCompiler/linux-build.sh delete mode 100755 Tools/linux-build.sh (limited to 'Tools') diff --git a/Tools/ResourceExtractor/ResourceExtractor.lpi b/Tools/ResourceExtractor/ResourceExtractor.lpi new file mode 100644 index 00000000..82ecf87e --- /dev/null +++ b/Tools/ResourceExtractor/ResourceExtractor.lpi @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tools/ResourceExtractor/ResourceExtractor.pas b/Tools/ResourceExtractor/ResourceExtractor.pas new file mode 100644 index 00000000..aa9cc3bc --- /dev/null +++ b/Tools/ResourceExtractor/ResourceExtractor.pas @@ -0,0 +1,152 @@ +program ResourceExtractor; + +{$ifdef FPC} + {$mode delphi}{$H+} +{$endif} + +uses + Classes, + SysUtils, + StrUtils; + + +var + ResCount: integer; + OutStream: TStringList; + + +procedure Init(); +begin + OutStream := TStringList.Create(); + + OutStream.Add('const'); + // placeholder for array-header (will be filled on file-saving) + OutStream.Add(''); +end; + +procedure SaveToFile(const OutFileName: string); +begin + // add array-header + OutStream[1] := ' resources: array[0..'+IntToStr(ResCount-1)+', 0..2] of string = ('; + // add trailer + OutStream.Add(' );'); + + // save file + try + OutStream.SaveToFile(OutFileName); + except + OutStream.Free(); + raise Exception.Create('Could not save to file: "' + OutFileName + '"'); + end; + + OutStream.Free(); +end; + +function AddResource(Fields: TStringList; const RCFileDir, ResDir: string): boolean; +var + ResName, ResType, ResFile: string; +begin + if (Fields.Count < 3) or + (AnsiStartsStr('//', Fields[0])) or + (Length(Fields[2]) < 3) then + begin + Result := false; + Exit; + end; + + // add a trailing comma to the last line + if (ResCount > 0) then + OutStream[OutStream.Count-1] := OutStream[OutStream.Count-1] + ','; + + ResName := Fields[0]; + ResType := Fields[1]; + ResFile := Fields[2]; + + Writeln('ADD: [' + ResType + ':' + ResName + ' = ' +ResFile + ']'); + + // quote fields + ResName := AnsiQuotedStr(ResName, '''')+','; + ResType := AnsiQuotedStr(ResType, '''')+','; + // strip surrounding quotes of filename + ResFile := AnsiMidStr(ResFile, 2, Length(Fields[2])-2); + // now translate the resource filename (relative to the RC-file) to be relative to the resource-dir + // 1st step: get absolute path of the resource + ResFile := ExpandFileName(RCFileDir + ResFile); + // 2nd step: get path of the resource relative to the resource-dir + // Note: both paths must be absolute and the base-path must have a trailing '/' or '\' + ResFile := ExtractRelativepath(ResDir, ResFile); + // 3rd step: ... and quote + ResFile := AnsiQuotedStr(ResFile, ''''); + + // compose line + OutStream.Add(Format(' (%-20S%-8S%S)', [ResName, ResType, ResFile])); + + Inc(ResCount); + + Result := true; +end; + +procedure ExtractResources(const InFileName, ResDir: string); +var + Fields: TStringList; + LineIndex: integer; + Lines: TStringList; + RCFileDirAbs, ResDirAbs: string; +begin + // get absolute paths + RCFileDirAbs := ExtractFilePath(ExpandFileName(InFileName)); + ResDirAbs := ExpandFileName(ResDir) + '/'; + + Lines := TStringList.Create(); + try + Lines.LoadFromFile(InFileName); + except + raise Exception.Create('Failed to open file: "' + InFileName + '"'); + end; + + Fields := TStringList.Create(); + for LineIndex := 0 to Lines.Count-1 do + begin + Fields.Clear(); + // split line into [Name, Type, File] + ExtractStrings([' ', #9], [], PChar(Lines[LineIndex]), Fields); + if (not AddResource(Fields, RCFileDirAbs, ResDirAbs)) then + Writeln( 'SKIP: "'+Lines[LineIndex]+'"'); + end; + + Lines.Free(); + Fields.Free(); +end; + +var + ProgName: string; +begin + if (ParamCount <> 3) then + begin + ProgName := ExtractFileName(ParamStr(0)); + WriteLn('Usage: ' + ProgName + ' RC-File Resource-Dir Output-File'); + Exit; + end; + + WriteLn('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'); + WriteLn('Converting "' + ParamStr(1) + '" to "' + ParamStr(3) + '"'); + WriteLn('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'); + + try + Init(); + ExtractResources(ParamStr(1), ParamStr(2)); + SaveToFile(ParamStr(3)); + except on E:Exception do + begin + WriteLn('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); + WriteLn('Conversion failed: ' + E.Message + '!'); + WriteLn('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); + Exit; + end; + end; + + WriteLn('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<'); + WriteLn('Conversion finished!'); + WriteLn('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<'); +end. + diff --git a/Tools/USDXResCompiler.lpi b/Tools/USDXResCompiler.lpi deleted file mode 100644 index cf94486e..00000000 --- a/Tools/USDXResCompiler.lpi +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tools/USDXResCompiler.lpr b/Tools/USDXResCompiler.lpr deleted file mode 100644 index 8e6e7921..00000000 --- a/Tools/USDXResCompiler.lpr +++ /dev/null @@ -1,159 +0,0 @@ -program USDXResCompiler; - -{$mode objfpc}{$H+} - -uses - Classes, - SysUtils, - LResources; - -var - lResourceFile : TMemoryStream; - -procedure AddFile( aResName, aResType, aFile : string ); -var - lTmpStream : TmemoryStream; -begin - if aFile[1] = '"' then - begin - aFile := copy( aFile, 2, length( aFile ) - 2 ); - end; - - if not fileexists( aFile ) then - begin - writeln( 'SKIPED' + ' ( '+aFile+' ) File not found' ); - exit; - end; - - lTmpStream := TmemoryStream.create(); - try - lTmpStream.loadfromfile( aFile ); - lTmpStream.position := 0; - - BinaryToLazarusResourceCode(lTmpStream, lResourceFile, aResName, aResType); - writeln( 'ADDED - ' + aResType + ' : ' + aResName + ' ( '+aFile+' )' ); - finally - freeandnil( lTmpStream ); - end; -end; - -procedure addresourceline( aRCLine : String ); -var - lName : String; - lType : String; - lFile : String; - lTmp , - lTmp2 : Integer; -begin - if trim( aRCLine ) = '' then - exit; - - if aRCLine[1] = '#' then - exit; - - if ( aRCLine[1] = '/' ) AND - ( aRCLine[2] = '/' ) THEN - exit; - - // find 2nd column... and put it in lTmp - lTmp := pos( ' ', aRcLine ); - lTmp2 := pos( #9, aRcLine ); - if lTmp2 < lTmp then - lTmp := lTmp2; - - // Name = Start to lTmp - lName := trim( copy( aRcLine, 1, lTmp ) ); - - // Type = lTmp to first " - lTmp2 := pos( '"', aRcLine ); - lType := trim( copy( aRcLine, lTmp, lTmp2-lTmp ) ); - - // File = " to end of line - lFile := trim( copy( aRcLine, lTmp2, maxint ) ); - - lFile := StringReplace( lFile, '\', PathDelim ,[rfReplaceAll] ); - -(* - writeln( aRcLine ); - writeln( lName ); - writeln( lType ); - writeln( lFile ); - writeln( '' ); -*) - AddFile( lName , lType , lFile ); - -end; - - -var - lRCFile : TStringList; - iCount : Integer; -begin - if not fileexists( paramstr(1) ) then - begin - writeln( 'MUST Specify Delphi format RC File' ); - exit; - end; - - lRCFile := TStringList.create(); - lResourceFile := TMemoryStream.create(); - try - lRCFile.loadfromfile( paramstr(1) ); - - if trim( lRCFile.text ) = '' then - exit; - - for iCount := 0 to lRCFile.count -1 do - begin - addresourceline( lRCFile[ iCount ] ); - end; - -(* - AddFile( 'Font', 'TEX', '..\Fonts\Normal\eurostar_regular.png' ); - AddFile( 'Font', 'FNT', '..\Fonts\Normal\eurostar_regular.dat' ); - - AddFile( 'FontB', 'TEX', '..\Fonts\Bold\eurostar_regular_bold.png' ); - AddFile( 'FontB', 'FNT', '..\Fonts\Bold\eurostar_regular_bold.dat' ); - - AddFile( 'FontO', 'TEX', '..\Fonts\Outline 1\Outline 1.PNG' ); - AddFile( 'FontO', 'FNT', '..\Fonts\Outline 1\Outline 1.dat' ); - - AddFile( 'FontO2', 'TEX', '..\Fonts\Outline 2\Outline 2.PNG' ); - AddFile( 'FontO2', 'FNT', '..\Fonts\Outline 2\Outline 2.dat' ); - - AddFile( 'MAINICON', 'ICON', '..\Graphics\ustar-icon_v01.ico' ); - - - AddFile( 'CRDTS_BG', 'TEX', '..\Graphics\credits_v5_bg.png' ); - AddFile( 'CRDTS_OVL', 'TEX', '..\Graphics\credits_v5_overlay.png' ); - AddFile( 'CRDTS_blindguard', 'TEX', '..\Graphics\names_blindguard.png' ); - AddFile( 'CRDTS_blindy', 'TEX', '..\Graphics\names_blindy.png' ); - AddFile( 'CRDTS_canni', 'TEX', '..\Graphics\names_canni.png' ); - AddFile( 'CRDTS_commandio', 'TEX', '..\Graphics\names_commandio.png' ); - AddFile( 'CRDTS_lazyjoker', 'TEX', '..\Graphics\names_lazyjoker.png' ); - AddFile( 'CRDTS_mog', 'TEX', '..\Graphics\names_mog.png' ); - AddFile( 'CRDTS_mota', 'TEX', '..\Graphics\names_mota.png' ); - AddFile( 'CRDTS_skillmaste', 'TEX', '..\Graphics\names_skillmaster.png' ); - AddFile( 'CRDTS_whiteshark', 'TEX', '..\Graphics\names_whiteshark.png' ); - AddFile( 'INTRO_L01', 'TEX', '..\Graphics\intro-l-01.png' ); - AddFile( 'INTRO_L02', 'TEX', '..\Graphics\intro-l-02.png' ); - AddFile( 'INTRO_L03', 'TEX', '..\Graphics\intro-l-03.png' ); - AddFile( 'INTRO_L04', 'TEX', '..\Graphics\intro-l-04.png' ); - AddFile( 'INTRO_L05', 'TEX', '..\Graphics\intro-l-05.png' ); - AddFile( 'INTRO_L06', 'TEX', '..\Graphics\intro-l-06.png' ); - AddFile( 'INTRO_L07', 'TEX', '..\Graphics\intro-l-07.png' ); - AddFile( 'INTRO_L08', 'TEX', '..\Graphics\intro-l-08.png' ); - AddFile( 'INTRO_L09', 'TEX', '..\Graphics\intro-l-09.png' ); - AddFile( 'OUTRO_BG', 'TEX', '..\Graphics\outro-bg.png' ); - AddFile( 'OUTRO_ESC', 'TEX', '..\Graphics\outro-esc.png' ); - AddFile( 'OUTRO_EXD', 'TEX', '..\Graphics\outro-exit-dark.png' ); -*) - - finally - lResourceFile.SaveToFile( 'UltraStar.lrs' ); - freeandnil( lResourceFile ); - - freeandnil( lRCFile ); - end; -end. - diff --git a/Tools/USDXResCompiler/USDXResCompiler.lpi b/Tools/USDXResCompiler/USDXResCompiler.lpi new file mode 100644 index 00000000..cf94486e --- /dev/null +++ b/Tools/USDXResCompiler/USDXResCompiler.lpi @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tools/USDXResCompiler/USDXResCompiler.lpr b/Tools/USDXResCompiler/USDXResCompiler.lpr new file mode 100644 index 00000000..8e6e7921 --- /dev/null +++ b/Tools/USDXResCompiler/USDXResCompiler.lpr @@ -0,0 +1,159 @@ +program USDXResCompiler; + +{$mode objfpc}{$H+} + +uses + Classes, + SysUtils, + LResources; + +var + lResourceFile : TMemoryStream; + +procedure AddFile( aResName, aResType, aFile : string ); +var + lTmpStream : TmemoryStream; +begin + if aFile[1] = '"' then + begin + aFile := copy( aFile, 2, length( aFile ) - 2 ); + end; + + if not fileexists( aFile ) then + begin + writeln( 'SKIPED' + ' ( '+aFile+' ) File not found' ); + exit; + end; + + lTmpStream := TmemoryStream.create(); + try + lTmpStream.loadfromfile( aFile ); + lTmpStream.position := 0; + + BinaryToLazarusResourceCode(lTmpStream, lResourceFile, aResName, aResType); + writeln( 'ADDED - ' + aResType + ' : ' + aResName + ' ( '+aFile+' )' ); + finally + freeandnil( lTmpStream ); + end; +end; + +procedure addresourceline( aRCLine : String ); +var + lName : String; + lType : String; + lFile : String; + lTmp , + lTmp2 : Integer; +begin + if trim( aRCLine ) = '' then + exit; + + if aRCLine[1] = '#' then + exit; + + if ( aRCLine[1] = '/' ) AND + ( aRCLine[2] = '/' ) THEN + exit; + + // find 2nd column... and put it in lTmp + lTmp := pos( ' ', aRcLine ); + lTmp2 := pos( #9, aRcLine ); + if lTmp2 < lTmp then + lTmp := lTmp2; + + // Name = Start to lTmp + lName := trim( copy( aRcLine, 1, lTmp ) ); + + // Type = lTmp to first " + lTmp2 := pos( '"', aRcLine ); + lType := trim( copy( aRcLine, lTmp, lTmp2-lTmp ) ); + + // File = " to end of line + lFile := trim( copy( aRcLine, lTmp2, maxint ) ); + + lFile := StringReplace( lFile, '\', PathDelim ,[rfReplaceAll] ); + +(* + writeln( aRcLine ); + writeln( lName ); + writeln( lType ); + writeln( lFile ); + writeln( '' ); +*) + AddFile( lName , lType , lFile ); + +end; + + +var + lRCFile : TStringList; + iCount : Integer; +begin + if not fileexists( paramstr(1) ) then + begin + writeln( 'MUST Specify Delphi format RC File' ); + exit; + end; + + lRCFile := TStringList.create(); + lResourceFile := TMemoryStream.create(); + try + lRCFile.loadfromfile( paramstr(1) ); + + if trim( lRCFile.text ) = '' then + exit; + + for iCount := 0 to lRCFile.count -1 do + begin + addresourceline( lRCFile[ iCount ] ); + end; + +(* + AddFile( 'Font', 'TEX', '..\Fonts\Normal\eurostar_regular.png' ); + AddFile( 'Font', 'FNT', '..\Fonts\Normal\eurostar_regular.dat' ); + + AddFile( 'FontB', 'TEX', '..\Fonts\Bold\eurostar_regular_bold.png' ); + AddFile( 'FontB', 'FNT', '..\Fonts\Bold\eurostar_regular_bold.dat' ); + + AddFile( 'FontO', 'TEX', '..\Fonts\Outline 1\Outline 1.PNG' ); + AddFile( 'FontO', 'FNT', '..\Fonts\Outline 1\Outline 1.dat' ); + + AddFile( 'FontO2', 'TEX', '..\Fonts\Outline 2\Outline 2.PNG' ); + AddFile( 'FontO2', 'FNT', '..\Fonts\Outline 2\Outline 2.dat' ); + + AddFile( 'MAINICON', 'ICON', '..\Graphics\ustar-icon_v01.ico' ); + + + AddFile( 'CRDTS_BG', 'TEX', '..\Graphics\credits_v5_bg.png' ); + AddFile( 'CRDTS_OVL', 'TEX', '..\Graphics\credits_v5_overlay.png' ); + AddFile( 'CRDTS_blindguard', 'TEX', '..\Graphics\names_blindguard.png' ); + AddFile( 'CRDTS_blindy', 'TEX', '..\Graphics\names_blindy.png' ); + AddFile( 'CRDTS_canni', 'TEX', '..\Graphics\names_canni.png' ); + AddFile( 'CRDTS_commandio', 'TEX', '..\Graphics\names_commandio.png' ); + AddFile( 'CRDTS_lazyjoker', 'TEX', '..\Graphics\names_lazyjoker.png' ); + AddFile( 'CRDTS_mog', 'TEX', '..\Graphics\names_mog.png' ); + AddFile( 'CRDTS_mota', 'TEX', '..\Graphics\names_mota.png' ); + AddFile( 'CRDTS_skillmaste', 'TEX', '..\Graphics\names_skillmaster.png' ); + AddFile( 'CRDTS_whiteshark', 'TEX', '..\Graphics\names_whiteshark.png' ); + AddFile( 'INTRO_L01', 'TEX', '..\Graphics\intro-l-01.png' ); + AddFile( 'INTRO_L02', 'TEX', '..\Graphics\intro-l-02.png' ); + AddFile( 'INTRO_L03', 'TEX', '..\Graphics\intro-l-03.png' ); + AddFile( 'INTRO_L04', 'TEX', '..\Graphics\intro-l-04.png' ); + AddFile( 'INTRO_L05', 'TEX', '..\Graphics\intro-l-05.png' ); + AddFile( 'INTRO_L06', 'TEX', '..\Graphics\intro-l-06.png' ); + AddFile( 'INTRO_L07', 'TEX', '..\Graphics\intro-l-07.png' ); + AddFile( 'INTRO_L08', 'TEX', '..\Graphics\intro-l-08.png' ); + AddFile( 'INTRO_L09', 'TEX', '..\Graphics\intro-l-09.png' ); + AddFile( 'OUTRO_BG', 'TEX', '..\Graphics\outro-bg.png' ); + AddFile( 'OUTRO_ESC', 'TEX', '..\Graphics\outro-esc.png' ); + AddFile( 'OUTRO_EXD', 'TEX', '..\Graphics\outro-exit-dark.png' ); +*) + + finally + lResourceFile.SaveToFile( 'UltraStar.lrs' ); + freeandnil( lResourceFile ); + + freeandnil( lRCFile ); + end; +end. + diff --git a/Tools/USDXResCompiler/linux-build.sh b/Tools/USDXResCompiler/linux-build.sh new file mode 100755 index 00000000..fd1b28b6 --- /dev/null +++ b/Tools/USDXResCompiler/linux-build.sh @@ -0,0 +1,3 @@ +clear +fpc -S2cgi -OG1 -gl -vewnhi -l -Filib/JEDI-SDLv1.0/SDL/Pas/ -Fu/usr/lib/lazarus/components/images/lib/i386-linux/ -Fu/usr/lib/lazarus/lcl/units/i386-linux/ -Fu/usr/lib/lazarus/lcl/units/i386-linux/gtk2/ -Fu/usr/lib/lazarus/packager/units/i386-linux/ -Fu. -dLCL -dLCLgtk2 USDXResCompiler.lpr + diff --git a/Tools/linux-build.sh b/Tools/linux-build.sh deleted file mode 100755 index fd1b28b6..00000000 --- a/Tools/linux-build.sh +++ /dev/null @@ -1,3 +0,0 @@ -clear -fpc -S2cgi -OG1 -gl -vewnhi -l -Filib/JEDI-SDLv1.0/SDL/Pas/ -Fu/usr/lib/lazarus/components/images/lib/i386-linux/ -Fu/usr/lib/lazarus/lcl/units/i386-linux/ -Fu/usr/lib/lazarus/lcl/units/i386-linux/gtk2/ -Fu/usr/lib/lazarus/packager/units/i386-linux/ -Fu. -dLCL -dLCLgtk2 USDXResCompiler.lpr - -- cgit v1.2.3