Move websearch images to %APPDATA%

This commit is contained in:
bao-qian
2016-05-07 19:16:13 +01:00
parent ae121895e9
commit 39ba1e0582
9 changed files with 77 additions and 40 deletions

View File

@@ -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);
}
}
}
}
}
}