From cd70038a3cc62c4088ae9cb82bdc00a661f2c6a3 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@993157c7-ee19-0410-b2c4-bb4e9862e678> Date: Thu, 26 Jul 2007 08:20:39 +0000 Subject: [PATCH] less ../../../ git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1355 993157c7-ee19-0410-b2c4-bb4e9862e678 --- OpenRa.FileFormats/FileSystem.cs | 9 ++++++--- OpenRa.FileFormats/Folder.cs | 2 +- OpenRa.FileFormats/Package.cs | 15 ++++----------- OpenRa.FileFormats/TileSet.cs | 2 +- OpenRa.FileFormats/Walkability.cs | 4 +--- OpenRa.Game/Game.cs | 2 +- OpenRa.Game/MainWindow.cs | 4 ++-- OpenRa.Game/Program.cs | 1 - OpenRa.TechTree/TechTree.cs | 8 ++++---- 9 files changed, 20 insertions(+), 27 deletions(-) diff --git a/OpenRa.FileFormats/FileSystem.cs b/OpenRa.FileFormats/FileSystem.cs index 91faad27f8..9361a40f2f 100644 --- a/OpenRa.FileFormats/FileSystem.cs +++ b/OpenRa.FileFormats/FileSystem.cs @@ -17,9 +17,12 @@ namespace OpenRa.FileFormats public static Stream Open(string filename) { - foreach (IFolder folder in mountedFolders) - try { return folder.GetContent(filename); } - catch { } + foreach( IFolder folder in mountedFolders ) + { + Stream s = folder.GetContent(filename); + if( s != null ) + return s; + } throw new FileNotFoundException("File not found", filename); } diff --git a/OpenRa.FileFormats/Folder.cs b/OpenRa.FileFormats/Folder.cs index e43f9b3a47..7f75880c26 100644 --- a/OpenRa.FileFormats/Folder.cs +++ b/OpenRa.FileFormats/Folder.cs @@ -14,7 +14,7 @@ namespace OpenRa.FileFormats public Stream GetContent(string filename) { try { return File.OpenRead(path + filename); } - catch { throw new FileNotFoundException("File not found", filename); } + catch { return null; } } } } diff --git a/OpenRa.FileFormats/Package.cs b/OpenRa.FileFormats/Package.cs index e0c3147ecf..2131e9b407 100644 --- a/OpenRa.FileFormats/Package.cs +++ b/OpenRa.FileFormats/Package.cs @@ -25,7 +25,7 @@ namespace OpenRa.FileFormats public Package(string filename) { this.filename = filename; - using (Stream s = File.OpenRead(filename)) + using (Stream s = FileSystem.Open(filename)) { BinaryReader reader = new BinaryReader(s); uint signature = reader.ReadUInt32(); @@ -124,7 +124,7 @@ namespace OpenRa.FileFormats foreach( PackageEntry e in index ) if (e.Hash == hash) { - using (Stream s = File.OpenRead(filename)) + using (Stream s = FileSystem.Open(filename)) { s.Seek( dataStart + e.Offset, SeekOrigin.Begin ); byte[] data = new byte[ e.Length ]; @@ -133,19 +133,12 @@ namespace OpenRa.FileFormats } } - throw new FileNotFoundException(); + return null; } public Stream GetContent(string filename) { - try - { - return GetContent(PackageEntry.HashFilename(filename)); - } - catch (FileNotFoundException e) - { - throw new FileNotFoundException("File not found", filename, e); - } + return GetContent(PackageEntry.HashFilename(filename)); } } diff --git a/OpenRa.FileFormats/TileSet.cs b/OpenRa.FileFormats/TileSet.cs index 7bb962411f..a2ed6b6ceb 100644 --- a/OpenRa.FileFormats/TileSet.cs +++ b/OpenRa.FileFormats/TileSet.cs @@ -32,7 +32,7 @@ namespace OpenRa.FileFormats Walkability walkability = new Walkability(); char tileSetChar = char.ToUpperInvariant( suffix[ 1 ] ); - StreamReader tileIdFile = File.OpenText( "../../../tileSet.til" ); + StreamReader tileIdFile = new StreamReader( FileSystem.Open( "tileSet.til" ) ); while( true ) { diff --git a/OpenRa.FileFormats/Walkability.cs b/OpenRa.FileFormats/Walkability.cs index ba0c20c16c..e7404f969b 100644 --- a/OpenRa.FileFormats/Walkability.cs +++ b/OpenRa.FileFormats/Walkability.cs @@ -8,14 +8,12 @@ namespace OpenRa.FileFormats { public class Walkability { - const string src = "../../../templates.ini"; - Dictionary> walkability = new Dictionary>(); public Walkability() { - IniFile file = new IniFile(File.OpenRead(src)); + IniFile file = new IniFile( FileSystem.Open( "templates.ini" ) ); Regex pattern = new Regex(@"tiletype(\d+)"); foreach (IniSection section in file.Sections) diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 1ee4ac4749..7aa09c2e23 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -30,7 +30,7 @@ namespace OpenRa.Game players.Add( i, new Player( i, string.Format( "Multi{0}", i ), OpenRa.TechTree.Race.Soviet ) ); map = new Map(new IniFile(FileSystem.Open(mapName))); - FileSystem.Mount(new Package("../../../" + map.Theater + ".mix")); + FileSystem.Mount(new Package(map.Theater + ".mix")); viewport = new Viewport(clientSize, map.Size, renderer); diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index cd38bdace4..a0bd8303c9 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -28,8 +28,8 @@ namespace OpenRa.Game public MainWindow(Settings settings) { FileSystem.Mount(new Folder("../../../")); - FileSystem.Mount(new Package("../../../conquer.mix")); - FileSystem.Mount(new Package("../../../hires.mix")); + FileSystem.Mount(new Package("conquer.mix")); + FileSystem.Mount(new Package("hires.mix")); FormBorderStyle = FormBorderStyle.None; BackColor = Color.Black; diff --git a/OpenRa.Game/Program.cs b/OpenRa.Game/Program.cs index 4d0171800b..6c40336c4c 100644 --- a/OpenRa.Game/Program.cs +++ b/OpenRa.Game/Program.cs @@ -22,7 +22,6 @@ namespace OpenRa.Game } catch( Exception e ) { - File.WriteAllText( "error.log", e.ToString() ); Log.Write( "{0}", e.ToString() ); throw; } diff --git a/OpenRa.TechTree/TechTree.cs b/OpenRa.TechTree/TechTree.cs index bc741d6b2f..ee9a757472 100644 --- a/OpenRa.TechTree/TechTree.cs +++ b/OpenRa.TechTree/TechTree.cs @@ -41,7 +41,7 @@ namespace OpenRa.TechTree IEnumerable> Lines(string filename, bool param) { Regex pattern = new Regex(@"^(\w+),([\w ]+)$"); - foreach (string s in File.ReadAllLines(filename)) + foreach (string s in File.ReadAllLines("../../../" + filename)) { Match m = pattern.Match(s); if (m == null || !m.Success) @@ -54,10 +54,10 @@ namespace OpenRa.TechTree void LoadRules() { - IniFile rulesFile = new IniFile(File.OpenRead("../../../rules.ini")); + IniFile rulesFile = new IniFile(FileSystem.Open("rules.ini")); IEnumerable> definitions = Concat( - Lines("../../../buildings.txt", true), - Lines("../../../units.txt", false)); + Lines("buildings.txt", true), + Lines("units.txt", false)); foreach (Tuple p in definitions) objects.Add(p.a, new Item(p.a, p.b, rulesFile.GetSection(p.a), p.c));