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 }
//problem with the api public void PictureBoxTestMethod(Part part) { stdole.IPictureDisp thumbNail = part.PartDocument.Thumbnail; Image image = IconTools.GetImage(thumbNail); //PictureBoxTest.Image = image; }
private void PopulateProcessList() { //grab the list of processes Process[] proc_list = Process.GetProcesses(); List <CProcess> Raw_procList = new List <CProcess>(proc_list.Length); //can only be as much as the proclist and less //grab their icons for (int p = 0; p < proc_list.Length; p++) { Process proc = proc_list[p]; try { String filePID = String.Format("{0}-{1}", Utilities.ToHexPID(proc.Id), proc.ProcessName); String filePath = proc.Modules[0].FileName; Icon proc_icon = IconTools.GetIconForFile(filePath, ShellIconSize.LargeIcon); if (proc_icon == null) { throw new Exception("unable to get icon for proc"); } Raw_procList.Add(new CProcess(proc, proc_icon)); } catch { //Console.WriteLine("Populate Process List Exception: " + ex.Message + "=>" + proc.ProcessName); } } //sort by PID List <CProcess> Sorted_procList = Raw_procList.OrderBy(o => o.iProcess.Id).ToList(); //finally populate the list for (int i = 0; i < Sorted_procList.Count; i++) { CProcess current = Sorted_procList[i]; //Format a nice name to display String ProcName = String.Format("{0}-{1}", Utilities.ToHexPID(current.iProcess.Id), current.iProcess.ProcessName); //add the icon to our imagelist iconList.Images.Add(current.IconAsBitmap); ListViewItem list_item = new ListViewItem(ProcName, iconList.Images.Count - 1); //(ICON) Name ListViewItem.ListViewSubItem sub_item_Path = new ListViewItem.ListViewSubItem(list_item, current.iProcess.Modules[0].FileName); list_item.SubItems.Add(sub_item_Path); //add subItem list_item.Tag = current; //add our proc as a Tag procListView.Items.Add(list_item); //add to list } //select the first item if (procListView.Items.Count > 0) { procListView.Items[0].Selected = true; procListView.Select(); } }
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)); } }
public void SetInfo(int bagType, int index, DataItem item) { _bagType = bagType; _index = index; iconSprite.gameObject.SetActive(item != null); textCount.gameObject.SetActive(item != null); if (item == null) { return; } IconTools.SetIcon(iconSprite, item.Icon); textCount.text = item.Count.ToString(); }
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]); }
public string GetIconForProcess(string path) { if (string.IsNullOrEmpty(path)) { return("null"); } var icon = IconTools.GetIconForFile(path, ShellIconSize.LargeIcon); if (icon == null) { return("null"); } var ms = new MemoryStream(); icon.ToBitmap().Save(ms, ImageFormat.Png); var byteImage = ms.ToArray(); var sigBase64 = Convert.ToBase64String(byteImage); //Get Base64 return(sigBase64); }
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); }
public void SetItems(ProcessModuleCollection processModules) { if (this.Created == false) { return; } List <ListViewItem> list = new List <ListViewItem>(); List <ProcessModule> processModuleList = processModules.Cast <ProcessModule>().ToList(); processModuleList.Sort(delegate(ProcessModule a, ProcessModule b) { return(a.BaseAddress.ToInt64().CompareTo(b.BaseAddress.ToInt64())); }); try { foreach (ProcessModule processModule in processModuleList) { ListViewItem item = new ListViewItem(); item.Text = processModule.ModuleName; string startAddress = String.Format("0x{0}", processModule.BaseAddress.ToString("X16")); string endAddress = String.Format("0x{0}", (processModule.BaseAddress.ToInt64() + processModule.ModuleMemorySize).ToString("X16")); string entryPointAddress = String.Format("0x{0}", processModule.EntryPointAddress.ToString("X16")); item.SubItems.Add(startAddress); item.SubItems.Add(endAddress); item.SubItems.Add(entryPointAddress); item.SubItems.Add(processModule.FileVersionInfo.ProductVersion); item.SubItems.Add(processModule.FileVersionInfo.FileVersion); item.SubItems.Add(processModule.FileVersionInfo.FileDescription); item.SubItems.Add(processModule.FileVersionInfo.FileName); try { string fileName = processModule.FileVersionInfo.FileName; string extension = Path.GetExtension(fileName).ToLower(); item.ImageKey = extension; if (SmallImageList.Images.ContainsKey(extension) == false) { Icon icon = IconTools.GetIconForFile(fileName, ShellIconSize.SmallIcon); if (icon != null) { SmallImageList.Images.Add(icon); SmallImageList.Images.SetKeyName(SmallImageList.Images.Count - 1, extension); } } } catch { } item.Tag = processModule; list.Add(item); } } catch { } BeginUpdate(); Items.Clear(); Items.AddRange(list.ToArray()); AutoResizeColumns(); EndUpdate(); }
public void SetInfo(DataShop item) { _item = item; IconTools.SetIcon(iconSprite, item.Icon); textName.text = item.Name; }