public Task <IEnumerable <IGameResource> > ResolveResourceTaskAsync() { return(Task.Run(() => { LogGameResourceInfoResolveStatus("开始进行游戏资源(Library)检查"); if (!(VersionInfo?.Natives?.Any() ?? false)) { return default; } if (!(VersionInfo?.Libraries?.Any() ?? false)) { return default; } var libDi = new DirectoryInfo(GamePathHelper.GetLibraryRootPath(BasePath)); if (!libDi.Exists) { libDi.Create(); } var lostLibrary = (from lib in VersionInfo.Libraries where !File.Exists(GamePathHelper.GetLibraryPath(BasePath, lib.Path.Replace('/', '\\'))) select lib).ToList(); lostLibrary.AddRange(from native in VersionInfo.Natives where !File.Exists(GamePathHelper.GetLibraryPath(BasePath, native.FileInfo.Path.Replace('/', '\\'))) select native.FileInfo); var result = new List <IGameResource>(); foreach (var lL in lostLibrary) { string uri; if (lL.Name.StartsWith("forge", StringComparison.Ordinal) || lL.Name.StartsWith("net.minecraftforge", StringComparison.Ordinal)) { uri = $"{ForgeUriRoot}{lL.Path.Replace('\\', '/')}"; } else { uri = $"{LibraryUriRoot}{lL.Path.Replace('\\', '/')}"; } var path = GamePathHelper.GetLibraryPath(BasePath, lL.Path.Replace('/', '\\')); result.Add(new LibraryDownloadInfo { Path = path, Title = lL.Name.Split(':')[1], Type = "Library/Native", Uri = uri, FileSize = lL.Size, CheckSum = lL.Sha1 }); } LogGameResourceInfoResolveStatus("检查Library完成"); return (IEnumerable <IGameResource>)result; })); }
/// <summary> /// 构造函数 /// </summary> /// <param name="launchSettings">启动设置</param> /// <param name="launcherProfileParser">Mojang官方launcher_profiles.json适配组件</param> /// <param name="versionLocator"></param> /// <param name="authResult"></param> /// <param name="rootPath"></param> /// <param name="rootVersion"></param> public DefaultLaunchArgumentParser(LaunchSettings launchSettings, ILauncherProfileParser launcherProfileParser, IVersionLocator versionLocator, AuthResult authResult, string rootPath, string rootVersion) { if (launchSettings == null || launcherProfileParser == null) { throw new ArgumentNullException(); } AuthResult = authResult; VersionLocator = versionLocator; RootPath = rootPath; LaunchSettings = launchSettings; LauncherProfileParser = launcherProfileParser; VersionInfo = LaunchSettings.VersionLocator.GetGame(LaunchSettings.Version); GameProfile = LauncherProfileParser.GetGameProfile(LaunchSettings.GameName); ClassPath = string.Join(string.Empty, VersionInfo.Libraries.Select(l => $"{GamePathHelper.GetLibraryPath(launchSettings.GameResourcePath, l.Path.Replace('/', '\\'))};")); ClassPath += string.IsNullOrEmpty(rootVersion) ? GamePathHelper.GetGameExecutablePath(rootPath, launchSettings.Version) : GamePathHelper.GetGameExecutablePath(rootPath, rootVersion); LastAuthResult = LaunchSettings.Authenticator.GetLastAuthResult(); }