[ALL] Stop using "using" for everything except databases

This commit is contained in:
Matt Nadareski
2016-09-22 15:36:02 -07:00
parent 6b43053b7d
commit 74fbe60686
6 changed files with 239 additions and 248 deletions

View File

@@ -499,7 +499,6 @@ namespace SabreTools.Helper
{
StreamReader sr = File.OpenText(filename);
string first = sr.ReadLine();
sr.Close();
sr.Dispose();
if (first.Contains("<") && first.Contains(">"))
{
@@ -1289,7 +1288,6 @@ namespace SabreTools.Helper
}
}
sr.Close();
sr.Dispose();
}
@@ -1454,7 +1452,6 @@ namespace SabreTools.Helper
}
}
sr.Close();
sr.Dispose();
}
@@ -2218,7 +2215,6 @@ namespace SabreTools.Helper
}
}
xtr.Close();
xtr.Dispose();
}
}
@@ -3215,8 +3211,8 @@ namespace SabreTools.Helper
WriteFooter(sw, outputFormat, datdata, depth, logger);
logger.Log("File written!" + Environment.NewLine);
sw.Close();
fs.Close();
sw.Dispose();
fs.Dispose();
}
}
catch (Exception ex)

View File

@@ -101,16 +101,17 @@ namespace SabreTools
// Now take care of the header and new output file
string hstr = string.Empty;
using (BinaryReader br = new BinaryReader(File.OpenRead(file)))
BinaryReader br = new BinaryReader(File.OpenRead(file));
// Extract the header as a string for the database
byte[] hbin = br.ReadBytes(headerSize);
for (int i = 0; i < headerSize; i++)
{
// Extract the header as a string for the database
byte[] hbin = br.ReadBytes(headerSize);
for (int i = 0; i < headerSize; i++)
{
hstr += BitConverter.ToString(new byte[] { hbin[i] });
}
hstr += BitConverter.ToString(new byte[] { hbin[i] });
}
br.Dispose();
// Then find an apply the exact rule to the file
SkipperRule rule = Skippers.MatchesSkipper(file, "", _logger);

View File

@@ -488,27 +488,32 @@ namespace SabreTools.Helper
// If there's a match, get the new information from the stream
if (rule.Tests != null && rule.Tests.Count != 0)
{
using (MemoryStream output = new MemoryStream())
{
FileStream input = File.OpenRead(file);
Skippers.TransformStream(input, output, rule, _logger, false, true);
Rom romNH = FileTools.GetSingleStreamInfo(output);
romNH.Name = "HEAD::" + rom.Name;
romNH.MachineName = rom.MachineName;
// Create the input and output streams
MemoryStream output = new MemoryStream();
FileStream input = File.OpenRead(file);
// Add the rom information to the Dat
key = romNH.Size + "-" + romNH.CRC;
if (matchdat.Files.ContainsKey(key))
{
matchdat.Files[key].Add(romNH);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(romNH);
matchdat.Files.Add(key, temp);
}
// Transform the stream and get the information from it
Skippers.TransformStream(input, output, rule, _logger, false, true);
Rom romNH = FileTools.GetSingleStreamInfo(output);
romNH.Name = "HEAD::" + rom.Name;
romNH.MachineName = rom.MachineName;
// Add the rom information to the Dat
key = romNH.Size + "-" + romNH.CRC;
if (matchdat.Files.ContainsKey(key))
{
matchdat.Files[key].Add(romNH);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(romNH);
matchdat.Files.Add(key, temp);
}
// Dispose of the streams
output.Dispose();
input.Dispose();
}
return true;
@@ -1096,12 +1101,14 @@ namespace SabreTools.Helper
}
// Write out the value to each of the romba depot files
using (StreamWriter tw = new StreamWriter(File.Open(Path.Combine(_outDir, ".romba_size"), FileMode.Create, FileAccess.Write)))
using (StreamWriter twb = new StreamWriter(File.Open(Path.Combine(_outDir, ".romba_size.backup"), FileMode.Create, FileAccess.Write)))
{
tw.Write(size);
twb.Write(size);
}
StreamWriter tw = new StreamWriter(File.Open(Path.Combine(_outDir, ".romba_size"), FileMode.Create, FileAccess.Write));
StreamWriter twb = new StreamWriter(File.Open(Path.Combine(_outDir, ".romba_size.backup"), FileMode.Create, FileAccess.Write));
tw.Write(size);
twb.Write(size);
tw.Dispose();
twb.Dispose();
}
return success;