/// <summary> /// 获取Native下载任务 /// </summary> /// <param name="source">下载源</param> /// <param name="native">native实例</param> /// <param name="core">所使用的核心</param> /// <returns>下载任务</returns> public static DownloadTask GetNativeDownloadTask(DownloadSource source, Native native, LaunchHandler core) { string from = GetNativeDownloadURL(source, native); string to = core.GetNativePath(native); return(new DownloadTask("版本系统依赖库文件" + native.Name, from, to)); }
public static DownloadTask GetCoreJsonDownloadTask(DownloadSource downloadSource, string verID, LaunchHandler core) { string to = core.GetJsonPath(verID); string from = GetCoreJsonDownloadURL(downloadSource, verID); return(new DownloadTask("游戏版本核心Json文件", from, to)); }
/// <summary> /// 获取Liteloader mod /// </summary> /// <param name="downloadSource">下载源</param> /// <param name="liteloader">liteloader信息</param> /// <returns></returns> public static DownloadTask GetLiteloaderDownloadURL(DownloadSource downloadSource, APIModules.JWLiteloader liteloader) { string local = App.Handler.GameRootPath + "\\mods\\" + liteloader.Version + ".jar"; string Source = BMCLUrl; switch (downloadSource) { case DownloadSource.Mojang: Source = BMCLUrl; break; case DownloadSource.BMCLAPI: Source = BMCLUrl; break; case DownloadSource.MCBBS: Source = MCBBSUrl; break; } Source += string.Format("maven/com/mumfrey/liteloader/{0}/liteloader-{0}", liteloader.Version) + ".jar"; DownloadTask dt = new DownloadTask(App.GetResourceString("String.NewDownloadTaskWindow.Core.Liteloader"), Source, local); return(dt); }
/// <summary> /// 获取assets下载任务 /// </summary> /// <param name="source">下载源</param> /// <param name="assets">assets实例</param> /// <param name="core">所使用的核心</param> /// <returns>下载任务</returns> public static DownloadTask GetAssetsDownloadTask(DownloadSource source, JAssetsInfo assets, LaunchHandler core) { string from = GetAssetsDownloadURL(source, assets); string to = core.GetAssetsPath(assets); return(new DownloadTask("游戏资源文件" + assets.Hash, from, to)); }
public FunctionAPIHandler(DownloadSource lib) { Source = lib; switch (Source) { case DownloadSource.Mojang: VersionListURL = "https://launchermeta.mojang.com/mc/game/version_manifest.json"; ForgeListURL = BMCLBase + "/forge/minecraft"; LiteloaderListURL = BMCLBase + "/liteloader/list"; FabricListURL = FabricUrl + "/v2/versions/loader"; FabricListVEURL = FabricUrl + "/v2/versions/game"; break; case DownloadSource.BMCLAPI: VersionListURL = BMCLBase + "/mc/game/version_manifest.json"; ForgeListURL = BMCLBase + "/forge/minecraft"; LiteloaderListURL = BMCLBase + "/liteloader/list"; FabricListURL = FabricUrl + "/v2/versions/loader"; FabricListVEURL = FabricUrl + "/v2/versions/game"; break; case DownloadSource.MCBBS: VersionListURL = MCBBSUrl + "/mc/game/version_manifest.json"; ForgeListURL = MCBBSUrl + "/forge/minecraft"; LiteloaderListURL = MCBBSUrl + "/liteloader/list"; FabricListURL = FabricUrl + "/v2/versions/loader"; FabricListVEURL = FabricUrl + "/v2/versions/game"; break; } }
public static DownloadTask GetCoreDownloadTask(DownloadSource downloadSource, Modules.Version version, LaunchHandler core) { string from = GetCoreDownloadURL(downloadSource, version); string to = core.GetJarPath(version); return(new DownloadTask("游戏版本核心", from, to)); }
/// <summary> /// 获取Lib下载任务 /// </summary> /// <param name="source">下载源</param> /// <param name="lib">lib实例</param> /// <param name="core">所使用的核心</param> /// <returns>下载任务</returns> public static DownloadTask GetLibDownloadTask(DownloadSource source, Modules.Library lib, LaunchHandler core) { string from = GetLibDownloadURL(source, lib); string to = core.GetLibraryPath(lib); return(new DownloadTask("版本依赖库文件" + lib.Name, from, to)); }
public static Task <List <DownloadTask> > GetLostAssetsDownloadTaskAsync(DownloadSource source, LaunchHandler core, Version ver) { return(Task.Factory.StartNew(() => { return GetLostAssetsDownloadTask(source, core, ver); })); }
/// <summary> /// 获取全部丢失的文件下载任务 /// </summary> /// <param name="source">下载源</param> /// <param name="core">使用的核心</param> /// <param name="version">检查的版本</param> /// <returns></returns> public static List <DownloadTask> GetLostDependDownloadTask(DownloadSource source, LaunchHandler core, Version version) { var lostLibs = GetLostLibs(core, version); var lostNatives = GetLostNatives(core, version); List <DownloadTask> tasks = new List <DownloadTask>(); string jarPath = core.GetJarPath(version); if (!File.Exists(jarPath)) { if (version.InheritsVersion != null) { Version inner = core.GetVersionByID(version.InheritsVersion); tasks.Add(GetDownloadUrl.GetCoreDownloadTask(source, inner, core)); } else { tasks.Add(GetDownloadUrl.GetCoreDownloadTask(source, version, core)); } } foreach (var item in lostLibs) { tasks.Add(GetDownloadUrl.GetLibDownloadTask(source, item.Value, core)); } foreach (var item in lostNatives) { tasks.Add(GetDownloadUrl.GetNativeDownloadTask(source, item.Value, core)); } return(tasks); }
public async Task <DownloadTask> GetLatestAICoreDownloadTask(DownloadSource source, string downloadTo) { string apiBase = string.Empty; switch (source) { case DownloadSource.Mojang: apiBase = "https://authlib-injector.yushi.moe/artifact/latest.json"; break; case DownloadSource.BMCLAPI: apiBase = "https://bmclapi2.bangbang93.com/mirrors/authlib-injector/artifact/latest.json"; break; default: apiBase = "https://authlib-injector.yushi.moe/artifact/latest.json"; break; } var jobj = JObject.Parse(await APIRequester.HttpGetStringAsync(apiBase)); string downloadURL = jobj.Value <string>("download_url"); string sha256 = jobj["checksums"].Value <string>("sha256"); return(new DownloadTask("AuthlibInjector核心", downloadURL, downloadTo) { Checker = new Util.Checker.SHA256Checker() { CheckSum = sha256, FilePath = downloadTo } }); }
/// <summary> /// 获取Lib下载地址 /// </summary> /// <param name="source">下载源</param> /// <param name="lib">lib实例</param> /// <returns>下载URL</returns> public static string GetLibDownloadURL(DownloadSource source, Library lib) { if (!string.IsNullOrWhiteSpace(lib.LibDownloadInfo?.URL)) { return(DoURLReplace(source, lib.LibDownloadInfo.URL)); } else { string libUrlPath = GetLibBasePath(lib).Replace('\\', '/'); if (lib.Url != null) { return(DoURLReplace(source, lib.Url) + libUrlPath); } else { switch (source) { case DownloadSource.Mojang: return(MojanglibrariesUrl + libUrlPath); case DownloadSource.BMCLAPI: return(BMCLLibrariesURL + libUrlPath); default: throw new ArgumentNullException("source"); } } } }
/// <summary> /// 获取Fabric下载 /// </summary> /// <param name="downloadSource">下载源</param> /// <param name="forge">Forge信息</param> /// <returns></returns> public static DownloadTask GetFabricDownloadURL(DownloadSource downloadSource, APIModules.JWFabric fabric, MCVersion version) { string local = PathManager.TempDirectory + "\\fabric-installer-0.6.1.45.jar"; DownloadTask dt = new DownloadTask(App.GetResourceString("String.NewDownloadTaskWindow.Core.Fabric"), @"https://maven.fabricmc.net/net/fabricmc/fabric-installer/0.6.1.45/fabric-installer-0.6.1.45.jar", local); dt.Todo = new Func <ProgressCallback, CancellationToken, Exception>((callback, cancelToken) => { try { IInstaller installer = new FabricInstaller(local, new CommonInstallOptions() { GameRootPath = App.Handler.GameRootPath, IsClient = true, DownloadSource = App.Config.MainConfig.Download.DownloadSource, Java = App.Handler.Java, obj = new APIModules.TwoObj { fabric = fabric, version = version } }); installer.BeginInstall(callback, cancelToken).Wait(); return(null); } catch (Exception ex) { return(ex); } }); return(dt); }
public static void DownloadDepot(int depotId, int depotVersionRequested, int appId = 0) { if (steam3 != null && appId > 0) { steam3.RequestAppInfo((uint)appId); } string contentName = GetAppOrDepotName(depotId, appId); if (!AccountHasAccess(depotId, false)) { Console.WriteLine("Depot {0} ({1}) is not available from this account.", depotId, contentName); return; } DownloadSource source = GetAppDownloadSource(appId); uint depotVersion = (uint)depotVersionRequested; if (source == DownloadSource.Steam3) { depotVersion = GetSteam3AppChangeNumber(appId); } string installDir; if (!CreateDirectories(depotId, depotVersion, out installDir)) { Console.WriteLine("Error: Unable to create install directories!"); return; } Console.WriteLine("Downloading \"{0}\" version {1} ...", contentName, depotVersion); if (steam3 != null) { steam3.RequestAppTicket((uint)depotId); } if (source == DownloadSource.Steam3) { ulong manifestID = GetSteam3DepotManifest(depotId, appId); if (manifestID == 0) { Console.WriteLine("Depot {0} ({1}) missing public subsection or manifest section.", depotId, contentName); return; } steam3.RequestDepotKey(( uint )depotId, ( uint )appId); byte[] depotKey = steam3.DepotKeys[(uint)depotId]; DownloadSteam3(depotId, manifestID, depotKey, installDir); } else { // steam2 path DownloadSteam2(depotId, depotVersionRequested, installDir); } }
public static string GetCoreJarDownloadURL(DownloadSource source, Modules.MCVersion ver) { if (ver.Downloads?.Client != null) { return(DoURLReplace(source, ver.Downloads.Client.URL)); } else { return(string.Format("{0}version/{1}/client", BMCLUrl, ver.ID)); } }
/// <summary> /// 获取assets下载地址 /// </summary> /// <param name="source">下载源</param> /// <param name="assets">assets实例</param> /// <returns>下载URL</returns> public static string GetAssetsDownloadURL(DownloadSource source, JAssetsInfo assets) { switch (source) { case DownloadSource.Mojang: return((MojangAssetsBaseUrl + GetAssetsPath(assets)).Replace('\\', '/')); case DownloadSource.BMCLAPI: return((BMCLUrl + "objects\\" + GetAssetsPath(assets)).Replace('\\', '/')); default: throw new ArgumentNullException("source"); } }
/// <summary> /// 获取native下载地址 /// </summary> /// <param name="source">下载源</param> /// <param name="native">native实例</param> /// <returns>下载URL</returns> public static string GetNativeDownloadURL(DownloadSource source, Native native) { switch (source) { case DownloadSource.Mojang: return((MojanglibrariesUrl + GetNativePath(native)).Replace('\\', '/')); case DownloadSource.BMCLAPI: return((BMCLLibrariesURL + GetNativePath(native)).Replace('\\', '/')); default: throw new ArgumentNullException("source"); } }
public FunctionAPIHandler(DownloadSource lib) { Source = lib; switch (Source) { case DownloadSource.Mojang: VersionListURL = "https://launchermeta.mojang.com/mc/game/version_manifest.json"; break; case DownloadSource.BMCLAPI: VersionListURL = BMCLBase + "/mc/game/version_manifest.json"; break; } }
/// <summary> /// 获取Native下载任务 /// </summary> /// <param name="source">下载源</param> /// <param name="native">native实例</param> /// <param name="core">所使用的核心</param> /// <returns>下载任务</returns> public static DownloadTask GetNativeDownloadTask(DownloadSource source, KeyValuePair <string, Native> native) { string from = GetNativeDownloadURL(source, native.Value); string to = native.Key; DownloadTask task = new DownloadTask("版本系统依赖库文件" + native.Value.Name, from, to); if (native.Value.NativeDownloadInfo != null) { task.Checker = new SHA1Checker() { CheckSum = native.Value.NativeDownloadInfo.SHA1, FilePath = to }; } return(task); }
public static DownloadTask GetCoreJarDownloadTask(DownloadSource downloadSource, Modules.Version version, LaunchHandler core) { string to = core.GetJarPath(version); string from = GetCoreJarDownloadURL(downloadSource, version); DownloadTask downloadTask = new DownloadTask("游戏版本核心Jar文件", from, to); if (!string.IsNullOrWhiteSpace(version.Downloads?.Client?.SHA1)) { downloadTask.Checker = new SHA1Checker() { CheckSum = version.Downloads.Client.SHA1, FilePath = to }; } return(downloadTask); }
/// <summary> /// 获取Lib下载任务 /// </summary> /// <param name="source">下载源</param> /// <param name="lib">lib实例</param> /// <param name="core">所使用的核心</param> /// <returns>下载任务</returns> public static DownloadTask GetLibDownloadTask(DownloadSource source, KeyValuePair <string, Library> lib) { string from = GetLibDownloadURL(source, lib.Value); string to = lib.Key; DownloadTask task = new DownloadTask("版本依赖库文件" + lib.Value.Name, from, to); if (lib.Value.LibDownloadInfo != null) { task.Checker = new SHA1Checker() { CheckSum = lib.Value.LibDownloadInfo.SHA1, FilePath = to }; } return(task); }
public static string GetCoreJsonDownloadURL(DownloadSource source, string verID) { switch (source) { case DownloadSource.Mojang: return(string.Format("{0}version/{1}/json", MojangMainUrl, verID)); case DownloadSource.BMCLAPI: return(string.Format("{0}version/{1}/json", BMCLUrl, verID)); case DownloadSource.MCBBS: return(string.Format("{0}version/{1}/json", MCBBSUrl, verID)); default: return(string.Format("{0}version/{1}/json", MojangMainUrl, verID)); } }
public static string DoURLReplace(DownloadSource source, string url) { switch (source) { case DownloadSource.Mojang: return(url); case DownloadSource.BMCLAPI: return(ReplaceURLByDic(url, bmclapiDic)); case DownloadSource.MCBBS: return(ReplaceURLByDic(url, mcbbsDic)); default: return(url); } }
/// <summary> /// 获取Forge下载 /// </summary> /// <param name="downloadSource">下载源</param> /// <param name="mcversion">Mc版本</param> /// <param name="forgeversion">Forge版本</param> /// <returns></returns> public static DownloadTask GetForgeDownloadURL(DownloadSource downloadSource, string mcversion, string forgeversion) { string local = App.Handler.GameRootPath + "\\forge-" + mcversion + "-" + forgeversion + "-installer.jar"; string forgePath = string.Format("maven/net/minecraftforge/forge/{0}-{1}/forge-{0}-{1}-installer.jar", mcversion, forgeversion); string Source = ForgeUrl; switch (downloadSource) { case DownloadSource.Mojang: Source = ForgeUrl; break; case DownloadSource.BMCLAPI: Source = BMCLUrl; break; case DownloadSource.MCBBS: Source = MCBBSUrl; break; } Source += forgePath; DownloadTask dt = new DownloadTask(App.GetResourceString("String.NewDownloadTaskWindow.Core.Forge"), Source, local); dt.Todo = new Func <ProgressCallback, CancellationToken, Exception>((callback, cancelToken) => { try { IInstaller installer = new ForgeInstaller(local, new CommonInstallOptions() { GameRootPath = App.Handler.GameRootPath, IsClient = true, DownloadSource = App.Config.MainConfig.Download.DownloadSource, Java = App.Handler.Java }); installer.BeginInstall(callback, cancelToken).Wait(); return(null); } catch (Exception ex) { return(ex); } }); return(dt); }
/// <summary> /// 获取Forge下载 /// </summary> /// <param name="downloadSource">下载源</param> /// <param name="forge">Forge信息</param> /// <returns></returns> public static DownloadTask GetForgeDownloadURL(DownloadSource downloadSource, APIModules.JWForge forge, MCVersion mc) { string local = PathManager.TempDirectory + "\\forge-" + forge.Build + ".jar"; string Source = BMCLUrl; switch (downloadSource) { case DownloadSource.Mojang: Source = BMCLUrl; break; case DownloadSource.BMCLAPI: Source = BMCLUrl; break; case DownloadSource.MCBBS: Source = MCBBSUrl; break; } Source += $"maven/net/minecraftforge/forge/{mc.ID}-{forge.Version}" + $"/forge-{mc.ID}-{forge.Version}-installer.jar"; DownloadTask dt = new(App.GetResourceString("String.NewDownloadTaskWindow.Core.Forge"), Source, local); dt.Todo = new Func <ProgressCallback, CancellationToken, Exception>((callback, cancelToken) => { try { IInstaller installer = new ForgeInstaller(local, new CommonInstallOptions() { GameRootPath = App.Handler.GameRootPath, IsClient = true, DownloadSource = App.Config.MainConfig.Download.DownloadSource, Java = App.Handler.Java }); installer.BeginInstall(callback, cancelToken).Wait(); return(null); } catch (Exception ex) { return(ex); } }); return(dt); }
public static async Task <bool> IsLostAssetsAsync(DownloadSource source, LaunchHandler core, Version ver) { string assetsPath = core.GetAssetsIndexPath(ver.Assets); if (!File.Exists(assetsPath)) { return(ver.AssetIndex != null); } else { var assets = await core.GetAssetsAsync(ver); return(await Task.Factory.StartNew(() => { return IsLostAnyAssetsFromJassets(core, assets); })); } }
public static string DoURLReplace(DownloadSource source, string url) { switch (source) { case DownloadSource.Mojang: return(url); case DownloadSource.BMCLAPI: Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add(@"https://launcher.mojang.com/", BMCLUrl); dic.Add(@"https://launchermeta.mojang.com/", BMCLUrl); dic.Add(@"http://files.minecraftforge.net/maven/", BMCLLibrariesURL); return(ReplaceURLByDic(url, dic)); default: return(null); } }
public void GetLatestTest(DownloadSource downloadSource) { var config = _ioc.Get <ConfigService>().Entries; config.DownloadSource = downloadSource; var authlibInjectorInstallService = _ioc.Get <AuthlibInjectorService>(); var latest = authlibInjectorInstallService.GetLatest().Result; Assert.IsNotNull(latest); Assert.IsTrue(latest.Build > 0); Assert.IsNotNull(latest.Url); Debug.WriteLine("---------------------------------------------------------------"); Debug.WriteLine($"Build: {latest.Build}"); Debug.WriteLine($"Version: {latest.Version}"); Debug.WriteLine($"Url: {latest.Url}"); Debug.WriteLine($"SHA-256: {latest.SHA256}"); }
public static string GetCoreDownloadURL(DownloadSource source, Modules.Version ver) { if (ver.Downloads != null) { switch (source) { case DownloadSource.Mojang: return(ver.Downloads.Client.URL); case DownloadSource.BMCLAPI: return(ver.Downloads.Client.URL.Replace(MojangMainUrl, BMCLUrl)); default: return(ver.Downloads.Client.URL); } } else { return(string.Format("{0}version/{1}/client", BMCLUrl, ver.ID)); } }
/// <summary> /// 获取native下载地址 /// </summary> /// <param name="source">下载源</param> /// <param name="native">native实例</param> /// <returns>下载URL</returns> public static string GetNativeDownloadURL(DownloadSource source, Native native) { if (!string.IsNullOrWhiteSpace(native.NativeDownloadInfo?.URL)) { return(DoURLReplace(source, native.NativeDownloadInfo.URL)); } else { switch (source) { case DownloadSource.Mojang: return((MojanglibrariesUrl + GetNativeBasePath(native)).Replace('\\', '/')); case DownloadSource.BMCLAPI: return((BMCLLibrariesURL + GetNativeBasePath(native)).Replace('\\', '/')); default: throw new ArgumentNullException("source"); } } }
static bool CreateDirectories( int depotId, uint depotVersion, DownloadSource source, out string installDir ) { installDir = null; try { if (ContentDownloader.Config.InstallDirectory == null || ContentDownloader.Config.InstallDirectory == "") { Directory.CreateDirectory( DEFAULT_DIR ); string depotPath = Path.Combine( DEFAULT_DIR, depotId.ToString() ); Directory.CreateDirectory( depotPath ); installDir = Path.Combine(depotPath, depotVersion.ToString()); Directory.CreateDirectory(installDir); } else { Directory.CreateDirectory(ContentDownloader.Config.InstallDirectory); installDir = ContentDownloader.Config.InstallDirectory; if (source == DownloadSource.Steam2) { string serverFolder = CDRManager.GetDedicatedServerFolder(depotId); if (serverFolder != null && serverFolder != "") { installDir = Path.Combine(ContentDownloader.Config.InstallDirectory, serverFolder); Directory.CreateDirectory(installDir); } } } } catch { return false; } return true; }
static bool CreateDirectories(int depotId, uint depotVersion, DownloadSource source, out string installDir) { installDir = null; try { if (ContentDownloader.Config.InstallDirectory == null || ContentDownloader.Config.InstallDirectory == "") { Directory.CreateDirectory(DEFAULT_DIR); string depotPath = Path.Combine(DEFAULT_DIR, depotId.ToString()); Directory.CreateDirectory(depotPath); installDir = Path.Combine(depotPath, depotVersion.ToString()); Directory.CreateDirectory(installDir); } else { Directory.CreateDirectory(ContentDownloader.Config.InstallDirectory); installDir = ContentDownloader.Config.InstallDirectory; if (source == DownloadSource.Steam2) { string serverFolder = CDRManager.GetDedicatedServerFolder(depotId); if (serverFolder != null && serverFolder != "") { installDir = Path.Combine(ContentDownloader.Config.InstallDirectory, serverFolder); Directory.CreateDirectory(installDir); } } } } catch { return(false); } return(true); }
void OnItemDownloadComplete(ISerializableObjectBase objectLoaded, bool wasLoadedSuccessfully, DownloadSource downloadSource) { if (didTimeOut == true || objectLoaded == null) return; for (int x = 0; x < downloadObjects.Length; x++) //go through all our download objects { if (downloadObjects[x].downloadObject.Equals(objectLoaded) == true) //if the finished object is one of them, set the values { decimal percentage = ((decimal)(x + 1) / (decimal)(downloadObjects.Length)) * (decimal)100.0; percentage = Math.Round(percentage, 0); DownloadGraphic.Show(percentage + "%"); downloadObjects[x].isFinished = true; downloadObjects[x].didDownloadSuccessfully = wasLoadedSuccessfully; downloadObjects[x].downloadSource = downloadSource; if (downloadObjects[x].didDownloadSuccessfully == true) //success downloading!! { if ((x + 1) < downloadObjects.Length) //if there is another object in the array, download it downloadObjects[x + 1].TryToDownload(OnItemDownloadComplete); else //we have downlaoded each object OnAllItemsDownloadedSuccessfully(); } else //fail!! try again { if (downloadObjects[x].downloadTries < failedDownloadRetries && downloadObjects[x].downloadObject.FileDoesExistOnServer == false) //try to redownload as many times as we need to downloadObjects[x].TryToDownload(OnItemDownloadComplete); else //if we tried more than the allowed number of times, call a failure event CantDownloadItem(downloadObjects[x]); } } } }