Skip to content

Commit e0532f7

Browse files
committed
Fixed
1 parent 91dbdf4 commit e0532f7

3 files changed

Lines changed: 51 additions & 22 deletions

File tree

ModuleLauncher.NET.Mods/Models/Utils/ModInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ public class ModInfo
1212

1313
public string? License { get; set; }
1414

15-
public List<string?>? Authors { get; set; }
15+
public List<string>? Authors { get; set; }
1616
}

ModuleLauncher.NET.Mods/Utilities/ModUtils.cs

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Diagnostics.CodeAnalysis;
22
using System.IO.Compression;
3-
using Manganese.Array;
43
using Manganese.Text;
54
using ModuleLauncher.NET.Mods.Models.Exceptions;
65
using ModuleLauncher.NET.Mods.Models.Utils;
@@ -20,16 +19,16 @@ public static async Task<ModInfo> GetModInfoAsync(FileInfo mod)
2019
{
2120
var archive = ZipFile.OpenRead(mod.FullName);
2221
if (archive.Entries.Any(e => e.Name == "mcmod.info"))
23-
return await GetModInfoLegacyForgeAsync(mod, archive);
22+
return await GetModInfoLegacyForgeAsync(archive);
2423
if (archive.Entries.Any(e => e.Name == "mods.toml"))
25-
return await GetModInfoForgeAsync(mod, archive);
24+
return await GetModInfoForgeAsync(archive);
2625
if (archive.Entries.Any(e => e.Name is "fabric.mod.json" or "quilt.mod.json"))
27-
return getModInfoFabricAsync(mod, archive);
26+
return await GetModInfoFabricAsync(archive);
2827

2928
throw new UnknownModException("Unknown mod or mod is corrupted");
3029
}
3130

32-
private static async Task<ModInfo> GetModInfoLegacyForgeAsync(FileInfo mod, ZipArchive archive)
31+
private static async Task<ModInfo> GetModInfoLegacyForgeAsync(ZipArchive archive)
3332
{
3433
var zipEntry = archive.GetEntry("mcmod.info")!;
3534
await using var stream = zipEntry.Open();
@@ -48,32 +47,57 @@ private static async Task<ModInfo> GetModInfoLegacyForgeAsync(FileInfo mod, ZipA
4847

4948
return re;
5049
}
51-
52-
private static async Task<ModInfo> GetModInfoForgeAsync(FileInfo mod, ZipArchive archive)
50+
51+
private static async Task<ModInfo> GetModInfoForgeAsync(ZipArchive archive)
5352
{
5453
var zipEntry = archive.GetEntry("META-INF/mods.toml")!;
5554
await using var stream = zipEntry.Open();
5655
using var raw = new StreamReader(stream);
56+
5757
var tomTable = TOML.Parse(raw);
5858
var modNode = tomTable["mods"].AsArray[0];
5959
var re = new ForgeModInfo
6060
{
6161
Id = modNode["modId"],
62-
Version = modNode["version"],
63-
Name = modNode["displayName"],
64-
Url = modNode["displayURL"],
65-
License = tomTable["license"],
66-
Description = modNode["description"],
67-
Authors = modNode.IsArray
68-
? modNode["authors"].AsArray.RawArray.Select(x => x.ToString()).ToList()
69-
: new List<string> { modNode["authors"] },
62+
Version = modNode["version"].HasValue ? modNode["version"] : tomTable["version"],
63+
Name = modNode["displayName"].HasValue ? modNode["displayName"] : tomTable["displayName"],
64+
Url = modNode["displayURL"].HasValue ? modNode["displayURL"] : tomTable["displayURL"],
65+
License = tomTable["license"].HasValue ? tomTable["license"] : modNode["license"],
66+
Description = modNode["description"].HasValue ? modNode["description"] : tomTable["descrption"],
7067
};
71-
68+
69+
if (modNode["authors"].HasValue)
70+
re.Authors = modNode["authors"].IsArray
71+
? modNode["authors"].AsArray.RawArray.Select(x => x.ToString()).ToList()!
72+
: new List<string> { modNode["authors"] };
73+
else
74+
re.Authors = tomTable["authors"].IsArray
75+
? tomTable["authors"].AsArray.RawArray.Select(x => x.ToString()).ToList()!
76+
: new List<string> { tomTable["authors"] };
77+
7278
return re;
7379
}
7480

75-
private static ModInfo getModInfoFabricAsync(FileInfo mod, ZipArchive archive)
81+
private static async Task<ModInfo> GetModInfoFabricAsync(ZipArchive archive)
7682
{
77-
return new ModInfo();
83+
var zipEntry = archive.GetEntry("quilt.mod.json") ?? archive.GetEntry("fabric.mod.json");
84+
await using var stream = zipEntry!.Open();
85+
using var raw = new StreamReader(stream);
86+
var content = await raw.ReadToEndAsync();
87+
88+
var re = new FabricModInfo
89+
{
90+
Id = content.Fetch("id"),
91+
Name = content.Fetch("name"),
92+
Description = content.Fetch("description"),
93+
Version = content.Fetch("version"),
94+
Authors = (content.FetchJToken("authorList") ?? content.FetchJToken("authors"))?.Select(t => t.ToString()).ToList(),
95+
License = content.Fetch("license"),
96+
HomePage = content.Fetch("contact.homepage"),
97+
Issues = content.Fetch("contact.issues"),
98+
Sources = content.Fetch("contact.sources")
99+
};
100+
101+
return re;
78102
}
79103
}

ModuleLauncher.NET.Runtime/Program.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
using ModuleLauncher.NET.Mods.Utilities;
1+
using Manganese.Text;
2+
using ModuleLauncher.NET.Mods.Utilities;
23
using Tommy;
34

4-
var info = await ModUtils.GetModInfoAsync(@"C:\Users\ahpx\Downloads\jei-1.19.2-forge-11.5.0.297.jar");
5-
info.Print();
5+
while (true)
6+
{
7+
var info = await ModUtils.GetModInfoAsync(AnsiConsole.Ask<string>("Mod [red]path[/]:").Trim('"'));
8+
info.ToJsonString().Print();
9+
}
10+
611

712
static class RuntimeUtils
813
{

0 commit comments

Comments
 (0)