remove the need for windows SDK

This commit is contained in:
Amir Tepper
2019-10-14 14:22:20 +03:00
parent 41e5d2524b
commit a89b2ca450
2 changed files with 28 additions and 6 deletions

View File

@@ -17,12 +17,15 @@ namespace Wox.Plugin.Program
{ {
private static readonly object IndexLock = new object(); private static readonly object IndexLock = new object();
private static Win32[] _win32s; private static Win32[] _win32s;
#if SDK
private static UWP.Application[] _uwps; private static UWP.Application[] _uwps;
private static BinaryStorage<UWP.Application[]> _uwpStorage;
#endif
private static PluginInitContext _context; private static PluginInitContext _context;
private static BinaryStorage<Win32[]> _win32Storage; private static BinaryStorage<Win32[]> _win32Storage;
private static BinaryStorage<UWP.Application[]> _uwpStorage;
private static Settings _settings; private static Settings _settings;
private readonly PluginJsonStorage<Settings> _settingsStorage; private readonly PluginJsonStorage<Settings> _settingsStorage;
@@ -35,11 +38,15 @@ namespace Wox.Plugin.Program
{ {
_win32Storage = new BinaryStorage<Win32[]>("Win32"); _win32Storage = new BinaryStorage<Win32[]>("Win32");
_win32s = _win32Storage.TryLoad(new Win32[] { }); _win32s = _win32Storage.TryLoad(new Win32[] { });
#if SDK
_uwpStorage = new BinaryStorage<UWP.Application[]>("UWP"); _uwpStorage = new BinaryStorage<UWP.Application[]>("UWP");
_uwps = _uwpStorage.TryLoad(new UWP.Application[] { }); _uwps = _uwpStorage.TryLoad(new UWP.Application[] { });
#endif
}); });
Log.Info($"|Wox.Plugin.Program.Main|Number of preload win32 programs <{_win32s.Length}>"); Log.Info($"|Wox.Plugin.Program.Main|Number of preload win32 programs <{_win32s.Length}>");
#if SDK
Log.Info($"|Wox.Plugin.Program.Main|Number of preload uwps <{_uwps.Length}>"); Log.Info($"|Wox.Plugin.Program.Main|Number of preload uwps <{_uwps.Length}>");
#endif
Task.Run(() => Task.Run(() =>
{ {
Stopwatch.Normal("|Wox.Plugin.Program.Main|Program index cost", IndexPrograms); Stopwatch.Normal("|Wox.Plugin.Program.Main|Program index cost", IndexPrograms);
@@ -50,7 +57,9 @@ namespace Wox.Plugin.Program
{ {
_settingsStorage.Save(); _settingsStorage.Save();
_win32Storage.Save(_win32s); _win32Storage.Save(_win32s);
#if SDK
_uwpStorage.Save(_uwps); _uwpStorage.Save(_uwps);
#endif
} }
public List<Result> Query(Query query) public List<Result> Query(Query query)
@@ -58,8 +67,14 @@ namespace Wox.Plugin.Program
lock (IndexLock) lock (IndexLock)
{ {
var results1 = _win32s.AsParallel().Select(p => p.Result(query.Search, _context.API)); var results1 = _win32s.AsParallel().Select(p => p.Result(query.Search, _context.API));
#if SDK
var results2 = _uwps.AsParallel().Select(p => p.Result(query.Search, _context.API)); var results2 = _uwps.AsParallel().Select(p => p.Result(query.Search, _context.API));
var result = results1.Concat(results2).Where(r => r.Score > 0).ToList(); #endif
var result = results1
#if SDK
.Concat(results2)
#endif
.Where(r => r.Score > 0).ToList();
return result; return result;
} }
} }
@@ -72,10 +87,13 @@ namespace Wox.Plugin.Program
public static void IndexPrograms() public static void IndexPrograms()
{ {
Win32[] w = { }; Win32[] w = { };
#if SDK
UWP.Application[] u = { }; UWP.Application[] u = { };
var t1 = Task.Run(() => var t1 = Task.Run(() =>
{ {
w = Win32.All(_settings); #endif
w = Win32.All(_settings);
#if SDK
}); });
var t2 = Task.Run(() => var t2 = Task.Run(() =>
{ {
@@ -91,11 +109,13 @@ namespace Wox.Plugin.Program
} }
}); });
Task.WaitAll(t1, t2); Task.WaitAll(t1, t2);
#endif
lock (IndexLock) lock (IndexLock)
{ {
_win32s = w; _win32s = w;
#if SDK
_uwps = u; _uwps = u;
#endif
} }
} }

View File

@@ -1,4 +1,5 @@
using System; #if SDK
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
@@ -584,3 +585,4 @@ namespace Wox.Plugin.Program.Programs
IntPtr ppvReserved); IntPtr ppvReserved);
} }
} }
#endif