/// <summary> /// Gets file icon as <b>Bitmap</b>. /// Returns null if the icon is not cached and failed to get it, eg file does not exist. /// </summary> /// <param name="file">Any file or folder.</param> /// <param name="useExt"> /// Get file type icon, depending on filename extension. Use this to avoid getting separate image object for each file of same type. /// This is ignored if filename extension is ".ico" or ".exe" or starts with ".exe," or ".dll,". /// </param> /// <param name="giFlags">Flags for <see cref="AIcon.GetFileIconImage"/>.</param> /// <param name="autoUpdate"> /// If not null, the cached image will be auto-updated when changed. Then will be called this function. It can update the image in UI. /// How it works: If this function finds cached image, it sets timer that after ~50 ms loads that icon/image from file again and compares with the cached image. If different, updates the cache. Does it once, not periodically. /// Use only in UI threads. Does not work if this thread does not retrieve/dispatch posted messages. /// </param> /// <param name="auParam">Something to pass to the <i>autoUpdate</i> callback function.</param> /// <remarks> /// If the icon is in the memory cache, gets it from there. /// Else if it is in the file cache, gets it from there and adds to the memory cache. /// Else gets from file (uses <see cref="AIcon.GetFileIconImage"/> and adds to the file cache and to the memory cache. /// </remarks> public Bitmap GetImage(string file, bool useExt, IconGetFlags giFlags = 0, Action <Bitmap, object> autoUpdate = null, object auParam = null) { if (useExt) { var ext = APath.GetExtension(file); if (ext.Length == 0) { if (AFile.ExistsAsDirectory(file)) { ext = file; } else { ext = ".no-ext"; } } else { //ext = ext.Lower(); if (ext.Eqi(".ico") || ext.Eqi(".exe") || ext.Starts(".exe,", true) || ext.Starts(".dll,", true)) { ext = file; } } file = ext; } else if (APath.IsFullPathExpandEnvVar(ref file)) { file = APath.Normalize_(file, noExpandEV: true); } return(_GetImage(file, giFlags, null, autoUpdate, auParam, true)); }
/// <summary> /// Gets file path extension like ".txt" or URL protocol like "http". /// Returns null if path does not end with ".extension" and does not start with "protocol:"; also if starts with "shell:". /// </summary> /// <param name="path">File path or URL. Can be just extension like ".txt" or protocol like "http:".</param> /// <param name="isProtocol">Receives true if URL or protocol.</param> internal static string GetExtensionOrProtocol(string path, out bool isProtocol) { isProtocol = false; if (path.NE()) { return(null); } if (!PathIsExtension(path)) { int i = path.IndexOf(':'); if (i > 1) { path = path.Remove(i); //protocol if (path == "shell") { return(null); //eg "shell:AppsFolder\Microsoft.WindowsCalculator_8wekyb3d8bbwe!App" } isProtocol = true; } else { path = APath.GetExtension(path); if (path.NE()) { return(null); } } } return(path); }