git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1953 993157c7-ee19-0410-b2c4-bb4e9862e678

This commit is contained in:
chrisf
2008-03-25 00:45:43 +00:00
parent eb7094d49e
commit 33e856345f
16 changed files with 126 additions and 179 deletions

View File

@@ -47,18 +47,19 @@ namespace OpenRa.FileFormats
bool ProcessEntry( string line )
{
Match m = entryPattern.Match( line );
if( m == null || !m.Success )
return false;
int comment = line.IndexOf(';');
if (comment >= 0)
line = line.Substring(0, comment);
if( currentSection == null )
throw new InvalidOperationException( "No current INI section" );
int eq = line.IndexOf('=');
if (eq < 0)
return false;
string keyName = m.Groups[ 1 ].Value;
string keyValue = m.Groups[ 2 ].Value;
currentSection.Add( keyName, keyValue );
if (currentSection == null)
throw new InvalidOperationException("No current INI section");
currentSection.Add(line.Substring(0, eq),
line.Substring(eq + 1, line.Length - eq - 1));
return true;
}

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}</ProjectGuid>
<OutputType>Library</OutputType>
@@ -14,6 +14,7 @@
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -23,6 +24,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -31,6 +33,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="MixDecrypt, Version=0.0.0.0, Culture=neutral, processorArchitecture=x86">

View File

@@ -13,39 +13,48 @@ namespace OpenRa.FileFormats
public class Package : IFolder
{
readonly string filename;
readonly List<PackageEntry> index;
readonly Dictionary<uint, PackageEntry> index;
readonly bool isRmix, isEncrypted;
readonly long dataStart;
readonly Stream s;
public ICollection<PackageEntry> Content
{
get { return index.AsReadOnly(); }
}
//public ICollection<PackageEntry> Content
//{
// get { return index.AsReadOnly(); }
//}
public static Dictionary<K, V> MakeDict<K,V>(IEnumerable<V> values, Converter<V, K> keyFunc)
{
var dict = new Dictionary<K, V>();
foreach (var v in values)
dict.Add(keyFunc(v), v);
return dict;
}
public Package(string filename)
{
this.filename = filename;
using (Stream s = FileSystem.Open(filename))
s = FileSystem.Open(filename);
BinaryReader reader = new BinaryReader(s);
uint signature = reader.ReadUInt32();
isRmix = 0 == (signature & ~(uint)(MixFileFlags.Checksum | MixFileFlags.Encrypted));
if (isRmix)
{
BinaryReader reader = new BinaryReader(s);
uint signature = reader.ReadUInt32();
isRmix = 0 == (signature & ~(uint)(MixFileFlags.Checksum | MixFileFlags.Encrypted));
if (isRmix)
isEncrypted = 0 != (signature & (uint)MixFileFlags.Encrypted);
if( isEncrypted )
{
isEncrypted = 0 != (signature & (uint)MixFileFlags.Encrypted);
if( isEncrypted )
{
index = ParseRaHeader( s, out dataStart );
return;
}
index = MakeDict(ParseRaHeader( s, out dataStart ), x => x.Hash );
return;
}
isEncrypted = false;
s.Seek(0, SeekOrigin.Begin);
index = ParseTdHeader(s, out dataStart);
}
isEncrypted = false;
s.Seek(0, SeekOrigin.Begin);
index = MakeDict(ParseTdHeader(s, out dataStart), x => x.Hash );
}
const long headerStart = 84;
@@ -121,19 +130,14 @@ namespace OpenRa.FileFormats
public Stream GetContent(uint hash)
{
foreach( PackageEntry e in index )
if (e.Hash == hash)
{
using (Stream s = FileSystem.Open(filename))
{
s.Seek( dataStart + e.Offset, SeekOrigin.Begin );
byte[] data = new byte[ e.Length ];
s.Read( data, 0, (int)e.Length );
return new MemoryStream(data);
}
}
PackageEntry e;
if (!index.TryGetValue(hash, out e))
return null;
return null;
s.Seek( dataStart + e.Offset, SeekOrigin.Begin );
byte[] data = new byte[ e.Length ];
s.Read( data, 0, (int)e.Length );
return new MemoryStream(data);
}
public Stream GetContent(string filename)

View File

@@ -39,13 +39,11 @@ namespace OpenRa.FileFormats
MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(name));
BinaryReader reader = new BinaryReader(ms);
int len = name.Length >> 2;
uint result = 0;
try
{
while(true)
result = ((result << 1) | (result >> 31)) + reader.ReadUInt32();
}
catch (EndOfStreamException) { }
while (len-- != 0)
result = ((result << 1) | (result >> 31)) + reader.ReadUInt32();
return result;
}