Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions OsuParsers/Decoders/BeatmapDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ public static class BeatmapDecoder
/// <returns>A usable beatmap.</returns>
public static Beatmap Decode(string path)
{
if (File.Exists(path))
return Decode(File.ReadAllLines(path));
else
throw new FileNotFoundException();
return Decode(File.ReadAllLines(path));
}

/// <summary>
Expand Down
40 changes: 12 additions & 28 deletions OsuParsers/Decoders/DatabaseDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public static class DatabaseDecoder
/// <returns>A usable <see cref="OsuDatabase"/>.</returns>
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();
}
}

/// <summary>
Expand Down Expand Up @@ -137,10 +137,10 @@ public static OsuDatabase DecodeOsu(Stream stream)
/// <returns>A usable <see cref="CollectionDatabase"/>.</returns>
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();
}
}

/// <summary>
Expand Down Expand Up @@ -182,10 +182,10 @@ public static CollectionDatabase DecodeCollection(Stream stream)
/// <returns>A usable <see cref="ScoresDatabase"/>.</returns>
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();
}
}

/// <summary>
Expand Down Expand Up @@ -246,10 +246,10 @@ public static ScoresDatabase DecodeScores(Stream stream)
/// <returns>A usable <see cref="PresenceDatabase"/>.</returns>
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();
}
}

/// <summary>
Expand Down Expand Up @@ -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;
}
}
}
}
8 changes: 4 additions & 4 deletions OsuParsers/Decoders/ReplayDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public static class ReplayDecoder
/// <returns>A usable <see cref="Replay"/>.</returns>
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);
}
}

/// <summary>
Expand Down
5 changes: 1 addition & 4 deletions OsuParsers/Decoders/StoryboardDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ public static class StoryboardDecoder
/// <returns>A usable storyboard.</returns>
public static Storyboard Decode(string path)
{
if (File.Exists(path))
return Decode(File.ReadAllLines(path));
else
throw new FileNotFoundException();
return Decode(File.ReadAllLines(path));
}

/// <summary>
Expand Down