Skip to content

Commit

Permalink
Move game finder and zip support to core interpreter project.
Browse files Browse the repository at this point in the history
  • Loading branch information
huguesv committed Nov 13, 2024
1 parent 71662c2 commit ef34e53
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// Copyright (c) Hugues Valois. All rights reserved.
// Licensed under the X11 license. See LICENSE in the project root for license information.

namespace Woohoo.Agi.Player;
#nullable enable

namespace Woohoo.Agi.Detection;

using Woohoo.Agi.Detection;
using Woohoo.Agi.Interpreter;
using Woohoo.Agi.Resources.Serialization;

internal class GameFinder
public class GameFinder
{
public static GameStartInfo FindGame(string folder)
public static GameStartInfo? FindGame(string folder)
{
var detector = CreateDetector();

Expand Down Expand Up @@ -56,16 +57,16 @@ public static GameStartInfo[] FindGames(GameDetector detector, string folder, bo
return [.. games];
}

private static GameStartInfo FindGame(GameDetector detector, IGameContainer container)
private static GameStartInfo? FindGame(GameDetector detector, IGameContainer container)
{
GameStartInfo startInfo = null;
GameStartInfo? startInfo = null;

var result = detector.Detect(container);
if (result is not null)
{
string id = ResourceLoader.GetGameId(container);

startInfo = new GameStartInfo(container, id, result.Platform, result.Interpreter, result.Name, result.Version);
startInfo = new GameStartInfo(container, id, result.Platform, result.Interpreter, result.Name ?? string.Empty, result.Version ?? string.Empty);
}

return startInfo;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) Hugues Valois. All rights reserved.
// Licensed under the X11 license. See LICENSE in the project root for license information.

namespace Woohoo.Agi.Player;
#nullable enable

namespace Woohoo.Agi.Interpreter;

using System.IO.Compression;
using Woohoo.Agi.Interpreter;

internal sealed class GameZipArchive : IGameContainer
{
Expand Down Expand Up @@ -118,7 +119,7 @@ public string[] GetFilesByExtension(string ext)
return [.. files];
}

private ZipArchiveEntry GetEntryOrdinalIgnoreCase(string entryName)
private ZipArchiveEntry? GetEntryOrdinalIgnoreCase(string entryName)
{
foreach (var entry in this.archive.Entries)
{
Expand Down
15 changes: 6 additions & 9 deletions src/Woohoo.Agi.Player/AgiPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace Woohoo.Agi.Player;

using Woohoo.Agi.Detection;
using Woohoo.Agi.Interpreter;
using Woohoo.Agi.Resources.Serialization;

internal abstract class AgiPlayer
{
Expand Down Expand Up @@ -71,7 +71,7 @@ public int Run(string[] args)
private static void DisplayInfo()
{
Console.WriteLine("{0} v{1}", UserInterface.PlayerName, UserInterface.PlayerVersion);
Console.WriteLine("Copyright (C) 2006-2018 Hugues Valois");
Console.WriteLine("Copyright (C) 2006-2024 Hugues Valois");
Console.WriteLine();

Console.WriteLine("Based upon the New Adventure Game Interpreter (NAGI)");
Expand Down Expand Up @@ -107,15 +107,12 @@ private int RunGames(string folder)

private int RunGame(string folder)
{
if (ResourceLoader.IsGameFolder(new GameFolder(folder)))
GameStartInfo startInfo = GameFinder.FindGame(folder);
if (startInfo is not null)
{
GameStartInfo startInfo = GameFinder.FindGame(folder);
if (startInfo is not null)
{
this.Interpreter.Start(startInfo, ReadPreferences());
this.Interpreter.Start(startInfo, ReadPreferences());

return 0;
}
return 0;
}

return -1;
Expand Down

0 comments on commit ef34e53

Please sign in to comment.