コード例 #1
0
        public static async Task<UpdateResponse> UpdateCore(string leagueOfLegendsFilePath, bool showMessages)
        {
            if (Directory.Exists(Path.Combine(Directories.CurrentDirectory, "iwanttogetbanned")))
            {
                return new UpdateResponse(CoreUpdateState.Operational, Utility.GetMultiLanguageText("NotUpdateNeeded"));
            }

            try
            {
                var leagueMd5 = Utility.Md5Checksum(leagueOfLegendsFilePath);
                var wr = WebRequest.Create(string.Format(CoreVersionCheckURL, leagueMd5));
                wr.Timeout = 4000;
                wr.Method = "GET";
                var response = await wr.GetResponseAsync();

                using (var stream = response.GetResponseStream())
                {
                    if (stream != null)
                    {
                        var ser = new DataContractJsonSerializer(typeof(UpdateInfo));
                        var updateInfo = (UpdateInfo)ser.ReadObject(stream);

                        if (updateInfo.version == "0")
                        {
                            var message = Utility.GetMultiLanguageText("WrongVersion") + leagueMd5;

                            if (showMessages)
                            {
                                MessageBox.Show(message);
                            }

                            return new UpdateResponse(CoreUpdateState.Maintenance, message);
                        }

                        if (updateInfo.version != Utility.Md5Checksum(Directories.CoreFilePath)
                            && updateInfo.url.StartsWith("https://github.com/joduskame/"))
                        {
                            try
                            {
                                var result = CoreUpdateState.Unknown;

                                await Application.Current.Dispatcher.Invoke(
                                    async () =>
                                        {
                                            var window = new UpdateWindow(UpdateAction.Core, updateInfo.url);
                                            window.Show();

                                            if (await window.Update())
                                            {
                                                result = CoreUpdateState.Operational;
                                            }
                                        });

                                return new UpdateResponse(result, Utility.GetMultiLanguageText("UpdateSuccess"));
                            }
                            catch (Exception e)
                            {
                                var message = Utility.GetMultiLanguageText("FailedToDownload") + e;

                                if (showMessages)
                                {
                                    MessageBox.Show(message);
                                }

                                return new UpdateResponse(CoreUpdateState.Unknown, message);
                            }
                            finally
                            {
                                if (File.Exists(UpdateZip))
                                {
                                    File.Delete(UpdateZip);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                return new UpdateResponse(CoreUpdateState.Unknown, Utility.GetMultiLanguageText("UpdateUnknown"));
            }

            return new UpdateResponse(CoreUpdateState.Operational, Utility.GetMultiLanguageText("NotUpdateNeeded"));
        }
コード例 #2
0
 public static async Task UpdateLoader(Tuple<bool, string> versionCheckResult)
 {
     if (versionCheckResult.Item1
         && (versionCheckResult.Item2.StartsWith("https://github.com/LeagueSharp/")
             || versionCheckResult.Item2.StartsWith("https://github.com/joduskame/")
             || versionCheckResult.Item2.StartsWith("https://github.com/Esk0r/")))
     {
         var window = new UpdateWindow(UpdateAction.Loader, versionCheckResult.Item2);
         window.Show();
         await window.Update();
     }
 }
コード例 #3
0
        public static async Task<UpdateResponse> UpdateCore(string path, bool showMessages)
        {
            if (Directory.Exists(Path.Combine(Directories.CurrentDirectory, "iwanttogetbanned")))
            {
                return new UpdateResponse(CoreUpdateState.Operational, Utility.GetMultiLanguageText("NotUpdateNeeded"));
            }

            try
            {
                if (!WebService.Client.IsAuthenticated)
                {
                    Utility.Log(LogStatus.Error, "UpdateCore", "WebService authentication failed", Logs.MainLog);
                    return new UpdateResponse(CoreUpdateState.Unknown, "WebService authentication failed");
                }

                var leagueChecksum = Utility.Md5Checksum(path);
                var coreChecksum = Utility.Md5Checksum(Directories.CoreFilePath);
                var core = WebService.Client.Core(leagueChecksum);

                if (core == null)
                {
                    return new UpdateResponse(
                        CoreUpdateState.Maintenance,
                        Utility.GetMultiLanguageText("WrongVersion") + Environment.NewLine + leagueChecksum);
                }

                if (core.HashCore != coreChecksum && (core.Url.StartsWith("https://github.com/joduskame/") || core.Url.StartsWith("https://github.com/LeagueSharp/")))
                {
                    try
                    {
                        var result = CoreUpdateState.Unknown;

                        await Application.Current.Dispatcher.Invoke(
                            async () =>
                                {
                                    var window = new UpdateWindow(UpdateAction.Core, core.Url);
                                    window.Show();

                                    if (await window.Update())
                                    {
                                        result = CoreUpdateState.Operational;
                                    }
                                });

                        return new UpdateResponse(result, Utility.GetMultiLanguageText("UpdateSuccess"));
                    }
                    catch (Exception e)
                    {
                        var message = Utility.GetMultiLanguageText("FailedToDownload") + e;

                        if (showMessages)
                        {
                            MessageBox.Show(message);
                        }

                        return new UpdateResponse(CoreUpdateState.Unknown, message);
                    }
                    finally
                    {
                        if (File.Exists(UpdateZip))
                        {
                            File.Delete(UpdateZip);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Utility.Log(LogStatus.Error, "UpdateCore", e.Message, Logs.MainLog);
            }

            return new UpdateResponse(CoreUpdateState.Operational, Utility.GetMultiLanguageText("NotUpdateNeeded"));
        }