Skip to content

Commit

Permalink
use %APPDATA%
Browse files Browse the repository at this point in the history
1. Fix can't find Result.ctor bug for plugin introduced in
c0889de
2. use %APPDATA% for all data, part of #389
3. MISC
  • Loading branch information
bao-qian committed Apr 27, 2016
1 parent 736f26c commit a7f1b24
Show file tree
Hide file tree
Showing 22 changed files with 157 additions and 159 deletions.
18 changes: 14 additions & 4 deletions Plugins/Wox.Plugin.Folder/FolderPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ public List<Result> Query(Query query)
x => x.Nickname.StartsWith(input, StringComparison.OrdinalIgnoreCase)).ToList();
List<Result> results =
userFolderLinks.Select(
item => new Result(item.Nickname, "Images/folder.png", "Ctrl + Enter to open the directory")
item => new Result()
{
Title = item.Nickname,
IcoPath = "Images/folder.png",
SubTitle = "Ctrl + Enter to open the directory",
Action = c =>
{
if (c.SpecialKeyState.CtrlPressed)
Expand Down Expand Up @@ -128,8 +131,10 @@ private List<Result> QueryInternal_Directory_Exists(string rawQuery)
string firstResult = "Open current directory";
if (incompleteName.Length > 0)
firstResult = "Open " + rawQuery;
results.Add(new Result(firstResult, "Images/folder.png")
results.Add(new Result
{
Title = firstResult,
IcoPath = "Images/folder.png",
Score = 10000,
Action = c =>
{
Expand All @@ -147,8 +152,11 @@ private List<Result> QueryInternal_Directory_Exists(string rawQuery)
if (incompleteName.Length != 0 && !dir.Name.ToLower().StartsWith(incompleteName))
continue;
DirectoryInfo dirCopy = dir;
var result = new Result(dir.Name, "Images/folder.png", "Ctrl + Enter to open the directory")
var result = new Result
{
Title = dir.Name,
IcoPath = "Images/folder.png",
SubTitle = "Ctrl + Enter to open the directory",
Action = c =>
{
if (c.SpecialKeyState.CtrlPressed)
Expand Down Expand Up @@ -180,8 +188,10 @@ private List<Result> QueryInternal_Directory_Exists(string rawQuery)
if (incompleteName.Length != 0 && !file.Name.ToLower().StartsWith(incompleteName))
continue;
string filePath = file.FullName;
var result = new Result(Path.GetFileName(filePath), "Images/file.png")
var result = new Result
{
Title = Path.GetFileName(filePath),
IcoPath = "Images/file.png",
Action = c =>
{
try
Expand Down
1 change: 0 additions & 1 deletion Plugins/Wox.Plugin.PluginManagement/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ private List<Result> ResultForInstallPlugin(Query query)
string pluginUrl = APIBASE + "/media/" + r1.plugin_file;
Client.DownloadFile(pluginUrl, filePath);
context.API.InstallPlugin(filePath);
context.API.ReloadPlugins();
}
catch (Exception exception)
{
Expand Down
2 changes: 1 addition & 1 deletion Wox.Core/Plugin/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal abstract class PluginConfig
/// </summary>
/// <param name="pluginDirectories"></param>
/// <returns></returns>
public static List<PluginMetadata> Parse(List<string> pluginDirectories)
public static List<PluginMetadata> Parse(string[] pluginDirectories)
{
pluginMetadatas.Clear();
foreach (string pluginDirectory in pluginDirectories)
Expand Down
2 changes: 1 addition & 1 deletion Wox.Core/Plugin/PluginInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal static void Install(string path)
return;
}

string pluginFolerPath = PluginManager.PluginDirectory;
string pluginFolerPath = PluginManager.UserDirectory;

string newPluginName = plugin.Name
.Replace("/", "_")
Expand Down
54 changes: 14 additions & 40 deletions Wox.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ namespace Wox.Core.Plugin
/// </summary>
public static class PluginManager
{
public const string DirectoryName = "Plugins";
private static IEnumerable<PluginPair> _contextMenuPlugins;

/// <summary>
/// Directories that will hold Wox plugin directory
/// </summary>
private static readonly List<string> PluginDirectories = new List<string>();

public static List<PluginPair> AllPlugins { get; private set; }

Expand All @@ -34,47 +32,31 @@ public static class PluginManager
private static IEnumerable<PluginPair> InstantQueryPlugins { get; set; }
public static IPublicAPI API { private set; get; }

public static readonly string PluginDirectory = Path.Combine(WoxDirectroy.Executable, DirectoryName);

private static void SetupPluginDirectories()
{
PluginDirectories.Add(PluginDirectory);
MakesurePluginDirectoriesExist();
}
public const string DirectoryName = "Plugins";
public static readonly string PreinstalledDirectory = Path.Combine(Infrastructure.Wox.ProgramPath, DirectoryName);
public static readonly string UserDirectory = Path.Combine(Infrastructure.Wox.DataPath, DirectoryName);
private static readonly string[] Directories = { PreinstalledDirectory, UserDirectory };

private static void MakesurePluginDirectoriesExist()
private static void ValidateUserDirectory()
{
foreach (string pluginDirectory in PluginDirectories)
if (!Directory.Exists(UserDirectory))
{
if (!Directory.Exists(pluginDirectory))
{
try
{
Directory.CreateDirectory(pluginDirectory);
}
catch (Exception e)
{
Log.Error(e);
}
}
Directory.CreateDirectory(UserDirectory);
}
}

/// <summary>
/// Load and init all Wox plugins
/// </summary>
///
public static void Initialize()
static PluginManager()
{
SetupPluginDirectories();

var metadatas = PluginConfig.Parse(PluginDirectories);
AllPlugins = new CSharpPluginLoader().LoadPlugin(metadatas).Concat(
new JsonRPCPluginLoader<PythonPlugin>().LoadPlugin(metadatas)).ToList();
ValidateUserDirectory();
}

public static void InitializePlugins(IPublicAPI api)
{
var metadatas = PluginConfig.Parse(Directories);
var plugins1 = new CSharpPluginLoader().LoadPlugin(metadatas);
var plugins2 = new JsonRPCPluginLoader<PythonPlugin>().LoadPlugin(metadatas);
AllPlugins = plugins1.Concat(plugins2).ToList();

//load plugin i18n languages
ResourceMerger.UpdatePluginLanguages();

Expand Down Expand Up @@ -228,14 +210,6 @@ private static bool IsGlobalPlugin(PluginMetadata metadata)
return metadata.ActionKeywords.Contains(Query.GlobalPluginWildcardSign);
}

private static bool IsInstantQueryPlugin(PluginPair plugin)
{
//any plugin that takes more than 200ms for AvgQueryTime won't be treated as IInstantQuery plugin anymore.
return plugin.AvgQueryTime < 200 &&
plugin.Plugin is IInstantQuery &&
InstantQueryPlugins.Any(p => p.Metadata.ID == plugin.Metadata.ID);
}

/// <summary>
/// get specified plugin, return null if not found
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Wox.Core/Plugin/PythonPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Wox.Core.Plugin
{
internal class PythonPlugin : JsonRPCPlugin
{
private static readonly string PythonHome = Path.Combine(WoxDirectroy.Executable, "PythonHome");
private static readonly string PythonHome = Path.Combine(Infrastructure.Wox.ProgramPath, "PythonHome");
private readonly ProcessStartInfo _startInfo;

public override string SupportedLanguage => AllowedLanguage.Python;
Expand Down
1 change: 0 additions & 1 deletion Wox.Core/Resource/Internationalization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.IO;
using System.Linq;
using System.Windows;
using Wox.Core.UserSettings;
using Wox.Infrastructure.Exception;
using Wox.Infrastructure.Logger;
using Wox.Plugin;
Expand Down
2 changes: 1 addition & 1 deletion Wox.Core/Resource/Resource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public abstract class Resource
{
public string DirectoryName { get; protected set; }

protected string DirectoryPath => Path.Combine(WoxDirectroy.Executable, DirectoryName);
protected string DirectoryPath => Path.Combine(Infrastructure.Wox.ProgramPath, DirectoryName);

public abstract ResourceDictionary GetResourceDictionary();
}
Expand Down
6 changes: 3 additions & 3 deletions Wox.Infrastructure/Image/ImageLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static ImageSource Load(string path, bool addToCache = true)
ImageSource image = null;
if (string.IsNullOrEmpty(path))
{
path = Path.Combine(WoxDirectroy.Executable, "Images", "app.png");
path = Path.Combine(Wox.ProgramPath, "Images", "app.png");
image = new BitmapImage(new Uri(path));
return image;
}
Expand Down Expand Up @@ -131,14 +131,14 @@ public static ImageSource Load(string path, bool addToCache = true)
}
else
{
path = Path.Combine(WoxDirectroy.Executable, "Images", Path.GetFileName(path));
path = Path.Combine(Wox.ProgramPath, "Images", Path.GetFileName(path));
if (File.Exists(path))
{
image = new BitmapImage(new Uri(path));
}
else
{
path = Path.Combine(WoxDirectroy.Executable, "Images", "app.png");
path = Path.Combine(Wox.ProgramPath, "Images", "app.png");
image = new BitmapImage(new Uri(path));
}
}
Expand Down
43 changes: 17 additions & 26 deletions Wox.Infrastructure/Storage/BinaryStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,20 @@ namespace Wox.Infrastructure.Storage
/// Normally, it has better performance, but not readable
/// You MUST mark implement class as Serializable
/// </summary>
public class BinaryStorage<T> where T : class, new()
public class BinaryStorage<T> : Storage<T> where T : new()
{
private T _binary;

private string FilePath { get; }
private string FileName { get; }
private const string FileSuffix = ".dat";
private string DirectoryPath { get; }
private const string DirectoryName = "Config";

public BinaryStorage()
{
FileName = typeof(T).Name;
DirectoryPath = Path.Combine(WoxDirectroy.Executable, DirectoryName);
FilePath = Path.Combine(DirectoryPath, FileName + FileSuffix); ;
FileSuffix = ".dat";
DirectoryName = "Cache";
DirectoryPath = Path.Combine(DirectoryPath, DirectoryName);
FilePath = Path.Combine(DirectoryPath, FileName + FileSuffix);

ValidateDirectory();
}

public T Load()
public override T Load()
{
if (!Directory.Exists(DirectoryPath))
{
Directory.CreateDirectory(DirectoryPath);
}

if (File.Exists(FilePath))
{
using (var stream = new FileStream(FilePath, FileMode.Open))
Expand All @@ -55,7 +45,7 @@ public T Load()
{
LoadDefault();
}
return _binary;
return Data;
}

private void Deserialize(FileStream stream)
Expand All @@ -69,27 +59,28 @@ private void Deserialize(FileStream stream)

try
{
_binary = (T)binaryFormatter.Deserialize(stream);
Data = (T)binaryFormatter.Deserialize(stream);
}
catch (SerializationException e)
{
LoadDefault();
Log.Error(e);
LoadDefault();
}
catch (InvalidCastException e)
{
LoadDefault();
Log.Error(e);
LoadDefault();
}
finally
{
AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
}
}

private void LoadDefault()
public override void LoadDefault()
{
_binary = new T();
Data = new T();
Save();
}

private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
Expand All @@ -108,7 +99,7 @@ private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs a
return ayResult;
}

public void Save()
public override void Save()
{
using (var stream = new FileStream(FilePath, FileMode.Create))
{
Expand All @@ -119,7 +110,7 @@ public void Save()

try
{
binaryFormatter.Serialize(stream, _binary);
binaryFormatter.Serialize(stream, Data);
}
catch (SerializationException e)
{
Expand Down
Loading

2 comments on commit a7f1b24

@NickCraver
Copy link

@NickCraver NickCraver commented on a7f1b24 Jun 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the public interface (IPublicAPI) changed here? This breaks the plugin model and quite literally breaks plugins (the Wow.Plugin.Runner plugin). This can't be how things work if people are to develop plugins for Wox. Changing a public interface is really, really bad. It should never be done. This is the result:

2016-06-16 14_33_51-192 168 1 115 - remote desktop connection

@bao-qian
Copy link
Member Author

@bao-qian bao-qian commented on a7f1b24 Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NickCraver
that api is exposed by mistake. no plugins should use it. even the plugin author don't know why he need it .

I will change public API carefully, since I will do statistics.

Please sign in to comment.