This commit is contained in:
qianlifeng
2015-01-28 10:16:10 +08:00
20 changed files with 184 additions and 100 deletions

View File

@@ -1,23 +0,0 @@
echo "start clean"
cd /d %~dp0
REM Clean Plugins
echo "clean plugins"
cd ..\Output\Release\Plugins
del NLog.dll /s
del NLog.config /s
del Wox.Plugin.pdb /s
del Wox.Plugin.dll /s
del Wox.Core.dll /s
del Wox.Core.pdb /s
del ICSharpCode.SharpZipLib.dll /s
del NAppUpdate.Framework.dll /s
del Wox.Infrastructure.dll /s
del Wox.Infrastructure.pdb /s
del Newtonsoft.Json.dll /s
del WindowsInput.dll /s
REM Clean Wox
echo "wox"
cd ..
del *.xml

View File

@@ -6,12 +6,13 @@ using System.Reflection;
using System.Windows.Forms; using System.Windows.Forms;
using WindowsInput; using WindowsInput;
using WindowsInput.Native; using WindowsInput.Native;
using Wox.Infrastructure;
using Wox.Infrastructure.Hotkey; using Wox.Infrastructure.Hotkey;
using Control = System.Windows.Controls.Control; using Control = System.Windows.Controls.Control;
namespace Wox.Plugin.CMD namespace Wox.Plugin.CMD
{ {
public class CMD : IPlugin, ISettingProvider, IPluginI18n public class CMD : IPlugin, ISettingProvider, IPluginI18n, IInstantSearch
{ {
private PluginInitContext context; private PluginInitContext context;
private bool WinRStroked; private bool WinRStroked;
@@ -37,6 +38,7 @@ namespace Wox.Plugin.CMD
context.API.PushResults(query, context.CurrentPluginMetadata, history); context.API.PushResults(query, context.CurrentPluginMetadata, history);
pushedResults.AddRange(history); pushedResults.AddRange(history);
try try
{ {
string basedir = null; string basedir = null;
@@ -72,6 +74,7 @@ namespace Wox.Plugin.CMD
} }
} }
catch (Exception) { } catch (Exception) { }
} }
return results; return results;
} }
@@ -207,5 +210,11 @@ namespace Wox.Plugin.CMD
{ {
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"); return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages");
} }
public bool IsInstantSearch(string query)
{
if (query.StartsWith(">")) return true;
return false;
}
} }
} }

View File

@@ -36,9 +36,9 @@
<StartupObject /> <StartupObject />
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Newtonsoft.Json"> <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath> <SpecificVersion>False</SpecificVersion>
<Private>True</Private> <HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="System" /> <Reference Include="System" />
@@ -82,6 +82,7 @@
<Content Include="Images\warning.png"> <Content Include="Images\warning.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<None Include="packages.config" />
<None Include="PortableEverything\Everything.exe"> <None Include="PortableEverything\Everything.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
@@ -93,7 +94,6 @@
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" />
<None Include="plugin.json"> <None Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>

Binary file not shown.

View File

@@ -9,7 +9,7 @@ using Wox.Plugin.WebSearch.SuggestionSources;
namespace Wox.Plugin.WebSearch namespace Wox.Plugin.WebSearch
{ {
public class WebSearchPlugin : IPlugin, ISettingProvider,IPluginI18n public class WebSearchPlugin : IPlugin, ISettingProvider, IPluginI18n, IInstantSearch
{ {
private PluginInitContext context; private PluginInitContext context;
@@ -97,5 +97,16 @@ namespace Wox.Plugin.WebSearch
{ {
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"); return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages");
} }
public bool IsInstantSearch(string query)
{
var strings = query.Split(' ');
if (strings.Length > 1)
{
return WebSearchStorage.Instance.EnableWebSearchSuggestion &&
WebSearchStorage.Instance.WebSearches.Exists(o => o.ActionWord == strings[0] && o.Enabled);
}
return false;
}
} }
} }

View File

@@ -20,6 +20,9 @@ namespace Wox.Core.Plugin
public static class PluginManager public static class PluginManager
{ {
public const string ActionKeywordWildcardSign = "*"; public const string ActionKeywordWildcardSign = "*";
private static List<PluginMetadata> pluginMetadatas;
private static List<IInstantSearch> instantSearches = new List<IInstantSearch>();
public static String DebuggerMode { get; private set; } public static String DebuggerMode { get; private set; }
public static IPublicAPI API { get; private set; } public static IPublicAPI API { get; private set; }
@@ -31,7 +34,6 @@ namespace Wox.Core.Plugin
/// </summary> /// </summary>
private static List<string> pluginDirectories = new List<string>(); private static List<string> pluginDirectories = new List<string>();
private static void SetupPluginDirectories() private static void SetupPluginDirectories()
{ {
pluginDirectories.Add(PluginDirectory); pluginDirectories.Add(PluginDirectory);
@@ -72,7 +74,7 @@ namespace Wox.Core.Plugin
API = api; API = api;
plugins.Clear(); plugins.Clear();
List<PluginMetadata> pluginMetadatas = PluginConfig.Parse(pluginDirectories); pluginMetadatas = PluginConfig.Parse(pluginDirectories);
plugins.AddRange(new CSharpPluginLoader().LoadPlugin(pluginMetadatas)); plugins.AddRange(new CSharpPluginLoader().LoadPlugin(pluginMetadatas));
plugins.AddRange(new JsonRPCPluginLoader<PythonPlugin>().LoadPlugin(pluginMetadatas)); plugins.AddRange(new JsonRPCPluginLoader<PythonPlugin>().LoadPlugin(pluginMetadatas));
@@ -95,6 +97,8 @@ namespace Wox.Core.Plugin
} }
}); });
} }
LoadInstantSearches();
} }
public static void InstallPlugin(string path) public static void InstallPlugin(string path)
@@ -140,6 +144,46 @@ namespace Wox.Core.Plugin
DebuggerMode = path; DebuggerMode = path;
} }
public static bool IsInstantSearch(string query)
{
return LoadInstantSearches().Any(o => o.IsInstantSearch(query));
}
private static List<IInstantSearch> LoadInstantSearches()
{
if (instantSearches.Count > 0) return instantSearches;
List<PluginMetadata> CSharpPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList();
foreach (PluginMetadata metadata in CSharpPluginMetadatas)
{
try
{
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IInstantSearch))).ToList();
if (types.Count == 0)
{
continue;
}
foreach (Type type in types)
{
instantSearches.Add(Activator.CreateInstance(type) as IInstantSearch);
}
}
catch (System.Exception e)
{
Log.Error(string.Format("Couldn't load plugin {0}: {1}", metadata.Name, e.Message));
#if (DEBUG)
{
throw;
}
#endif
}
}
return instantSearches;
}
/// <summary> /// <summary>
/// get specified plugin, return null if not found /// get specified plugin, return null if not found
/// </summary> /// </summary>

View File

@@ -0,0 +1,11 @@
namespace Wox.Core.Updater
{
public class Release
{
public string version { get; set; }
public string download_link { get; set; }
public string download_link1 { get; set; }
public string download_link2 { get; set; }
public string description { get; set; }
}
}

View File

@@ -1,11 +1,7 @@
using System; using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wox.Core.Exception; using Wox.Core.Exception;
namespace Wox.Core.Version namespace Wox.Core.Updater
{ {
public class SemanticVersion : IComparable public class SemanticVersion : IComparable
{ {

View File

@@ -1,13 +1,15 @@
 using System;
using System;
using System.IO; using System.IO;
using System.Reflection;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Threading; using System.Windows.Threading;
using NAppUpdate.Framework; using NAppUpdate.Framework;
using NAppUpdate.Framework.Common; using NAppUpdate.Framework.Common;
using NAppUpdate.Framework.Sources; using NAppUpdate.Framework.Sources;
using Newtonsoft.Json;
using Wox.Core.i18n; using Wox.Core.i18n;
using Wox.Core.UserSettings; using Wox.Core.UserSettings;
using Wox.Infrastructure.Http;
using Wox.Infrastructure.Logger; using Wox.Infrastructure.Logger;
namespace Wox.Core.Updater namespace Wox.Core.Updater
@@ -15,6 +17,9 @@ namespace Wox.Core.Updater
public class UpdaterManager public class UpdaterManager
{ {
private static UpdaterManager instance; private static UpdaterManager instance;
private const string VersionCheckURL = "https://api.getwox.com/release/latest/";
private const string UpdateFeedURL = "http://127.0.0.1:8888/Update.xml";
private static SemanticVersion currentVersion;
public static UpdaterManager Instance public static UpdaterManager Instance
{ {
@@ -33,12 +38,45 @@ namespace Wox.Core.Updater
UpdateManager.Instance.UpdateSource = GetUpdateSource(); UpdateManager.Instance.UpdateSource = GetUpdateSource();
} }
public bool IsUpdateAvailable() public SemanticVersion CurrentVersion
{ {
return UpdateManager.Instance.UpdatesAvailable > 0; get
{
if (currentVersion == null)
{
currentVersion = new SemanticVersion(Assembly.GetExecutingAssembly().GetName().Version);
}
return currentVersion;
}
}
private bool IsNewerThanCurrent(Release release)
{
if (release == null) return false;
return new SemanticVersion(release.version) > CurrentVersion;
} }
public void CheckUpdate() public void CheckUpdate()
{
string json = HttpRequest.Get(VersionCheckURL, HttpProxy.Instance);
if (!string.IsNullOrEmpty(json))
{
try
{
Release newRelease = JsonConvert.DeserializeObject<Release>(json);
if (IsNewerThanCurrent(newRelease))
{
StartUpdate();
}
}
catch
{
}
}
}
private void StartUpdate()
{ {
UpdateManager updManager = UpdateManager.Instance; UpdateManager updManager = UpdateManager.Instance;
updManager.BeginCheckForUpdates(asyncResult => updManager.BeginCheckForUpdates(asyncResult =>
@@ -104,7 +142,7 @@ namespace Wox.Core.Updater
{ {
// Normally this would be a web based source. // Normally this would be a web based source.
// But for the demo app, we prepare an in-memory source. // But for the demo app, we prepare an in-memory source.
var source = new SimpleWebSource("http://127.0.0.1:8888/Update.xml"); var source = new SimpleWebSource(UpdateFeedURL);
return source; return source;
} }
} }

View File

@@ -1,36 +0,0 @@
using System.Reflection;
namespace Wox.Core.Version
{
public class VersionManager
{
private static VersionManager versionManager;
private static SemanticVersion currentVersion;
public static VersionManager Instance
{
get
{
if (versionManager == null)
{
versionManager = new VersionManager();
}
return versionManager;
}
}
private VersionManager() { }
public SemanticVersion CurrentVersion
{
get
{
if (currentVersion == null)
{
currentVersion = new SemanticVersion(Assembly.GetExecutingAssembly().GetName().Version);
}
return currentVersion;
}
}
}
}

View File

@@ -69,6 +69,7 @@
<Compile Include="Exception\WoxI18nException.cs" /> <Compile Include="Exception\WoxI18nException.cs" />
<Compile Include="Exception\WoxJsonRPCException.cs" /> <Compile Include="Exception\WoxJsonRPCException.cs" />
<Compile Include="Exception\WoxPluginException.cs" /> <Compile Include="Exception\WoxPluginException.cs" />
<Compile Include="Updater\Release.cs" />
<Compile Include="Updater\UpdaterManager.cs" /> <Compile Include="Updater\UpdaterManager.cs" />
<Compile Include="UserSettings\HttpProxy.cs" /> <Compile Include="UserSettings\HttpProxy.cs" />
<Compile Include="i18n\AvailableLanguages.cs" /> <Compile Include="i18n\AvailableLanguages.cs" />
@@ -99,8 +100,7 @@
<Compile Include="UserSettings\CustomizedPluginConfig.cs" /> <Compile Include="UserSettings\CustomizedPluginConfig.cs" />
<Compile Include="UserSettings\PluginHotkey.cs" /> <Compile Include="UserSettings\PluginHotkey.cs" />
<Compile Include="UserSettings\UserSettingStorage.cs" /> <Compile Include="UserSettings\UserSettingStorage.cs" />
<Compile Include="Version\SemanticVersion.cs" /> <Compile Include="Updater\SemanticVersion.cs" />
<Compile Include="Version\VersionManager.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />

View File

@@ -16,8 +16,8 @@ using Wox.Core;
using Wox.Core.Exception; using Wox.Core.Exception;
using Wox.Core.i18n; using Wox.Core.i18n;
using Wox.Core.UI; using Wox.Core.UI;
using Wox.Core.Updater;
using Wox.Core.UserSettings; using Wox.Core.UserSettings;
using Wox.Core.Version;
using Wox.Infrastructure.Http; using Wox.Infrastructure.Http;
namespace Wox.CrashReporter namespace Wox.CrashReporter
@@ -36,7 +36,7 @@ namespace Wox.CrashReporter
private void SetException(Exception exception) private void SetException(Exception exception)
{ {
tbSummary.AppendText(exception.Message); tbSummary.AppendText(exception.Message);
tbVersion.Text = VersionManager.Instance.CurrentVersion.ToString(); tbVersion.Text = UpdaterManager.Instance.CurrentVersion.ToString();
tbDatetime.Text = DateTime.Now.ToString(); tbDatetime.Text = DateTime.Now.ToString();
tbStackTrace.AppendText(exception.StackTrace); tbStackTrace.AppendText(exception.StackTrace);
tbSource.Text = exception.Source; tbSource.Text = exception.Source;

View File

@@ -15,11 +15,9 @@
Error - error messages Error - error messages
Fatal - very serious errors--> Fatal - very serious errors-->
<targets> <targets>
<target xsi:type="File" name="file" fileName="${basedir}/logs/${shortdate}.log"/> <target xsi:type="File" name="file" fileName="${basedir}/Logs/${shortdate}.log"/>
<target xsi:type="Console" name="console" />
</targets> </targets>
<rules> <rules>
<logger name="*" minlevel="Warn" writeTo="file" /> <logger name="*" minlevel="Warn" writeTo="file" />
<logger name="*" minlevel="Debug" writeTo="console" />
</rules> </rules>
</nlog> </nlog>

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Wox.Plugin
{
public interface IInstantSearch
{
bool IsInstantSearch(string query);
}
}

View File

@@ -17,4 +17,4 @@ using System.Runtime.InteropServices;
[assembly: InternalsVisibleTo("Wox")] [assembly: InternalsVisibleTo("Wox")]
[assembly: InternalsVisibleTo("Wox.Core")] [assembly: InternalsVisibleTo("Wox.Core")]
[assembly: InternalsVisibleTo("Wox.Test")] [assembly: InternalsVisibleTo("Wox.Test")]

View File

@@ -46,6 +46,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="AllowedLanguage.cs" /> <Compile Include="AllowedLanguage.cs" />
<Compile Include="EventHandler.cs" /> <Compile Include="EventHandler.cs" />
<Compile Include="IInstantSearch.cs" />
<Compile Include="IHttpProxy.cs" /> <Compile Include="IHttpProxy.cs" />
<Compile Include="IPluginI18n.cs" /> <Compile Include="IPluginI18n.cs" />
<Compile Include="IPlugin.cs" /> <Compile Include="IPlugin.cs" />

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using NUnit.Framework; using NUnit.Framework;
using Wox.Core.Version; using Wox.Core.Updater;
namespace Wox.Test namespace Wox.Test
{ {

View File

@@ -337,18 +337,27 @@ namespace Wox
if (pnlResult.Dirty) pnlResult.Clear(); if (pnlResult.Dirty) pnlResult.Clear();
}, TimeSpan.FromMilliseconds(100), null); }, TimeSpan.FromMilliseconds(100), null);
queryHasReturn = false; queryHasReturn = false;
var q = new Query(lastQuery); Query query = new Query(lastQuery);
FireBeforeWoxQueryEvent(q); FireBeforeWoxQueryEvent(query);
Query(q); Query(query);
Dispatcher.DelayInvoke("ShowProgressbar", originQuery => Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
{ {
if (!queryHasReturn && originQuery == lastQuery && !string.IsNullOrEmpty(lastQuery)) if (!queryHasReturn && originQuery == tbQuery.Text && !string.IsNullOrEmpty(lastQuery))
{ {
StartProgress(); StartProgress();
} }
}, TimeSpan.FromMilliseconds(150), lastQuery); }, TimeSpan.FromMilliseconds(150), tbQuery.Text);
FireAfterWoxQueryEvent(q); FireAfterWoxQueryEvent(query);
}, TimeSpan.FromMilliseconds(200)); }, TimeSpan.FromMilliseconds(GetSearchDelay(lastQuery)));
}
private int GetSearchDelay(string query)
{
if (!string.IsNullOrEmpty(query) && PluginManager.IsInstantSearch(query))
{
return 0;
}
return 200;
} }
private void FireAfterWoxQueryEvent(Query q) private void FireAfterWoxQueryEvent(Query q)

View File

@@ -20,8 +20,8 @@ using System.Windows.Data;
using Microsoft.Win32; using Microsoft.Win32;
using Wox.Core.i18n; using Wox.Core.i18n;
using Wox.Core.Theme; using Wox.Core.Theme;
using Wox.Core.Updater;
using Wox.Core.UserSettings; using Wox.Core.UserSettings;
using Wox.Core.Version;
namespace Wox namespace Wox
{ {
@@ -217,7 +217,7 @@ namespace Wox
#region About #region About
tbVersion.Text = VersionManager.Instance.CurrentVersion.ToString(); tbVersion.Text = UpdaterManager.Instance.CurrentVersion.ToString();
string activateTimes = string.Format(InternationalizationManager.Instance.GetTranslation("about_activate_times"), string activateTimes = string.Format(InternationalizationManager.Instance.GetTranslation("about_activate_times"),
UserSettingStorage.Instance.ActivateTimes); UserSettingStorage.Instance.ActivateTimes);
tbActivatedTimes.Text = activateTimes; tbActivatedTimes.Text = activateTimes;

View File

@@ -313,10 +313,24 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>xcopy /Y $(ProjectDir)Themes\* $(TargetDir)Themes\ <PostBuildEvent>xcopy /Y $(ProjectDir)Themes\* $(TargetDir)Themes\
xcopy /Y /E $(ProjectDir)Images\* $(TargetDir)Images\ xcopy /Y /E $(ProjectDir)Images\* $(TargetDir)Images\
del /s /q "$(TargetDir)*.xml" xcopy /Y /D /E $(SolutionDir)PythonHome\* $(TargetDir)PythonHome\
xcopy /Y /D /E $(SolutionDir)PythonHome\* $(TargetDir)PythonHome\</PostBuildEvent>
cd "$(TargetDir)" &amp; del /s /q *.xml
cd "$(TargetDir)Plugins" &amp; del /s /q NLog.dll
cd "$(TargetDir)Plugins" &amp; del /s /q NLog.config
cd "$(TargetDir)Plugins" &amp; del /s /q Wox.Plugin.pdb
cd "$(TargetDir)Plugins" &amp; del /s /q Wox.Plugin.dll
cd "$(TargetDir)Plugins" &amp; del /s /q Wox.Core.dll
cd "$(TargetDir)Plugins" &amp; del /s /q Wox.Core.pdb
cd "$(TargetDir)Plugins" &amp; del /s /q ICSharpCode.SharpZipLib.dll
cd "$(TargetDir)Plugins" &amp; del /s /q NAppUpdate.Framework.dll
cd "$(TargetDir)Plugins" &amp; del /s /q Wox.Infrastructure.dll
cd "$(TargetDir)Plugins" &amp; del /s /q Wox.Infrastructure.pdb
cd "$(TargetDir)Plugins" &amp; del /s /q Newtonsoft.Json.dll
cd "$(TargetDir)Plugins" &amp; del /s /q WindowsInput.dll</PostBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.