Skip to content

Commit

Permalink
Update GamePathHelper.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
laolarou726 committed Apr 2, 2024
1 parent 99f0bff commit f10f9bf
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion ProjBobcat/ProjBobcat/Class/Helper/GamePathHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Immutable;
using System.IO;

namespace ProjBobcat.Class.Helper;
Expand Down Expand Up @@ -41,7 +42,22 @@ public static string GetGamePath(string id)
/// <returns></returns>
public static string GetGameJsonPath(string rootPath, string id)
{
return Path.Combine(rootPath, "versions", id, $"{id}.json");
var dir = Path.Combine(rootPath, "versions", id);
var possibleFiles = Directory.EnumerateFiles(dir, "*.json").ToImmutableList();

if (possibleFiles.Count == 1) return possibleFiles[0];
if (possibleFiles.Count > 1)
{
foreach (var file in possibleFiles)
{
var name = Path.GetFileNameWithoutExtension(file);

if (name.Equals(id, StringComparison.OrdinalIgnoreCase)) return file;
if (id.Contains(name, StringComparison.OrdinalIgnoreCase)) return file;
}
}

return Path.Combine(dir, $"{id}.json");
}

/// <summary>
Expand Down

0 comments on commit f10f9bf

Please sign in to comment.