public DownloadProperties(string DownloadID) { InitializeComponent(); properties = Downloads.DownloadEntries.Where(download => download.DownloadID == DownloadID).FirstOrDefault(); FileIcon.Source = IconTools.GetIconForExtension(properties.FileName, ShellIconSize.LargeIcon).IconToImageSource(); FileName.Text = properties.FileName; FileType.Text = SHGetFileInfo_Wrapper.GetFileTypeDescription(properties.FileName); Status.Text = properties.Status != null ? properties.Status : "Unknown"; Size.Text = properties.SizePretty != null ? properties.SizePretty : "Unknown"; SaveTo_txtBox.Text = properties.SaveTo; Address.Text = properties.DownloadLink.ToString(); Description.Text = properties.Description; authUser.Text = properties.AuthUsername; authPass.Password = properties.AuthPassword; if (properties.Status == "Complete") { SaveTo_button.Content = "Move"; btnOpen.IsEnabled = true; Address.IsReadOnly = true; } SaveTo_txtBox.SelectAll(); // select all text in this box on window load (to show that the box is selectable) this.PreviewKeyDown += new KeyEventHandler(HandleEsc); // Close window when escape is hit }
private Icon GetIcon(string file, bool smol) { if (smol) { return(IconTools.GetIconForExtension(Path.GetExtension(file), ShellIconSize.SmallIcon)); } else { return(IconTools.GetIconForExtension(Path.GetExtension(file), ShellIconSize.LargeIcon)); } }
private static string IconFromFilePath(string fullName) { try { Icon icon = IconTools.GetIconForExtension(fullName, ShellIconSize.SmallIcon); Bitmap bitmap = icon.ToBitmap(); MemoryStream stream = new MemoryStream(); bitmap.Save(stream, ImageFormat.Png); byte[] bytes = stream.ToArray(); return(Convert.ToBase64String(bytes)); } catch { return(string.Empty); } }
void WhenWindowIsLoaded(object sender, RoutedEventArgs e) { // get filename from the uri & assign it to the string filename | Example value of filename = "filename.ext" Task <List <Object> > task = Task.Factory.StartNew(() => Helper.GetFileInfo(DownloadLink, authUser, authPass)); task.ContinueWith(t => { string FileName = (string)t.Result[0]; long FileSize = (long)t.Result[1]; if (FileName != null) // when there's no internet connection, the result is always null { filename = FileName; // outside this method, they execute before the result is assigned to the filename // append filename to the SaveLocationComboBox items (downloads paths) for (int i = 0; i < SaveLocationComboBox.Items.Count; i++) { SaveLocationComboBox.Items[i] = SaveLocationComboBox.Items[i] + filename; } // Example value of filenamepath = "C:\Users\Random\Downloads\filename.ext" filenamepath = DownloadDirectory + filename; // fill SaveLocationComboBox with the path and the filename SaveLocationComboBox.Text = filenamepath; // get icon for the given filename & put it into the FileExtIcon Image element FileExtIcon.Source = IconTools.GetIconForExtension(filename, ShellIconSize.LargeIcon).IconToImageSource(); } if (FileSize != 0) // when there's no internet connection, the result is always 0 { filesize = FileSize; FileSizeLabel.Content = Helper.SizeSuffix(filesize); } // to set the correct redirected url (doesn't do anything when not redirected because the url remains the same) Uri newURL = (Uri)t.Result[2]; if (newURL != null) { DownloadLink = newURL; LinkBox.Text = DownloadLink.ToString(); } }, TaskScheduler.FromCurrentSynchronizationContext()); }
public DownloadFileInfo(Uri Link, string authUsername = null, string authPassword = null, string LinkObtainedFrom = null) { InitializeComponent(); DownloadLink = Link; authUser = authUsername; // value will be null if it isn't assigned by the caller of this method authPass = authPassword; // same obtainedFrom = LinkObtainedFrom; // same // fill LinkBox Text with the DownloadLink LinkBox.Text = DownloadLink.ToString(); // populate folders history into the SaveLocationComboBox Helper.ComboBoxHistory("foldersHistory.txt", SaveLocationComboBox); // if there's a path saved by the user while previously downloading a file, set it as the DownloadDirectory if (SaveLocationComboBox.Items.Count > 0) { DownloadDirectory = SaveLocationComboBox.Items[0].ToString(); } // set a temporary filename before the background process is completed filename = System.IO.Path.GetFileName(DownloadLink.ToString()); // append filename to the SaveLocationComboBox items (downloads paths) for (int i = 0; i < SaveLocationComboBox.Items.Count; i++) { SaveLocationComboBox.Items[i] = SaveLocationComboBox.Items[i] + filename; } // Example value of filenamepath = "C:\Users\Random\Downloads\filename.ext" filenamepath = DownloadDirectory + filename;; // fill SaveLocationComboBox with the path and the filename SaveLocationComboBox.Text = filenamepath; // set this, so that the ComboBox.Text isn't empty while the thread is working in the background SaveLocationComboBox.Text = DownloadDirectory + filename; // try to get the FileExtIcon Image Element Source from the filename, if you can FileExtIcon.Source = IconTools.GetIconForExtension(filename, ShellIconSize.LargeIcon).IconToImageSource(); }
private void MainWindow_Loaded(object sender, RoutedEventArgs e) { EnableBlur(); mMultiIcon.Load(@"C:\Users\erkan\AppData\Local\GitHubDesktop\GitHubDesktop.exe"); mMultiIcon.Load(@"D:\Portable\Adobe\InDesign CC 2018\InDesign13\InDesignPortable.exe"); mMultiIcon.Load(@"C:\Windows\System32\notepad.exe"); List <IconImage> iconImageList = new List <IconImage>(); foreach (var item in mMultiIcon[0]) { iconImageList.Add(item); // Dosyay ya ait bütün boyutlardaki iconlar listeye eklenir } IconImage iconImage = iconImageList.OrderByDescending(x => x.Size.Height).First(); //DP_Container.Children.Add(new System.Windows.Controls.Image() //{ // Source = ToImageSource(iconImage.Icon), // Width = 50, // Stretch = Stretch.Uniform //}); Icon largeIcon = IconTools.GetIconForExtension(".html", ShellIconSize.LargeIcon); //DockPanel.SetDock(DP_Container, Dock.Left); //GetIcon(@"C:\Users\erkan\OneDrive\Masaüstü").ForEach(x => //{ // DP_Container.Children.Add(new System.Windows.Controls.Image() // { // Source = ToImageSource(largeIcon), // Height = 60, // Stretch = Stretch.Uniform // }); //}); }
public static BitmapSource GetIconForExtension(string extension) { if (iconStore == null) { iconStore = new Dictionary <string, BitmapSource>(); } if (!iconStore.ContainsKey(extension)) { using (var ico = IconTools.GetIconForExtension(extension, ShellIconSize.SmallIcon)) { var image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon( ico.Handle, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(16, 16)); iconStore[extension] = image; } } return(iconStore[extension]); }
static void Main(string[] args) { do { // Show help? if (args.Length == 0) { ShowHelp(); break; } // Show licence? if (args[0] == "--licence") { ShowLicence(); break; } // Check number of arguaments if (args.Length < 2) { eExitCode = ExitCodes.eInvalidNumArgs; Console.WriteLine("Invalid number of arguments supplied."); break; } if (bDebug) { Console.WriteLine("DEBUG: Params Valid"); } // Is arg 0 a valid file? sExtractFile = args[0]; if (File.Exists(sExtractFile) == false) { eExitCode = ExitCodes.eFileNotFound; Console.WriteLine("File not found, " + sExtractFile); break; } if (bDebug) { Console.WriteLine("DEBUG: File is: " + sExtractFile); } // Is arg 1 a valid dir? sExportDir = args[1]; if (Directory.Exists(sExportDir) == false) { // Try and create it! try { Directory.CreateDirectory(sExportDir); if (bDebug) { Console.WriteLine("DEBUG: Directory Created: " + sExportDir); } } catch (Exception eXcep) { eExitCode = ExitCodes.eSaveDirInvalid; Console.WriteLine("Directory error, " + eXcep.Message); break; } } if (bDebug) { Console.WriteLine("DEBUG: Directory is: " + sExportDir); } // OK, lets get the icon... Icon icoExtract; try { icoExtract = IconTools.GetIconForExtension(Path.GetExtension(sExtractFile), ShellIconSize.LargeIcon); } catch (Exception eXcep) { eExitCode = ExitCodes.eIconExtractFailed; Console.WriteLine("Extract failed, " + eXcep.Message); break; } if (bDebug) { Console.WriteLine("DEBUG: Icon extracted to resource object"); } string sExtractedFileName = Path.GetExtension(sExtractFile).Substring(1) + "-ico.png"; string sFullPath = Path.Combine(sExportDir, sExtractedFileName); try { icoExtract.ToBitmap().Save(sFullPath, ImageFormat.Png); } catch (Exception eXcep) { eExitCode = ExitCodes.eSavePNGFailed; Console.WriteLine("Save PNG failed, " + eXcep.Message); break; } if (bDebug) { Console.WriteLine("DEBUG: Icon Saved: " + sFullPath); } } while (false); if (bDebug) { Console.WriteLine("End of program. Exit Code: " + eExitCode.ToString() + " (" + ((int)eExitCode).ToString() + ")."); Console.WriteLine("Press any key to exit..."); Console.ReadLine(); } Environment.Exit((int)eExitCode); }