public static String RetrieveAssociatedIcon([NotNull] String extensionOrFileOrProtocol, [CanBeNull] out Int32?identifier, out IconIdentifierType identifierType) { if (String.IsNullOrWhiteSpace(extensionOrFileOrProtocol)) { throw new ArgumentNullException(nameof(extensionOrFileOrProtocol)); } identifier = null; identifierType = IconIdentifierType.Unknown; // Special case: The result buffer contains "%1". We treat this case like: "oh hey, your supplied file path is already the file containing the icon!". var result = SafeNativeMethods.AssocQueryString(extensionOrFileOrProtocol, NativeMethods.ASSOCSTR.ASSOCSTR_DEFAULTICON); if (result == "%1") { return(String.Empty); } if (result.IndexOf(',') == -1) { identifier = 0; identifierType = IconIdentifierType.Index; return(result); } Int32 extractedIdentifier; var file = NativeResourceDescriptor.SplitResourceString(result, out extractedIdentifier); identifier = extractedIdentifier; identifierType = IconIdentifier.Identify(extractedIdentifier); return(file); }
public static NativeResourceDescriptor ParseFromResourceString(String resourceString) { try { Int32 identifier; var file = NativeResourceDescriptor.SplitResourceString(resourceString, out identifier); return(new NativeResourceDescriptor(file, (UInt32)Math.Abs(identifier))); } catch (Exception ex) { throw new InvalidOperationException($"Cannot parse '{resourceString}' to NativeResourceDescriptor.", ex); } }