Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Added Linux & macOS Support. #12

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Fix read InheritsVersion AssetsIndex
  • Loading branch information
ZhaiSoul committed Jul 16, 2018
commit 5dcdd0cb0fbe1454bdbf9f75d2c585d8801bc3a4
139 changes: 87 additions & 52 deletions KMCCC.Shared/Modules/JVersion/JVersionLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,47 +70,77 @@ public IEnumerable<Version> GetAllVersions()
/// <returns>Version的信息</returns>
internal Version GetVersionInternal(string id)
{
try
{
if (_locatingVersion.Contains(id))
{
return null;
}
_locatingVersion.Add(id);
try
{
if (_locatingVersion.Contains(id))
{
return null;
}
_locatingVersion.Add(id);

if (_versions.TryGetValue(id, out Version version))
{
return version;
}

var jver = LoadVersion(_core.GetVersionJsonPath(id));
if (jver == null)
{
return null;
}
if (jver == null)
{
return null;
}

version = new Version();
if (string.IsNullOrWhiteSpace(jver.Id))
{
return null;
}
version = new Version();
if (string.IsNullOrWhiteSpace(jver.Id))
{
return null;
}
if (jver.arguments == null && string.IsNullOrWhiteSpace(jver.MinecraftArguments))
{
return null;
}
if (string.IsNullOrWhiteSpace(jver.MainClass))
{
return null;
}
if (string.IsNullOrWhiteSpace(jver.Assets))
{
jver.Assets = "legacy";
}
if (jver.Libraries == null)
{
return null;
}
version.Id = jver.Id;
if (string.IsNullOrWhiteSpace(jver.MainClass))
{
return null;
}
if (string.IsNullOrWhiteSpace(jver.Assets))
{
jver.Assets = "legacy";
}
if (jver.Libraries == null)
{
return null;
}
version.Id = jver.Id;
if (jver.AssetsIndex != null)
{
version.AssetsIndex = new GameFileInfo()
{
ID = jver.AssetsIndex.ID,
Path = jver.AssetsIndex.Path,
SHA1 = jver.AssetsIndex.SHA1,
Size = jver.AssetsIndex.Size,
TotalSize = jver.AssetsIndex.TotalSize,
Url = jver.AssetsIndex.Url
};
}
if (jver.Downloads != null)
{
version.Downloads = new Download()
{
Client = new GameFileInfo()
{
SHA1 = jver.Downloads.Client.SHA1,
Size = jver.Downloads.Client.Size,
Url = jver.Downloads.Client.Url
},
Server = new GameFileInfo()
{
SHA1 = jver.Downloads.Server.SHA1,
Size = jver.Downloads.Server.Size,
Url = jver.Downloads.Server.Url
}
};
}
version.MinecraftArguments = jver.MinecraftArguments ?? UsefulTools.PrintfArray(jver.arguments.game);
version.Assets = jver.Assets;
version.MainClass = jver.MainClass;
Expand Down Expand Up @@ -161,29 +191,7 @@ internal Version GetVersionInternal(string id)
}
}
}
version.AssetsIndex = new GameFileInfo()
{
ID = jver.AssetsIndex.ID,
SHA1 = jver.AssetsIndex.SHA1,
Size = jver.AssetsIndex.Size,
TotalSize = jver.AssetsIndex.TotalSize,
Url = jver.AssetsIndex.Url
};
version.Downloads = new Download()
{
Client = new GameFileInfo()
{
SHA1 = jver.Downloads.Client.SHA1,
Size = jver.Downloads.Client.Size,
Url = jver.Downloads.Client.Url
},
Server = new GameFileInfo()
{
SHA1 = jver.Downloads.Server.SHA1,
Size = jver.Downloads.Server.Size,
Url = jver.Downloads.Server.Url
},
};

if (jver.InheritsVersion != null)
{
var target = GetVersionInternal(jver.InheritsVersion);
Expand All @@ -195,6 +203,8 @@ internal Version GetVersionInternal(string id)
{
if (version.Assets == "legacy")
version.Assets = null;
version.AssetsIndex = version.AssetsIndex ?? target.AssetsIndex;
version.Downloads = version.Downloads ?? target.Downloads;
version.Assets = version.Assets ?? target.Assets;
version.JarId = version.JarId ?? target.JarId;
version.MainClass = version.MainClass ?? target.MainClass;
Expand All @@ -204,6 +214,31 @@ internal Version GetVersionInternal(string id)
version.AssetsIndex = version.AssetsIndex ?? target.AssetsIndex;
}
}

version.AssetsIndex = new GameFileInfo()
{
ID = version.AssetsIndex.ID,
SHA1 = version.AssetsIndex.SHA1,
Size = version.AssetsIndex.Size,
TotalSize = version.AssetsIndex.TotalSize,
Url = version.AssetsIndex.Url
};
version.Downloads = new Download()
{
Client = new GameFileInfo()
{
SHA1 = version.Downloads.Client.SHA1,
Size = version.Downloads.Client.Size,
Url = version.Downloads.Client.Url
},
Server = new GameFileInfo()
{
SHA1 = version.Downloads.Server.SHA1,
Size = version.Downloads.Server.Size,
Url = version.Downloads.Server.Url
},
};

version.JarId = version.JarId ?? version.Id;
_versions.Add(version.Id, version);
return version;
Expand Down
3 changes: 3 additions & 0 deletions KMCCC.Simple/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private static void Main()

}

/*
try
{
var ping = new ServerPing("mc.hypixel.net", 25565);
Expand All @@ -50,11 +51,13 @@ private static void Main()
Console.WriteLine("{0} / {1}", server.players.online, server.players.max);
Console.WriteLine(server.version.name);
Console.WriteLine(server.modinfo);

}
catch(Exception ex)
{
Console.WriteLine("服务器信息获取失败:"+ex.Message+"\n"+ Timer.ToString());
}
*/

Console.WriteLine("初始化"+Timer.ToString());
using (_fs = new FileStream("mc.log", FileMode.Create))
Expand Down