Move some user settings to its own dll (cmd,folder plugin and etc)

This commit is contained in:
qianlifeng
2015-01-05 22:41:17 +08:00
parent 6162904c59
commit ce451e4dd4
62 changed files with 342 additions and 222 deletions

View File

@@ -2,7 +2,6 @@
using System.Diagnostics;
using System.IO;
using System.Threading;
using Wox.Infrastructure.Storage.UserSettings;
namespace Wox.Plugin.Program
{
@@ -21,7 +20,7 @@ namespace Wox.Plugin.Program
}
watchedPath.Add(path);
foreach (string fileType in UserSettingStorage.Instance.ProgramSuffixes.Split(';'))
foreach (string fileType in ProgramStorage.Instance.ProgramSuffixes.Split(';'))
{
FileSystemWatcher watcher = new FileSystemWatcher
{

View File

@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Wox.Infrastructure.Storage;
namespace Wox.Plugin.Program
@@ -9,6 +11,11 @@ namespace Wox.Plugin.Program
{
public List<Program> Programs = new List<Program>();
protected override string ConfigFolder
{
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
}
protected override string ConfigName
{
get { return "ProgramIndexCache"; }

View File

@@ -2,7 +2,6 @@
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using Wox.Infrastructure.Storage.UserSettings;
namespace Wox.Plugin.Program
{
@@ -19,7 +18,7 @@ namespace Wox.Plugin.Program
private void Setting_Loaded(object sender, RoutedEventArgs e)
{
programSourceView.ItemsSource = UserSettingStorage.Instance.ProgramSources;
programSourceView.ItemsSource = ProgramStorage.Instance.ProgramSources;
}
private void ReIndexing()
@@ -40,13 +39,13 @@ namespace Wox.Plugin.Program
{
string path = folderBrowserDialog.SelectedPath;
UserSettingStorage.Instance.ProgramSources.Add(new ProgramSource()
ProgramStorage.Instance.ProgramSources.Add(new ProgramSource()
{
Location = path,
Type = "FileSystemProgramSource",
Enabled = true
});
UserSettingStorage.Instance.Save();
ProgramStorage.Instance.Save();
ReIndexing();
}
}
@@ -59,8 +58,8 @@ namespace Wox.Plugin.Program
if (MessageBox.Show("Are your sure to delete " + selectedProgramSource.Location, "Delete ProgramSource",
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
UserSettingStorage.Instance.ProgramSources.Remove(selectedProgramSource);
UserSettingStorage.Instance.Save();
ProgramStorage.Instance.ProgramSources.Remove(selectedProgramSource);
ProgramStorage.Instance.Save();
ReIndexing();
}
}
@@ -81,7 +80,7 @@ namespace Wox.Plugin.Program
{
string path = folderBrowserDialog.SelectedPath;
selectedProgramSource.Location = path;
UserSettingStorage.Instance.Save();
ProgramStorage.Instance.Save();
ReIndexing();
}
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
namespace Wox.Plugin.Program
{
[Serializable]
public class ProgramSource
{
public string Location { get; set; }
public string Type { get; set; }
public int BonusPoints { get; set; }
public bool Enabled { get; set; }
public Dictionary<string, string> Meta { get; set; }
public override string ToString()
{
return (this.Type ?? "") + ":" + this.Location ?? "";
}
}
}

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using Wox.Infrastructure.Storage.UserSettings;
namespace Wox.Plugin.Program.ProgramSources
{

View File

@@ -1,7 +1,6 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
using Wox.Infrastructure.Storage.UserSettings;
namespace Wox.Plugin.Program.ProgramSources
{

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Wox.Infrastructure.Storage.UserSettings;
using Log = Wox.Infrastructure.Logger.Log;
namespace Wox.Plugin.Program.ProgramSources
@@ -39,7 +38,7 @@ namespace Wox.Plugin.Program.ProgramSources
{
foreach (string file in Directory.GetFiles(path))
{
if (UserSettingStorage.Instance.ProgramSuffixes.Split(';').Any(o => file.EndsWith("." + o)))
if (ProgramStorage.Instance.ProgramSuffixes.Split(';').Any(o => file.EndsWith("." + o)))
{
Program p = CreateEntry(file);
list.Add(p);

View File

@@ -1,5 +1,4 @@
using System;
using Wox.Infrastructure.Storage.UserSettings;
namespace Wox.Plugin.Program.ProgramSources
{

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Newtonsoft.Json;
using Wox.Infrastructure.Storage;
namespace Wox.Plugin.Program
{
public class ProgramStorage : JsonStrorage<ProgramStorage>
{
[JsonProperty]
public List<ProgramSource> ProgramSources { get; set; }
[JsonProperty]
public string ProgramSuffixes { get; set; }
protected override string ConfigFolder
{
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
}
protected override ProgramStorage LoadDefault()
{
ProgramSources = new List<ProgramSource>();
return this;
}
protected override void OnAfterLoad(ProgramStorage storage)
{
if (string.IsNullOrEmpty(storage.ProgramSuffixes))
{
storage.ProgramSuffixes = "lnk;exe;appref-ms;bat";
}
}
protected override string ConfigName
{
get { return "setting"; }
}
}
}

View File

@@ -1,5 +1,4 @@
using System.Windows;
using Wox.Infrastructure.Storage.UserSettings;
namespace Wox.Plugin.Program
{
@@ -12,7 +11,7 @@ namespace Wox.Plugin.Program
{
InitializeComponent();
tbSuffixes.Text = UserSettingStorage.Instance.ProgramSuffixes;
tbSuffixes.Text = ProgramStorage.Instance.ProgramSuffixes;
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
@@ -23,7 +22,7 @@ namespace Wox.Plugin.Program
return;
}
UserSettingStorage.Instance.ProgramSuffixes = tbSuffixes.Text;
ProgramStorage.Instance.ProgramSuffixes = tbSuffixes.Text;
MessageBox.Show("Sucessfully update file suffixes");
}
}

View File

@@ -1,10 +1,9 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Wox.Infrastructure;
using Wox.Infrastructure.Storage.UserSettings;
using Wox.Plugin.Program.ProgramSources;
namespace Wox.Plugin.Program
@@ -90,10 +89,10 @@ namespace Wox.Plugin.Program
{
List<ProgramSource> programSources = new List<ProgramSource>();
programSources.AddRange(LoadDeaultProgramSources());
if (UserSettingStorage.Instance.ProgramSources != null &&
UserSettingStorage.Instance.ProgramSources.Count(o => o.Enabled) > 0)
if (ProgramStorage.Instance.ProgramSources != null &&
ProgramStorage.Instance.ProgramSources.Count(o => o.Enabled) > 0)
{
programSources.AddRange(UserSettingStorage.Instance.ProgramSources.Where(o => o.Enabled));
programSources.AddRange(ProgramStorage.Instance.ProgramSources.Where(o => o.Enabled));
}
sources.Clear();

View File

@@ -59,10 +59,12 @@
<Compile Include="ProgramSetting.xaml.cs">
<DependentUpon>ProgramSetting.xaml</DependentUpon>
</Compile>
<Compile Include="ProgramSource.cs" />
<Compile Include="ProgramSources\AppPathsProgramSource.cs" />
<Compile Include="ProgramSources\CommonStartMenuProgramSource.cs" />
<Compile Include="ProgramSources\FileSystemProgramSource.cs" />
<Compile Include="ProgramSources\UserStartMenuProgramSource.cs" />
<Compile Include="ProgramStorage.cs" />
<Compile Include="ProgramSuffixes.xaml.cs">
<DependentUpon>ProgramSuffixes.xaml</DependentUpon>
</Compile>