private void LoadFromPhysicalDirectory(string Path) { try { // Loading item file and creating new item object // get extra information on this file that the System.IO.FileInfo doesn't give us Win32.Shell32.SHFileInfo FileInfo = new Win32.Shell32.SHFileInfo(); Win32.Shell32.Shell32API.SHGetFileInfo(Path, 0, ref FileInfo, (uint)System.Runtime.InteropServices.Marshal.SizeOf(FileInfo), Win32.Shell32.ShellGetFileInfoFlags.DisplayName | Win32.Shell32.ShellGetFileInfoFlags.FileTypeName | Win32.Shell32.ShellGetFileInfoFlags.LargeIcon | Win32.Shell32.ShellGetFileInfoFlags.Icon); // set the item name to the file name this.Name = FileInfo.szDisplayName; // set the item description to the file type this.Description = FileInfo.szTypeName; // keep the path value this._Path = Path; // NON EXISTANT IN NEW CLASS //this.ItemPath=Path; // setting properties // NON EXISTANT IN NEW CLASS //this.Line=Line; // NON EXISTATN IN NEW CLASS //this.ColorKey=Color.FromArgb(0, Color.White); // Adding new Texture to registry // checking if it has a custom Icon string ExtensionImage = ""; string ToggledExtensionImage = ""; ExtensionImage = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), @"extensions\folder.png"); ToggledExtensionImage = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), @"extensions\folder_open.png"); if (System.IO.File.Exists(ExtensionImage)) { //ImagePath=ExtensionImage; if (OrbitTextureCache.IsInCache(ExtensionImage)) { this.SetIcon(OrbitTextureCache.GetReference(ExtensionImage)); } else { SetIcon(ExtensionImage); OrbitTextureCache.InsertInCache(this._Icon, ExtensionImage); } //SetIcon(ExtensionImage); if (System.IO.File.Exists(ToggledExtensionImage)) { //ToggledImagePath=ToggledExtensionImage; SetToggledIcon(ToggledExtensionImage); } } else { try { // getting the handle to the icon from the SHFileInfo structure using (Icon IconO = Icon.FromHandle(FileInfo.hIcon)) { // create the biggest possible icon using (Icon icon = new Icon(IconO, 256, 256)) { // convert to bitmap using (Bitmap IconPic = Orbit.Utilities.ImageHelper.GetBitmapFromIcon(icon)) { // setting it to be the icon this.SetIcon(IconPic); } } } } catch (Exception) { this.CannotLoadIcon(); } } // don't forget to destroy the handle to the other icon Win32.User32.User32API.DestroyIcon(FileInfo.hIcon); } catch (Exception) { throw; } }
private void LoadFromPhysicalFile(string Path) { try { // Loading item file and creating new item object // get extra information on this file that the System.IO.FileInfo doesn't give us Win32.Shell32.SHFileInfo FileInfo = new Win32.Shell32.SHFileInfo(); Win32.Shell32.Shell32API.SHGetFileInfo(Path, 0, ref FileInfo, (uint)System.Runtime.InteropServices.Marshal.SizeOf(FileInfo), Win32.Shell32.ShellGetFileInfoFlags.DisplayName | Win32.Shell32.ShellGetFileInfoFlags.FileTypeName | Win32.Shell32.ShellGetFileInfoFlags.LargeIcon | Win32.Shell32.ShellGetFileInfoFlags.Icon); // set the item name to the file name this.Name = FileInfo.szDisplayName; // set the item description to the file type this.Description = FileInfo.szTypeName; // keep the path value this._Path = Path; // NON EXISTANT IN NEW CLASS //this.ItemPath=Path.Substring(0, Path.Length-(Path.Length-Path.LastIndexOf("\\")))+"\\"; // setting properties // NON EXISTANT IN NEW CLASS //this.Line=Line; // NON EXISTANT IN NEW CLASS //this.ColorKey=Color.FromArgb(0, Color.White); // Adding new Texture to registry // checking if it has a custom Icon string ExtensionImage = ""; //string ToggledExtensionImage=""; // get the file extension string Extension = System.IO.Path.GetExtension(Path); // get the filename of the supposed image for this extension string ExtensionFileName = Extension.Replace(".", "").ToLower() + ".png"; // get the path for that file ExtensionImage = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), @"extensions\" + ExtensionFileName); // if the file exists, assign it to be the image // else, load its default filetype icon if (System.IO.File.Exists(ExtensionImage)) { if (OrbitTextureCache.IsInCache(ExtensionImage)) { this.SetIcon(OrbitTextureCache.GetReference(ExtensionImage)); } else { SetIcon(ExtensionImage); OrbitTextureCache.InsertInCache(this._Icon, ExtensionImage); } //SetIcon(ExtensionImage); } else { string textureId = System.IO.Path.GetExtension(Path); if (textureId.ToLower() != ".lnk" && OrbitTextureCache.IsInCache(textureId)) { this.SetIcon(OrbitTextureCache.GetReference(textureId)); } else { try { // getting the handle to the icon from the SHFileInfo structure using (Icon IconO = Icon.FromHandle(FileInfo.hIcon)) { // create the biggest possible icon using (Icon icon = new Icon(IconO, 128, 128)) { // convert to bitmap using (Bitmap IconPic = Orbit.Utilities.ImageHelper.GetBitmapFromIcon(icon)) { // setting it to be the icon this.SetIcon(IconPic); //this.SetOverlay(IconPic); // overlay not needed anymore. will use standard icon } } } } catch (Exception) { this.CannotLoadIcon(); } if (textureId.ToLower() != ".lnk") { OrbitTextureCache.InsertInCache(this._Icon, textureId); } } } // don't forget to destroy the handle to the other icon Win32.User32.User32API.DestroyIcon(FileInfo.hIcon); } catch (Exception) { throw; } }