public override System.Drawing.Icon GetIcon() { System.Drawing.Icon icon = null; if (String.IsNullOrEmpty(FileName)) { } else { if (FileName.StartsWith("http://")) { return(BrowserIcon); } else if (LPath.IsValid(FileName)) { var p = new LPath(FileName); if (p.IsDirectory) { icon = IconReader.GetFolderIcon(IconReader.IconSize.Large, IconReader.FolderType.Closed); } else if (p.IsFile) { icon = IconReader.GetFileIcon(p, IconReader.IconSize.Large, false); } } } return(icon); }
public FSA(TCPGecko UGecko, TreeView UTreeView, ToolStripMenuItem UExtractToolStripMenuItem, TextBox UFileSwapCode, ExceptionHandler UExceptionHandling) { exceptionHandling = UExceptionHandling; imgList = new ImageList(); #if !MONO System.Drawing.Icon ni = IconReader.GetFolderIcon(IconReader.IconSize.Small, IconReader.FolderType.Closed); imgList.Images.Add(ni); ni = IconReader.GetFolderIcon(IconReader.IconSize.Small, IconReader.FolderType.Open); imgList.Images.Add(ni); ni = IconReader.GetFileIcon("?.?", IconReader.IconSize.Small, false); imgList.Images.Add(ni); #endif treeView = UTreeView; treeView.ImageList = imgList; treeView.NodeMouseClick += TreeView_NodeMouseClick; treeView.AfterSelect += treeView_AfterSelect; treeView.ContextMenuStrip.Opening += ContextMenuStrip_Opening; extractToolStripMenuItem = UExtractToolStripMenuItem; extractToolStripMenuItem.Click += extractToolStripMenuItem_Click; gecko = UGecko; fileSwapCode = UFileSwapCode; selectedFile = -1; }
public void ShowDataToLV(ExplorerNode parent) { lv_data.Clear(); foreach (ExplorerNode item in parent.Child) { LV_data dt = new LV_data(); dt.Node = item; if (item.Info.DateMod != time_default) { dt.d_mod = item.Info.DateMod.ToString(timeformat); } if (item.Info.Size >= 0) { dt.SizeString = UnitConventer.ConvertSize(item.Info.Size, 2, UnitConventer.unit_size); string extension = item.GetExtension(); dt.ImgSource = Setting_UI.GetImage( item.GetRoot.NodeType.Type == CloudType.LocalDisk ? IconReader.GetFileIcon(item.GetFullPathString(), IconReader.IconSize.Small, false) : //some large file make slow. IconReader.GetFileIcon("." + extension, IconReader.IconSize.Small, false) ).Source; } else { dt.SizeString = "-1"; dt.ImgSource = Setting_UI.GetImage(IconReader.GetFolderIcon(IconReader.IconSize.Small, IconReader.FolderType.Closed)).Source; } lv_data.Add(dt); } }
public ImageSource GetFolderIconImage(string folderPath, bool closed, bool small) { return(LoadBitmap(IconReader.GetFolderIcon( folderPath, (small) ? IconReader.IconSize.Small : IconReader.IconSize.Large, (closed) ? IconReader.FolderType.Closed : IconReader.FolderType.Opened))); }
/// <summary> /// Update Files OLV /// </summary> private void UpdateOLV() { fileName.ImageGetter = delegate(object x) { try { Icon ico; string path = ((FInfo)x).Path; if (File.Exists(path)) { ico = IconReader.GetFileIcon(path, IconReader.IconSize.Small, false); //ico = Icon.ExtractAssociatedIcon(path); } else if (Directory.Exists(path)) { ico = IconReader.GetFolderIcon(path, IconReader.IconSize.Small, IconReader.FolderType.Open); } else { ico = IconReader.GetFileIcon(RelativePath + Path.DirectorySeparatorChar + path, IconReader.IconSize.Small, false); } //ico = Icon.ExtractAssociatedIcon(RelativePath + Path.DirectorySeparatorChar + path); //Icon ico = Icon.ExtractAssociatedIcon(((FInfo)x).Path); //ico = IconReader.GetFileIcon(((FInfo)x).Path, IconReader.IconSize.Small, false); return(ico.ToBitmap()); } catch { return(null); } }; fileName.AspectGetter = delegate(object x) { return(((FInfo)x).Name); }; filePath.AspectGetter = delegate(object x) { return(((FInfo)x).Path); }; fileVersion.AspectGetter = delegate(object x) { return(((FInfo)x).Version); }; fileGroup.AspectGetter = delegate(object x) { return(((FInfo)x).Group); }; fileDescription.AspectGetter = delegate(object x) { return(((FInfo)x).Description); }; this.fileName.GroupKeyGetter = delegate(object x) { return(((FInfo)x).Group); }; this.filePath.GroupKeyGetter = delegate(object x) { return(((FInfo)x).Group); }; this.fileVersion.GroupKeyGetter = delegate(object x) { return(((FInfo)x).Group); }; this.fileGroup.GroupKeyGetter = delegate(object x) { return(((FInfo)x).Group); }; this.fileDescription.GroupKeyGetter = delegate(object x) { return(((FInfo)x).Group); }; olvFiles.ShowGroups = true; olvFiles.SetObjects(FileList); }
private void IconHelperInit() { _smallImageList.ColorDepth = ColorDepth.Depth32Bit; _smallImageList.ImageSize = new System.Drawing.Size(16, 16); _iconListManager = new IconListManager(_smallImageList, IconReader.IconSize.Small); treeView1.ImageList = _smallImageList; treeView1.ImageList.Images.Add(IconReader.GetFolderIcon(IconReader.IconSize.Small, IconReader.FolderType.Open)); treeView1.ImageList.Images.Add(IconReader.GetFolderIcon(IconReader.IconSize.Small, IconReader.FolderType.Closed)); }
private BitmapSource GetIcon(IconReader.IconSize size) { var ic = IconReader.GetFolderIcon(Path, size, IconReader.FolderType.Open); var icon = Imaging.CreateBitmapSourceFromHBitmap((ic.ToBitmap()).GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); icon.Freeze(); ic.Dispose(); return(icon); }
public Bitmap GetFolderIconBitmap(string path) { try { return(IconReader.GetFolderIcon(IconReader.IconSize.Large, IconReader.FolderType.Open).ToBitmap()); } catch (Exception) { return(SystemIcons.WinLogo.ToBitmap()); } }
/// <returns>null if path is null, otherwise - an icon</returns> public static ImageSource FindIconForFolder(bool large, bool is_open) { var cache = large ? _largeIconCache : _smallIconCache; ImageSource icon; if (cache.TryGetValue("", out icon)) { return(icon); } icon = IconReader.GetFolderIcon(large ? IconReader.IconSize.Large : IconReader.IconSize.Small, is_open ? IconReader.FolderType.Open : IconReader.FolderType.Closed).ToImageSource(); cache.Add("", icon); return(icon); }
private bool SetLnk(ref bool isLnkDirectory, ref string resolvedLnkPath) { bool handled = false; resolvedLnkPath = LnkHelper.GetResolvedFileName(TargetFilePath); if (LnkHelper.IsDirectory(resolvedLnkPath)) { Icon = IconReader.GetFolderIcon(TargetFilePath, IconReader.FolderType.Open, true); handled = true; isLnkDirectory = true; } else if (string.IsNullOrEmpty(resolvedLnkPath)) { Log.Info($"Resolve *.LNK '{TargetFilePath}' has no icon"); #warning [Feature] Resolve network root #48, start here } else { IWshShell shell = new WshShell(); IWshShortcut lnk = shell.CreateShortcut(TargetFilePath) as IWshShortcut; Arguments = lnk.Arguments; WorkingDirectory = lnk.WorkingDirectory; string iconLocation = lnk.IconLocation; if (iconLocation.Length > 2) { iconLocation = iconLocation.Substring(0, iconLocation.Length - 2); if (System.IO.File.Exists(iconLocation)) { try { Icon = Icon.ExtractAssociatedIcon(iconLocation); handled = true; } catch (ArgumentException ex) { Log.Warn($"iconLocation:'{iconLocation}'", ex); } } } TargetFilePath = resolvedLnkPath; } SetText(Path.GetFileNameWithoutExtension(TargetFilePathOrig)); return(handled); }
public FST(USBGecko UGecko, TreeView UTreeView, TextBox UFileSwapCode, Button USetAsSourceButton, Button USetAsTargetButton, Button UGenerateFileSwap, Label USourceFileName, Label UTargetFileName, TextBox UGeneratedSwapCode, Button USwapNowButton, ExceptionHandler UExceptionHandling) { exceptionHandling = UExceptionHandling; imgList = new ImageList(); #if !MONO System.Drawing.Icon ni = IconReader.GetFolderIcon(IconReader.IconSize.Small, IconReader.FolderType.Closed); imgList.Images.Add(ni); ni = IconReader.GetFolderIcon(IconReader.IconSize.Small, IconReader.FolderType.Open); imgList.Images.Add(ni); ni = IconReader.GetFileIcon("?.?", IconReader.IconSize.Small, false); imgList.Images.Add(ni); #endif treeView = UTreeView; treeView.ImageList = imgList; treeView.NodeMouseClick += TreeView_NodeMouseClick; gecko = UGecko; fstTextPositions = new List <fstEntry>(); fileSwapCode = UFileSwapCode; sourceFile = null; targetFile = null; setAsSourceButton = USetAsSourceButton; setAsTargetButton = USetAsTargetButton; generateFileSwap = UGenerateFileSwap; sourceFileName = USourceFileName; targetFileName = UTargetFileName; generatedSwapCode = UGeneratedSwapCode; swapFilesNow = USwapNowButton; setAsSourceButton.Click += SourceButtonClick; setAsTargetButton.Click += TargetButtonClick; generateFileSwap.Click += GenSwapButtonClick; swapFilesNow.Click += ImmediateSwap; generatedSwapCode.Text = ""; targetFileName.Text = ""; sourceFileName.Text = ""; setAsSourceButton.Enabled = false; setAsTargetButton.Enabled = false; generateFileSwap.Enabled = false; swapFilesNow.Enabled = false; selectedFile = -1; }
public void FillListView() { listViewManager.ClearListView(); listViewManager.SetColumns(columns); DriveInfo[] allDrives = DriveInfo.GetDrives(); foreach (DriveInfo drive in allDrives) { if (!Stopped) { ListViewFileItem item = new ListViewFileItem(drive.Name); item.Name = drive.Name; item.Attributes = FileAttributes.Directory; item.ImageKey = item.Name; Icon icon = IconReader.GetFolderIcon(null, IconReader.IconSize.Large, IconReader.FolderType.Open); listViewManager.AddListViewItem(item, icon); } } }
/// <summary> /// Get the icon of a directory /// </summary> /// <param name="large">16x16 or 32x32 icon</param> /// <returns>an icon</returns> public static ImageSource FindIconForDir(bool large) { var icon = large ? LargeDirIcon : SmallDirIcon; if (icon != null) { return(icon); } icon = IconReader.GetFolderIcon(large ? IconReader.IconSize.Large : IconReader.IconSize.Small, false) .ToImageSource(); if (large) { LargeDirIcon = icon; } else { SmallDirIcon = icon; } return(icon); }
private void MainForm_Load(object sender, EventArgs e) { Setting_UI.ReloadUI_Flag = false; icon_folder = IconReader.GetFolderIcon(IconReader.IconSize.Small, IconReader.FolderType.Closed); TimeFormat = Setting_UI.reflection_eventtocore.SettingAndLanguage.GetSetting(SettingsKey.DATE_TIME_FORMAT); LoadLanguage(); AddNewTabControl(); TV_item.BeginUpdate(); foreach (var drive in DriveInfo.GetDrives()) { TV_item.Nodes.Add(new TreeNode_(drive.RootDirectory.ToString().Replace("\\", null), 0)); } foreach (ItemNode cloud in Setting_UI.reflection_eventtocore.AccountsAndCloud.GetListAccountCloud()) { TV_item.Nodes.Add(new TreeNode_(cloud)); } TV_item.EndUpdate(); this.Activate(); }
private TreeNode CreateTreeNode(string FullPath) { string key = FullPath.ToLower(); string name = ""; object tag = null; if (PathIsDirectory(key)) { DirectoryInfo info = new DirectoryInfo(FullPath); key = kDirectoryImageKey; name = info.Name; tag = info; } else { FileInfo info = new FileInfo(FullPath); name = info.Name; tag = info; } if (!m_FileIcons.Images.ContainsKey(key)) { if (key == "directory") { m_FileIcons.Images.Add(key, IconReader.GetFolderIcon(Environment.CurrentDirectory, IconReader.IconSize.Small, IconReader.FolderType.Open).ToBitmap()); } else { m_FileIcons.Images.Add(key, IconReader.GetFileIcon(FullPath, IconReader.IconSize.Small, false)); } } TreeNode node = new TreeNode(name); node.Tag = tag; node.ImageKey = key; node.SelectedImageKey = key; return(node); }
private void LoadDirectory(string path) { currentDirectory = path; FillDirectories(currentDirectory); List <FtpItem> list = FTPAdapter.GetDirList(currentDirectory). OrderBy(x => x.ItemType != FtpItemType.Directory).ThenBy(x => x.Name).ToList(); list.Insert(0, new FtpItem("..", DateTime.Now, 0, null, null, FtpItemType.Unknown, null)); lvFTPList.Items.Clear(); lvFTPList.SmallImageList = new ImageList { ColorDepth = ColorDepth.Depth32Bit }; foreach (FtpItem file in list) { if (file.ItemType == FtpItemType.Directory && (file.Name == "." || file.Name == "..")) { continue; } ListViewItem lvi = new ListViewItem(file.Name); lvi.Tag = file; if (file.ItemType != FtpItemType.Unknown) { if (file.ItemType == FtpItemType.File) { lvi.SubItems.Add(file.Size.ToString("N0")); } else { lvi.SubItems.Add(string.Empty); } lvi.SubItems.Add(IconReader.GetDisplayName(file.Name, file.ItemType == FtpItemType.Directory)); lvi.SubItems.Add(file.Modified.ToLocalTime().ToString()); lvi.SubItems.Add(file.Attributes); } string ext; if (file.ItemType == FtpItemType.Directory || file.ItemType == FtpItemType.Unknown) { ext = "Directory"; } else if (Path.HasExtension(file.Name)) { ext = Path.GetExtension(file.Name); } else { ext = "File"; } if (!lvFTPList.SmallImageList.Images.Keys.Contains(ext)) { Icon icon; if (ext == "Directory") { icon = IconReader.GetFolderIcon(IconReader.IconSize.Small, IconReader.FolderType.Closed); } else { icon = IconReader.GetFileIcon(ext, IconReader.IconSize.Small, false); } if (icon != null) { lvFTPList.SmallImageList.Images.Add(ext, icon.ToBitmap()); } } if (lvFTPList.SmallImageList.Images.Keys.Contains(ext)) { lvi.ImageKey = ext; } lvFTPList.Items.Add(lvi); } CheckFiles(false); }
internal bool ReadIcon(bool isDirectory, ref string resolvedLnkPath) { bool isLnkDirectory = false; if (string.IsNullOrEmpty(TargetFilePath)) { Log.Info($"TargetFilePath from {resolvedLnkPath} empty"); } else if (isDirectory) { Icon = IconReader.GetFolderIcon(TargetFilePath, IconReader.FolderType.Closed, false); } else { bool handled = false; string fileExtension = Path.GetExtension(TargetFilePath); if (fileExtension == ".lnk") { handled = SetLnk(ref isLnkDirectory, ref resolvedLnkPath); } else if (fileExtension == ".url") { handled = SetUrl(); } else if (fileExtension == ".sln") { handled = SetSln(); } if (!handled) { try { Icon = IconReader.GetFileIconWithCache(TargetFilePath, false); diposeIcon = false; // other project -> fails sometimes //icon = IconHelper.ExtractIcon(TargetFilePath, 0); // standard way -> fails sometimes //icon = Icon.ExtractAssociatedIcon(filePath); // API Code Pack -> fails sometimes //ShellFile shellFile = ShellFile.FromFilePath(filePath); //Bitmap shellThumb = shellFile.Thumbnail.ExtraLargeBitmap; } catch (Exception ex) { if (ex is SecurityException || ex is ArgumentException || ex is UnauthorizedAccessException || ex is PathTooLongException || ex is NotSupportedException) { Log.Warn($"path:'{TargetFilePath}'", ex); } else { throw; } } } } return(isLnkDirectory); }
public virtual Icon GetDirectoryIcon(DirectoryInfo dir) { Icon icon = IconReader.GetFolderIcon(dir.FullName, IconReader.IconSize.Large, IconReader.FolderType.Open); return(icon); }