From a972a52be4ca42b3a2f53686320005dd96fbb6ef Mon Sep 17 00:00:00 2001 From: CoenraadS Date: Tue, 22 Jul 2014 13:30:39 +0200 Subject: [PATCH] Optimize default icon method. Simply return the first pointer, ignore the others. Assume if the first one doesn't work, none of them will work. --- .../ControlPanel/ControlPanelList.cs | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs index d32b77a24f..9f3fbcfcbb 100644 --- a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs +++ b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs @@ -43,7 +43,7 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel [DllImport("kernel32.dll")] static extern IntPtr FindResource(IntPtr hModule, IntPtr lpName, IntPtr lpType); - static Queue iconQueue; + static IntPtr defaultIconPtr; static RegistryKey nameSpace = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace"); @@ -237,25 +237,19 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel dataFilePointer = LoadLibraryEx(iconString[0], IntPtr.Zero, LOAD_LIBRARY_AS_DATAFILE); - if (iconString.Count < 2) + if (iconString.Count == 2) { - iconString.Add("0"); + iconIndex = (IntPtr)sanitizeUint(iconString[1]); + + iconPtr = LoadImage(dataFilePointer, iconIndex, 1, iconSize, iconSize, 0); } - - iconIndex = (IntPtr)sanitizeUint(iconString[1]); - - iconPtr = LoadImage(dataFilePointer, iconIndex, 1, iconSize, iconSize, 0); - if (iconPtr == IntPtr.Zero) { - iconQueue = new Queue(); + defaultIconPtr = IntPtr.Zero; EnumResourceNamesWithID(dataFilePointer, GROUP_ICON, new EnumResNameDelegate(EnumRes), IntPtr.Zero); //Iterate through resources. - while (iconPtr == IntPtr.Zero && iconQueue.Count > 0) - { - iconPtr = LoadImage(dataFilePointer, iconQueue.Dequeue(), 1, iconSize, iconSize, 0); - } + iconPtr = LoadImage(dataFilePointer, defaultIconPtr, 1, iconSize, iconSize, 0); } FreeLibrary(dataFilePointer); @@ -334,8 +328,8 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel { //Debug.WriteLine("Type: " + GET_RESOURCE_NAME(lpszType)); //Debug.WriteLine("Name: " + GET_RESOURCE_NAME(lpszName)); - iconQueue.Enqueue(lpszName); - return true; + defaultIconPtr = lpszName; + return false; } } }