mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
Move websearch images to %APPDATA%
This commit is contained in:
@@ -6,6 +6,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using Wox.Infrastructure;
|
||||||
using Wox.Infrastructure.Storage;
|
using Wox.Infrastructure.Storage;
|
||||||
using Wox.Plugin.Everything.Everything;
|
using Wox.Plugin.Everything.Everything;
|
||||||
|
|
||||||
@@ -15,9 +16,7 @@ namespace Wox.Plugin.Everything
|
|||||||
{
|
{
|
||||||
private readonly EverythingAPI _api = new EverythingAPI();
|
private readonly EverythingAPI _api = new EverythingAPI();
|
||||||
|
|
||||||
public const string SDK = "EverythingSDK";
|
|
||||||
public const string DLL = "Everything.dll";
|
public const string DLL = "Everything.dll";
|
||||||
internal static string SDKPath;
|
|
||||||
|
|
||||||
private PluginInitContext _context;
|
private PluginInitContext _context;
|
||||||
|
|
||||||
@@ -130,34 +129,16 @@ namespace Wox.Plugin.Everything
|
|||||||
_settings = _storage.Load();
|
_settings = _storage.Load();
|
||||||
|
|
||||||
var pluginDirectory = context.CurrentPluginMetadata.PluginDirectory;
|
var pluginDirectory = context.CurrentPluginMetadata.PluginDirectory;
|
||||||
var bundledSDKDirectory = Path.Combine(pluginDirectory, SDK, CpuType());
|
const string sdk = "EverythingSDK";
|
||||||
var bundledSDKPath = Path.Combine(bundledSDKDirectory, DLL);
|
var bundledSDKDirectory = Path.Combine(pluginDirectory, sdk, CpuType());
|
||||||
|
var sdkDirectory = Path.Combine(_storage.DirectoryPath, sdk, CpuType());
|
||||||
|
Helper.ValidateDataDirectory(bundledSDKDirectory, sdkDirectory);
|
||||||
|
|
||||||
var SDKDirectory = Path.Combine(_storage.DirectoryPath, SDK, CpuType());
|
var sdkPath = Path.Combine(sdkDirectory, DLL);
|
||||||
SDKPath = Path.Combine(SDKDirectory, DLL);
|
LoadLibrary(sdkPath);
|
||||||
if (!Directory.Exists(SDKDirectory))
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(SDKDirectory);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!File.Exists(SDKPath))
|
|
||||||
{
|
|
||||||
File.Copy(bundledSDKPath, SDKPath);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var newSDK = new FileInfo(bundledSDKPath).LastWriteTimeUtc;
|
|
||||||
var oldSDK = new FileInfo(SDKPath).LastWriteTimeUtc;
|
|
||||||
if (oldSDK != newSDK)
|
|
||||||
{
|
|
||||||
File.Copy(bundledSDKPath, SDKPath, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadLibrary(SDKPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string CpuType()
|
private static string CpuType()
|
||||||
{
|
{
|
||||||
return Environment.Is64BitOperatingSystem ? "x64" : "x86";
|
return Environment.Is64BitOperatingSystem ? "x64" : "x86";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using Wox.Infrastructure;
|
||||||
using Wox.Infrastructure.Storage;
|
using Wox.Infrastructure.Storage;
|
||||||
using Wox.Plugin.WebSearch.SuggestionSources;
|
using Wox.Plugin.WebSearch.SuggestionSources;
|
||||||
|
|
||||||
@@ -20,8 +22,8 @@ namespace Wox.Plugin.WebSearch
|
|||||||
private CancellationTokenSource _updateSource;
|
private CancellationTokenSource _updateSource;
|
||||||
private CancellationToken _updateToken;
|
private CancellationToken _updateToken;
|
||||||
|
|
||||||
public const string ImageDirectory = "Images";
|
public const string Images = "Images";
|
||||||
public static string PluginDirectory;
|
public static string ImagesDirectory;
|
||||||
|
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
@@ -86,7 +88,7 @@ namespace Wox.Plugin.WebSearch
|
|||||||
var task = Task.Run(() =>
|
var task = Task.Run(() =>
|
||||||
{
|
{
|
||||||
results.AddRange(ResultsFromSuggestions(keyword, subtitle, webSearch));
|
results.AddRange(ResultsFromSuggestions(keyword, subtitle, webSearch));
|
||||||
|
|
||||||
}, _updateToken);
|
}, _updateToken);
|
||||||
|
|
||||||
if (!task.Wait(waittime))
|
if (!task.Wait(waittime))
|
||||||
@@ -123,12 +125,24 @@ namespace Wox.Plugin.WebSearch
|
|||||||
return new List<Result>();
|
return new List<Result>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Main()
|
||||||
|
{
|
||||||
|
var plugins = Infrastructure.Wox.Plugins;
|
||||||
|
var assemblyName = typeof(Main).Assembly.GetName().Name;
|
||||||
|
var pluginDirectory = Path.Combine(Infrastructure.Wox.SettingsPath, plugins, assemblyName);
|
||||||
|
ImagesDirectory = Path.Combine(pluginDirectory, Images);
|
||||||
|
}
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
public void Init(PluginInitContext context)
|
||||||
{
|
{
|
||||||
Context = context;
|
Context = context;
|
||||||
PluginDirectory = Context.CurrentPluginMetadata.PluginDirectory;
|
|
||||||
_storage = new PluginJsonStorage<Settings>();
|
_storage = new PluginJsonStorage<Settings>();
|
||||||
_settings = _storage.Load();
|
_settings = _storage.Load();
|
||||||
|
|
||||||
|
var pluginDirectory = context.CurrentPluginMetadata.PluginDirectory;
|
||||||
|
var bundledImagesDirectory = Path.Combine(pluginDirectory, Images);
|
||||||
|
Helper.ValidateDataDirectory(bundledImagesDirectory, ImagesDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region ISettingProvider Members
|
#region ISettingProvider Members
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace Wox.Plugin.WebSearch
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
_icon = value;
|
_icon = value;
|
||||||
IconPath = Path.Combine(Main.PluginDirectory, Main.ImageDirectory, value);
|
IconPath = Path.Combine(Main.ImagesDirectory, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ namespace Wox.Plugin.WebSearch
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
internal string IconPath { get; private set; } = Path.Combine
|
internal string IconPath { get; private set; } = Path.Combine
|
||||||
(
|
(
|
||||||
Main.PluginDirectory, Main.ImageDirectory, DefaultIcon
|
Main.ImagesDirectory, DefaultIcon
|
||||||
);
|
);
|
||||||
|
|
||||||
public string Url { get; set; }
|
public string Url { get; set; }
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ namespace Wox.Plugin.WebSearch
|
|||||||
|
|
||||||
private void SelectIconButtonOnClick(object sender, RoutedEventArgs e)
|
private void SelectIconButtonOnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var directory = Path.Combine(Main.PluginDirectory, Main.ImageDirectory);
|
var directory = Path.Combine(Main.ImagesDirectory, Main.Images);
|
||||||
var dlg = new OpenFileDialog
|
var dlg = new OpenFileDialog
|
||||||
{
|
{
|
||||||
InitialDirectory = directory,
|
InitialDirectory = directory,
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
<Reference Include="PresentationCore" />
|
<Reference Include="PresentationCore" />
|
||||||
<Reference Include="PresentationFramework" />
|
<Reference Include="PresentationFramework" />
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xaml" />
|
<Reference Include="System.Xaml" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Wox.Infrastructure
|
namespace Wox.Infrastructure
|
||||||
{
|
{
|
||||||
static class Helper
|
public static class Helper
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// http://www.yinwang.org/blog-cn/2015/11/21/programming-philosophy
|
/// http://www.yinwang.org/blog-cn/2015/11/21/programming-philosophy
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static T RequireNonNull<T>(this T obj)
|
public static T NonNull<T>(this T obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
@@ -18,5 +19,41 @@ namespace Wox.Infrastructure
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void RequireNonNull<T>(this T obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
throw new NullReferenceException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ValidateDataDirectory(string bundledDataDirectory, string dataDirectory)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!Directory.Exists(dataDirectory))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(dataDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var bundledDataPath in Directory.GetFiles(bundledDataDirectory))
|
||||||
|
{
|
||||||
|
var data = Path.GetFileName(bundledDataPath);
|
||||||
|
var dataPath = Path.Combine(dataDirectory, data.NonNull());
|
||||||
|
if (!File.Exists(dataPath))
|
||||||
|
{
|
||||||
|
File.Copy(bundledDataPath, dataPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var time1 = new FileInfo(bundledDataPath).LastWriteTimeUtc;
|
||||||
|
var time2 = new FileInfo(dataPath).LastWriteTimeUtc;
|
||||||
|
if (time1 != time2)
|
||||||
|
{
|
||||||
|
File.Copy(bundledDataPath, dataPath, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ namespace Wox.Infrastructure.Logger
|
|||||||
private static string CallerType()
|
private static string CallerType()
|
||||||
{
|
{
|
||||||
var stackTrace = new StackTrace();
|
var stackTrace = new StackTrace();
|
||||||
var stackFrames = stackTrace.GetFrames().RequireNonNull();
|
var stackFrames = stackTrace.GetFrames().NonNull();
|
||||||
var callingFrame = stackFrames[2];
|
var callingFrame = stackFrames[2];
|
||||||
var method = callingFrame.GetMethod();
|
var method = callingFrame.GetMethod();
|
||||||
var type = $"{method.DeclaringType.RequireNonNull().FullName}.{method.Name}";
|
var type = $"{method.DeclaringType.NonNull().FullName}.{method.Name}";
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
public static void Error(System.Exception e)
|
public static void Error(System.Exception e)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Wox.Infrastructure;
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
|
|
||||||
namespace Wox.Infrastructure.Storage
|
namespace Wox.Infrastructure.Storage
|
||||||
@@ -14,8 +15,8 @@ namespace Wox.Infrastructure.Storage
|
|||||||
internal JsonStrorage()
|
internal JsonStrorage()
|
||||||
{
|
{
|
||||||
FileSuffix = ".json";
|
FileSuffix = ".json";
|
||||||
DirectoryName = "Settings";
|
DirectoryName = Wox.Settings;
|
||||||
DirectoryPath = Path.Combine(DirectoryPath, DirectoryName);
|
DirectoryPath = Wox.SettingsPath;
|
||||||
FilePath = Path.Combine(DirectoryPath, FileName + FileSuffix);
|
FilePath = Path.Combine(DirectoryPath, FileName + FileSuffix);
|
||||||
|
|
||||||
ValidateDirectory();
|
ValidateDirectory();
|
||||||
|
|||||||
@@ -8,9 +8,12 @@ namespace Wox.Infrastructure
|
|||||||
{
|
{
|
||||||
public const string Name = "Wox";
|
public const string Name = "Wox";
|
||||||
public const string Plugins = "Plugins";
|
public const string Plugins = "Plugins";
|
||||||
|
public const string Settings = "Settings";
|
||||||
|
|
||||||
public static readonly string ProgramPath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).ToString();
|
public static readonly string ProgramPath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).ToString();
|
||||||
public static readonly string DataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Name);
|
public static readonly string DataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Name);
|
||||||
public static readonly string UserDirectory = Path.Combine(DataPath, Plugins);
|
public static readonly string UserDirectory = Path.Combine(DataPath, Plugins);
|
||||||
public static readonly string PreinstalledDirectory = Path.Combine(ProgramPath, Plugins);
|
public static readonly string PreinstalledDirectory = Path.Combine(ProgramPath, Plugins);
|
||||||
|
public static readonly string SettingsPath = Path.Combine(DataPath, Settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user