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>
        /// 联网获取新闻列表
        /// </summary>
        /// <returns>新闻列表</returns>
        public async Task <List <JWNews> > GetNewList()
        {
            string json = await APIRequester.HttpGetStringAsync(NewListURL);

            var e = JsonConvert.DeserializeObject <List <JWNews> >(json);

            return(e);
        }
        /// <summary>
        /// 联网获取版本列表
        /// </summary>
        /// <returns>版本列表</returns>
        public async Task <List <JWVersion> > GetVersionList()
        {
            string json = await APIRequester.HttpGetStringAsync(VersionListURL);

            var e = JsonConvert.DeserializeObject <JWVersions>(json);

            return(e.Versions);
        }
        /// <summary>
        /// 联网获取指定版本所有的Liteloader
        /// </summary>
        /// <param name="version">要搜索的版本</param>
        /// <returns>Liteloader列表</returns>
        public async Task <JWLiteloader> GetLiteloaderList(Version version)
        {
            string json = await APIRequester.HttpGetStringAsync(string.Format("{0}/?mcversion={1}", LiteloaderListURL, version.ID));

            var e = JsonConvert.DeserializeObject <JWLiteloader>(json);

            return(e);
        }
        /// <summary>
        /// 联网获取指定版本所有的FORGE
        /// </summary>
        /// <param name="version">要搜索的版本</param>
        /// <returns>Forge列表</returns>
        public async Task <List <JWForge> > GetForgeList(Version version)
        {
            string json = await APIRequester.HttpGetStringAsync(string.Format("{0}/{1}", ForgeListURL, version.ID));

            var e = JsonConvert.DeserializeObject <List <JWForge> >(json);

            return(e);
        }
示例#6
0
        public async Task <APIModules> GetInfoAsync()
        {
            string json = await APIRequester.HttpGetStringAsync(BaseURL);

            return(await Task.Factory.StartNew(() =>
            {
                return JsonConvert.DeserializeObject <APIModules>(json);
            }));
        }
        public async Task <APIModules> GetInfoAsync()
        {
            string json = await APIRequester.HttpGetStringAsync(string.Format("https://auth2.nide8.com:233/{0}", Nide8ID));

            return(await Task.Factory.StartNew(() =>
            {
                return JsonConvert.DeserializeObject <APIModules>(json);
            }));
        }
示例#8
0
 public Task UpdateBaseURL()
 {
     return(Task.Factory.StartNew(async() =>
     {
         APIModules module = JsonConvert.DeserializeObject <APIModules>(await APIRequester.HttpGetStringAsync(BaseURL));
         if (!string.IsNullOrWhiteSpace(module.APIRoot))
         {
             this.BaseURL = module.APIRoot;
         }
     }));
 }
        //作者觉得使用这个方法判断是否丢失文件不如直接根据GetLostDependDownloadTask方法返回的列表的Count数来判断
        //毕竟这种方法大部分用在启动前判断是否丢失文件,但是如果丢失还是要获取一次列表,效率并没怎样优化
        //public static bool IsLostAnyDependent(LaunchHandler core, Version version)
        //{
        //    return IsLostJarCore(core, version) || IsLostAnyLibs(core, version) || IsLostAnyNatives(core, version);
        //}

        /// <summary>
        /// 获取全部丢失的文件下载任务
        /// </summary>
        /// <param name="source">下载源</param>
        /// <param name="core">使用的核心</param>
        /// <param name="version">检查的版本</param>
        /// <returns></returns>
        public async static Task <List <DownloadTask> > GetLostDependDownloadTaskAsync(DownloadSource source, LaunchHandler core, Version version)
        {
            var lostLibs              = GetLostLibs(core, version);
            var lostNatives           = GetLostNatives(core, version);
            List <DownloadTask> tasks = new List <DownloadTask>();

            if (IsLostJarCore(core, version))
            {
                if (version.Jar == null)
                {
                    tasks.Add(GetDownloadUrl.GetCoreJarDownloadTask(source, version, core));
                }
            }

            if (version.InheritsVersion != null)
            {
                string innerJsonPath = core.GetJsonPath(version.InheritsVersion);
                string innerJsonStr;
                if (!File.Exists(innerJsonPath))
                {
                    innerJsonStr = await APIRequester.HttpGetStringAsync(GetDownloadUrl.GetCoreJsonDownloadURL(source, version.InheritsVersion));

                    string jsonFolder = Path.GetDirectoryName(innerJsonPath);
                    if (!Directory.Exists(jsonFolder))
                    {
                        Directory.CreateDirectory(jsonFolder);
                    }
                    File.WriteAllText(innerJsonPath, innerJsonStr);
                }
                else
                {
                    innerJsonStr = File.ReadAllText(innerJsonPath);
                }
                Version innerVer = core.JsonToVersion(innerJsonStr);
                if (innerVer != null)
                {
                    tasks.AddRange(await GetLostDependDownloadTaskAsync(source, core, innerVer));
                }
            }
            foreach (var item in lostLibs)
            {
                tasks.Add(GetDownloadUrl.GetLibDownloadTask(source, item));
            }
            foreach (var item in lostNatives)
            {
                tasks.Add(GetDownloadUrl.GetNativeDownloadTask(source, item));
            }
            return(tasks);
        }
示例#10
0
        private async Task AppendVersionsDownloadTask(IList list)
        {
            try
            {
                foreach (JWVersion item in list)
                {
                    string json = await APIRequester.HttpGetStringAsync(apiHandler.DoURLReplace(item.Url));

                    NsisoLauncherCore.Modules.Version ver = App.handler.JsonToVersion(json);
                    string jsonPath = App.handler.GetJsonPath(ver.ID);

                    string dir = Path.GetDirectoryName(jsonPath);
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    File.WriteAllText(jsonPath, json);

                    List <DownloadTask> tasks = new List <DownloadTask>();

                    tasks.Add(new DownloadTask("资源引导", apiHandler.DoURLReplace(ver.AssetIndex.URL), App.handler.GetAssetsIndexPath(ver.Assets)));

                    tasks.AddRange(await NsisoLauncherCore.Util.FileHelper.GetLostDependDownloadTaskAsync(App.config.MainConfig.Download.DownloadSource, App.handler, ver));

                    App.downloader.SetDownloadTasks(tasks);
                    App.downloader.StartDownload();
                }
            }
            catch (WebException ex)
            {
                this.Dispatcher.Invoke(new Action(() =>
                {
                    this.ShowMessageAsync("获取版本信息失败", "请检查您的网络是否正常或更改下载源/n原因:" + ex.Message);
                }));
            }
            catch (Exception ex)
            {
                AggregateExceptionArgs args = new AggregateExceptionArgs()
                {
                    AggregateException = new AggregateException(ex)
                };
                App.CatchAggregateException(this, args);
            }
        }
        /// <summary>
        /// 获取丢失的资源文件下载任务
        /// </summary>
        /// <param name="source"></param>
        /// <param name="core"></param>
        /// <param name="version"></param>
        /// <returns></returns>
        public async static Task <List <DownloadTask> > GetLostAssetsDownloadTaskAsync(DownloadSource source, LaunchHandler core, Version ver)
        {
            List <DownloadTask> tasks  = new List <DownloadTask>();
            JAssets             assets = null;

            string assetsPath = core.GetAssetsIndexPath(ver.Assets);

            if (!File.Exists(assetsPath))
            {
                if (ver.AssetIndex != null)
                {
                    string jsonUrl    = GetDownloadUrl.DoURLReplace(source, ver.AssetIndex.URL);
                    string assetsJson = await APIRequester.HttpGetStringAsync(jsonUrl);

                    assets = core.GetAssetsByJson(assetsJson);
                    tasks.Add(new DownloadTask("资源文件引导", jsonUrl, assetsPath));
                }
                else
                {
                    return(tasks);
                }
            }
            else
            {
                assets = core.GetAssets(ver);
            }
            var lostAssets = GetLostAssets(core, assets);

            foreach (var item in lostAssets)
            {
                DownloadTask task = GetDownloadUrl.GetAssetsDownloadTask(source, item.Value, core);
                if (!tasks.Contains(task))
                {
                    tasks.Add(task);
                }
            }
            return(tasks);
        }