mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
fix Wox handled exception at launch #221
This commit is contained in:
@@ -4,6 +4,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.Serialization.Formatters.Binary;
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Wox.Infrastructure.Logger;
|
||||||
|
|
||||||
namespace Wox.Infrastructure.Storage
|
namespace Wox.Infrastructure.Storage
|
||||||
{
|
{
|
||||||
@@ -24,7 +25,7 @@ namespace Wox.Infrastructure.Storage
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FileStream fileStream = new FileStream(ConfigPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
FileStream fileStream = new FileStream(ConfigPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
||||||
serializedObject = binaryFormatter.Deserialize(fileStream) as T;
|
serializedObject = binaryFormatter.Deserialize(fileStream) as T;
|
||||||
fileStream.Close();
|
fileStream.Close();
|
||||||
@@ -37,10 +38,22 @@ namespace Wox.Infrastructure.Storage
|
|||||||
|
|
||||||
protected override void SaveInternal()
|
protected override void SaveInternal()
|
||||||
{
|
{
|
||||||
FileStream fileStream = new FileStream(ConfigPath, FileMode.Create);
|
try
|
||||||
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
{
|
||||||
binaryFormatter.Serialize(fileStream, serializedObject);
|
FileStream fileStream = new FileStream(ConfigPath, FileMode.Create);
|
||||||
fileStream.Close();
|
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
||||||
|
binaryFormatter.Serialize(fileStream, serializedObject);
|
||||||
|
fileStream.Close();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Error(e.Message);
|
||||||
|
#if (DEBUG)
|
||||||
|
{
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace Wox.Plugin.SystemPlugins.Program
|
|||||||
public class Programs : BaseSystemPlugin, ISettingProvider
|
public class Programs : BaseSystemPlugin, ISettingProvider
|
||||||
{
|
{
|
||||||
private static object lockObject = new object();
|
private static object lockObject = new object();
|
||||||
|
private static List<Program> programs = new List<Program>();
|
||||||
private static List<IProgramSource> sources = new List<IProgramSource>();
|
private static List<IProgramSource> sources = new List<IProgramSource>();
|
||||||
private static Dictionary<string, Type> SourceTypes = new Dictionary<string, Type>() {
|
private static Dictionary<string, Type> SourceTypes = new Dictionary<string, Type>() {
|
||||||
{"FileSystemProgramSource", typeof(FileSystemProgramSource)},
|
{"FileSystemProgramSource", typeof(FileSystemProgramSource)},
|
||||||
@@ -29,7 +30,7 @@ namespace Wox.Plugin.SystemPlugins.Program
|
|||||||
if (query.RawQuery.Trim().Length <= 1) return new List<Result>();
|
if (query.RawQuery.Trim().Length <= 1) return new List<Result>();
|
||||||
|
|
||||||
var fuzzyMather = FuzzyMatcher.Create(query.RawQuery);
|
var fuzzyMather = FuzzyMatcher.Create(query.RawQuery);
|
||||||
List<Program> returnList = ProgramCacheStorage.Instance.Programs.Where(o => MatchProgram(o, fuzzyMather)).ToList();
|
List<Program> returnList = programs.Where(o => MatchProgram(o, fuzzyMather)).ToList();
|
||||||
returnList.ForEach(ScoreFilter);
|
returnList.ForEach(ScoreFilter);
|
||||||
returnList = returnList.OrderByDescending(o => o.Score).ToList();
|
returnList = returnList.OrderByDescending(o => o.Score).ToList();
|
||||||
|
|
||||||
@@ -75,6 +76,7 @@ namespace Wox.Plugin.SystemPlugins.Program
|
|||||||
protected override void InitInternal(PluginInitContext context)
|
protected override void InitInternal(PluginInitContext context)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
programs = ProgramCacheStorage.Instance.Programs;
|
||||||
using (new Timeit("Program Index"))
|
using (new Timeit("Program Index"))
|
||||||
{
|
{
|
||||||
IndexPrograms();
|
IndexPrograms();
|
||||||
@@ -121,10 +123,10 @@ namespace Wox.Plugin.SystemPlugins.Program
|
|||||||
}
|
}
|
||||||
|
|
||||||
// filter duplicate program
|
// filter duplicate program
|
||||||
tempPrograms = tempPrograms.GroupBy(x => new { x.ExecutePath, x.ExecuteName })
|
programs = tempPrograms.GroupBy(x => new { x.ExecutePath, x.ExecuteName })
|
||||||
.Select(g => g.First()).ToList();
|
.Select(g => g.First()).ToList();
|
||||||
|
|
||||||
ProgramCacheStorage.Instance.Programs = tempPrograms;
|
ProgramCacheStorage.Instance.Programs = programs;
|
||||||
ProgramCacheStorage.Instance.Save();
|
ProgramCacheStorage.Instance.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user