Use using constructs on disposable io objects in LLRaw to ensure they are always closed even if an exception is thrown.
parent
06a52b43df
commit
4717132b82
|
@ -74,12 +74,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
|
||||||
public ITerrainChannel LoadFile(string filename)
|
public ITerrainChannel LoadFile(string filename)
|
||||||
{
|
{
|
||||||
FileInfo file = new FileInfo(filename);
|
FileInfo file = new FileInfo(filename);
|
||||||
FileStream s = file.Open(FileMode.Open, FileAccess.Read);
|
|
||||||
ITerrainChannel retval = LoadStream(s);
|
|
||||||
|
|
||||||
s.Close();
|
ITerrainChannel channel;
|
||||||
|
|
||||||
return retval;
|
using (FileStream s = file.Open(FileMode.Open, FileAccess.Read))
|
||||||
|
channel = LoadStream(s);
|
||||||
|
|
||||||
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight)
|
public ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight)
|
||||||
|
@ -87,9 +88,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
|
||||||
TerrainChannel retval = new TerrainChannel(sectionWidth, sectionHeight);
|
TerrainChannel retval = new TerrainChannel(sectionWidth, sectionHeight);
|
||||||
|
|
||||||
FileInfo file = new FileInfo(filename);
|
FileInfo file = new FileInfo(filename);
|
||||||
FileStream s = file.Open(FileMode.Open, FileAccess.Read);
|
|
||||||
BinaryReader bs = new BinaryReader(s);
|
|
||||||
|
|
||||||
|
using (FileStream s = file.Open(FileMode.Open, FileAccess.Read))
|
||||||
|
using (BinaryReader bs = new BinaryReader(s))
|
||||||
|
{
|
||||||
int currFileYOffset = fileHeight - 1;
|
int currFileYOffset = fileHeight - 1;
|
||||||
|
|
||||||
// if our region isn't on the first Y section of the areas to be landscaped, then
|
// if our region isn't on the first Y section of the areas to be landscaped, then
|
||||||
|
@ -105,6 +107,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
|
||||||
// got to the Y start offset within the file of our region
|
// got to the Y start offset within the file of our region
|
||||||
// so read the file bits associated with our region
|
// so read the file bits associated with our region
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
// for each Y within our Y offset
|
// for each Y within our Y offset
|
||||||
for (y = sectionHeight - 1; y >= 0; y--)
|
for (y = sectionHeight - 1; y >= 0; y--)
|
||||||
{
|
{
|
||||||
|
@ -139,9 +142,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
|
||||||
currFileXOffset++;
|
currFileXOffset++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
bs.Close();
|
|
||||||
s.Close();
|
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -158,7 +159,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
|
||||||
|
|
||||||
TerrainChannel retval = new TerrainChannel(trimmedDimension, trimmedDimension);
|
TerrainChannel retval = new TerrainChannel(trimmedDimension, trimmedDimension);
|
||||||
|
|
||||||
BinaryReader bs = new BinaryReader(s);
|
using (BinaryReader bs = new BinaryReader(s))
|
||||||
|
{
|
||||||
int y;
|
int y;
|
||||||
for (y = 0; y < retval.Height; y++)
|
for (y = 0; y < retval.Height; y++)
|
||||||
{
|
{
|
||||||
|
@ -169,8 +171,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
|
||||||
bs.ReadBytes(11); // Advance the stream to next bytes.
|
bs.ReadBytes(11); // Advance the stream to next bytes.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
bs.Close();
|
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -178,16 +179,15 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
|
||||||
public void SaveFile(string filename, ITerrainChannel map)
|
public void SaveFile(string filename, ITerrainChannel map)
|
||||||
{
|
{
|
||||||
FileInfo file = new FileInfo(filename);
|
FileInfo file = new FileInfo(filename);
|
||||||
FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write);
|
|
||||||
SaveStream(s, map);
|
|
||||||
|
|
||||||
s.Close();
|
using (FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write))
|
||||||
|
SaveStream(s, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveStream(Stream s, ITerrainChannel map)
|
public void SaveStream(Stream s, ITerrainChannel map)
|
||||||
{
|
{
|
||||||
BinaryWriter binStream = new BinaryWriter(s);
|
using (BinaryWriter binStream = new BinaryWriter(s))
|
||||||
|
{
|
||||||
// Output the calculated raw
|
// Output the calculated raw
|
||||||
for (int y = 0; y < map.Height; y++)
|
for (int y = 0; y < map.Height; y++)
|
||||||
{
|
{
|
||||||
|
@ -240,8 +240,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
|
||||||
binStream.Write(alpha10);
|
binStream.Write(alpha10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
binStream.Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string FileExtension
|
public string FileExtension
|
||||||
|
@ -269,6 +268,5 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue