예제 #1
0
        private void StartPatcher()
        {
            try
            {
                var bgThead = new Thread(() =>
                {
                    LogTextBox("Starting Patcher");

                    var client = new WebClient();
                    client.DownloadProgressChanged += client_DownloadProgressChanged;
                    client.DownloadFileCompleted   += client_DownloadDDragon;
                    client.DownloadProgressChanged +=
                        (o, e) => Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        double bytesIn    = double.Parse(e.BytesReceived.ToString(CultureInfo.InvariantCulture));
                        double totalBytes =
                            double.Parse(e.TotalBytesToReceive.ToString(CultureInfo.InvariantCulture));
                        double percentage            = bytesIn / totalBytes * 100;
                        CurrentProgressLabel.Content = "Downloaded " + e.BytesReceived + " of " +
                                                       e.TotalBytesToReceive;
                        CurrentProgressBar.Value =
                            int.Parse(Math.Truncate(percentage).ToString(CultureInfo.InvariantCulture));
                    }));

                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        TotalProgressLabel.Content = "20%";
                        TotalProgessBar.Value      = 20;
                    }));

                    #region idk

                    client = new WebClient();
                    if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "Client", "Login.mp3")))
                    {
                        client.DownloadFile(
                            new Uri(
                                "https://s12.solidfilesusercontent.com/MDE1MWYxZGJmYWFhNzJmNGQ2N2ZhOWE0NzU4Yjk2ZDYwZjY3MGU2OToxWHp3OTk6dUllemo3WDM0RnlScUgxZk1YWXpKYmN0RXBn/7a0671ed14/Login.mp3"),
                            Path.Combine(Client.ExecutingDirectory, "Client", "Login.mp3"));
                    }

                    if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "Client", "Login.mp4")))
                    {
                        client.DownloadFile(
                            new Uri(
                                "https://s8.solidfilesusercontent.com/MzkxMTBjOTllZDczMTBjZDUwNzgwOTc1NTYwZmY1Nzg2YThkZDI5MzoxWHp2eE86alBDQXBkU1FuNmt6R3dsTzcycEtoOXpGdVZr/a38bbf759c/Login.mp4"),
                            Path.Combine(Client.ExecutingDirectory, "Client", "Login.mp4"));
                    }

                    #endregion idk

                    #region DDragon

                    var encoding = new ASCIIEncoding();
                    if (!Directory.Exists(Path.Combine(Client.ExecutingDirectory, "Assets")))
                    {
                        Directory.CreateDirectory(Path.Combine(Client.ExecutingDirectory, "Assets"));
                    }

                    if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDRagon")))
                    {
                        FileStream versionLol =
                            File.Create(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDRagon"));
                        versionLol.Write(encoding.GetBytes("0.0.0"), 0, encoding.GetBytes("0.0.0").Length);

                        versionLol.Close();
                    }


                    var patcher = new RiotPatcher();
                    string dDragonDownloadUrl = patcher.GetDragon();
                    if (!String.IsNullOrEmpty(dDragonDownloadUrl))
                    {
                        LogTextBox("DataDragon Version: " + patcher.DDragonVersion);
                        string dDragonVersion =
                            File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDragon"));
                        LogTextBox("Current DataDragon Version: " + dDragonVersion);

                        Client.Version = dDragonVersion;
                        Client.Log("DDragon Version (LOL Version) = " + dDragonVersion);

                        LogTextBox("Client Version: " + Client.Version);

                        if (patcher.DDragonVersion != dDragonVersion)
                        {
                            try
                            {
                                if (!Directory.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "temp")))
                                {
                                    Directory.CreateDirectory(Path.Combine(Client.ExecutingDirectory, "Assets", "temp"));
                                }

                                Dispatcher.BeginInvoke(DispatcherPriority.Input,
                                                       new ThreadStart(() => { CurrentProgressLabel.Content = "Downloading DataDragon"; }));
                                client.DownloadFile(dDragonDownloadUrl,
                                                    Path.Combine(Client.ExecutingDirectory, "Assets",
                                                                 "dragontail-" + patcher.DDragonVersion + ".tgz"));


                                Dispatcher.BeginInvoke(DispatcherPriority.Input,
                                                       new ThreadStart(() => { CurrentProgressLabel.Content = "Extracting DataDragon"; }));

                                Stream inStream =
                                    File.OpenRead(Path.Combine(Client.ExecutingDirectory, "Assets",
                                                               "dragontail-" + patcher.DDragonVersion + ".tgz"));

                                using (var gzipStream = new GZipInputStream(inStream))
                                {
                                    TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream);
                                    tarArchive.ExtractContents(Path.Combine(Client.ExecutingDirectory, "Assets", "temp"));
                                    //tarArchive.Close();
                                }
                                inStream.Close();

                                Copy(
                                    Path.Combine(Client.ExecutingDirectory, "Assets", "temp", patcher.DDragonVersion,
                                                 "data"), Path.Combine(Client.ExecutingDirectory, "Assets", "data"));
                                Copy(
                                    Path.Combine(Client.ExecutingDirectory, "Assets", "temp", patcher.DDragonVersion,
                                                 "img"), Path.Combine(Client.ExecutingDirectory, "Assets"));
                                DeleteDirectoryRecursive(Path.Combine(Client.ExecutingDirectory, "Assets", "temp"));

                                FileStream versionDDragon =
                                    File.Create(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDRagon"));
                                versionDDragon.Write(encoding.GetBytes(patcher.DDragonVersion), 0,
                                                     encoding.GetBytes(patcher.DDragonVersion).Length);

                                Client.Version = dDragonVersion;
                                versionDDragon.Close();
                            }
                            catch
                            {
                                Client.Log(
                                    "Probably updated version number without actually uploading the files.");
                            }
                        }
                    }
                    else
                    {
                        LogTextBox(
                            "Failed to get DDragon version. Either not able to be found or unknown error (most likely the website is in maitenance, please try again in an hour or so)");
                        LogTextBox(
                            "Continuing could cause errors. Report this as an issue if it occurs again in a few hours.");
                    }

                    #endregion DDragon

                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        TotalProgressLabel.Content = "40%";
                        TotalProgessBar.Value      = 40;
                    }));

                    // Try get LoL path from registry

                    //A string that looks like C:\Riot Games\League of Legends\
                    string lolRootPath = GetLolRootPath(false);

                    #region lol_air_client

                    if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR")))
                    {
                        FileStream versionAir =
                            File.Create(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                        versionAir.Write(encoding.GetBytes("0.0.0.0"), 0, encoding.GetBytes("0.0.0.0").Length);
                        versionAir.Close();
                    }

                    BaseUpdateRegion updateRegion = BaseUpdateRegion.GetUpdateRegion(Client.UpdateRegion);
                    string latestAir = patcher.GetListing(updateRegion.AirListing);
                    LogTextBox("Air Assets Version: " + latestAir);
                    string airVersion =
                        File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                    LogTextBox("Current Air Assets Version: " + airVersion);
                    var updateClient = new WebClient();
                    if (airVersion != latestAir)
                    {
                        //Download Air Assists from riot
                        try
                        {
                            string airManifestLink = updateRegion.AirManifest + "releases/" + latestAir + "/packages/files/packagemanifest";
                            string[] allFiles      = patcher.GetManifest(airManifestLink);
                            int i = 0;
                            while (!allFiles[i].Contains("gameStats_en_US.sqlite"))
                            {
                                i++;
                            }

                            updateClient.DownloadFile(new Uri(updateRegion.BaseLink + allFiles[i].Split(',')[0]), Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite"));

                            GetAllPngs(allFiles);
                            if (File.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR")))
                            {
                                File.Delete(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                            }

                            using (
                                FileStream file =
                                    File.Create(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR")))
                                file.Write(encoding.GetBytes(latestAir), 0,
                                           encoding.GetBytes(latestAir).Length);
                        }
                        catch (Exception e)
                        {
                            Client.Log(e.Message);
                        }
                    }

                    if (airVersion != latestAir)
                    {
                        Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                        {
                            SkipPatchButton.IsEnabled    = true;
                            CurrentProgressLabel.Content = "Retrieving Air Assets";
                        }));
                    }

                    #endregion lol_air_client

                    //string GameVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "RADS", "VERSION_LOL"));

                    #region lol_game_client

                    LogTextBox("Trying to detect League of Legends GameClient");
                    LogTextBox("League of Legends is located at: " + lolRootPath);
                    //RADS\solutions\lol_game_client_sln\releases
                    string gameLocation = Path.Combine(lolRootPath, "RADS", "solutions", "lol_game_client_sln",
                                                       "releases");

                    string solutionListing =
                        patcher.GetListing(
                            updateRegion.SolutionListing);

                    string solutionVersion = solutionListing.Split(new[] { Environment.NewLine }, StringSplitOptions.None)[0];
                    LogTextBox("Latest League of Legends GameClient: " + solutionVersion);
                    LogTextBox("Checking if League of Legends is Up-To-Date");

                    bool toExit = false;
                    if (Client.UpdateRegion == "Garena")
                    {
                        XmlReader reader     = XmlReader.Create("http://updateres.garenanow.com/im/versions.xml");
                        string garenaVersion = "";
                        while (reader.Read())
                        {
                            if (reader.GetAttribute("name") == "lol")
                            {
                                garenaVersion = reader.GetAttribute("latest_version");
                                break;
                            }
                        }
                        try
                        {
                            if (garenaVersion == File.ReadAllText(Path.Combine(Path.GetDirectoryName(lolRootPath), "lol.version")))
                            {
                                LogTextBox("League of Legends is Up-To-Date");
                                Client.Location     = Path.Combine(lolRootPath, "Game");
                                Client.RootLocation = lolRootPath;
                            }
                            else
                            {
                                LogTextBox("League of Legends is not Up-To-Date. Please Update League Of Legends");
                                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                                {
                                    SkipPatchButton.IsEnabled   = true;
                                    FindClientButton.Visibility = Visibility.Visible;
                                }));
                                toExit = true;
                            }
                        }
                        catch
                        {
                            LogTextBox("Can't find League of Legends version file. Make sure you select correct update region.");
                            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                            {
                                SkipPatchButton.IsEnabled   = true;
                                FindClientButton.Visibility = Visibility.Visible;
                            }));
                            toExit = true;
                        }
                    }
                    else if (Directory.Exists(Path.Combine(gameLocation, solutionVersion)))
                    {
                        LogTextBox("League of Legends is Up-To-Date");
                        Client.Location = Path.Combine(lolRootPath, "RADS", "solutions", "lol_game_client_sln",
                                                       "releases", solutionVersion, "deploy");
                        Client.RootLocation = lolRootPath;
                    }
                    else
                    {
                        LogTextBox("League of Legends is not Up-To-Date. Please Update League Of Legends");
                        Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                        {
                            SkipPatchButton.IsEnabled   = true;
                            FindClientButton.Visibility = Visibility.Visible;
                        }));
                        toExit = true;
                    }

                    #endregion lol_game_client

                    if (toExit)
                    {
                        return;
                    }

                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        TotalProgressLabel.Content   = "100%";
                        TotalProgessBar.Value        = 100;
                        SkipPatchButton.Content      = "Play";
                        CurrentProgressLabel.Content = "Finished Patching";
                        CurrentStatusLabel.Content   = "Ready To Play";
                        SkipPatchButton.IsEnabled    = true;
                        SkipPatchButton_Click(null, null);
                    }));

                    LogTextBox("LegendaryClient Has Finished Patching");
                })
                {
                    IsBackground = true
                };

                bgThead.Start();
            }
            catch (Exception e)
            {
                Client.Log(e.Message + " - in PatcherPage updating progress.");
            }
        }
예제 #2
0
        private async void StartPatcher()
        {
            var client = new WebClient();

            client.DownloadProgressChanged +=
                (o, e) => Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                double bytesIn    = double.Parse(e.BytesReceived.ToString(CultureInfo.InvariantCulture));
                double totalBytes =
                    double.Parse(e.TotalBytesToReceive.ToString(CultureInfo.InvariantCulture));
                double percentage = bytesIn / totalBytes * 100;

                CurrentProgressLabel.Content = string.Format("Downloaded {0} MBs of {1} MBs",
                                                             (e.BytesReceived / 1024d / 1024d).ToString("0.00"),
                                                             (e.TotalBytesToReceive / 1024d / 1024d).ToString("0.00"));
                CurrentProgressBar.Value =
                    int.Parse(Math.Truncate(percentage).ToString(CultureInfo.InvariantCulture));
            }));

            await Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                TotalProgressLabel.Content = "20%";
                TotalProgessBar.Value = 20;
            }));

            #region Plugins
            LogTextBox("Checking Plugin dependencies...");
            //Check if LIB is not extracted
            if (File.Exists(Path.Combine(Client.ExecutingDirectory, "Client", "LIB", "abc.py")))
            {
                LogTextBox("Plugin dependencies are installed");
            }
            else
            {
                if (File.Exists(Path.Combine(Client.ExecutingDirectory, "Client", "LIB", "LIB.zip")))
                {
                    LogTextBox("Extracting Plugin dependencies...");
                    //Extract the zip
                    ZipFile.ExtractToDirectory(Path.Combine(Client.ExecutingDirectory, "Client", "LIB", "LIB.zip"), Path.Combine(Client.ExecutingDirectory, "Client", "LIB"));
                    //delete it
                    File.Delete(Path.Combine(Client.ExecutingDirectory, "Client", "LIB", "LIB.zip"));
                    LogTextBox("Plugin dependencies are installed");
                }
                else
                {
                    LogTextBox("Plugin dependencies are NOT installed. Some features of the Plugins might not work!");
                }
            }
            #endregion

            #region DDragon

            var encoding = new ASCIIEncoding();
            if (!Directory.Exists(Path.Combine(Client.ExecutingDirectory, "Assets")))
            {
                Directory.CreateDirectory(Path.Combine(Client.ExecutingDirectory, "Assets"));
            }

            if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDRagon")))
            {
                FileStream versionLol =
                    File.Create(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDRagon"));
                versionLol.Write(encoding.GetBytes("0.0.0"), 0, encoding.GetBytes("0.0.0").Length);

                versionLol.Close();
            }


            string dDragonDownloadUrl = patcher.GetDragon();
            if (!string.IsNullOrEmpty(dDragonDownloadUrl))
            {
                LogTextBox("Newest DataDragon Version: " + patcher.DDragonVersion);
                string dDragonVersion =
                    File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDragon"));
                LogTextBox("Current DataDragon Version: " + dDragonVersion);

                Client.Log("DDragon Version (LOL Version) = " + dDragonVersion);

                if (patcher.DDragonVersion != dDragonVersion)
                {
                    try
                    {
                        if (!Directory.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "temp")))
                        {
                            Directory.CreateDirectory(Path.Combine(Client.ExecutingDirectory, "Assets", "temp"));
                        }

                        await Dispatcher.BeginInvoke(DispatcherPriority.Input,
                                                     new ThreadStart(() => { CurrentProgressLabel.Content = "Downloading DataDragon"; }));

                        string ddragonLocation = Path.Combine(Client.ExecutingDirectory, "Assets",
                                                              "dragontail-" + patcher.DDragonVersion + ".tgz");
                        if (File.Exists(ddragonLocation))
                        {
                            client.OpenRead(dDragonDownloadUrl);
                            var asd = new FileInfo(ddragonLocation);
                            if (asd.Length != Convert.ToInt64(client.ResponseHeaders["Content-Length"]))
                            {
                                await client.DownloadFileTaskAsync(dDragonDownloadUrl,
                                                                   Path.Combine(Client.ExecutingDirectory, "Assets",
                                                                                "dragontail-" + patcher.DDragonVersion + ".tgz"));

                                await Task.Run(() => DDragonDownloaded());
                            }
                            else
                            {
                                await Task.Run(() => DDragonDownloaded());
                            }
                        }
                        else
                        {
                            await client.DownloadFileTaskAsync(dDragonDownloadUrl,
                                                               Path.Combine(Client.ExecutingDirectory, "Assets",
                                                                            "dragontail-" + patcher.DDragonVersion + ".tgz"));

                            await Task.Run(() => DDragonDownloaded());
                        }
                    }
                    catch
                    {
                        Client.Log(
                            "Probably updated version number without actually uploading the files.");
                    }
                }
                else
                {
                    AirPatcher();
                }
            }
            else
            {
                LogTextBox(
                    "Failed to get DDragon version. Either not able to be found or unknown error (most likely the website is in maitenance, please try again in an hour or so)");
                LogTextBox(
                    "Continuing could cause errors. Report this as an issue if it occurs again in a few hours.");
            }
        }
예제 #3
0
        private void StartPatcher()
        {
            bgThread = new Thread(() =>
            {
                LogTextBox("Starting Patcher");

                WebClient client = new WebClient();

                #region Configure download bar
                client.DownloadProgressChanged += (o, e) =>
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        double bytesIn               = double.Parse(e.BytesReceived.ToString());
                        double totalBytes            = double.Parse(e.TotalBytesToReceive.ToString());
                        double percentage            = bytesIn / totalBytes * 100;
                        CurrentProgressLabel.Content = "Downloaded " + e.BytesReceived + " of " + e.TotalBytesToReceive;
                        CurrentProgressBar.Value     = int.Parse(Math.Truncate(percentage).ToString());
                    }));
                };
                #endregion

                #region Update this client

                string CurrentMD5 = GetMd5();
                LogTextBox("MD5: " + CurrentMD5);
                string VersionString = "";
                try
                {
                    VersionString = client.DownloadString(new Uri("http://legendaryclient.com/update.html"));
                }
                catch
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Could not retrieve update files!";
                        Client.Log("Couldn't get update files for LegendaryClient");
                    }));
                    return;
                }

                string[] VersionSplit = VersionString.Split('|');

                LogTextBox("Update data: " + VersionSplit[0] + "|" + VersionSplit[1]);
                Client.Log("Update data: " + VersionSplit[0] + "|" + VersionSplit[1]);

#if !DEBUG //Dont patch client while in DEBUG
                if (VersionSplit.Length == 3)
                {
                    string[] versionArray = VersionString.Split('|');
                    if (VersionSplit[0] != CurrentMD5)
                    {
                        LogTextBox("LegendaryClient needs to be updated");

                        /*Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                         * {
                         *  CurrentStatusLabel.Content = "Downloading latest LegendaryClient...";
                         * }));
                         *
                         * client.DownloadFile(versionArray[2], "COL.ZIP");
                         * Directory.CreateDirectory("Patch");
                         * System.IO.Compression.ZipFile.ExtractToDirectory("COL.ZIP", "Patch");
                         * File.Delete("COL.ZIP");
                         * System.Diagnostics.Process.Start("Patcher.exe");
                         * Environment.Exit(0);*/
                    }
                }
#endif
                LogTextBox("LegendaryClient is up to date");
                Client.Log("LC Patched");

                #endregion LegendaryClient

                #region ProgressBar 20%
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    TotalProgressLabel.Content = "20%";
                    TotalProgessBar.Value      = 20;
                }));
                #endregion

                #region Get DDragon data

                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                if (!Directory.Exists("Assets"))
                {
                    Directory.CreateDirectory("Assets");
                }
                if (!File.Exists(Path.Combine("Assets", "VERSION_DDRagon")))
                {
                    var VersionLOL = File.Create(Path.Combine("Assets", "VERSION_DDRagon"));
                    VersionLOL.Write(encoding.GetBytes("0.0.0"), 0, encoding.GetBytes("0.0.0").Length);
                    VersionLOL.Close();
                }

                RiotPatcher patcher       = new RiotPatcher();
                string DDragonDownloadURL = patcher.GetDragon();
                if (!DDragonDownloadURL.StartsWith("http:"))
                {
                    DDragonDownloadURL = "http:" + DDragonDownloadURL;
                }
                LogTextBox("DataDragon Version: " + patcher.DDragonVersion);
                string DDragonVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDragon"));
                LogTextBox("Current DataDragon Version: " + DDragonVersion);
                Client.Log("DD: " + patcher.DDragonVersion + "|" + DDragonVersion);

                if (patcher.DDragonVersion != DDragonVersion)
                {
                    if (!Directory.Exists(Path.Combine("Assets", "temp")))
                    {
                        Directory.CreateDirectory(Path.Combine("Assets", "temp"));
                    }

                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Downloading DataDragon";
                    }));

                    client.DownloadFile(DDragonDownloadURL, Path.Combine("Assets", "dragontail-" + patcher.DDragonVersion + ".tgz"));

                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Extracting DataDragon";
                    }));

                    Stream inStream = File.OpenRead(Path.Combine("Assets", "dragontail-" + patcher.DDragonVersion + ".tgz"));
                    using (GZipInputStream gzipStream = new GZipInputStream(inStream))
                    {
                        TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream);
                        tarArchive.ExtractContents(Path.Combine("Assets", "temp"));
                        tarArchive.CloseArchive();
                    }
                    inStream.Close();

                    Copy(Path.Combine("Assets", "temp", patcher.DDragonVersion, "data"), Path.Combine("Assets", "data"));
                    Copy(Path.Combine("Assets", "temp", patcher.DDragonVersion, "img"), Path.Combine("Assets"));
                    Directory.Delete(Path.Combine("Assets", "temp"), true);

                    var VersionDDragon = File.Create(Path.Combine("Assets", "VERSION_DDRagon"));
                    VersionDDragon.Write(encoding.GetBytes(patcher.DDragonVersion), 0, encoding.GetBytes(patcher.DDragonVersion).Length);
                    VersionDDragon.Close();
                }

                #endregion DDragon

                #region ProgressBar 50%
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    TotalProgressLabel.Content = "50%";
                    TotalProgessBar.Value      = 50;
                }));
                #endregion

                #region Update lol_air_client

                if (!File.Exists(Path.Combine("Assets", "VERSION_AIR")))
                {
                    var VersionAIR = File.Create(Path.Combine("Assets", "VERSION_AIR"));
                    VersionAIR.Write(encoding.GetBytes("0.0.0.0"), 0, encoding.GetBytes("0.0.0.0").Length);
                    VersionAIR.Close();
                }

                string LatestAIR = patcher.GetLatestAir();
                LogTextBox("Air Assets Version: " + LatestAIR);
                string AirVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                LogTextBox("Current Air Assets Version: " + AirVersion);
                bool RetrieveCurrentInstallation = false;
                string AirLocation = "";
                Client.Log("AIR: " + LatestAIR + "|" + AirVersion);

                if (AirVersion == "0.0.0.0")
                {
                    LogTextBox("Checking for existing League of Legends Installation");
                    AirLocation = Path.Combine("League of Legends", "RADS", "projects", "lol_air_client", "releases");
                    if (Directory.Exists(AirLocation))
                    {
                        RetrieveCurrentInstallation = true;
                    }
                    else if (Directory.Exists(Path.Combine(System.IO.Path.GetPathRoot(Environment.SystemDirectory), "Riot Games", AirLocation)))
                    {
                        RetrieveCurrentInstallation = true;
                        AirLocation = Path.Combine(System.IO.Path.GetPathRoot(Environment.SystemDirectory), "Riot Games", AirLocation);
                    }
                    else
                    {
                        LogTextBox("Unable to find existing League of Legends. Copy your League of Legends folder into + "
                                   + Client.ExecutingDirectory
                                   + " to make the patching process quicker");
                    }

                    if (RetrieveCurrentInstallation)
                    {
                        Client.Log("Got previous installation: " + AirLocation);
                        LogTextBox("Getting Air Assets from " + AirLocation);
                        Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                        {
                            CurrentProgressLabel.Content = "Copying Air Assets";
                        }));
                        AirVersion = patcher.GetCurrentAirInstall(AirLocation);
                        LogTextBox("Retrieved currently installed Air Assets");
                        LogTextBox("Current Air Assets Version: " + AirVersion);
                    }
                }

                if (AirVersion != LatestAIR)
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Retrieving Air Assets";
                    }));
                    AirLocation = Path.Combine("League of Legends", "RADS", "projects", "lol_air_client", "releases");
                    if (Directory.Exists(AirLocation))
                    {
                        AirVersion = patcher.GetCurrentAirInstall(AirLocation);
                        LogTextBox("Retrieved currently installed Air Assets");
                        LogTextBox("Current Air Assets Version: " + AirVersion);
                    }
                }

                #endregion lol_air_client

                #region ProgressBar 70%
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    TotalProgressLabel.Content = "70%";
                    TotalProgessBar.Value      = 70;
                }));
                #endregion

                #region Update lol_game_client

                if (!Directory.Exists("RADS"))
                {
                    Directory.CreateDirectory("RADS");
                }

                if (!File.Exists(Path.Combine("RADS", "VERSION_LOL")))
                {
                    var VersionGAME = File.Create(Path.Combine("RADS", "VERSION_LOL"));
                    VersionGAME.Write(encoding.GetBytes("0.0.0.0"), 0, encoding.GetBytes("0.0.0.0").Length);
                    VersionGAME.Close();
                }

                string LatestGame = patcher.GetLatestGame();
                LogTextBox("League of Legends Version: " + LatestGame);
                string GameVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "RADS", "VERSION_LOL"));
                LogTextBox("Current League of Legends Version: " + GameVersion);
                RetrieveCurrentInstallation = false;
                string GameLocation         = "";

                if (GameVersion == "0.0.0.0")
                {
                    LogTextBox("Checking for existing League of Legends Installation");
                    GameLocation = Path.Combine("League of Legends", "RADS");
                    if (Directory.Exists(GameLocation))
                    {
                        RetrieveCurrentInstallation = true;
                    }
                    else if (Directory.Exists(Path.Combine(System.IO.Path.GetPathRoot(Environment.SystemDirectory), "Riot Games", GameLocation)))
                    {
                        RetrieveCurrentInstallation = true;
                        GameLocation = Path.Combine(System.IO.Path.GetPathRoot(Environment.SystemDirectory), "Riot Games", GameLocation);
                    }
                    else
                    {
                        LogTextBox("Unable to find existing League of Legends. Copy your League of Legends folder into + "
                                   + Client.ExecutingDirectory
                                   + " to make the patching process quicker");
                    }

                    if (RetrieveCurrentInstallation)
                    {
                        LogTextBox("Getting League Of Legends from " + GameLocation);
                        Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                        {
                            CurrentProgressLabel.Content = "Copying League of Legends";
                        }));
                        GameVersion = patcher.GetCurrentGameInstall(GameLocation);
                        LogTextBox("Retrieved currently installed League of Legends");
                        LogTextBox("Current League of Legends Version: " + GameVersion);
                    }
                }

                if (GameVersion != LatestGame)
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Retrieving League of Legends";
                    }));
                    GameLocation = Path.Combine("League of Legends", "RADS");
                    if (Directory.Exists(GameLocation))
                    {
                        GameVersion = patcher.GetCurrentGameInstall(GameLocation);
                        LogTextBox("Retrieved currently installed League of Legends");
                        LogTextBox("Current League of Legends Version: " + GameVersion);
                    }
                }

                #endregion lol_game_client

                #region ProgressBar 90%
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    TotalProgressLabel.Content = "90%";
                    TotalProgessBar.Value      = 90;
                }));
                #endregion

                FinishPatching();
            });
            bgThread.IsBackground = true;
            bgThread.Start();
        }
예제 #4
0
        private void StartPatcher()
        {
            try
            {
                Thread bgThead = new Thread(() =>
                {
                    LogTextBox("Starting Patcher");

                    WebClient client = new WebClient();
                    client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                    client.DownloadFileCompleted   += new AsyncCompletedEventHandler(client_DownloadDDragon);
                    client.DownloadProgressChanged += (o, e) =>
                    {
                        Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                        {
                            double bytesIn               = double.Parse(e.BytesReceived.ToString());
                            double totalBytes            = double.Parse(e.TotalBytesToReceive.ToString());
                            double percentage            = bytesIn / totalBytes * 100;
                            CurrentProgressLabel.Content = "Downloaded " + e.BytesReceived + " of " + e.TotalBytesToReceive;
                            CurrentProgressBar.Value     = int.Parse(Math.Truncate(percentage).ToString());
                        }));
                    };

                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        TotalProgressLabel.Content = "20%";
                        TotalProgessBar.Value      = 20;
                    }));

                    #region DDragon

                    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                    if (!Directory.Exists(Path.Combine(Client.ExecutingDirectory, "Assets")))
                    {
                        Directory.CreateDirectory(Path.Combine(Client.ExecutingDirectory, "Assets"));
                    }
                    if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDRagon")))
                    {
                        var VersionLOL = File.Create(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDRagon"));
                        VersionLOL.Write(encoding.GetBytes("0.0.0"), 0, encoding.GetBytes("0.0.0").Length);

                        VersionLOL.Close();
                    }


                    RiotPatcher patcher       = new RiotPatcher();
                    string DDragonDownloadURL = patcher.GetDragon();
                    LogTextBox("DataDragon Version: " + patcher.DDragonVersion);
                    string DDragonVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDragon"));
                    LogTextBox("Current DataDragon Version: " + DDragonVersion);

                    Client.Version = DDragonVersion;
                    Client.Log("DDragon Version (LOL Version) = " + DDragonVersion);

                    LogTextBox("Client Version: " + Client.Version);

                    if (patcher.DDragonVersion != DDragonVersion)
                    {
                        try
                        {
                            if (!Directory.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "temp")))
                            {
                                Directory.CreateDirectory(Path.Combine(Client.ExecutingDirectory, "Assets", "temp"));
                            }

                            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                            {
                                CurrentProgressLabel.Content = "Downloading DataDragon";
                            }));
                            client.DownloadFile(DDragonDownloadURL, Path.Combine(Client.ExecutingDirectory, "Assets", "dragontail-" + patcher.DDragonVersion + ".tgz"));


                            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                            {
                                CurrentProgressLabel.Content = "Extracting DataDragon";
                            }));

                            Stream inStream = File.OpenRead(Path.Combine(Client.ExecutingDirectory, "Assets", "dragontail-" + patcher.DDragonVersion + ".tgz"));

                            using (GZipInputStream gzipStream = new GZipInputStream(inStream))
                            {
                                TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream);
                                tarArchive.ExtractContents(Path.Combine(Client.ExecutingDirectory, "Assets", "temp"));
                                //tarArchive.Close();
                                tarArchive = null;
                            }
                            inStream.Close();

                            Copy(Path.Combine(Client.ExecutingDirectory, "Assets", "temp", patcher.DDragonVersion, "data"), Path.Combine(Client.ExecutingDirectory, "Assets", "data"));
                            Copy(Path.Combine(Client.ExecutingDirectory, "Assets", "temp", patcher.DDragonVersion, "img"), Path.Combine(Client.ExecutingDirectory, "Assets"));
                            DeleteDirectoryRecursive(Path.Combine(Client.ExecutingDirectory, "Assets", "temp"));

                            var VersionDDragon = File.Create(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDRagon"));
                            VersionDDragon.Write(encoding.GetBytes(patcher.DDragonVersion), 0, encoding.GetBytes(patcher.DDragonVersion).Length);

                            Client.Version = DDragonVersion;
                            VersionDDragon.Close();
                        }
                        catch
                        {
                            Client.Log("Probably updated version number without actually uploading the files. Thanks riot.");
                        }
                    }

                    #endregion DDragon

                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        TotalProgressLabel.Content = "40%";
                        TotalProgessBar.Value      = 40;
                    }));

                    // Try get LoL path from registry

                    //A string that looks like C:\Riot Games\League of Legends\
                    string lolRootPath = GetLolRootPath();

                    #region lol_air_client

                    if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR")))
                    {
                        var VersionAIR = File.Create(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                        VersionAIR.Write(encoding.GetBytes("0.0.0.0"), 0, encoding.GetBytes("0.0.0.0").Length);
                        VersionAIR.Close();
                    }

                    string LatestAIR = patcher.GetLatestAir();
                    LogTextBox("Air Assets Version: " + LatestAIR);
                    string AirVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                    LogTextBox("Current Air Assets Version: " + AirVersion);
                    WebClient UpdateClient = new WebClient();
                    string Release         = UpdateClient.DownloadString("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/releaselisting_NA");
                    string[] LatestVersion = Release.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

                    var vers = LatestVersion[0];
                    if (AirVersion != LatestVersion[0])
                    {
                        //Download Air Assists from riot
                        try
                        {
                            string Package = UpdateClient.DownloadString("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/" + LatestVersion[0] + "/packages/files/packagemanifest");
                            GetAllPngs(Package);
                            if (File.Exists(Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite")))
                            {
                                File.Delete(Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite"));
                            }
                            string[] x = Package.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

                            string locationv = LatestVersion[0];
                            foreach (string m in x)
                            {
                                if (m.Contains("/files/assets/data/gameStats/gameStats_en_US.sqlite"))
                                {
                                    string l  = m.Split(',')[0];
                                    locationv = l.Replace("/projects/lol_air_client/releases/", "").Replace("/files/assets/data/gameStats/gameStats_en_US.sqlite", "");
                                }
                            }
                            UpdateClient.DownloadFile(new Uri("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/" + locationv + "/files/assets/data/gameStats/gameStats_en_US.sqlite"), Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite"));

                            if (File.Exists(System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR")))
                            {
                                File.Delete(System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                            }
                            var file = File.Create(System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                            file.Write(encoding.GetBytes(LatestVersion[0]), 0, encoding.GetBytes(LatestVersion[0]).Length);
                            file.Close();
                        }
                        catch
                        {
                            Client.Log("Probably riot updated air client version without actually releasing the latest version. Why riot, why? Trying to download last version.");

                            LatestVersion = Release.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                            Console.WriteLine("XXXXXXX" + "http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/" + LatestVersion[0] + "/packages/files/packagemanifest");
                            string Package = UpdateClient.DownloadString("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/" + LatestVersion[0] + "/packages/files/packagemanifest");
                            GetAllPngs(Package);
                            if (File.Exists(Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite")))
                            {
                                File.Delete(Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite"));
                            }
                            string locationv = LatestVersion[0];
                            string[] x       = Package.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                            string locationm = LatestVersion[0];
                            foreach (string m in x)
                            {
                                if (m.Contains("/files/assets/data/gameStats/gameStats_en_US.sqlite"))
                                {
                                    string l  = m.Split(',')[0];
                                    locationm = l.Replace("/projects/lol_air_client/releases/", "").Replace("/files/assets/data/gameStats/gameStats_en_US.sqlite", "");
                                }
                            }
                            UpdateClient.DownloadFile(new Uri("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/" + locationv + "/files/assets/data/gameStats/gameStats_en_US.sqlite"), Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite"));

                            if (File.Exists(System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR")))
                            {
                                File.Delete(System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                            }
                            var file = File.Create(System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                            file.Write(encoding.GetBytes(LatestVersion[1]), 0, encoding.GetBytes(LatestVersion[1]).Length);
                            file.Close();
                        }
                    }

                    if (AirVersion != LatestAIR)
                    {
                        Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                        {
                            PlayButton.IsEnabled         = true;
                            CurrentProgressLabel.Content = "Retrieving Air Assets";
                        }));
                    }

                    #endregion lol_air_client


                    //string GameVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "RADS", "VERSION_LOL"));
                    #region lol_game_client
                    LogTextBox("Trying to detect League of Legends GameClient");
                    LogTextBox("League of Legends is located at: " + lolRootPath);
                    //RADS\solutions\lol_game_client_sln\releases
                    var GameLocation = Path.Combine(lolRootPath, "RADS", "solutions", "lol_game_client_sln", "releases");

                    string LolVersion2   = new WebClient().DownloadString("http://l3cdn.riotgames.com/releases/live/projects/lol_game_client/releases/releaselisting_NA");
                    string LolVersion    = new WebClient().DownloadString("http://l3cdn.riotgames.com/releases/live/solutions/lol_game_client_sln/releases/releaselisting_NA");
                    string GameClientSln = LolVersion.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)[0];
                    string GameClient    = LolVersion2.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)[0];
                    LogTextBox("Latest League of Legends GameClient: " + GameClientSln);
                    LogTextBox("Checking if League of Legends is Up-To-Date");

                    string LolLauncherVersion = new WebClient().DownloadString("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/releaselisting_NA");
                    string LauncherVersion    = LolLauncherVersion.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)[0];
                    if (Directory.Exists(Path.Combine(GameLocation, GameClientSln)))
                    {
                        LogTextBox("League of Legends is Up-To-Date");
                        Client.LOLCLIENTVERSION    = LolVersion2;
                        Client.Location            = Path.Combine(lolRootPath, "RADS", "solutions", "lol_game_client_sln", "releases", GameClientSln, "deploy");
                        Client.LoLLauncherLocation = Path.Combine(lolRootPath, "RADS", "projects", "lol_air_client", "releases", LauncherVersion, "deploy");
                        Client.RootLocation        = lolRootPath;
                    }
                    else
                    {
                        LogTextBox("League of Legends is not Up-To-Date. Please Update League Of Legends");
                        return;
                    }
                    #endregion lol_game_client

                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        TotalProgressLabel.Content   = "100%";
                        TotalProgessBar.Value        = 100;
                        CurrentProgressLabel.Content = "Finished Patching";
                        CurrentStatusLabel.Content   = "Ready To Play";
                        PlayButton.IsEnabled         = true;
                    }));

                    LogTextBox("LegendaryClient Has Finished Patching");
                });

                bgThead.Start();

                Client.Log("LegendaryClient Has Finished Patching");
            }
            catch (Exception e)
            {
                Client.Log(e.Message + " - in PatcherPage updating progress.");
            }
        }
예제 #5
0
        private void StartPatcher()
        {
            Thread bgThead = new Thread(() =>
            {
                LogTextBox("Starting Patcher");

                WebClient client = new WebClient();
                client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                client.DownloadFileCompleted   += new AsyncCompletedEventHandler(client_DownloadDDragon);
                client.DownloadProgressChanged += (o, e) =>
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        double bytesIn               = double.Parse(e.BytesReceived.ToString());
                        double totalBytes            = double.Parse(e.TotalBytesToReceive.ToString());
                        double percentage            = bytesIn / totalBytes * 100;
                        CurrentProgressLabel.Content = "Downloaded " + e.BytesReceived + " of " + e.TotalBytesToReceive;
                        CurrentProgressBar.Value     = int.Parse(Math.Truncate(percentage).ToString());
                    }));
                };

                #region LegendaryClient

                string CurrentMD5 = GetMd5();
                LogTextBox("MD5: " + CurrentMD5);


                UpdateData legendaryupdatedata = new UpdateData();
                var version = LegendaryClientPatcher.GetLatestLCVersion();
                LogTextBox("Most Up to date LegendaryClient Version: " + version);
                string versionAsString = version;

                if (version != Client.LegendaryClientVersion)
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        MessageOverlay overlay              = new MessageOverlay();
                        overlay.MessageTextBox.Text         = "An update is available LegendaryClient";
                        overlay.MessageTitle.Content        = "Update Notification";
                        overlay.AcceptButton.Content        = "Update LegendaryClient";
                        overlay.AcceptButton.Click         += update;
                        overlay.MessageTextBox.TextChanged += Text_Changed;
                        Client.OverlayContainer.Content     = overlay.Content;
                        //Client.OverlayContainer.Visibility = Visibility.Visible;

                        CurrentProgressLabel.Content = "LegendaryClient Is Out of Date!";
                    }));
                    LogTextBox("LegendaryClient Is Out of Date!");

                    //return;
                }
                else if (Client.LegendaryClientVersion == version)
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "LegendaryClient Is Up To Date!";
                    }));
                    LogTextBox("LegendaryClient Is Up To Date!");
                }
                else if (version == null)
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Could not check LegendaryClient Version!";
                    }));
                    LogTextBox("Could not check LegendaryClient Version!");
                    return;
                }

                #endregion LegendaryClient

                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    TotalProgressLabel.Content = "20%";
                    TotalProgessBar.Value      = 20;
                }));

                #region DDragon

                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                if (!Directory.Exists("Assets"))
                {
                    Directory.CreateDirectory("Assets");
                }
                if (!File.Exists(Path.Combine("Assets", "VERSION_DDRagon")))
                {
                    var VersionLOL = File.Create(Path.Combine("Assets", "VERSION_DDRagon"));
                    VersionLOL.Write(encoding.GetBytes("0.0.0"), 0, encoding.GetBytes("0.0.0").Length);

                    VersionLOL.Close();
                }


                RiotPatcher patcher       = new RiotPatcher();
                string DDragonDownloadURL = patcher.GetDragon();
                LogTextBox("DataDragon Version: " + patcher.DDragonVersion);
                string DDragonVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDragon"));
                LogTextBox("Current DataDragon Version: " + DDragonVersion);

                Client.Version = DDragonVersion;
                Client.Log("DDragon Version (LOL Version) = " + DDragonVersion);

                LogTextBox("Client Version: " + Client.Version);

                if (patcher.DDragonVersion != DDragonVersion)
                {
                    if (!Directory.Exists(Path.Combine("Assets", "temp")))
                    {
                        Directory.CreateDirectory(Path.Combine("Assets", "temp"));
                    }

                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Downloading DataDragon";
                    }));

                    client.DownloadFile(DDragonDownloadURL, Path.Combine("Assets", "dragontail-" + patcher.DDragonVersion + ".tgz"));

                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Extracting DataDragon";
                    }));

                    Stream inStream = File.OpenRead(Path.Combine("Assets", "dragontail-" + patcher.DDragonVersion + ".tgz"));

                    using (GZipInputStream gzipStream = new GZipInputStream(inStream))
                    {
                        TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream);
                        tarArchive.ExtractContents(Path.Combine("Assets", "temp"));
                        tarArchive.CloseArchive();
                    }
                    inStream.Close();

                    Copy(Path.Combine("Assets", "temp", patcher.DDragonVersion, "data"), Path.Combine("Assets", "data"));
                    Copy(Path.Combine("Assets", "temp", patcher.DDragonVersion, "img"), Path.Combine("Assets"));
                    DeleteDirectoryRecursive(Path.Combine("Assets", "temp"));

                    var VersionDDragon = File.Create(Path.Combine("Assets", "VERSION_DDRagon"));
                    VersionDDragon.Write(encoding.GetBytes(patcher.DDragonVersion), 0, encoding.GetBytes(patcher.DDragonVersion).Length);

                    Client.Version = DDragonVersion;
                    VersionDDragon.Close();
                }

                #endregion DDragon

                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    TotalProgressLabel.Content = "40%";
                    TotalProgessBar.Value      = 40;
                }));

                // Try get LoL path from registry

                //A string that looks like C:\Riot Games\League of Legends\
                string lolRootPath = GetLolRootPath();

                #region lol_air_client

                if (!File.Exists(Path.Combine("Assets", "VERSION_AIR")))
                {
                    var VersionAIR = File.Create(Path.Combine("Assets", "VERSION_AIR"));
                    VersionAIR.Write(encoding.GetBytes("0.0.0.0"), 0, encoding.GetBytes("0.0.0.0").Length);
                    VersionAIR.Close();
                }

                string LatestAIR = patcher.GetLatestAir();
                LogTextBox("Air Assets Version: " + LatestAIR);
                string AirVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                LogTextBox("Current Air Assets Version: " + AirVersion);
                bool RetrieveCurrentInstallation = false;
                WebClient UpdateClient           = new WebClient();
                string Release       = UpdateClient.DownloadString("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/releaselisting");
                string LatestVersion = Release.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)[0];

                if (AirVersion != LatestVersion)
                {
                    //Download Air Assists from riot
                    string Package = UpdateClient.DownloadString("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/" + LatestVersion + "/packages/files/packagemanifest");
                    GetAllPngs(Package);
                    if (File.Exists(Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite")))
                    {
                        File.Delete(Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite"));
                    }
                    UpdateClient.DownloadFile(new Uri("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/" + LatestVersion + "/files/assets/data/gameStats/gameStats_en_US.sqlite"), Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite"));

                    if (File.Exists(System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR")))
                    {
                        File.Delete(System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                    }
                    var file = File.Create(System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                    file.Write(encoding.GetBytes(LatestVersion), 0, encoding.GetBytes(LatestVersion).Length);
                    file.Close();
                }

                if (AirVersion != LatestAIR)
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        SkipPatchButton.IsEnabled    = true;
                        CurrentProgressLabel.Content = "Retrieving Air Assets";
                    }));
                }

                #endregion lol_air_client


                //string GameVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "RADS", "VERSION_LOL"));
                #region lol_game_client
                LogTextBox("Trying to detect League of Legends GameClient");
                LogTextBox("League of Legends is located at: " + lolRootPath);
                //RADS\solutions\lol_game_client_sln\releases
                var GameLocation = Path.Combine(lolRootPath, "RADS", "solutions", "lol_game_client_sln", "releases");

                string LolVersion2   = new WebClient().DownloadString("http://l3cdn.riotgames.com/releases/live/projects/lol_game_client/releases/releaselisting_NA");
                string LolVersion    = new WebClient().DownloadString("http://l3cdn.riotgames.com/releases/live/solutions/lol_game_client_sln/releases/releaselisting_NA");
                string GameClientSln = LolVersion.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)[0];
                string GameClient    = LolVersion2.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)[0];
                LogTextBox("Latest League of Legends GameClient: " + GameClientSln);
                LogTextBox("Checking if League of Legends is Up-To-Date");

                string LolLauncherVersion = new WebClient().DownloadString("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/releaselisting_NA");
                string LauncherVersion    = LolLauncherVersion.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)[0];
                if (Directory.Exists(Path.Combine(GameLocation, GameClientSln)))
                {
                    LogTextBox("League of Legends is Up-To-Date");
                    //Client.LaunchGameLocation = Path.Combine(Client.GameLocation, GameClientSln);
                    //C:\Riot Games\League of Legends\RADS\projects\lol_game_client\releases\0.0.0.243\deploy
                    Client.LOLCLIENTVERSION = LolVersion2;
                    //C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.50\deploy
                    Client.Location = Path.Combine(lolRootPath, "RADS", "solutions", "lol_game_client_sln", "releases", GameClientSln, "deploy");
                    //C:\Riot Games\League of Legends\RADS\projects\lol_air_client\releases\0.0.1.104
                    Client.LoLLauncherLocation = Path.Combine(lolRootPath, "RADS", "projects", "lol_air_client", "releases", LauncherVersion, "deploy");
                    Client.RootLocation        = lolRootPath;
                }
                else
                {
                    LogTextBox("League of Legends is not Up-To-Date. Please Update League Of Legends");
                    return;
                }


                if (!Directory.Exists("RADS"))
                {
                    Directory.CreateDirectory("RADS");
                }

                if (!File.Exists(Path.Combine("RADS", "VERSION_LOL")))
                {
                    var VersionGAME = File.Create(Path.Combine("RADS", "VERSION_LOL"));
                    VersionGAME.Write(encoding.GetBytes("0.0.0.0"), 0, encoding.GetBytes("0.0.0.0").Length);
                    VersionGAME.Close();
                }

                string LatestGame = patcher.GetLatestGame();
                LogTextBox("League Of Legends Version: " + LatestGame);
                string GameVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "RADS", "VERSION_LOL"));
                LogTextBox("Current League of Legends Version: " + GameVersion);
                RetrieveCurrentInstallation = false;
                string NGameLocation        = "";

                if (GameVersion != GameClient)
                {
                    LogTextBox("Checking for existing League of Legends Installation");
                    NGameLocation = Path.Combine("League of Legends", "RADS");
                    if (Directory.Exists(NGameLocation))
                    {
                        RetrieveCurrentInstallation = true;
                    }
                    else if (Directory.Exists(Path.Combine(System.IO.Path.GetPathRoot(Environment.SystemDirectory), "Riot Games", NGameLocation)))
                    {
                        RetrieveCurrentInstallation = true;
                        NGameLocation = Path.Combine(System.IO.Path.GetPathRoot(Environment.SystemDirectory), "Riot Games", NGameLocation);
                    }
                    else
                    {
                        LogTextBox("Unable to find existing League of Legends. Copy your League of Legends folder into + "
                                   + Client.ExecutingDirectory
                                   + " to make the patching process quicker");
                    }

                    if (RetrieveCurrentInstallation)
                    {
                        LogTextBox("Getting League Of Legends from " + NGameLocation);
                        Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                        {
                            CurrentProgressLabel.Content = "Copying League of Legends";
                        }));
                        LogTextBox("Retrieved currently installed League of Legends");
                        LogTextBox("Current League of Legends Version: " + NGameLocation);
                    }
                }

                if (GameVersion != LatestGame)
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Retrieving League of Legends";
                    }));
                }
                #endregion lol_game_client



                FinishPatching(LatestVersion);
            });

            bgThead.Start();
        }
        private void StartPatcher()
        {
            try
            {
                Thread bgThead = new Thread(() =>
                {
                    LogTextBox("Starting Patcher");

                    WebClient client = new WebClient();
                    client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                    client.DownloadFileCompleted   += new AsyncCompletedEventHandler(client_DownloadDDragon);
                    client.DownloadProgressChanged += (o, e) =>
                    {
                        Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                        {
                            double bytesIn               = double.Parse(e.BytesReceived.ToString());
                            double totalBytes            = double.Parse(e.TotalBytesToReceive.ToString());
                            double percentage            = bytesIn / totalBytes * 100;
                            CurrentProgressLabel.Content = "Downloaded " + e.BytesReceived + " of " + e.TotalBytesToReceive;
                            CurrentProgressBar.Value     = int.Parse(Math.Truncate(percentage).ToString());
                        }));
                    };

                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        TotalProgressLabel.Content = "20%";
                        TotalProgessBar.Value      = 20;
                    }));
                    #region idk

                    client = new WebClient();
                    if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "Client", "Login.mp3")))
                    {
                        client.DownloadFile(new Uri("http://eddy5641.github.io/LegendaryClient/Login/Login.mp3"), Path.Combine(Client.ExecutingDirectory, "Client", "Login.mp3"));
                    }
                    if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "Client", "Login.mp4")))
                    {
                        client.DownloadFile(new Uri("http://eddy5641.github.io/LegendaryClient/Login/Login.mp4"), Path.Combine(Client.ExecutingDirectory, "Client", "Login.mp4"));
                    }
                    #endregion idk

                    #region DDragon

                    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                    if (!Directory.Exists(Path.Combine(Client.ExecutingDirectory, "Assets")))
                    {
                        Directory.CreateDirectory(Path.Combine(Client.ExecutingDirectory, "Assets"));
                    }
                    if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDRagon")))
                    {
                        var VersionLOL = File.Create(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDRagon"));
                        VersionLOL.Write(encoding.GetBytes("0.0.0"), 0, encoding.GetBytes("0.0.0").Length);

                        VersionLOL.Close();
                    }


                    RiotPatcher patcher       = new RiotPatcher();
                    string DDragonDownloadURL = patcher.GetDragon();
                    if (!String.IsNullOrEmpty(DDragonDownloadURL))
                    {
                        LogTextBox("DataDragon Version: " + patcher.DDragonVersion);
                        string DDragonVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDragon"));
                        LogTextBox("Current DataDragon Version: " + DDragonVersion);

                        Client.Version = DDragonVersion;
                        Client.Log("DDragon Version (LOL Version) = " + DDragonVersion);

                        LogTextBox("Client Version: " + Client.Version);

                        if (patcher.DDragonVersion != DDragonVersion)
                        {
                            try
                            {
                                if (!Directory.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "temp")))
                                {
                                    Directory.CreateDirectory(Path.Combine(Client.ExecutingDirectory, "Assets", "temp"));
                                }

                                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                                {
                                    CurrentProgressLabel.Content = "Downloading DataDragon";
                                }));
                                client.DownloadFile(DDragonDownloadURL, Path.Combine(Client.ExecutingDirectory, "Assets", "dragontail-" + patcher.DDragonVersion + ".tgz"));


                                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                                {
                                    CurrentProgressLabel.Content = "Extracting DataDragon";
                                }));

                                Stream inStream = File.OpenRead(Path.Combine(Client.ExecutingDirectory, "Assets", "dragontail-" + patcher.DDragonVersion + ".tgz"));

                                using (GZipInputStream gzipStream = new GZipInputStream(inStream))
                                {
                                    TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream);
                                    tarArchive.ExtractContents(Path.Combine(Client.ExecutingDirectory, "Assets", "temp"));
                                    //tarArchive.Close();
                                    tarArchive = null;
                                }
                                inStream.Close();

                                Copy(Path.Combine(Client.ExecutingDirectory, "Assets", "temp", patcher.DDragonVersion, "data"), Path.Combine(Client.ExecutingDirectory, "Assets", "data"));
                                Copy(Path.Combine(Client.ExecutingDirectory, "Assets", "temp", patcher.DDragonVersion, "img"), Path.Combine(Client.ExecutingDirectory, "Assets"));
                                DeleteDirectoryRecursive(Path.Combine(Client.ExecutingDirectory, "Assets", "temp"));

                                var VersionDDragon = File.Create(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDRagon"));
                                VersionDDragon.Write(encoding.GetBytes(patcher.DDragonVersion), 0, encoding.GetBytes(patcher.DDragonVersion).Length);

                                Client.Version = DDragonVersion;
                                VersionDDragon.Close();
                            }
                            catch
                            {
                                Client.Log("Probably updated version number without actually uploading the files. Thanks riot.");
                            }
                        }
                    }
                    else
                    {
                        LogTextBox("Failed to get DDragon version. Either not able to be found or unknown error (most likely the website is in maitenance, please try again in an hour or so)");
                        LogTextBox("Continuing could cause errors. Report this as an issue if it occurs again in a few hours.");
                    }

                    #endregion DDragon

                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        TotalProgressLabel.Content = "40%";
                        TotalProgessBar.Value      = 40;
                    }));

                    // Try get LoL path from registry

                    //A string that looks like C:\Riot Games\League of Legends\
                    string lolRootPath = GetLolRootPath(false);

                    #region lol_air_client

                    if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR")))
                    {
                        var VersionAIR = File.Create(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                        VersionAIR.Write(encoding.GetBytes("0.0.0.0"), 0, encoding.GetBytes("0.0.0.0").Length);
                        VersionAIR.Close();
                    }

                    string LatestAIR = patcher.GetLatestAir();
                    LogTextBox("Air Assets Version: " + LatestAIR);
                    string AirVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                    LogTextBox("Current Air Assets Version: " + AirVersion);
                    WebClient UpdateClient = new WebClient();
                    string Release         = UpdateClient.DownloadString("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/releaselisting_NA");
                    string[] LatestVersion = Release.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                    latestversion          = LatestVersion;
                    var vers = LatestVersion[0];
                    if (AirVersion != LatestVersion[0])
                    {
                        //Download Air Assists from riot
                        try
                        {
                            string Package = UpdateClient.DownloadString("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/" + LatestVersion[0] + "/packages/files/packagemanifest");
                            try
                            {
                                UpdateClient.DownloadFile(new Uri("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/" + LatestVersion[0] + "/files/assets/data/gameStats/gameStats_en_US.sqlite"), Path.Combine(Client.ExecutingDirectory, "Client", "gameStats_en_US.sqlite"));
                            }
                            catch
                            {
                                Client.Log("gameStats_en_US.sqlite not found on l3cdn.riotgames.com - skiping");
                                Client.Log("Please get updated copy of this file from your league folder.");
                            }
                            GetAllPngs(Package);
                            string[] x = Package.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

                            if (File.Exists(System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR")))
                            {
                                File.Delete(System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                            }
                            using (var file = File.Create(System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR")))
                            {
                                file.Write(encoding.GetBytes(LatestVersion[0]), 0, encoding.GetBytes(LatestVersion[0]).Length);
                            }
                        }
                        catch (Exception e)
                        {
                            Client.Log(e.Message);
                        }
                    }

                    if (AirVersion != LatestAIR)
                    {
                        Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                        {
                            SkipPatchButton.IsEnabled    = true;
                            CurrentProgressLabel.Content = "Retrieving Air Assets";
                        }));
                    }

                    #endregion lol_air_client


                    //string GameVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "RADS", "VERSION_LOL"));
                    #region lol_game_client
                    LogTextBox("Trying to detect League of Legends GameClient");
                    LogTextBox("League of Legends is located at: " + lolRootPath);
                    //RADS\solutions\lol_game_client_sln\releases
                    var GameLocation = Path.Combine(lolRootPath, "RADS", "solutions", "lol_game_client_sln", "releases");

                    string LolVersion2   = new WebClient().DownloadString("http://l3cdn.riotgames.com/releases/live/projects/lol_game_client/releases/releaselisting_NA");
                    string LolVersion    = new WebClient().DownloadString("http://l3cdn.riotgames.com/releases/live/solutions/lol_game_client_sln/releases/releaselisting_NA");
                    string GameClientSln = LolVersion.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)[0];
                    string GameClient    = LolVersion2.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)[0];
                    LogTextBox("Latest League of Legends GameClient: " + GameClientSln);
                    LogTextBox("Checking if League of Legends is Up-To-Date");

                    string LolLauncherVersion = new WebClient().DownloadString("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/releaselisting_NA");
                    string LauncherVersion    = LolLauncherVersion.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)[0];
                    bool toExit = false;

                    if (Directory.Exists(Path.Combine(GameLocation, GameClientSln)))
                    {
                        LogTextBox("League of Legends is Up-To-Date");
                        Client.LOLCLIENTVERSION    = LolVersion2;
                        Client.Location            = Path.Combine(lolRootPath, "RADS", "solutions", "lol_game_client_sln", "releases", GameClientSln, "deploy");
                        Client.LoLLauncherLocation = Path.Combine(lolRootPath, "RADS", "projects", "lol_air_client", "releases", LauncherVersion, "deploy");
                        Client.RootLocation        = lolRootPath;
                    }
                    else
                    {
                        LogTextBox("League of Legends is not Up-To-Date. Please Update League Of Legends");
                        Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                        {
                            SkipPatchButton.IsEnabled   = true;
                            FindClientButton.Visibility = Visibility.Visible;
                        }));
                        toExit = true;
                    }
                    #endregion lol_game_client

                    if (!toExit)
                    {
                        Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                        {
                            TotalProgressLabel.Content   = "100%";
                            TotalProgessBar.Value        = 100;
                            SkipPatchButton.Content      = "Play";
                            CurrentProgressLabel.Content = "Finished Patching";
                            CurrentStatusLabel.Content   = "Ready To Play";
                            SkipPatchButton.IsEnabled    = true;
                            SkipPatchButton_Click(null, null);
                        }));

                        LogTextBox("LegendaryClient Has Finished Patching");
                    }
                });

                bgThead.IsBackground = true;
                bgThead.Start();
            }
            catch (Exception e)
            {
                Client.Log(e.Message + " - in PatcherPage updating progress.");
            }
        }