git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1321 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
40
OpenRa.FileFormats/FileSystem.cs
Normal file
40
OpenRa.FileFormats/FileSystem.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using OpenRa.FileFormats;
|
||||
|
||||
namespace OpenRa.FileFormats
|
||||
{
|
||||
public class Folder : IFolder
|
||||
{
|
||||
readonly string path;
|
||||
|
||||
public Folder(string path) { this.path = path; }
|
||||
|
||||
public Stream GetContent(string filename)
|
||||
{
|
||||
try { return File.OpenRead(path + filename); }
|
||||
catch { throw new FileNotFoundException("File not found", filename); }
|
||||
}
|
||||
}
|
||||
|
||||
public static class FileSystem
|
||||
{
|
||||
static List<IFolder> mountedFolders = new List<IFolder>();
|
||||
|
||||
public static void Mount(IFolder folder)
|
||||
{
|
||||
mountedFolders.Add(folder);
|
||||
}
|
||||
|
||||
public static Stream Open(string filename)
|
||||
{
|
||||
foreach (IFolder folder in mountedFolders)
|
||||
try { return folder.GetContent(filename); }
|
||||
catch { }
|
||||
|
||||
throw new FileNotFoundException("File not found", filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Blowfish.cs" />
|
||||
<Compile Include="FileSystem.cs" />
|
||||
<Compile Include="Format40.cs" />
|
||||
<Compile Include="Format80.cs" />
|
||||
<Compile Include="IniFile.cs" />
|
||||
|
||||
@@ -13,8 +13,6 @@ namespace OpenRa.FileFormats
|
||||
readonly Dictionary<ushort, Dictionary<int, int>> walk =
|
||||
new Dictionary<ushort, Dictionary<int, int>>(); // cjf will fix
|
||||
|
||||
public readonly Package MixFile;
|
||||
|
||||
string NextLine( StreamReader reader )
|
||||
{
|
||||
string ret;
|
||||
@@ -29,12 +27,11 @@ namespace OpenRa.FileFormats
|
||||
return ret;
|
||||
}
|
||||
|
||||
public TileSet( Package mixFile, string suffix )
|
||||
public TileSet( string suffix )
|
||||
{
|
||||
Walkability walkability = new Walkability();
|
||||
|
||||
char tileSetChar = char.ToUpperInvariant( suffix[ 1 ] );
|
||||
MixFile = mixFile;
|
||||
StreamReader tileIdFile = File.OpenText( "../../../tileSet.til" );
|
||||
|
||||
while( true )
|
||||
@@ -58,9 +55,11 @@ namespace OpenRa.FileFormats
|
||||
if (!walk.ContainsKey((ushort)(start + i)))
|
||||
walk.Add((ushort)(start + i), walkability.GetWalkability(tilename));
|
||||
|
||||
Stream s = mixFile.GetContent(tilename + suffix);
|
||||
if (!tiles.ContainsKey((ushort)(start + i)))
|
||||
tiles.Add((ushort)(start + i), new Terrain(s));
|
||||
using( Stream s = FileSystem.Open( tilename + suffix ) )
|
||||
{
|
||||
if( !tiles.ContainsKey( (ushort)( start + i ) ) )
|
||||
tiles.Add( (ushort)( start + i ), new Terrain( s ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user