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
13 changes: 8 additions & 5 deletions DoomLauncher/Handlers/Sync/GameInfoSyncAction.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using DoomLauncher.Interfaces;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;


namespace DoomLauncher.Handlers.Sync
{
Expand All @@ -15,13 +14,17 @@ public class GameInfoSyncAction : ISyncAction
public SyncResult ApplyToGameFile(IGameFile gameFile, IArchiveReader reader, string[] mapInfoData)
{
// Normally it's GAMEINFO, but I've seen GAMEINFO.txt in the wild.
var entry = reader.Entries.FirstOrDefault(x => x.Name.ToLower().StartsWith("gameinfo"));
var entry = reader.Entries.LastOrDefault(x => x.Name.ToLower().StartsWith("gameinfo"));
if (entry != null)
{
var text = entry.ReadString(Encoding.UTF7);
var text = entry.ReadString(Encoding.UTF8);
var mapping = ParseGameInfo(text);

if (mapping.TryGetValue("STARTUPTITLE", out var title) && !string.IsNullOrWhiteSpace(title))
if (mapping.TryGetValue("STARTUPTITLE", out var title)
&& !string.IsNullOrWhiteSpace(title)
// Supercharge is a popular gameplay mod that is sometimes shipped inside another wad.
// In that case, we don't want to override the wad's actual title.
&& !title.Equals("Supercharge"))
{
gameFile.Title = title;
}
Expand Down
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- "Resync recommended" button so that users can benefit from significant syncing improvements
- TitlePics are no longer considered screenshots; right click on a screenshot to set as main image
- Support for wide image title pic in Heretic + Hexen
- Resyncing is better at deciding the right title

## Bug Fixes:
- Upgraded SharpCompress utility to eliminate moderate vulnerability
Expand Down
4 changes: 2 additions & 2 deletions UnitTest/Tests/Helpers/Tree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Tree
public byte[] Content { get; }

public string ContentString =>
Encoding.UTF7.GetString(Content);
Encoding.UTF8.GetString(Content);

public List<Tree> Children { get; }

Expand All @@ -32,7 +32,7 @@ public Tree(string name, byte[] content, params Tree[] children)
public Tree(string name, string content, params Tree[] children)
{
Name = name;
Content = Encoding.UTF7.GetBytes(content);
Content = Encoding.UTF8.GetBytes(content);
Children = children.ToList();
}
}
Expand Down
38 changes: 38 additions & 0 deletions UnitTest/Tests/TestGameInfoSyncAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,44 @@ public void ApplyToGameFile_FindsTitleInGAMEINFO()
Assert.AreEqual("The Big Tree", gameFile.Title);
}

[TestMethod]
public void ApplyToGameFile_FindsTitleInTheLastGAMEINFO()
{
var gameFile = new GameFile()
{
FileName = "blah.wad"
};

var syncAction = new GameInfoSyncAction();

Tree files = new Tree("root",
new Tree("GAMEINFO", "STARTUPTITLE = \"Wrong answer\""),
new Tree("GAMEINFO.real", "STARTUPTITLE = \"Right answer\""));
var reader = new TreeReader(files);

var result = syncAction.ApplyToGameFile(gameFile, reader, new string[0]);

Assert.AreEqual("Right answer", gameFile.Title);
}

[TestMethod]
public void ApplyToGameFile_IgnoresSuperchargeTitleInGAMEINFO()
{
var gameFile = new GameFile()
{
FileName = "blah.wad"
};

var syncAction = new GameInfoSyncAction();

Tree files = new Tree("root", new Tree("GAMEINFO", "IWAD = \"blah.wad\"\nSTARTUPTITLE = \"Supercharge\"\nSOMETHING_ELSE = blah"));
var reader = new TreeReader(files);

var result = syncAction.ApplyToGameFile(gameFile, reader, new string[0]);

Assert.IsTrue(string.IsNullOrEmpty(gameFile.Title));
}

[TestMethod]
public void ApplyToGameFile_FindsIntendedGameInGAMEINFO()
{
Expand Down