Пример #1
0
        /// <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, MCVersion 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 HttpRequesterAPI.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);
                tasks.Add(task);
            }
            return(tasks);
        }
Пример #2
0
        public async Task <BitmapImage> GetByJson(string url)
        {
            string data = await HttpRequesterAPI.HttpGetStringAsync(url);

            if (string.IsNullOrWhiteSpace(data) || data.Contains("error"))
            {
                return(bitmap);
            }
            var obj1       = JObject.Parse(data);
            var properties = obj1["properties"];

            byte[] inArray = Convert.FromBase64String(properties[0]["value"].ToString());
            string c       = Encoding.UTF8.GetString(inArray);

            if (!string.IsNullOrWhiteSpace(c))
            {
                var obj2 = JObject.Parse(c);
                var obj3 = obj2["textures"];
                if (obj3.HasValues)
                {
                    var textures             = obj3["SKIN"]["url"].ToString();
                    HttpResponseMessage temp = await HttpRequesterAPI.HttpGetAsync(textures);

                    var img = Image.FromStream(await temp.Content.ReadAsStreamAsync());
                    return(CaptureImage(img));
                }
                return(bitmap);
            }
            return(bitmap);
        }
Пример #3
0
        public async Task <NsisoLauncherVersionResponse> GetLatestLauncherVersion()
        {
            try
            {
                Dictionary <string, string> args = new Dictionary <string, string>();
                args.Add("app_key", App_key);
                //表模型
                args.Add("model_name", "VersionList");
                //order
                args.Add("order", "[\"id DESC\"]");
                //查询规则(ID>0)
                args.Add("where", "[[\"id\", \">\", \"0\"]]");
                //仅返回一条(即ID最高的最新版本)
                args.Add("perpage", "1");
                string result = await HttpRequesterAPI.HttpPostReadAsStringForString(APIUrl + "?s=App.Table.FreeQuery", args);

                PhalApiClientResponse desObj          = JsonConvert.DeserializeObject <PhalApiClientResponse>(result);
                JObject listJobj                      = desObj.Data;
                NsisoLauncherVersionListResponse list = listJobj.ToObject <NsisoLauncherVersionListResponse>();
                return(list.List.FirstOrDefault());
            }
            catch
            {
                return(null);
            }
        }
Пример #4
0
        /// <summary>
        /// 联网获取指定版本所有的FABRIC
        /// </summary>
        /// <param name="version">要搜索的版本</param>
        /// <returns>Forge列表</returns>
        public async Task <List <JWFabric> > GetFabricList(MCVersion version)
        {
            string json = await HttpRequesterAPI.HttpGetStringAsync(FabricListVEURL);

            var    e = JsonConvert.DeserializeObject <List <JWFabric> >(json);
            string ver;

            if (string.IsNullOrWhiteSpace(version.InheritsVersion))
            {
                ver = version.ID;
            }
            else
            {
                ver = version.InheritsVersion;
            }
            var a = e.Where(b => b.Version == ver).ToList();

            if (a.Count == 0)
            {
                return(null);
            }
            json = await HttpRequesterAPI.HttpGetStringAsync(FabricListURL);

            e = JsonConvert.DeserializeObject <List <JWFabric> >(json);
            return(e);
        }
Пример #5
0
        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 HttpRequesterAPI.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
                }
            });
        }
Пример #6
0
        /// <summary>
        /// 联网获取指定版本所有的FORGE
        /// </summary>
        /// <param name="version">要搜索的版本</param>
        /// <returns>Forge列表</returns>
        public async Task <List <JWForge> > GetForgeList(MCVersion version)
        {
            string json = await HttpRequesterAPI.HttpGetStringAsync(string.Format("{0}/{1}", ForgeListURL, version.ID));

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

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

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

            return(e);
        }
Пример #8
0
        public async Task <APIModules> GetInfoAsync()
        {
            string json = await HttpRequesterAPI.HttpGetStringAsync(string.Format("https://auth2.nide8.com:233/{0}", Nide8ID));

            return(await Task.Factory.StartNew(() =>
            {
                return JsonConvert.DeserializeObject <APIModules>(json);
            }));
        }
Пример #9
0
        /// <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, MCVersion version, MetroWindow window)
        {
            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 HttpRequesterAPI.HttpGetStringAsync(GetDownloadUrl.GetCoreJsonDownloadURL(source, version.InheritsVersion));

                    if (innerJsonStr == null)
                    {
                        await window.ShowMessageAsync("检查错误", "检查源错误,请切换下载源后重试");

                        return(new List <DownloadTask>());
                    }
                    string jsonFolder = Path.GetDirectoryName(innerJsonPath);
                    if (!Directory.Exists(jsonFolder))
                    {
                        Directory.CreateDirectory(jsonFolder);
                    }
                    File.WriteAllText(innerJsonPath, innerJsonStr);
                }
                else
                {
                    innerJsonStr = File.ReadAllText(innerJsonPath);
                }
                MCVersion innerVer = core.JsonToVersion(innerJsonStr);
                if (innerVer != null)
                {
                    tasks.AddRange(await GetLostDependDownloadTaskAsync(source, core, innerVer, window));
                }
            }
            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
        public async Task <BitmapImage> GetByUrl(string url)
        {
            HttpResponseMessage temp = await HttpRequesterAPI.HttpGetAsync(url);

            if (temp != null)
            {
                var img = Image.FromStream(await temp.Content.ReadAsStreamAsync());
                return(CaptureImage(img));
            }
            return(bitmap);
        }
Пример #11
0
        /// <summary>
        /// 联网获取版本列表
        /// </summary>
        /// <returns>版本列表</returns>
        public async Task <List <JWVersion> > GetVersionList()
        {
            string json = await HttpRequesterAPI.HttpGetStringAsync(VersionListURL);

            if (json != null)
            {
                var e = JsonConvert.DeserializeObject <JWVersions>(json);
                return(e.Versions);
            }
            return(null);
        }
Пример #12
0
        /// <summary>
        /// 异步报告日志
        /// </summary>
        /// <param name="level">日志等级</param>
        /// <param name="log">日志内容</param>
        /// <returns></returns>
        public async Task PostLogAsync(Modules.LogLevel level, string log)
        {
            var escapeLog = Uri.EscapeDataString(log);
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("app_key", App_key);
            args.Add("super_type", level.ToString());
            args.Add("super_message", log);
            var result = await HttpRequesterAPI.HttpPostReadAsStringForString(APIUrl + "?s=App.Market_SuperLogger.Record", args);

            Console.WriteLine(result);
        }
Пример #13
0
 /// <summary>
 /// 刷新使用次数计数器(统计)
 /// </summary>
 /// <returns></returns>
 public async Task RefreshUsingTimesCounter()
 {
     if (!NoTracking)
     {
         try
         {
             Dictionary <string, string> args = new Dictionary <string, string>();
             args.Add("app_key", App_key);
             args.Add("type", "forever");
             args.Add("name", "NsisoLauncher(Color_yr edit)UsingTimes");
             args.Add("value", "1");
             await HttpRequesterAPI.HttpPostAsync(APIUrl + "?s=App.Main_Counter.SmartRefresh", args);
         }
         catch
         { }
     }
 }
Пример #14
0
        /// <summary>
        /// 资源检查
        /// </summary>
        public async Task <dynamic> Check()
        {
            string Url = App.Config.MainConfig.Server.UpdataCheck.Address;

            try
            {
                var res = await HttpRequesterAPI.HttpGetAsync(Url);

                if (res.IsSuccessStatusCode)
                {
                    JObject json = JObject.Parse(await res.Content.ReadAsStringAsync());
                    UpdataObj = json.ToObject <UpdataOBJ>();
                    if (UpdataObj == null)
                    {
                        return(true);
                    }
                    if (string.IsNullOrWhiteSpace(App.Config.MainConfig.Server.UpdataCheck.Packname))
                    {
                        return(this);
                    }
                    else if (!CheckVersion())
                    {
                        return(false);
                    }
                    else if (App.Config.MainConfig.Server.UpdataCheck.Version != UpdataObj.Version)
                    {
                        return(this);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch
            {
            }
            return(null);
        }
Пример #15
0
        public static async Task <Exception> DownloadForgeJLibrariesAsync(ProgressCallback monitor, DownloadSource source, CancellationToken cancelToken, List <JLibrary> libs, string librariesDir)
        {
            try
            {
                foreach (var item in libs)
                {
                    monitor.SetDoneSize(0);
                    monitor.SetState(string.Format("补全库文件{0}", item.Name));
                    Exception exception = null;
                    for (int i = 1; i <= 3; i++)
                    {
                        try
                        {
                            string from         = GetDownloadUrl.DoURLReplace(source, item.Downloads.Artifact.URL);
                            string to           = Path.Combine(librariesDir, item.Downloads.Artifact.Path);
                            string buffFilename = to + ".downloadtask";

                            if (File.Exists(to))
                            {
                                goto a;
                            }
                            if (string.IsNullOrWhiteSpace(from))
                            {
                                goto a;
                            }
                            if (Path.IsPathRooted(to))
                            {
                                string dirName = Path.GetDirectoryName(to);
                                if (!Directory.Exists(dirName))
                                {
                                    Directory.CreateDirectory(dirName);
                                }
                            }
                            if (File.Exists(buffFilename))
                            {
                                File.Delete(buffFilename);
                            }

                            using (var getResult = await HttpRequesterAPI.HttpGetAsync(from, cancelToken))
                            {
                                getResult.EnsureSuccessStatusCode();
                                monitor.SetTotalSize(getResult.Content.Headers.ContentLength.GetValueOrDefault());
                                using (Stream responseStream = await getResult.Content.ReadAsStreamAsync())
                                {
                                    using (FileStream fs = new FileStream(buffFilename, FileMode.Create))
                                    {
                                        byte[] bArr = new byte[1024];
                                        int    size = await responseStream.ReadAsync(bArr, 0, (int)bArr.Length);

                                        while (size > 0)
                                        {
                                            if (cancelToken.IsCancellationRequested)
                                            {
                                                return(null);
                                            }
                                            fs.Write(bArr, 0, size);
                                            size = responseStream.Read(bArr, 0, (int)bArr.Length);
                                            monitor.IncreaseDoneSize(size);
                                        }
                                    }
                                }
                            }

                            //下载完成后转正
                            File.Move(buffFilename, to);
                            monitor.SetDone();

                            break;
                        }
                        catch (Exception e)
                        {
                            exception = e;
                            monitor.SetState(string.Format("重试第{0}次", i));

                            //继续重试
                            continue;
                        }
                    }
                    a :;
                }
                return(null);
            }
            catch (Exception e)
            {
                return(e);
            }
        }