From a5d63bc3839d260c1464e2690c0ed857493b861b Mon Sep 17 00:00:00 2001 From: Coenraad Stijne Date: Sat, 19 Jul 2014 12:39:26 +0200 Subject: [PATCH 1/4] Control Panel Split Logic --- .../ControlPanel/ControlPanelList.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs index acbb4b37e6..f60d1b587f 100644 --- a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs +++ b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs @@ -121,7 +121,7 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel if (currentKey.GetValue("LocalizedString") != null) { - localizedStringRaw = currentKey.GetValue("LocalizedString").ToString().Split(new char[] { ',' }, 2); + localizedStringRaw = currentKey.GetValue("LocalizedString").ToString().Split(new string[] { ",-" }, StringSplitOptions.None); if (localizedStringRaw.Length > 1) { @@ -142,9 +142,7 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel localizedString = resource.ToString(); - /*This shouldn't be necessary, but some apps (e.g. Bootcamp) - * don't follow Microsoft's standard. Have to make a choice whether - * empty string == failure, or use default name. I'm using default name */ + //Some apps don't return a string, although they do have a stringIndex. Use Default value. if (String.IsNullOrEmpty(localizedString)) { @@ -184,7 +182,7 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel if (currentKey.GetValue("InfoTip") != null) { - infoTipRaw = currentKey.GetValue("InfoTip").ToString().Split(new char[] { ',' }, 2); + infoTipRaw = currentKey.GetValue("InfoTip").ToString().Split(new string[] { ",-" }, StringSplitOptions.None); if (infoTipRaw.Length == 2) { @@ -204,6 +202,10 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel infoTip = resource.ToString(); } + else + { + infoTip = currentKey.GetValue("InfoTip").ToString(); + } } else { @@ -298,12 +300,10 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel args = args.Remove(x); } - uint size; - if (uint.TryParse(args, out size)) - { - return size; - } - return 0; + /*If the logic is correct, this should never through an exception. + * If there is an exception, then need to analyze what the input is. + * Returning the wrong number will cause more errors */ + return Convert.ToUInt32(args); } private static bool IS_INTRESOURCE(IntPtr value) From 10204a4526c4026954eaecf5c580151392a51a01 Mon Sep 17 00:00:00 2001 From: Coenraad Stijne Date: Sat, 19 Jul 2014 14:31:19 +0200 Subject: [PATCH 2/4] Save icons using GUID filename --- Wox.Plugin.SystemPlugins/ControlPanel/ControlPanel.cs | 6 +++--- Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelItem.cs | 4 +++- Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanel.cs b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanel.cs index e2af713e16..ba3bf828bb 100644 --- a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanel.cs +++ b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanel.cs @@ -51,9 +51,9 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel foreach (ControlPanelItem item in controlPanelItems) { - if (!File.Exists(iconFolder + item.LocalizedString + fileType) && item.Icon != null) + if (!File.Exists(iconFolder + item.GUID + fileType) && item.Icon != null) { - item.Icon.ToBitmap().Save(iconFolder + item.LocalizedString + fileType); + item.Icon.ToBitmap().Save(iconFolder + item.GUID + fileType); } } } @@ -75,7 +75,7 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel Title = item.LocalizedString, SubTitle = item.InfoTip, Score = item.Score, - IcoPath = "Images\\ControlPanelIcons\\" + item.LocalizedString + fileType, + IcoPath = "Images\\ControlPanelIcons\\" + item.GUID + fileType, Action = e => { try diff --git a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelItem.cs b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelItem.cs index faceb6481d..6d76e269a0 100644 --- a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelItem.cs +++ b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelItem.cs @@ -8,16 +8,18 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel { public string LocalizedString { get; private set; } public string InfoTip { get; private set; } + public string GUID { get; private set; } public ProcessStartInfo ExecutablePath { get; private set; } public Icon Icon { get; private set; } public int Score { get; set; } - public ControlPanelItem(string newLocalizedString, string newInfoTip, ProcessStartInfo newExecutablePath, Icon newIcon) + public ControlPanelItem(string newLocalizedString, string newInfoTip, string newGUID, ProcessStartInfo newExecutablePath, Icon newIcon) { LocalizedString = newLocalizedString; InfoTip = newInfoTip; ExecutablePath = newExecutablePath; Icon = newIcon; + GUID = newGUID; } } } diff --git a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs index f60d1b587f..11f824add7 100644 --- a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs +++ b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs @@ -78,7 +78,7 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel myIcon = getIcon(currentKey, size); - controlPanelItems.Add(new ControlPanelItem(localizedString, infoTip, executablePath, myIcon)); + controlPanelItems.Add(new ControlPanelItem(localizedString, infoTip, key, executablePath, myIcon)); } } From 60df4995842ef112717bdc4fe18540c61b854c65 Mon Sep 17 00:00:00 2001 From: Coenraad Stijne Date: Sat, 19 Jul 2014 15:34:52 +0200 Subject: [PATCH 3/4] Better icon-handeling. And enumerate through ICON instead of GROUP_ICON --- .../ControlPanel/ControlPanelList.cs | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs index 11f824add7..12999293f7 100644 --- a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs +++ b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs @@ -243,31 +243,32 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel iconIndex = (IntPtr)sanitizeUint(iconString[1]); - if (iconIndex == IntPtr.Zero) + iconPtr = LoadImage(dataFilePointer, iconIndex, 1, iconSize, iconSize, 0); + + if (iconPtr == IntPtr.Zero) { iconQueue = new Queue(); - EnumResourceNamesWithID(dataFilePointer, GROUP_ICON, new EnumResNameDelegate(EnumRes), IntPtr.Zero); //Iterate through resources. + EnumResourceNamesWithID(dataFilePointer, 3, new EnumResNameDelegate(EnumRes), IntPtr.Zero); //Iterate through resources. while (iconPtr == IntPtr.Zero && iconQueue.Count > 0) { iconPtr = LoadImage(dataFilePointer, iconQueue.Dequeue(), 1, iconSize, iconSize, 0); } } - else - { - iconPtr = LoadImage(dataFilePointer, iconIndex, 1, iconSize, iconSize, 0); - } FreeLibrary(dataFilePointer); - try + if (iconPtr != IntPtr.Zero) { - myIcon = Icon.FromHandle(iconPtr); - myIcon = (Icon)myIcon.Clone(); //Remove pointer dependancy. - } - catch - { - //Silently fail for now.. + try + { + myIcon = Icon.FromHandle(iconPtr); + myIcon = (Icon)myIcon.Clone(); //Remove pointer dependancy. + } + catch + { + //Silently fail for now. + } } } } From a72d1a13b697a890d0ee4c0e204490054115cba7 Mon Sep 17 00:00:00 2001 From: Coenraad Stijne Date: Sat, 19 Jul 2014 18:14:31 +0200 Subject: [PATCH 4/4] Better path handeling Thanks @orzFly --- .../ControlPanel/ControlPanelList.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs index 12999293f7..b2c0153702 100644 --- a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs +++ b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs @@ -101,7 +101,20 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel else if (currentKey.OpenSubKey("Shell\\Open\\Command") != null && currentKey.OpenSubKey("Shell\\Open\\Command").GetValue(null) != null) { //Other files (usually third party items) - executablePath.FileName = Environment.ExpandEnvironmentVariables(currentKey.OpenSubKey("Shell\\Open\\Command").GetValue(null).ToString()); + string value = Environment.ExpandEnvironmentVariables(currentKey.OpenSubKey("Shell\\Open\\Command").GetValue(null).ToString()); + + if (value[0] == '"') + { + for (int x = 1; x < value.Length && value[x] != '"'; x++) + { + executablePath.FileName += value[x]; + } + executablePath.Arguments = value.Remove(0, executablePath.FileName.Length + 2).Trim(); + } + else + { + executablePath.FileName = value; + } } else {