mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
Move websearch images to %APPDATA%
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Wox.Infrastructure
|
||||
{
|
||||
static class Helper
|
||||
public static class Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// http://www.yinwang.org/blog-cn/2015/11/21/programming-philosophy
|
||||
/// </summary>
|
||||
public static T RequireNonNull<T>(this T obj)
|
||||
public static T NonNull<T>(this T obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
@@ -18,5 +19,41 @@ namespace Wox.Infrastructure
|
||||
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()
|
||||
{
|
||||
var stackTrace = new StackTrace();
|
||||
var stackFrames = stackTrace.GetFrames().RequireNonNull();
|
||||
var stackFrames = stackTrace.GetFrames().NonNull();
|
||||
var callingFrame = stackFrames[2];
|
||||
var method = callingFrame.GetMethod();
|
||||
var type = $"{method.DeclaringType.RequireNonNull().FullName}.{method.Name}";
|
||||
var type = $"{method.DeclaringType.NonNull().FullName}.{method.Name}";
|
||||
return type;
|
||||
}
|
||||
public static void Error(System.Exception e)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Logger;
|
||||
|
||||
namespace Wox.Infrastructure.Storage
|
||||
@@ -14,8 +15,8 @@ namespace Wox.Infrastructure.Storage
|
||||
internal JsonStrorage()
|
||||
{
|
||||
FileSuffix = ".json";
|
||||
DirectoryName = "Settings";
|
||||
DirectoryPath = Path.Combine(DirectoryPath, DirectoryName);
|
||||
DirectoryName = Wox.Settings;
|
||||
DirectoryPath = Wox.SettingsPath;
|
||||
FilePath = Path.Combine(DirectoryPath, FileName + FileSuffix);
|
||||
|
||||
ValidateDirectory();
|
||||
|
||||
@@ -8,9 +8,12 @@ namespace Wox.Infrastructure
|
||||
{
|
||||
public const string Name = "Wox";
|
||||
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 DataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Name);
|
||||
public static readonly string UserDirectory = Path.Combine(DataPath, 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