public ImageSource GetFileIconImage(string filePath, bool small) { return(LoadBitmap(IconReader.GetFileIcon( filePath, (small) ? IconReader.IconSize.Small : IconReader.IconSize.Large, false))); }
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 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 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); } }
private void button1_Click(object sender, EventArgs e) { OpenFileDialog pFileDlg = new OpenFileDialog(); pFileDlg.Filter = "All Files(*.*)|*.*"; pFileDlg.Title = "편집할 파일을 선택하여 주세요."; if (pFileDlg.ShowDialog() == DialogResult.OK) { string strFullPathFile = pFileDlg.FileName; string Filename = pFileDlg.SafeFileName; if (pm.containProgram(Filename)) { MessageBox.Show("이미 저장한 프로그램입니다."); } else { //MessageBox.Show(strFullPathFile); Icon icn = IconReader.GetFileIcon(strFullPathFile, IconReader.IconSize.Large, false); iconView.Images.Add(icn); iconList.Items.Add(Filename, iconList.Items.Count); pm.saveProgram(Filename, strFullPathFile); } } }
/// <summary> /// Get an icon for a given filename /// </summary> /// <param name="fileName">any filename</param> /// <param name="large">16x16 or 32x32 icon</param> /// <returns>null if path is null, otherwise - an icon</returns> public static ImageSource FindIconForFilename(string fileName, bool large, bool isfolder = false) { var extension = Path.GetExtension(fileName); if (extension == null) { return(null); } //var cache = large ? _largeIconCache : _smallIconCache; ImageSource icon; //if (cache.TryGetValue(extension, out icon)) // icon = IconReader.GetFileIcon(fileName, large ? IconReader.IconSize.Large : IconReader.IconSize.Small, false, true).ToImageSource(); //else // icon = IconReader.GetFileIcon(fileName, large ? IconReader.IconSize.Large : IconReader.IconSize.Small, false).ToImageSource(); if (isfolder) { icon = IconReader.GetFileIcon(fileName, large ? IconReader.IconSize.Large : IconReader.IconSize.Small, false, true).ToImageSource(); } else { icon = IconReader.GetFileIcon(fileName, large ? IconReader.IconSize.Large : IconReader.IconSize.Small, false).ToImageSource(); } //cache.Add(extension, icon); return(icon); }
private BitmapSource GetIcon(IconReader.IconSize size) { var path = Path; if (Path.ToLower().EndsWith(".lnk")) { var shell = new WshShell(); var link = (IWshShortcut)shell.CreateShortcut(Path); if (link.TargetPath != string.Empty) { var info = new FileInfo(link.TargetPath); if (info.Exists) { path = link.TargetPath; } } } var ic = IconReader.GetFileIcon(path, size, false); var icon = Imaging.CreateBitmapSourceFromHBitmap((ic.ToBitmap()).GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); icon.Freeze(); ic.Dispose(); return(icon); }
private void paintIcon() { Dictionary <string, string> programlist = pm.returnProgramlist(); Bitmap myBitmap; int positionX = 30; int positionY = 220; int i = 0; pictureBox = new PictureBox[programlist.Count]; nCount = programlist.Count; if (nCount > 10) { pindex = 5; } else { pindex = nCount / 2; } foreach (KeyValuePair <string, string> kvp in programlist) { Icon icn = IconReader.GetFileIcon(kvp.Value, IconReader.IconSize.Large, false); myBitmap = icn.ToBitmap(); myBitmap = ResizeBitmap(myBitmap, 50, 50); // CenterPictureBox(pictureBox[i], myBitmap); pictureBox[i] = new PictureBox(); pictureBox[i].Name = kvp.Value; pictureBox[i].Tag = kvp.Key; pictureBox[i].Size = new Size(100, 100); //first index = total /2, if total > 10 then index 5 if (pindex == i) { selectindex(); pictureBox[i].Location = new Point(positionX, positionY - indexPositionY); } else { pictureBox[i].Location = new Point(positionX, positionY); } pictureBox[i].TabIndex = 10; pictureBox[i].TabStop = false; pictureBox[i].Visible = true; pictureBox[i].Parent = this; pictureBox[i].BorderStyle = BorderStyle.None; pictureBox[i].Image = myBitmap; pictureBox[i].Paint += new PaintEventHandler(Form1_Paint); pictureBox[i].Padding = new Padding(4, 0, 4, 0); pictureBox[i].BackColor = Color.Aqua; pictureBox[i].SizeMode = PictureBoxSizeMode.CenterImage; positionX += 100; i++; } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { ItemType type; if (!Enum.TryParse <ItemType>(value.GetType().Name, out type)) { return(null); } IconSize size; if (!Enum.TryParse <IconSize>((string)parameter, out size)) { size = IconSize.Small; } if (type == ItemType.File) { Icon icon = IconReader.GetFileIcon(((File)value).Extension.ToLower(), size, false); return(icon.ToImageSource()); } else { if ((type == ItemType.DriveModel) && !Enum.TryParse <ItemType>(((DriveModel)value).DriveType.ToString(), out type)) { return(null); } string key = type.ToString() + size.ToString(); if (!_folderIconCache.ContainsKey(key)) { _folderIconCache.Add(key, IconReader.GetIcon(type, size).ToImageSource()); } return(_folderIconCache[key]); } }
/// <summary> /// Real method to get the file icon after parsing the parameter. /// </summary> /// <param name="value">The databound value.</param> /// <param name="large">if set to <c>true</c> return large icon.</param> /// <returns></returns> protected virtual ImageSource GetFileIconCore(object value, bool large) { if (value == null) { return(null); } return(IconReader.GetFileIcon(value.ToString(), large ? IconReader.IconSize.Large : IconReader.IconSize.Small, false)); }
/// <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); }
static AppIconImage() { StretchProperty.OverrideMetadata(typeof(AppIconImage), new FrameworkPropertyMetadata(Stretch.Uniform)); SourceProperty.OverrideMetadata(typeof(AppIconImage), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(SourceChanged), new CoerceValueCallback(SourceCoerceCallback))); string exePath = GetExePath(); __appSmallIcon = IconReader.GetFileIcon(exePath, IconReader.IconSize.Small, false); //__appLargeIcon = IconReader.GetFileIcon(exePath, IconReader.IconSize.Large, false); }
/// <summary> /// Grabs the associated icon with a path. /// </summary> /// <param name="path">The path to grab.</param> /// <returns>Bitmap icon object.</returns> public Bitmap GetFileIconBitmap(string path) { try { return(IconReader.GetFileIcon(path, IconReader.IconSize.Large, false).ToBitmap()); } catch (Exception ex) { MessageBox.Show(ex.Message); return(SystemIcons.WinLogo.ToBitmap()); } }
private void programMark() { Dictionary <string, string> programlist = pm.returnProgramlist(); //key : file name, Value : path foreach (KeyValuePair <string, string> kvp in programlist) { Icon icn = IconReader.GetFileIcon(kvp.Value, IconReader.IconSize.Large, false); iconView.Images.Add(icn); iconList.Items.Add(kvp.Key, iconList.Items.Count); } }
void WriteItem(HttpMultiThreadDownloader mtdo) { if (mtdo == null || mtdo.Info == null) { return; } var fullList = listView1.Items.Cast <ListViewItem>(); var itemlist = fullList.Where(x => x.Text == mtdo.Info.ServerFileName || x.SubItems[7].Text == mtdo.Info.Url); var i = -1; if (listView1.SmallImageList == null) { listView1.SmallImageList = new ImageList(); } var subitems = new string[] { mtdo.Info.ServerFileName, mtdo.ProgressString, mtdo.TotalBytesReceived.ToHumanReadableSize(), mtdo.Info.ContentSize > 0 ? mtdo.Info.ContentSize.ToHumanReadableSize() : mtdo.Status == HttpDownloaderStatus.Completed ? mtdo.TotalBytesReceived.ToHumanReadableSize() : "Unknown", mtdo.Status.ToString(), mtdo.Speed.ToHumanReadableSize() + "/s", mtdo.Info.ResumeCapability.ToString(), mtdo.Url }; if (itemlist.Any()) { var it = itemlist.First(); i = it.Index; for (int j = 0; j < it.SubItems.Count; j++) { var a = (System.Windows.Forms.ListViewItem.ListViewSubItem)it.SubItems[j]; a.Text = subitems[j]; } listView1.SmallImageList.Images[i] = IconReader.GetFileIcon(mtdo.FilePath, IconReader.IconSize.Small, false).ToBitmap(); } else { listView1.SmallImageList.Images.Add(IconReader.GetFileIcon(mtdo.FilePath, IconReader.IconSize.Small, false)); var lvi = new ListViewItem(subitems, listView1.Items.Count); listView1.Items.Add(lvi); } }
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 Image GetFileIcon(string path) { if (string.IsNullOrEmpty(path)) { return(Data.DefaultIcon); } try { return(IconReader.GetFileIcon(path, IconSize, false) .ToBitmap()); } catch { return(Data.DefaultIcon); } }
public static bool TrySetDefaultIcon(string path, out Image img) { try { img = IconReader.GetFileIcon( path, IconReader.IconSize.Small, false).ToBitmap(); return(true); } catch { img = Data.DefaultIcon; return(false); } }
/// <summary> /// Get an icon for a given filename /// </summary> /// <param name="fileName">any filename</param> /// <param name="large">16x16 or 32x32 icon</param> /// <returns>null if path is null, otherwise - an icon</returns> public static ImageSource FindIconForFilename(string fileName, bool large) { if (System.IO.Directory.Exists(fileName)) { fileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Explorer.exe"); } var extension = Path.GetExtension(fileName); if (extension == null) { return(null); } ImageSource icon; icon = IconReader.GetFileIcon(fileName, large ? IconReader.IconSize.Large : IconReader.IconSize.Small, false).ToImageSource(); return(icon); }
/// <summary> /// Get an icon for a given filename /// </summary> /// <param name="fileName">any filename</param> /// <param name="large">16x16 or 32x32 icon</param> /// <returns>null if path is null, otherwise - an icon</returns> public static ImageSource FindIconForFilename(string fileName, bool large) { var extension = Path.GetExtension(fileName); if (extension == null) { return(null); } var cache = large ? _largeIconCache : _smallIconCache; if (cache.TryGetValue(extension, out ImageSource icon)) { return(icon); } icon = IconReader.GetFileIcon(fileName, large ? IconReader.IconSize.Large : IconReader.IconSize.Small, false).ToImageSource(); cache.Add(extension, icon); return(icon); }
/// <summary> /// Get an icon for a given filename /// </summary> /// <param name="fileName">any filename</param> /// <param name="large">16x16 or 32x32 icon</param> /// <returns>null if path is null, otherwise - an icon</returns> public static ImageSource FindIconForFilename(string fileName, bool large) { string extension = Path.GetExtension(fileName); if (string.IsNullOrEmpty(extension)) { return(null); } Dictionary <string, ImageSource> cache = large ? _largeIconCache : _smallIconCache; ImageSource icon; if (cache.TryGetValue(extension, out icon)) { return(icon); } icon = IconReader.GetFileIcon(fileName, large ? IconReader.IconSize.Large : IconReader.IconSize.Small, false).ToImageSource(); cache.Add(extension, icon); return(icon); }
/* * private void iconList_MouseDoubleClick(object sender, MouseEventArgs e) * { * string filename = iconList.FocusedItem.Text; * int fileindex = iconList.FocusedItem.Index; * iconList.Items.RemoveAt(fileindex); * pm.deleteProgram(filename); * } */ private void iconList_MouseDoubleClick(object sender, MouseEventArgs e) { Dictionary <string, string> programlist = pm.returnProgramlist(); string filename = iconList.FocusedItem.Text; int fileindex = iconList.FocusedItem.Index; pm.deleteProgram(filename); iconView.Images.Clear(); iconList.Items.Clear(); foreach (KeyValuePair <string, string> kvp in programlist) { Icon icn = IconReader.GetFileIcon(kvp.Value, IconReader.IconSize.Large, false); iconView.Images.Add(icn); iconList.Items.Add(kvp.Key, iconList.Items.Count); } }
public static System.Windows.Media.Imaging.BitmapFrame GetIcon(string filename) { string ext = Path.GetExtension(filename); if (cache.ContainsKey(ext)) { return(cache[ext]); } else { System.Drawing.Icon i = IconReader.GetFileIcon(filename, IconReader.IconSize.Large, false); MemoryStream iconStream = new MemoryStream(); i.Save(iconStream); iconStream.Seek(0, SeekOrigin.Begin); var bf = System.Windows.Media.Imaging.BitmapFrame.Create(iconStream); bf = ResizeHelper(bf, 16, 16, BitmapScalingMode.Fant); cache.Add(ext, bf); return(bf); } }
bool TrySetDefaultIcon() { if (!System.IO.File.Exists(pathTextBox.Text)) { IconPictureBox.Image = Data.DefaultIcon; return(false); } try { IconPictureBox.Image = IconReader.GetFileIcon( pathTextBox.Text, IconReader.IconSize.Small, false).ToBitmap(); return(true); } catch { return(false); } }
private void getInfo(string path) { F.async(() => { setText(path); Thread.Sleep(new Random().Next(1000)); double bytes = 0; short unit = 0; DateTime date = new FileInfo(path).LastWriteTimeUtc; if (File.Exists(path)) { bytes = new FileInfo(path).Length; } else { bytes = Tools.getFolderBytes(path); } if (bytes == -1) { return; } while (bytes > 1024) { bytes /= 1024; unit++; } setText(string.Format("{0} \t {1:#,0.0##} {2} \t {3}", Path.GetFileName(path), bytes, Tools.getUnitString(unit), date.ToString("yyyy-MM-dd HH:mm:ss"))); }); F.async(() => { if (Directory.Exists(path)) { img = Properties.Resources.folder; } else { img = IconReader.GetFileIcon(Path.GetExtension(path), IconReader.IconSize.Large, false); } }); }
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); }
public MainForm() { InitializeComponent(); olvJobs.Initialize(); olvJobs.ContextMenu = cmnuJobs; colName.AspectGetter = x => ((ApplicationJob)x).Name; colName.GroupKeyGetter = delegate(object x) { ApplicationJob job = (ApplicationJob)x; if (job.Name.Length == 0) { return(string.Empty); } return(job.Name[0].ToString().ToUpper()); }; // Gray out disabled jobs olvJobs.RowFormatter = delegate(OLVListItem item) { item.ForeColor = !((ApplicationJob)item.RowObject).Enabled ? Color.Gray : olvJobs.ForeColor; }; colName.ImageGetter = delegate(object x) { ApplicationJob job = (ApplicationJob)x; // Gray icon if disabled if (!job.Enabled && !string.IsNullOrEmpty(job.CurrentLocation) && m_Updater.GetStatus(job) == Updater.Status.Idle) { try { string disabledKey = job.CurrentLocation + "|Disabled"; if (!imlStatus.Images.ContainsKey(disabledKey)) { // No icon if no file exists if (!File.Exists(job.CurrentLocation)) { return(0); } Icon programIcon = IconReader.GetFileIcon(job.CurrentLocation, IconReader.IconSize.Small, false); imlStatus.Images.Add(disabledKey, MakeGrayscale(programIcon.ToBitmap())); } return(disabledKey); } catch (ArgumentException) { // no icon could be determined, use default } } // If available and idle, use the program icon if (m_Updater.GetStatus(job) == Updater.Status.Idle && !string.IsNullOrEmpty(job.CurrentLocation)) { try { if (!imlStatus.Images.ContainsKey(job.CurrentLocation)) { // No icon if no file exists if (!File.Exists(job.CurrentLocation)) { return(0); } Icon programIcon = IconReader.GetFileIcon(job.CurrentLocation, IconReader.IconSize.Small, false); imlStatus.Images.Add(job.CurrentLocation, programIcon); } return(job.CurrentLocation); } catch (ArgumentException) { // no icon could be determined, use default } } return((int)m_Updater.GetStatus(job)); }; colStatus.AspectGetter = x => this.m_Updater.GetStatus(x as ApplicationJob); colStatus.AspectToStringConverter = delegate(object x) { switch ((Updater.Status)x) { case Updater.Status.Downloading: return("Downloading"); case Updater.Status.Failure: return("Failed"); case Updater.Status.Idle: return("Idle"); case Updater.Status.NoUpdate: return("No update"); case Updater.Status.UpdateSuccessful: return("Updated"); case Updater.Status.UpdateAvailable: return("Update available"); } return(string.Empty); }; colTarget.AspectGetter = delegate(object x) { ApplicationJob job = x as ApplicationJob; return(job.Variables.ReplaceAllInString(job.TargetPath, DateTime.MinValue, null, true)); }; colTarget.GroupKeyGetter = x => ((ApplicationJob)x).TargetPath.ToLower(); colLastUpdate.AspectGetter = x => ((ApplicationJob)x).LastUpdated; colLastUpdate.AspectToStringFormat = "{0:g}"; colLastUpdate.GroupKeyGetter = delegate(object x) { ApplicationJob job = (ApplicationJob)x; if (job.LastUpdated == null) { return(DateTime.MinValue); } return(job.LastUpdated.Value.Date); }; colLastUpdate.GroupKeyToTitleConverter = delegate(object x) { if ((DateTime)x == DateTime.MinValue) { return(string.Empty); } return(((DateTime)x).ToString("d")); }; colProgress.AspectGetter = x => this.m_Updater.GetProgress(x as ApplicationJob); colProgress.Renderer = new ApplicationJobsListView.ProgressRenderer(m_Updater, 0, 100); m_Updater.ProgressChanged += this.m_Updater_ProgressChanged; m_Updater.StatusChanged += this.m_Updater_StatusChanged; m_Updater.UpdateCompleted += this.m_Updater_UpdateCompleted; m_Updater.UpdatesFound += this.m_Updater_UpdatesFound; LogDialog.Instance.VisibleChanged += delegate { mnuLog.Checked = LogDialog.Instance.Visible; }; this.olvJobs.FilterChanged += this.olvJobs_FilterChanged; imlStatus.Images.Add(Resources.Document); imlStatus.Images.Add(Resources.Import); imlStatus.Images.Add(Resources.New); imlStatus.Images.Add(Resources.NewDownloaded); imlStatus.Images.Add(Resources.Symbol_Check); imlStatus.Images.Add(Resources.Symbol_Delete); imlStatus.Images.Add(Resources.Document_Restricted); }
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); }
private void RefreshAppListView(string strKeyword = "") { lblState.Text = "Scanning..."; // backup sort type at before SortOrder soTemp = lvApp.Sorting; lvApp.Sorting = SortOrder.None; // lock listview ListViewUtil.LockUpdate(lvApp); // clear controls Global.siMain.Clear(); lvApp.Items.Clear(); imglstAppSmall.Images.Clear(); picAppIcon.Image = null; lblDisplayName.Text = ""; lblPublisher.Text = ""; bool isOdd = false; // get registrys foreach (string strUninstallSubkey in Registry.LocalMachine.OpenSubKey(strUninstallRegistryLocation).GetSubKeyNames()) { // write struct SoftwareInformation siTemp = new SoftwareInformation(); // `Registry Location` siTemp.strRegistryLocation = strUninstallRegistryLocation + @"\" + strUninstallSubkey; // get registry sub key RegistryKey regkeyTemp = Registry.LocalMachine.OpenSubKey(siTemp.strRegistryLocation); if (regkeyTemp == null) { continue; } // System Component try { siTemp.isSystemComponent = ((Int32)regkeyTemp.GetValue("SystemComponent") == 1); } catch { siTemp.isSystemComponent = false; } if (!tsmiViewSystemComponent.Checked && siTemp.isSystemComponent) { continue; } // `Name` siTemp.strDisplayName = (string)regkeyTemp.GetValue("DisplayName"); if (siTemp.strDisplayName == null) { continue; } // icon siTemp.strDisplayIcon = (string)regkeyTemp.GetValue("DisplayIcon"); { StringBuilder sbTemp = new StringBuilder(siTemp.strDisplayIcon); PathParseIconLocation(sbTemp); siTemp.strDisplayIcon = sbTemp.ToString(); } // `Publisher` siTemp.strPublisher = (string)regkeyTemp.GetValue("Publisher"); // `Version` siTemp.strDisplayVersion = (string)regkeyTemp.GetValue("DisplayVersion"); // `Installed Time` siTemp.dtLastWriteTime = RegQuery.lastWriteTime(@"HKEY_LOCAL_MACHINE\" + siTemp.strRegistryLocation); string strLastWriteTime = siTemp.dtLastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"); // filepath of uninstaller siTemp.strUninstallString = (string)regkeyTemp.GetValue("UninstallString"); /* * // get realpath * StringBuilder sbQuote = new StringBuilder(siTemp.strUninstallString); * if (!File.Exists(siTemp.strUninstallString)) * PathRemoveArgs(sbQuote); * PathUnquoteSpaces(sbQuote); * StringBuilder sbUninstallString = new StringBuilder(260); * PathSearchAndQualify(sbQuote.ToString(), sbUninstallString, 260); * strUninstallString = sbUninstallString.ToString(); */ // `Help Link` siTemp.strHelpLink = (string)regkeyTemp.GetValue("HelpLink"); // `Support Link` siTemp.strSupportLink = (string)regkeyTemp.GetValue("URLInfoAbout"); // `File Location` siTemp.strFileLocation = (string)regkeyTemp.GetValue("InstallLocation"); if (siTemp.strFileLocation == null) { if (siTemp.strDisplayIcon != null) { siTemp.strFileLocation = FileUtil.DirName(siTemp.strDisplayIcon); } } else { StringBuilder sbTemp = new StringBuilder(siTemp.strFileLocation); PathRemoveBackslash(sbTemp); PathUnquoteSpaces(sbTemp); siTemp.strFileLocation = sbTemp.ToString(); } // `Size` siTemp.lngFileLocationSize = FileUtil.GetDirSize(siTemp.strFileLocation); string strFileLocationSize = siTemp.lngFileLocationSize != -1 ? FileUtil.ConvertHumanReadableFileSize(siTemp.lngFileLocationSize) : null; // search filter if (!((siTemp.strDisplayName != null && StringUtil.InStr(siTemp.strDisplayName, strKeyword)) || (siTemp.strPublisher != null && StringUtil.InStr(siTemp.strPublisher, strKeyword)) || (siTemp.strDisplayVersion != null && StringUtil.InStr(siTemp.strDisplayVersion, strKeyword)) || (strLastWriteTime != null && StringUtil.InStr(strLastWriteTime, strKeyword)) || (strFileLocationSize != null && StringUtil.InStr(strFileLocationSize, strKeyword)))) { continue; } // large icon for preview Icon icoTempLarge = IconReader.GetFileIcon(siTemp.strDisplayIcon, IconReader.IconSize.Large, false); siTemp.imgLargeIcon = icoTempLarge.ToBitmap(); // add listview item ListViewItem lviTemp = new ListViewItem(); lviTemp.Text = siTemp.strDisplayName; // set small icon Icon icoTempSmall = IconReader.GetFileIcon(siTemp.strDisplayIcon, IconReader.IconSize.Small, false); imglstAppSmall.Images.Add(icoTempSmall); lviTemp.ImageIndex = imglstAppSmall.Images.Count - 1; // set subitems if (tsmiViewPublisher.Checked) { lviTemp.SubItems.Add(siTemp.strPublisher); } if (tsmiViewVersion.Checked) { lviTemp.SubItems.Add(siTemp.strDisplayVersion); } if (tsmiViewInstallTime.Checked) { lviTemp.SubItems.Add(strLastWriteTime); } if (tsmiViewSize.Checked) { lviTemp.SubItems.Add(strFileLocationSize); } if (tsmiViewHelpLink.Checked) { lviTemp.SubItems.Add(siTemp.strHelpLink); } if (tsmiViewSupportLink.Checked) { lviTemp.SubItems.Add(siTemp.strSupportLink); } if (tsmiViewFileLocation.Checked) { lviTemp.SubItems.Add(siTemp.strFileLocation); } if (tsmiViewRegistryLocation.Checked) { lviTemp.SubItems.Add(@"HKEY_LOCAL_MACHINE\" + siTemp.strRegistryLocation); } // set backcolor if (isOdd = !isOdd) { lviTemp.BackColor = MyColor.Odd; } else { lviTemp.BackColor = MyColor.Even; } // set forecolor if (!FileUtil.IsDir(siTemp.strFileLocation)) { lviTemp.ForeColor = MyColor.Danger; } // add struct Global.siMain.Add(siTemp); // for access to struct by listview item ListViewUtil.SetSoftwareInformationIndexOfList(lviTemp, Global.siMain.Count - 1); lvApp.Items.Add(lviTemp); lblInstallCount.Text = "Installations : " + lvApp.Items.Count.ToString(); } // sort lblState.Text = "Sorting..."; lvApp.Sorting = soTemp; if (lvApp.Sorting == SortOrder.Ascending) // asc { for (int i = 0; i < lvApp.Columns.Count; i++) { if (lvApp.Columns[i].Text.Contains(" ∧")) { lvApp.ListViewItemSorter = new ListViewItemComparer(i, lvApp.Columns[i].Text.Replace(" ∨", "").Replace(" ∧", ""), SortOrder.Ascending); lvApp.Sorting = SortOrder.Ascending; lvApp.Sort(); break; } } } else if (lvApp.Sorting == SortOrder.Descending) // desc { for (int i = 0; i < lvApp.Columns.Count; i++) { if (lvApp.Columns[i].Text.Contains(" ∨")) { lvApp.ListViewItemSorter = new ListViewItemComparer(i, lvApp.Columns[i].Text.Replace(" ∨", "").Replace(" ∧", ""), SortOrder.Descending); lvApp.Sorting = SortOrder.Descending; lvApp.Sort(); break; } } } // unlock listview ListViewUtil.UnlockUpdate(lvApp); }
public void SetData_GetList_AddItemTo_LVnTV_(ExplorerListItem load) { if (load.addToTV && load.TV_node != null)//add folder to tree view { ((TreeNode)load.TV_node).Nodes.Clear(); foreach (ItemNode c in load.node.Childs) { if (c.Info.Size > 0) { continue; } TreeNode_ child = new TreeNode_(c); ((TreeNode_)load.TV_node).Nodes.Add(child); } if (load.explandTV) { ((TreeNode)load.TV_node).Expand(); } } // Add LV tab index if (load.indexLV_tab != -1) { List <ItemLV> ListItem_LV = new List <ItemLV>(); DateTime temp = new DateTime(0); foreach (ItemNode c in load.node.Childs) { if (c.Info.Size > 0) { continue; } string datetime = ""; if (c.Info.DateMod != temp) { try { datetime = c.Info.DateMod.ToString(TimeFormat); } catch { } } ListItem_LV.Add(new ItemLV() { str = new string[] { c.Info.Name, "Folder", string.Empty, datetime, c.Info.MimeType, c.Info.ID }, icon = icon_folder }); } foreach (ItemNode c in load.node.Childs) { if (c.Info.Size < 1) { continue; } string extension = c.GetExtension(); ListItem_LV.Add(new ItemLV() { str = new string[] { c.Info.Name, "File", c.Info.Size.ToString(), c.Info.DateMod.ToString(TimeFormat), c.Info.MimeType, c.Info.ID }, icon = c.GetRoot.RootType.Type == CloudType.LocalDisk ? IconReader.GetFileIcon(c.GetFullPathString(), IconReader.IconSize.Small, false) : //some large file make slow. IconReader.GetFileIcon("." + extension, IconReader.IconSize.Small, false) }); } list_UCLVitem[load.indexLV_tab].AddListViewItem(ListItem_LV); } //set tab text name tabControl1.TabPages[load.indexLV_tab].Text = load.node.Info.Name; //set tooltip tab tabControl1.TabPages[load.indexLV_tab].ToolTipText = load.node.GetFullPathString(); //set PathNode list_UCLVitem[load.indexLV_tab].pathUC1.Node = load.node; //OldPathLV inpath = new OldPathLV(); //inpath.ID = list.id_folder; //inpath.Path = loaditemthread.path.TrimEnd(new char[] { '\\', '/' }); ////set old Path TextBox //list_UCLVitem[loaditemthread.indexLV_tab].oldpathlv.Add(inpath); }