Skip to content

Commit

Permalink
ltm hash parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
adelikat committed Nov 11, 2024
1 parent c683eca commit d78c44c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 1 deletion.
10 changes: 9 additions & 1 deletion TASVideos.Parsers/Parsers/Ltm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class Ltm : Parser, IParser
private const string VariableFramerateHeader = "variable_framerate=";
private const string LengthSecondsHeader = "length_sec=";
private const string LengthNanosecondsHeader = "length_nsec=";

private const string Md5 = "md5=";
public async Task<IParseResult> Parse(Stream file, long length)
{
var result = new SuccessResult(FileExtension)
Expand Down Expand Up @@ -94,6 +94,14 @@ public async Task<IParseResult> Parse(Stream file, long length)
{
lengthNanoseconds = ParseDoubleFromConfig(s);
}
else if (s.StartsWith(Md5))
{
var md5 = ParseStringFromConfig(s);
if (md5.Length == 32)
{
result.Hashes.Add(HashType.Md5, md5.ToLower());
}
}
}

break;
Expand Down
21 changes: 21 additions & 0 deletions tests/TASVideos.MovieParsers.Tests/LtmSampleFiles/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[General]
authors=
auto_restart=false
frame_count=307
framerate_den=1
framerate_num=60
game_name=flashplayer
initial_time_nsec=0
initial_time_sec=1
keyboard_support=true
length_nsec=116666666
length_sec=5
libtas_major_version=1
libtas_minor_version=4
libtas_patch_version=1
md5=abcdefab
mouse_support=true
nb_controllers=0
rerecord_count=0
savestate_frame_count=307
variable_framerate=false
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
30 changes: 30 additions & 0 deletions tests/TASVideos.MovieParsers.Tests/LtmTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,34 @@ public async Task VariableFramerate()
Assert.AreEqual(30.002721239119342, result.FrameRateOverride);
AssertNoWarningsOrErrors(result);
}

[TestMethod]
public async Task Hash()
{
var result = await _ltmParser.Parse(Embedded("hash.ltm"), EmbeddedLength("hash.ltm"));
Assert.AreEqual(1, result.Hashes.Count);
Assert.AreEqual(HashType.Md5, result.Hashes.First().Key);
Assert.AreEqual("7d66e47fdc0807927c40ce1491c68ad3", result.Hashes.First().Value);
}

[TestMethod]
public async Task NoHash()
{
var result = await _ltmParser.Parse(Embedded("no-hash.ltm"), EmbeddedLength("no-hash.ltm"));
Assert.AreEqual(0, result.Hashes.Count);
}

[TestMethod]
public async Task MissingHash()
{
var result = await _ltmParser.Parse(Embedded("missing-hash.ltm"), EmbeddedLength("missing-hash.ltm"));
Assert.AreEqual(0, result.Hashes.Count);
}

[TestMethod]
public async Task InvalidHash()
{
var result = await _ltmParser.Parse(Embedded("invalid-hash.ltm"), EmbeddedLength("invalid-hash.ltm"));
Assert.AreEqual(0, result.Hashes.Count);
}
}

0 comments on commit d78c44c

Please sign in to comment.