Merge branch 'master' into dotnet45

This commit is contained in:
bao-qian
2015-11-12 22:02:40 +00:00
60 changed files with 1717 additions and 671 deletions

View File

@@ -1,163 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Microsoft.Win32;
namespace Wox.Core.Exception
{
public class ExceptionFormatter
{
public static string FormatExcpetion(System.Exception exception)
{
return CreateExceptionReport(exception);
}
private static string CreateExceptionReport(System.Exception ex)
{
var sb = new StringBuilder();
sb.AppendLine();
sb.AppendLine("## Exception");
sb.AppendLine();
sb.AppendLine("```");
var exlist = new List<StringBuilder>();
while (ex != null)
{
var exsb = new StringBuilder();
exsb.Append(ex.GetType().FullName);
exsb.Append(": ");
exsb.AppendLine(ex.Message);
if (ex.Source != null)
{
exsb.Append(" Source: ");
exsb.AppendLine(ex.Source);
}
if (ex.TargetSite != null)
{
exsb.Append(" TargetAssembly: ");
exsb.AppendLine(ex.TargetSite.Module.Assembly.ToString());
exsb.Append(" TargetModule: ");
exsb.AppendLine(ex.TargetSite.Module.ToString());
exsb.Append(" TargetSite: ");
exsb.AppendLine(ex.TargetSite.ToString());
}
exsb.AppendLine(ex.StackTrace);
exlist.Add(exsb);
ex = ex.InnerException;
}
foreach (var result in exlist.Select(o => o.ToString()).Reverse())
{
sb.AppendLine(result);
}
sb.AppendLine("```");
sb.AppendLine();
sb.AppendLine("## Environment");
sb.AppendLine();
sb.Append("* Command Line: ");
sb.AppendLine(Environment.CommandLine);
sb.Append("* Timestamp: ");
sb.AppendLine(XmlConvert.ToString(DateTime.Now));
sb.Append("* IntPtr Length: ");
sb.AppendLine(IntPtr.Size.ToString());
sb.Append("* System Version: ");
sb.AppendLine(Environment.OSVersion.VersionString);
sb.Append("* CLR Version: ");
sb.AppendLine(Environment.Version.ToString());
sb.AppendLine("* Installed .NET Framework: ");
foreach (var result in GetFrameworkVersionFromRegistry())
{
sb.Append(" * ");
sb.AppendLine(result);
}
sb.AppendLine();
sb.AppendLine("## Assemblies - " + AppDomain.CurrentDomain.FriendlyName);
sb.AppendLine();
foreach (var ass in AppDomain.CurrentDomain.GetAssemblies().OrderBy(o => o.GlobalAssemblyCache ? 50 : 0))
{
sb.Append("* ");
sb.Append(ass.FullName);
sb.Append(" (");
sb.Append(string.IsNullOrEmpty(ass.Location) ? "not supported" : ass.Location);
sb.AppendLine(")");
}
return sb.ToString();
}
// http://msdn.microsoft.com/en-us/library/hh925568%28v=vs.110%29.aspx
private static List<string> GetFrameworkVersionFromRegistry()
{
try
{
var result = new List<string>();
using (RegistryKey ndpKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\"))
{
foreach (string versionKeyName in ndpKey.GetSubKeyNames())
{
if (versionKeyName.StartsWith("v"))
{
RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName);
string name = (string)versionKey.GetValue("Version", "");
string sp = versionKey.GetValue("SP", "").ToString();
string install = versionKey.GetValue("Install", "").ToString();
if (install != "")
if (sp != "" && install == "1")
result.Add(string.Format("{0} {1} SP{2}", versionKeyName, name, sp));
else
result.Add(string.Format("{0} {1}", versionKeyName, name));
if (name != "")
{
continue;
}
foreach (string subKeyName in versionKey.GetSubKeyNames())
{
RegistryKey subKey = versionKey.OpenSubKey(subKeyName);
name = (string)subKey.GetValue("Version", "");
if (name != "")
sp = subKey.GetValue("SP", "").ToString();
install = subKey.GetValue("Install", "").ToString();
if (install != "")
{
if (sp != "" && install == "1")
result.Add(string.Format("{0} {1} {2} SP{3}", versionKeyName, subKeyName, name, sp));
else if (install == "1")
result.Add(string.Format("{0} {1} {2}", versionKeyName, subKeyName, name));
}
}
}
}
}
using (RegistryKey ndpKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"))
{
int releaseKey = (int)ndpKey.GetValue("Release");
{
if (releaseKey == 378389)
result.Add("v4.5");
if (releaseKey == 378675)
result.Add("v4.5.1 installed with Windows 8.1");
if (releaseKey == 378758)
result.Add("4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2");
}
}
return result;
}
catch (System.Exception e)
{
return new List<string>();
}
}
}
}

View File

@@ -1,12 +0,0 @@
namespace Wox.Core.Exception
{
/// <summary>
/// Represent exceptions that wox can't handle and MUST close running Wox.
/// </summary>
public class WoxCritialException : WoxException
{
public WoxCritialException(string msg) : base(msg)
{
}
}
}

View File

@@ -1,20 +0,0 @@
namespace Wox.Core.Exception
{
/// <summary>
/// Base Wox Exceptions
/// </summary>
public class WoxException : System.Exception
{
public WoxException(string msg)
: base(msg)
{
}
public WoxException(string msg, System.Exception innerException)
: base(msg, innerException)
{
}
}
}

View File

@@ -1,9 +0,0 @@
namespace Wox.Core.Exception
{
public class WoxHttpException :WoxException
{
public WoxHttpException(string msg) : base(msg)
{
}
}
}

View File

@@ -1,9 +0,0 @@
namespace Wox.Core.Exception
{
public class WoxI18nException:WoxException
{
public WoxI18nException(string msg) : base(msg)
{
}
}
}

View File

@@ -1,10 +0,0 @@
namespace Wox.Core.Exception
{
public class WoxJsonRPCException : WoxException
{
public WoxJsonRPCException(string msg)
: base(msg)
{
}
}
}

View File

@@ -1,13 +0,0 @@
namespace Wox.Core.Exception
{
public class WoxPluginException : WoxException
{
public string PluginName { get; set; }
public WoxPluginException(string pluginName,System.Exception e)
: base(e.Message,e)
{
PluginName = pluginName;
}
}
}

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Wox.Infrastructure.Exception;
using Wox.Infrastructure.Logger;
using Wox.Plugin;
@@ -19,10 +20,10 @@ namespace Wox.Core.Plugin
try
{
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IPlugin))).ToList();
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IPlugin))).ToList();
if (types.Count == 0)
{
Log.Warn(string.Format("Couldn't load plugin {0}: didn't find the class that implement IPlugin", metadata.Name));
Log.Warn($"Couldn't load plugin {metadata.Name}: didn't find the class that implement IPlugin");
continue;
}
@@ -39,12 +40,7 @@ namespace Wox.Core.Plugin
}
catch (System.Exception e)
{
Log.Error(string.Format("Couldn't load plugin {0}: {1}", metadata.Name, e.Message));
#if (DEBUG)
{
throw;
}
#endif
Log.Error(new WoxPluginException(metadata.Name, $"Couldn't load plugin", e));
}
}

View File

@@ -5,7 +5,7 @@ using System.Reflection;
using System.Threading;
using System.Windows.Forms;
using Newtonsoft.Json;
using Wox.Core.Exception;
using Wox.Infrastructure.Exception;
using Wox.Infrastructure.Logger;
using Wox.Plugin;
@@ -74,7 +74,7 @@ namespace Wox.Core.Plugin
}
catch (System.Exception e)
{
Log.Error(e.Message);
Log.Error(e);
}
}
return null;

View File

@@ -2,8 +2,8 @@
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using Wox.Core.Exception;
using Wox.Core.UserSettings;
using Wox.Infrastructure.Exception;
using Wox.Infrastructure.Logger;
using Wox.Plugin;
@@ -47,7 +47,7 @@ namespace Wox.Core.Plugin
}
catch (System.Exception e)
{
Log.Error(ExceptionFormatter.FormatExcpetion(e));
Log.Fatal(e);
}
}
PluginMetadata metadata = GetPluginMetadata(directory);
@@ -63,7 +63,7 @@ namespace Wox.Core.Plugin
string configPath = Path.Combine(pluginDirectory, pluginConfigName);
if (!File.Exists(configPath))
{
Log.Warn(string.Format("parse plugin {0} failed: didn't find config file.", configPath));
Log.Warn($"parse plugin {configPath} failed: didn't find config file.");
return null;
}
@@ -77,40 +77,25 @@ namespace Wox.Core.Plugin
// for plugin still use old ActionKeyword
metadata.ActionKeyword = metadata.ActionKeywords?[0];
}
catch (System.Exception)
catch (System.Exception e)
{
string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath);
Log.Warn(error);
#if (DEBUG)
{
throw new WoxException(error);
}
#endif
string msg = $"Parse plugin config {configPath} failed: json format is not valid";
Log.Error(new WoxException(msg));
return null;
}
if (!AllowedLanguage.IsAllowed(metadata.Language))
{
string error = string.Format("Parse plugin config {0} failed: invalid language {1}", configPath, metadata.Language);
Log.Warn(error);
#if (DEBUG)
{
throw new WoxException(error);
}
#endif
string msg = $"Parse plugin config {configPath} failed: invalid language {metadata.Language}";
Log.Error(new WoxException(msg));
return null;
}
if (!File.Exists(metadata.ExecuteFilePath))
{
string error = string.Format("Parse plugin config {0} failed: ExecuteFile {1} didn't exist", configPath, metadata.ExecuteFilePath);
Log.Warn(error);
#if (DEBUG)
{
throw new WoxException(error);
}
#endif
string msg = $"Parse plugin config {configPath} failed: ExecuteFile {metadata.ExecuteFilePath} didn't exist";
Log.Error(new WoxException(msg));
return null;
}

View File

@@ -4,13 +4,13 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using Wox.Core.Exception;
using Wox.Core.i18n;
using Wox.Core.UI;
using Wox.Core.UserSettings;
using Wox.Infrastructure;
using Wox.Infrastructure.Exception;
using Wox.Infrastructure.Logger;
using Wox.Plugin;
using Stopwatch = Wox.Infrastructure.Stopwatch;
namespace Wox.Core.Plugin
{
@@ -30,7 +30,7 @@ namespace Wox.Core.Plugin
public static IEnumerable<PluginPair> AllPlugins { get; private set; }
public static List<PluginPair> GlobalPlugins { get; } = new List<PluginPair>();
public static Dictionary<string, PluginPair> NonGlobalPlugins { get; } = new Dictionary<string, PluginPair>();
public static Dictionary<string, PluginPair> NonGlobalPlugins { get; set; } = new Dictionary<string, PluginPair>();
private static IEnumerable<PluginPair> InstantQueryPlugins { get; set; }
public static IPublicAPI API { private set; get; }
@@ -56,9 +56,9 @@ namespace Wox.Core.Plugin
{
Directory.CreateDirectory(pluginDirectory);
}
catch (System.Exception e)
catch (Exception e)
{
Log.Error(e.Message);
Log.Error(e);
}
}
}
@@ -69,7 +69,7 @@ namespace Wox.Core.Plugin
/// </summary>
public static void Init(IPublicAPI api)
{
if (api == null) throw new WoxCritialException("api is null");
if (api == null) throw new WoxFatalException("api is null");
SetupPluginDirectories();
API = api;
@@ -164,7 +164,7 @@ namespace Wox.Core.Plugin
if (customizedPluginConfig != null && customizedPluginConfig.Disabled) continue;
if (IsInstantQueryPlugin(plugin))
{
Stopwatch.Debug($"Instant Query for {plugin.Metadata.Name}", () =>
Stopwatch.Normal($"Instant QueryForPlugin for {plugin.Metadata.Name}", () =>
{
QueryForPlugin(plugin, query);
});
@@ -173,7 +173,10 @@ namespace Wox.Core.Plugin
{
ThreadPool.QueueUserWorkItem(state =>
{
QueryForPlugin(plugin, query);
Stopwatch.Normal($"Normal QueryForPlugin for {plugin.Metadata.Name}", () =>
{
QueryForPlugin(plugin, query);
});
});
}
}
@@ -184,7 +187,7 @@ namespace Wox.Core.Plugin
try
{
List<Result> results = new List<Result>();
var milliseconds = Stopwatch.Normal($"Query for {pair.Metadata.Name}", () =>
var milliseconds = Stopwatch.Normal($"Plugin.Query cost for {pair.Metadata.Name}", () =>
{
results = pair.Plugin.Query(query) ?? results;
results.ForEach(o => { o.PluginID = pair.Metadata.ID; });
@@ -193,9 +196,9 @@ namespace Wox.Core.Plugin
pair.AvgQueryTime = pair.QueryCount == 1 ? milliseconds : (pair.AvgQueryTime + milliseconds) / 2;
API.PushResults(query, pair.Metadata, results);
}
catch (System.Exception e)
catch (Exception e)
{
throw new WoxPluginException(pair.Metadata.Name, e);
throw new WoxPluginException(pair.Metadata.Name, $"QueryForPlugin failed", e);
}
}
@@ -237,18 +240,66 @@ namespace Wox.Core.Plugin
{
return plugin.LoadContextMenus(result);
}
catch (System.Exception e)
catch (Exception e)
{
Log.Error($"Couldn't load plugin context menus {pluginPair.Metadata.Name}: {e.Message}");
#if (DEBUG)
{
throw;
}
#endif
Log.Error(new WoxPluginException(pluginPair.Metadata.Name, $"Couldn't load plugin context menus", e));
}
}
return new List<Result>();
}
public static void UpdateActionKeywordForPlugin(PluginPair plugin, string oldActionKeyword, string newActionKeyword)
{
var actionKeywords = plugin.Metadata.ActionKeywords;
if (string.IsNullOrEmpty(newActionKeyword))
{
string msg = InternationalizationManager.Instance.GetTranslation("newActionKeywordsCannotBeEmpty");
throw new WoxPluginException(plugin.Metadata.Name, msg);
}
if (NonGlobalPlugins.ContainsKey(newActionKeyword))
{
string msg = InternationalizationManager.Instance.GetTranslation("newActionKeywordsHasBeenAssigned");
throw new WoxPluginException(plugin.Metadata.Name, msg);
}
// add new action keyword
if (string.IsNullOrEmpty(oldActionKeyword))
{
actionKeywords.Add(newActionKeyword);
if (newActionKeyword == Query.GlobalPluginWildcardSign)
{
GlobalPlugins.Add(plugin);
}
else
{
NonGlobalPlugins[newActionKeyword] = plugin;
}
}
// update existing action keyword
else
{
int index = actionKeywords.IndexOf(oldActionKeyword);
actionKeywords[index] = newActionKeyword;
if (oldActionKeyword == Query.GlobalPluginWildcardSign)
{
GlobalPlugins.Remove(plugin);
}
else
{
NonGlobalPlugins.Remove(oldActionKeyword);
}
if (newActionKeyword == Query.GlobalPluginWildcardSign)
{
GlobalPlugins.Add(plugin);
}
else
{
NonGlobalPlugins[newActionKeyword] = plugin;
}
}
}
}
}

View File

@@ -35,7 +35,7 @@ namespace Wox.Core.Theme
}
catch (System.Exception e)
{
Log.Error(e.Message);
Log.Error(e);
}
}
}

View File

@@ -1,5 +1,5 @@
using System;
using Wox.Core.Exception;
using Wox.Infrastructure.Exception;
namespace Wox.Core.Updater
{

View File

@@ -2,9 +2,11 @@
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using Newtonsoft.Json;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
namespace Wox.Core.UserSettings
{
@@ -118,7 +120,7 @@ namespace Wox.Core.UserSettings
public void IncreaseActivateTimes()
{
ActivateTimes++;
if (ActivateTimes%15 == 0)
if (ActivateTimes % 15 == 0)
{
Save();
}
@@ -162,6 +164,26 @@ namespace Wox.Core.UserSettings
storage.Language = "en";
}
}
public void UpdateActionKeyword(PluginMetadata metadata)
{
var customizedPluginConfig = CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID);
if (customizedPluginConfig == null)
{
CustomizedPluginConfigs.Add(new CustomizedPluginConfig()
{
Disabled = false,
ID = metadata.ID,
Name = metadata.Name,
ActionKeywords = metadata.ActionKeywords
});
}
else
{
customizedPluginConfig.ActionKeywords = metadata.ActionKeywords;
}
Save();
}
}
public enum OpacityMode

View File

@@ -27,7 +27,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<OutputPath>..\Output\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
@@ -58,13 +58,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="APIServer.cs" />
<Compile Include="Exception\ExceptionFormatter.cs" />
<Compile Include="Exception\WoxCritialException.cs" />
<Compile Include="Exception\WoxException.cs" />
<Compile Include="Exception\WoxHttpException.cs" />
<Compile Include="Exception\WoxI18nException.cs" />
<Compile Include="Exception\WoxJsonRPCException.cs" />
<Compile Include="Exception\WoxPluginException.cs" />
<Compile Include="Updater\Release.cs" />
<Compile Include="Updater\UpdaterManager.cs" />
<Compile Include="Updater\WoxUpdateSource.cs" />

View File

@@ -4,9 +4,9 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using Wox.Core.Exception;
using Wox.Core.UI;
using Wox.Core.UserSettings;
using Wox.Infrastructure.Exception;
using Wox.Infrastructure.Logger;
using Wox.Plugin;
@@ -32,7 +32,7 @@ namespace Wox.Core.i18n
}
catch (System.Exception e)
{
Log.Error(e.Message);
Log.Error(e);
}
}
}
@@ -122,12 +122,8 @@ namespace Wox.Core.i18n
}
catch (System.Exception e)
{
Log.Warn("Update Plugin metadata translation failed:" + e.Message);
#if (DEBUG)
{
throw;
}
#endif
var woxPluginException = new WoxPluginException(pluginPair.Metadata.Name, "Update Plugin metadata translation failed:", e);
Log.Error(woxPluginException);
}
}