diff options
author | tobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2008-04-07 08:50:43 +0000 |
---|---|---|
committer | tobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2008-04-07 08:50:43 +0000 |
commit | c316180c74e144a5faecfe30ab38c8e4e0ef9e91 (patch) | |
tree | c3c917ece6b85f6284e474b28e64680a3cc20836 /Tools | |
parent | b007aad2fa55bb72b69ecfb56ba6207d31eff684 (diff) | |
download | usdx-c316180c74e144a5faecfe30ab38c8e4e0ef9e91.tar.gz usdx-c316180c74e144a5faecfe30ab38c8e4e0ef9e91.tar.xz usdx-c316180c74e144a5faecfe30ab38c8e4e0ef9e91.zip |
- 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
Diffstat (limited to '')
-rw-r--r-- | Tools/ResourceExtractor/ResourceExtractor.lpi | 106 | ||||
-rw-r--r-- | Tools/ResourceExtractor/ResourceExtractor.pas | 152 | ||||
-rw-r--r-- | Tools/USDXResCompiler/USDXResCompiler.lpi (renamed from Tools/USDXResCompiler.lpi) | 0 | ||||
-rw-r--r-- | Tools/USDXResCompiler/USDXResCompiler.lpr (renamed from Tools/USDXResCompiler.lpr) | 0 | ||||
-rwxr-xr-x | Tools/USDXResCompiler/linux-build.sh (renamed from Tools/linux-build.sh) | 0 |
5 files changed, 258 insertions, 0 deletions
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 @@ +<?xml version="1.0"?> +<CONFIG> + <ProjectOptions> + <PathDelim Value="/"/> + <Version Value="6"/> + <General> + <Flags> + <MainUnitHasUsesSectionForAllUnits Value="False"/> + <MainUnitHasCreateFormStatements Value="False"/> + <MainUnitHasTitleStatement Value="False"/> + </Flags> + <MainUnit Value="0"/> + <IconPath Value="./"/> + <TargetFileExt Value=""/> + <ActiveEditorIndexAtStart Value="0"/> + </General> + <VersionInfo> + <ProjectVersion Value=""/> + <Language Value=""/> + <CharSet Value=""/> + </VersionInfo> + <PublishOptions> + <Version Value="2"/> + <IgnoreBinaries Value="False"/> + <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/> + <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/> + </PublishOptions> + <RunParams> + <local> + <FormatVersion Value="1"/> + <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> + </local> + </RunParams> + <Units Count="3"> + <Unit0> + <Filename Value="ResourceExtractor.pas"/> + <IsPartOfProject Value="True"/> + <UnitName Value="ResourceExtractor"/> + <CursorPos X="1" Y="131"/> + <TopLine Value="108"/> + <EditorIndex Value="0"/> + <UsageCount Value="21"/> + <Loaded Value="True"/> + </Unit0> + <Unit1> + <Filename Value="../USDXResCompiler.lpr"/> + <UnitName Value="USDXResCompiler"/> + <CursorPos X="17" Y="96"/> + <TopLine Value="89"/> + <UsageCount Value="10"/> + </Unit1> + <Unit2> + <Filename Value="../../Game/Code/resource.inc"/> + <CursorPos X="1" Y="1"/> + <TopLine Value="1"/> + <UsageCount Value="10"/> + </Unit2> + </Units> + <JumpHistory Count="8" HistoryIndex="7"> + <Position1> + <Filename Value="ResourceExtractor.pas"/> + <Caret Line="144" Column="23" TopLine="104"/> + </Position1> + <Position2> + <Filename Value="ResourceExtractor.pas"/> + <Caret Line="120" Column="1" TopLine="99"/> + </Position2> + <Position3> + <Filename Value="ResourceExtractor.pas"/> + <Caret Line="140" Column="25" TopLine="105"/> + </Position3> + <Position4> + <Filename Value="ResourceExtractor.pas"/> + <Caret Line="146" Column="32" TopLine="103"/> + </Position4> + <Position5> + <Filename Value="ResourceExtractor.pas"/> + <Caret Line="139" Column="27" TopLine="105"/> + </Position5> + <Position6> + <Filename Value="ResourceExtractor.pas"/> + <Caret Line="140" Column="8" TopLine="105"/> + </Position6> + <Position7> + <Filename Value="ResourceExtractor.pas"/> + <Caret Line="139" Column="27" TopLine="106"/> + </Position7> + <Position8> + <Filename Value="ResourceExtractor.pas"/> + <Caret Line="144" Column="7" TopLine="106"/> + </Position8> + </JumpHistory> + </ProjectOptions> + <CompilerOptions> + <Version Value="5"/> + <SearchPaths> + <SrcPath Value="../../Game/Code/"/> + </SearchPaths> + <CodeGeneration> + <Generate Value="Faster"/> + </CodeGeneration> + <Other> + <CompilerPath Value="$(CompPath)"/> + </Other> + </CompilerOptions> +</CONFIG> 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/USDXResCompiler.lpi index cf94486e..cf94486e 100644 --- a/Tools/USDXResCompiler.lpi +++ b/Tools/USDXResCompiler/USDXResCompiler.lpi diff --git a/Tools/USDXResCompiler.lpr b/Tools/USDXResCompiler/USDXResCompiler.lpr index 8e6e7921..8e6e7921 100644 --- a/Tools/USDXResCompiler.lpr +++ b/Tools/USDXResCompiler/USDXResCompiler.lpr diff --git a/Tools/linux-build.sh b/Tools/USDXResCompiler/linux-build.sh index fd1b28b6..fd1b28b6 100755 --- a/Tools/linux-build.sh +++ b/Tools/USDXResCompiler/linux-build.sh |