private void IMDB_backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { var args = e.Argument as List <string>; if (args != null) { var iconPath = $@"{Folder_textBox.Text}\{CleanString(args[1], false)}.jpg"; if (Exists(iconPath)) { Delete(iconPath); } using (var client = new WebClient()) { try { client.DownloadFile(BaseUrl + args[0], iconPath); } catch { pictureBox1.Image = null; Invoke(new MethodInvoker(delegate { MessageBox.Show(this, @"Couldn't Find The Requested Artwork", @"Sorry"); })); Movie_radioButton.CheckedChanged -= Movie_radioButton_CheckedChanged; Movie_radioButton.Invoke(new MethodInvoker(delegate { Movie_radioButton.Checked = false; })); Movie_radioButton.CheckedChanged += Movie_radioButton_CheckedChanged; TV_radioButton.CheckedChanged -= TV_radioButton_CheckedChanged; TV_radioButton.Invoke(new MethodInvoker(delegate { TV_radioButton.Checked = false; })); TV_radioButton.CheckedChanged += TV_radioButton_CheckedChanged; return; } } SetAttributes(iconPath, GetAttributes(iconPath) | FileAttributes.Hidden); if (!Pics.Contains(iconPath)) { Pics.Add(iconPath); } ProcessItem(iconPath); if (Icone_textBox.InvokeRequired) { Icone_textBox.Invoke(new MethodInvoker(delegate { Icone_textBox.Text = iconPath; })); } } Set.Invoke(new MethodInvoker(delegate { Set.Enabled = true; })); }
private void Local_backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { var filename = e.Argument as string; var icofile = GetTempPath() + ChangeExtension(GetFileName(filename), "png"); Icone_textBox.Invoke(new MethodInvoker(delegate { Icone_textBox.Text = filename; })); var file = GetFileNameWithoutExtension(e.Argument.ToString()); var dir = GetDirectoryName(filename); var extension = GetExtension(filename); //var name = $@"{dir}\{file + _mRnd}{extension}"; var name = $@"{dir}\{file}{extension}"; var viewer = new Viewer(name); var destfile = ChangeExtension(icofile, GetExtension(filename)); if (extension == null) { return; } extension = extension.ToLower(); if (extension.Equals(".jpg") || extension.Equals(".jpeg") || extension.Equals(".png") || extension.Equals(".bmp")) { try { if (Exists(destfile)) { SetAttributes(destfile, FileAttributes.Normal); Delete(destfile); } Copy(filename, destfile, true); SetAttributes(destfile, FileAttributes.Normal); if (!IconConvert.ConvertToIcon(destfile, ChangeExtension(destfile, "ico"))) { Dispose(); } } catch (Exception ex) { Invoke(new MethodInvoker(delegate { MessageBox.Show(this, ex.Message); })); } } else if (extension.Equals(".dll") || extension.Equals(".exe")) { var ico = DialogResult.None; var iconPick = new IconPickerDialog { FileName = filename }; Invoke(new MethodInvoker(delegate { ico = iconPick.ShowDialog(this); })); if (ico == DialogResult.OK) { var fileName = iconPick.FileName; var index = iconPick.IconIndex; Icon icon; Icon[] splitIcons; try { var extractor = new IconExtractor(fileName); icon = extractor.GetIcon(index); splitIcons = IconUtil.Split(icon); } catch (Exception ex) { MessageBox.Show(this, ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Icone_textBox.Text = string.Format(fileName); // Update icons. icon.Dispose(); var viewerList = viewer.list; viewerList.BeginUpdate(); foreach (var i in splitIcons) { var item = new Viewer.IconListViewItem(); var size = i.Size; var bits = IconUtil.GetBitCount(i); item.ToolTipText = $"{size.Width}x{size.Height}, {bits} bits"; item.Bitmap = IconUtil.ToBitmap(i); i.Dispose(); viewerList.Items.Add(item); } viewer.ShowDialog(); var exit = viewer.Exit; viewerList.EndUpdate(); if (!exit) { destfile = GetTempPath() + GetFileName(ChangeExtension(name, @"png")); if (!IconConvert.ConvertToIcon(destfile, ChangeExtension(destfile, "ico"))) { Dispose(); } } else { //Folder_textBox.Text = ""; Icone_textBox.Text = ""; if (pictureBox1.Image == null) { return; } pictureBox1.Image.Dispose(); pictureBox1.Image = null; } } } if (Exists(destfile)) { if (!Pics.Contains(destfile)) { Pics.Add(destfile); } if (!Pics.Contains(ChangeExtension(destfile, "ico"))) { Pics.Add(ChangeExtension(destfile, "ico")); } if (!Pics.Contains(ChangeExtension(destfile, "png"))) { Pics.Add(ChangeExtension(destfile, "png")); } using (var temp = new Bitmap(destfile)) pictureBox1.Image = new Bitmap(temp); } else { if (!extension.Equals(".dll")) { destfile = filename; var img = Image.FromFile(destfile); pictureBox1.Image = img; } else { Icone_textBox.Text = ""; } } if (Icone_textBox.Text != "") { Set.Invoke(new MethodInvoker(delegate { Set.Enabled = true; })); } }