コード例 #1
0
        private void UpdateDownloadEmoteText(DownloadInfo DI)
        {
            label11.Text = "Downloading emote " + DI.CurrentDownload + " of " + DI.TotalDownloads.ToString();

            float value      = (float)DI.CurrentDownload / DI.TotalDownloads;
            float percentage = value * 100;

            progressBar1.Value = (int)percentage;
        }
コード例 #2
0
        private async Task <int> DownloadEmote(string emote, string link, DownloadInfo DI)
        {
            string path = GetImagesFolderPath();

            WebClient wc = new WebClient();

            wc.DownloadFileCompleted   += new AsyncCompletedEventHandler(complete);
            wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(updateProgressBar);
            wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36");

            // Check for deleted emote.
            try
            {
                WebRequest request = WebRequest.Create(new Uri(link));
                request.Method = "HEAD";

                using (WebResponse response = await request.GetResponseAsync())
                {
                    //Console.WriteLine("{0} {1}", response.ContentLength, response.ContentType);
                }

                wc.DownloadFileAsync(new Uri(link), path + emote + ".png", DI);
                //Console.WriteLine(link + " " + path + emote);
            }
            catch (WebException exception)
            {
                #region debug
                //string responseText;

                //string test = exception.Message + " - " + exception.Response + " - " + exception.Status;
                //Console.WriteLine(test);

                //var responseStream = exception.Response?.GetResponseStream();

                //if (responseStream != null)
                //{
                //    using (var reader = new StreamReader(responseStream))
                //    {
                //        responseText = reader.ReadToEnd();
                //        Console.WriteLine(responseText + emote);
                //    }
                //}
                #endregion
            }

            await Task.Delay(50);

            return(1);
        }
コード例 #3
0
        private async Task ReadEmoteFile(string emoteFile)
        {
            DownloadInfo DI = new DownloadInfo();

            bool addedNewEmotes = false;

            // Read file
            List <string> currentEmotes = new List <string>();

            foreach (String path in Directory.GetFiles(GetImagesFolderPath()))
            {
                Console.WriteLine(path);

                currentEmotes.Add(Path.GetFileNameWithoutExtension(path));
            }

            string[] lines = File.ReadAllLines(emoteFile);

            List <string> emoteNames = new List <string>();
            List <string> emoteLinks = new List <string>();


            foreach (string line in lines)
            {
                string[] splitLine = line.Split(' ');

                bool emoteFound = false;

                // Look for emote
                foreach (string emote in currentEmotes)
                {
                    splitLine[0] = CheckSpecialCaseEmotes(splitLine[0]);
                    if (splitLine[0] == emote || splitLine[0].Contains(":"))
                    {
                        emoteFound = true;
                    }
                }

                if (!emoteFound)
                {
                    DI.TotalDownloads++;
                    addedNewEmotes = true;
                    UpdateDownloadEmoteText(DI);

                    splitLine[0] = CheckSpecialCaseEmotes(splitLine[0]);

                    // add to list
                    emoteNames.Add(splitLine[0]);
                    emoteLinks.Add(splitLine[1]);
                }
            }

            List <Task <int> > downloadTasks = new List <Task <int> >();

            for (int i = 0; i < emoteNames.Count; i++)
            {
                // Add emotes to task list
                downloadTasks.Add(DownloadEmote(emoteNames[i], emoteLinks[i], DI));
            }

            // Download all emotes parallel
            var result = await Task.WhenAll(downloadTasks);

            if (addedNewEmotes && DI.CurrentDownload > 1)
            {
                MessageBox.Show(DI.CurrentDownload.ToString() + " new emotes were added!");
                ResetProgressBar();
                ReloadEmotes();
            }
            else
            {
                MessageBox.Show("No new emotes were added");
                ResetProgressBar();
            }

            if (File.Exists(emoteFile))
            {
                File.Delete(emoteFile);
            }
        }