Beispiel #1
0
        private async void btnDeets_Click(object sender, RoutedEventArgs e)
        {
            var strUrl = txtUrl.Text;

            if (string.IsNullOrWhiteSpace(strUrl))
            {
                MessageBox.Show("Add url to first box");
                return;
            }

            var config = ConfigManager.GetConfig();

            if (config.Items.Any(i => i.Url == strUrl))
            {
                MessageBox.Show("Item already added with the same url");
                return;
            }

            try
            {
                var addon = await new CurseAddonSource().GetAddonDetails(strUrl);
                txtName.Text     = addon.Name;
                txtVersion.Text  = addon.SiteVersion;
                txtSupports.Text = addon.Supports;
                btnAdd.IsEnabled = true;
                newItem          = addon;
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Failed to retrived addon details from '{txtUrl.Text}'. Check Url and try again. {Environment.NewLine} {ex.Message}",
                                "You are not prepared", MessageBoxButton.OK, MessageBoxImage.Error);
                btnAdd.IsEnabled = false;
            }
        }
Beispiel #2
0
        public async Task <string> GetZipFile(AddonConfigItem config)
        {
            if (!string.IsNullOrWhiteSpace(config.ArchivePath) && File.Exists(config.ArchivePath))
            {
                return(config.ArchivePath);
            }

            HttpResponseMessage response;

            using (var client = new HttpClient())
            {
                response = await client.GetAsync(config.DownloadLink).ConfigureAwait(false);
            }

            var path = string.Empty;

            if (response.IsSuccessStatusCode)
            {
                path = $"archive\\{config.Name.Replace(" ", "")}.{config.Version}.zip";
                using (var fileStream = File.Create(path))
                {
                    using (var zipStream = await response.Content.ReadAsStreamAsync())
                    {
                        zipStream.Seek(0, SeekOrigin.Begin);
                        zipStream.CopyTo(fileStream);
                    }
                }
            }

            return(path);
        }
Beispiel #3
0
        public async Task <AddonConfigItem> GetAddonDetails(string addonUrl, bool awaitConfig = false)
        {
            HttpResponseMessage response;

            using (var client = new HttpClient())
            {
                response = await client.GetAsync(addonUrl).ConfigureAwait(awaitConfig);
            }

            AddonConfigItem addon = null;

            if (response.IsSuccessStatusCode)
            {
                using (var pageStream = await response.Content.ReadAsStreamAsync())
                {
                    var page = new HtmlDocument();
                    page.Load(pageStream);

                    addon = new AddonConfigItem
                    {
                        Name        = page.DocumentNode.SelectSingleNode("//div[@id='project-overview']//h2")?.InnerText,
                        SiteVersion = page.DocumentNode.SelectSingleNode("//li[@class='newest-file']")?.InnerText?.Replace("Newest File: ", ""),
                        Supports    = page.DocumentNode.SelectSingleNode("//li[@class='version']")?.InnerText?.Replace("Supports: ", ""),
                        Url         = addonUrl
                    };
                }
            }

            if (addon != null)
            {
                await GetDownloadUrl(addon);
            }

            return(addon);
        }
Beispiel #4
0
        private async Task UpdateItem(AddonConfigItem item, Action done)
        {
            var source  = new CurseAddonSource();
            var zipPath = await source.GetZipFile(item);

            if (!string.IsNullOrWhiteSpace(zipPath))
            {
                ZipFile.ExtractToDirectory(zipPath, extractPath);
                CopyFiles(extractPath, path);
            }

            done?.Invoke();
        }
Beispiel #5
0
        public async Task GetDownloadUrl(AddonConfigItem config)
        {
            HttpResponseMessage response;

            using (var client = new HttpClient())
            {
                response = await client.GetAsync(config.Url + "/download").ConfigureAwait(false);
            }

            if (response.IsSuccessStatusCode)
            {
                using (var pageStream = await response.Content.ReadAsStreamAsync())
                {
                    var page = new HtmlDocument();
                    page.Load(pageStream);
                    config.DownloadLink = page.DocumentNode.SelectSingleNode("//div[@id='file-download']//a[@class='download-link']").Attributes["data-href"].Value;
                }
            }
        }