diff --git a/OsuParsers/Decoders/BeatmapDecoder.cs b/OsuParsers/Decoders/BeatmapDecoder.cs
index 38d4e6b..b786736 100644
--- a/OsuParsers/Decoders/BeatmapDecoder.cs
+++ b/OsuParsers/Decoders/BeatmapDecoder.cs
@@ -29,10 +29,7 @@ public static class BeatmapDecoder
/// A usable beatmap.
public static Beatmap Decode(string path)
{
- if (File.Exists(path))
- return Decode(File.ReadAllLines(path));
- else
- throw new FileNotFoundException();
+ return Decode(File.ReadAllLines(path));
}
///
diff --git a/OsuParsers/Decoders/DatabaseDecoder.cs b/OsuParsers/Decoders/DatabaseDecoder.cs
index eb5a5c7..6e09b3b 100644
--- a/OsuParsers/Decoders/DatabaseDecoder.cs
+++ b/OsuParsers/Decoders/DatabaseDecoder.cs
@@ -18,10 +18,10 @@ public static class DatabaseDecoder
/// A usable .
public static OsuDatabase DecodeOsu(string path)
{
- if (TryOpenReadFile(path, out var stream))
+ using (var stream = new FileStream(path, FileMode.Open))
+ {
return DecodeOsu(stream);
- else
- throw new FileNotFoundException();
+ }
}
///
@@ -137,10 +137,10 @@ public static OsuDatabase DecodeOsu(Stream stream)
/// A usable .
public static CollectionDatabase DecodeCollection(string path)
{
- if (TryOpenReadFile(path, out var stream))
+ using (var stream = File.OpenRead(path))
+ {
return DecodeCollection(stream);
- else
- throw new FileNotFoundException();
+ }
}
///
@@ -182,10 +182,10 @@ public static CollectionDatabase DecodeCollection(Stream stream)
/// A usable .
public static ScoresDatabase DecodeScores(string path)
{
- if (TryOpenReadFile(path, out var stream))
+ using (var stream = File.OpenRead(path))
+ {
return DecodeScores(stream);
- else
- throw new FileNotFoundException();
+ }
}
///
@@ -246,10 +246,10 @@ public static ScoresDatabase DecodeScores(Stream stream)
/// A usable .
public static PresenceDatabase DecodePresence(string path)
{
- if (TryOpenReadFile(path, out var stream))
+ using (var stream = File.OpenRead(path))
+ {
return DecodePresence(stream);
- else
- throw new FileNotFoundException();
+ }
}
///
@@ -285,21 +285,5 @@ public static PresenceDatabase DecodePresence(Stream stream)
return db;
}
-
- // Tools
-
- private static bool TryOpenReadFile(string path, out Stream stream)
- {
- if (File.Exists(path))
- {
- stream = new FileStream(path, FileMode.Open);
- return true;
- }
- else
- {
- stream = null;
- return false;
- }
- }
}
}
diff --git a/OsuParsers/Decoders/ReplayDecoder.cs b/OsuParsers/Decoders/ReplayDecoder.cs
index 4572a64..9c87f7f 100644
--- a/OsuParsers/Decoders/ReplayDecoder.cs
+++ b/OsuParsers/Decoders/ReplayDecoder.cs
@@ -21,10 +21,10 @@ public static class ReplayDecoder
/// A usable .
public static Replay Decode(string path)
{
- if (File.Exists(path))
- return Decode(new FileStream(path, FileMode.Open));
- else
- throw new FileNotFoundException();
+ using(var stream = File.OpenRead(path))
+ {
+ return Decode(stream);
+ }
}
///
diff --git a/OsuParsers/Decoders/StoryboardDecoder.cs b/OsuParsers/Decoders/StoryboardDecoder.cs
index 423bf4e..6025062 100644
--- a/OsuParsers/Decoders/StoryboardDecoder.cs
+++ b/OsuParsers/Decoders/StoryboardDecoder.cs
@@ -26,10 +26,7 @@ public static class StoryboardDecoder
/// A usable storyboard.
public static Storyboard Decode(string path)
{
- if (File.Exists(path))
- return Decode(File.ReadAllLines(path));
- else
- throw new FileNotFoundException();
+ return Decode(File.ReadAllLines(path));
}
///