clean up some stream using code (using blocks, dispose calls, etc)

This commit is contained in:
Gered 2013-08-29 23:18:37 -04:00
parent bd55d43ab3
commit 25c08c807a
3 changed files with 19 additions and 12 deletions

View file

@ -10,12 +10,14 @@ namespace Blarg.GameFramework.Graphics.Atlas.Json
{
public static TextureAtlas Load(string file)
{
var stream = Framework.FileSystem.Open(file);
string path = null;
if (file.Contains("/"))
path = file.Substring(0, file.LastIndexOf('/') + 1);
return Load(stream, path);
using (var stream = Framework.FileSystem.Open(file))
{
string path = null;
if (file.Contains("/"))
path = file.Substring(0, file.LastIndexOf('/') + 1);
return Load(stream, path);
}
}
public static TextureAtlas Load(Stream file, string texturePath = null)
@ -25,6 +27,7 @@ namespace Blarg.GameFramework.Graphics.Atlas.Json
var reader = new StreamReader(file);
var definition = JsonConvert.DeserializeObject<JsonTextureAtlasDefinition>(reader.ReadToEnd());
reader.Dispose();
if (definition.Texture == null)
throw new ConfigFileException("No texture file specified.");

View file

@ -32,6 +32,7 @@ namespace Blarg.GameFramework.TileMap.Json
var reader = new StreamReader(file);
var map = JsonConvert.DeserializeObject<JsonTileMap>(reader.ReadToEnd());
reader.Dispose();
if (map.Chunks == null || map.Chunks.Count == 0)
throw new ConfigFileException("Invalid map: no chunks.");

View file

@ -11,12 +11,14 @@ namespace Blarg.GameFramework.TileMap.Meshes.Json
{
public static TileMeshCollection Load(string file, TextureAtlas atlas)
{
var stream = Framework.FileSystem.Open(file);
string path = null;
if (file.Contains("/"))
path = file.Substring(0, file.LastIndexOf('/') + 1);
return Load(stream, atlas, path);
using (var stream = Framework.FileSystem.Open(file))
{
string path = null;
if (file.Contains("/"))
path = file.Substring(0, file.LastIndexOf('/') + 1);
return Load(stream, atlas, path);
}
}
public static TileMeshCollection Load(Stream file, TextureAtlas atlas, string filePath = null)
@ -28,6 +30,7 @@ namespace Blarg.GameFramework.TileMap.Meshes.Json
var reader = new StreamReader(file);
var definition = JsonConvert.DeserializeObject<JsonTileMeshCollection>(reader.ReadToEnd());
reader.Dispose();
var collection = new TileMeshCollection(atlas);