private async Task GetMediaFiles(PatcherFile[] files)
        {
            var currentVersion = new Version(File.ReadAllText(GetAssetsDirectory("VERSION_AIR")));

            if (!Directory.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "champions")))
                Directory.CreateDirectory(Path.Combine(Client.ExecutingDirectory, "Assets", "champions"));

            if (!Directory.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "sounds")))
                Directory.CreateDirectory(Path.Combine(Client.ExecutingDirectory, "Assets", "sounds"));

            if (!Directory.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "sounds", "champions")))
                Directory.CreateDirectory(Path.Combine(Client.ExecutingDirectory, "Assets", "sounds", "champions"));

            if (!Directory.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "sounds", "ambient")))
                Directory.CreateDirectory(Path.Combine(Client.ExecutingDirectory, "Assets", "sounds", "ambient"));

            if (!Directory.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon")))
                Directory.CreateDirectory(Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon"));

            //Select all files to calculate the size
            files =
                files.Where(
                    f =>
                        new Version(f.Version) > currentVersion && (f.SavePath.EndsWith(".jpg") || f.SavePath.EndsWith(".png") || f.SavePath.EndsWith(".mp3")) &&
                        (f.SavePath.Contains("assets/images/champions/") || f.SavePath.Contains("assets/images/abilities/") ||
                         f.SavePath.Contains("assets/storeImages/content/summoner_icon/") || (f.SavePath.Contains("assets/sounds/") && f.SavePath.Contains("en_US/champions/")) ||
                         (f.SavePath.Contains("assets/sounds/") && f.SavePath.Contains("assets/sounds/ambient")) ||
                         (f.SavePath.Contains("assets/sounds/") && f.SavePath.Contains("assets/sounds/matchmakingqueued.mp3")))).ToArray();

            _mediaTotalSize = files.Sum(s => s.FileSize);

            var humanSize = GetHumanSize(_mediaTotalSize);
            LogTextBox(String.Format("Downloading {0} files ({1}) from http://l3cdn.riotgames.com", files.Length, humanSize));

            await Task.Run(() => Parallel.ForEach(files, new ParallelOptions() {MaxDegreeOfParallelism = 10}, DoFileDownload));
        }
        private void DoFileDownload(PatcherFile f)
        {
            var savePlace = f.SavePath;

            if (savePlace.Contains("assets/images/champions/"))
            {
                using (var wc = new WebClient())
                {
                    var saveName = Regex.Split(f.SavePath, "/champions/")[1];
                    //LogTextBox(String.Format("Downloading {0} ({1}KB) from http://l3cdn.riotgames.com", Path.GetFileName(f.RelativePath), f.FileSize/1024));
                    wc.DownloadFile(f.AbsolutePath, GetAssetsDirectory("champions", saveName));
                    lock (_mediaDownloadedLock)
                        _mediaDownloaded += f.FileSize;
                }
            }
            else if (savePlace.Contains("assets/images/abilities/"))
            {
                using (var wc = new WebClient())
                {
                    var saveName = Regex.Split(f.SavePath, "/abilities/")[1];
                    //LogTextBox(String.Format("Downloading {0} ({1}KB) from http://l3cdn.riotgames.com", Path.GetFileName(f.RelativePath), f.FileSize/1024));
                    wc.DownloadFile(f.AbsolutePath,
                        saveName.ToLower().Contains("passive")
                            ? GetAssetsDirectory("passive", saveName)
                            : GetAssetsDirectory("spell", saveName));
                    lock (_mediaDownloadedLock)
                        _mediaDownloaded += f.FileSize;
                }
            }
            else if (savePlace.Contains("assets/storeImages/content/summoner_icon/"))
            {
                using (var wc = new WebClient())
                {
                    var saveName = Regex.Split(f.SavePath, "/summoner_icon/")[1];
                    //LogTextBox(String.Format("Downloading {0} ({1}KB) from http://l3cdn.riotgames.com", Path.GetFileName(f.RelativePath), f.FileSize/1024));
                    wc.DownloadFile(f.AbsolutePath,
                        saveName.ToLower().Contains("_")
                            ? GetAssetsDirectory("profileicon", Regex.Split(saveName, "_")[0] + ".png")
                            : GetAssetsDirectory("profileicon", saveName.Replace("profileIcon", String.Empty)));
                    lock (_mediaDownloadedLock)
                        _mediaDownloaded += f.FileSize;
                }
            }
            else if (savePlace.Contains("assets/sounds/"))
            {
                using (var wc = new WebClient())
                {
                    if (savePlace.Contains("en_US/champions/"))
                    {
                        var saveName = Regex.Split(f.SavePath, "/champions/")[1];
                        //LogTextBox(String.Format("Downloading {0} ({1}KB) from http://l3cdn.riotgames.com", Path.GetFileName(f.RelativePath), f.FileSize/1024));
                        wc.DownloadFile(f.AbsolutePath, GetAssetsDirectory("sounds", "champions", saveName));
                        lock (_mediaDownloadedLock)
                            _mediaDownloaded += f.FileSize;
                    }
                    else if (savePlace.Contains("assets/sounds/ambient"))
                    {
                        var saveName = Regex.Split(f.SavePath, "/ambient/")[1];
                        //LogTextBox(String.Format("Downloading {0} ({1}KB) from http://l3cdn.riotgames.com", Path.GetFileName(f.RelativePath), f.FileSize/1024));
                        wc.DownloadFile(f.AbsolutePath, GetAssetsDirectory("sounds", "ambient", saveName));
                        lock (_mediaDownloadedLock)
                            _mediaDownloaded += f.FileSize;
                    }
                    else if (savePlace.Contains("assets/sounds/matchmakingqueued.mp3"))
                    {
                        //LogTextBox(String.Format("Downloading {0} ({1}KB) from http://l3cdn.riotgames.com", Path.GetFileName(f.RelativePath), f.FileSize/1024));
                        wc.DownloadFile(f.AbsolutePath, GetAssetsDirectory("sounds", "matchmakingqueued.mp3"));
                        lock (_mediaDownloadedLock)
                            _mediaDownloaded += f.FileSize;
                    }
                    else
                        Debugger.Break();
                }
            }
            else
                Debugger.Break();

            Dispatcher.Invoke(() =>
            {
                double percentage;
                long finished;

                lock (_mediaDownloadedLock)
                {
                    percentage = Convert.ToDouble(_mediaDownloaded)/Convert.ToDouble(_mediaTotalSize)*100d;
                    finished = _mediaDownloaded;
                }

                string humanTotal = GetHumanSize(_mediaTotalSize);
                string humanFinished = GetHumanSize(finished);

                CurrentProgressLabel.Content = String.Format("Downloaded {0} of {1}", humanFinished, humanTotal);
                CurrentProgressBar.Value = percentage;
            });
        }
        private async Task DownloadTheme(PatcherFile[] files)
        {
            try
            {
                if (!Directory.Exists(GetAssetsDirectory("themes")))
                    Directory.CreateDirectory(GetAssetsDirectory("themes"));

                using (var wc = new WebClient())
                {
                    LogTextBox("Updating Theme");
                    await wc.DownloadFileTaskAsync(files.First(f => f.RelativePath.Contains("theme.properties")).AbsolutePath, GetAssetsDirectory("themes", "theme.properties"));
                }

                if (!File.Exists(GetAssetsDirectory("themes", "theme.properties")))
                    throw new Exception("Downloading of the file \"theme.properties\" failed");

                var theme = File.ReadAllLines(GetAssetsDirectory("themes", "theme.properties")).First(s => s.StartsWith("themeConfig=")).Split('=')[1].Split(',')[0];
                if (theme == "")
                    return;

                if (!Directory.Exists(GetAssetsDirectory("themes", theme)))
                    Directory.CreateDirectory(GetAssetsDirectory("themes", theme));
                else if (Directory.GetFiles(GetAssetsDirectory("themes", theme)).Any())
                {
                    Client.Theme = theme;
                    return;
                }

                var themePatcherFiles = files.Where(l => l.RelativePath.ToLower().Contains("loop") && l.RelativePath.Contains(theme)).ToList();
                Parallel.ForEach(themePatcherFiles,
                    new ParallelOptions {MaxDegreeOfParallelism = 10},
                    file =>
                    {
                        LogTextBox(String.Format("Downloading {0} ({1} KB) from http://l3cdn.riotgames.com", Path.GetFileName(file.RelativePath), file.FileSize/1024));
                        var fname = Path.GetFileName(file.RelativePath);
                        var localPath = GetAssetsDirectory("themes", theme, fname);
                        new WebClient().DownloadFile(file.AbsolutePath, localPath);
                    });

                var flv = Directory.GetFiles(GetAssetsDirectory("themes", theme), "*.flv");

                foreach (var item in flv)
                {
                    var inputFile = new MediaFile {Filename = GetAssetsDirectory("themes", theme, item)};

                    var outputFile = new MediaFile {Filename = GetAssetsDirectory("themes", theme, item).Replace(".flv", ".mp4")};

                    LogTextBox(String.Format("Converting {0}", Path.GetFileName(item)));
                    await Task.Run(() =>
                    {
                        using (var engine = new Engine())
                            engine.Convert(inputFile, outputFile);
                    });
                }
                Client.Theme = theme;
            }
            catch (Exception ex)
            {
                Client.Log(ex);
            }
        }