From 43791452312e6a7b4b8e436eacf8d918069da10a Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Fri, 23 Jan 2015 21:52:46 +0800 Subject: [PATCH] Add activate statistics --- Wox.Core/UserSettings/UserSettingStorage.cs | 24 ++++++++----- Wox.Core/Wox.Core.csproj | 4 +-- Wox.Infrastructure/Storage/BinaryStorage.cs | 38 +++++++++++++-------- Wox.Infrastructure/Storage/JsonStorage.cs | 12 +++++-- Wox/ActionKeyword.xaml | 9 +++-- Wox/ActionKeyword.xaml.cs | 2 +- Wox/ImageLoader/ImageCacheStroage.cs | 11 ++---- Wox/Languages/en.xaml | 4 +++ Wox/Languages/zh-cn.xaml | 6 ++-- Wox/Languages/zh-tw.xaml | 4 ++- Wox/MainWindow.xaml.cs | 1 + Wox/SettingWindow.xaml | 5 ++- Wox/SettingWindow.xaml.cs | 6 +++- Wox/Storage/UserSelectedRecordStorage.cs | 11 ++---- appveyor.yml | 2 +- 15 files changed, 83 insertions(+), 56 deletions(-) diff --git a/Wox.Core/UserSettings/UserSettingStorage.cs b/Wox.Core/UserSettings/UserSettingStorage.cs index 5f7c243c74..0e6d8a94e2 100644 --- a/Wox.Core/UserSettings/UserSettingStorage.cs +++ b/Wox.Core/UserSettings/UserSettingStorage.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json; using Wox.Infrastructure.Storage; using Wox.Plugin; using System.Drawing; +using System.Reflection; namespace Wox.Core.UserSettings { @@ -14,6 +15,10 @@ namespace Wox.Core.UserSettings [JsonProperty] public bool DontPromptUpdateMsg { get; set; } + [JsonProperty] + public int ActivateTimes { get; set; } + + [JsonProperty] public bool EnableUpdateLog { get; set; } @@ -140,15 +145,7 @@ namespace Wox.Core.UserSettings protected override string ConfigFolder { - get - { - string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE"); - if (userProfilePath == null) - { - throw new ArgumentException("Environment variable USERPROFILE is empty"); - } - return Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Config"); - } + get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); } } protected override string ConfigName @@ -156,6 +153,15 @@ namespace Wox.Core.UserSettings get { return "config"; } } + public void IncreaseActivateTimes() + { + ActivateTimes++; + if (ActivateTimes % 15 == 0) + { + Save(); + } + } + protected override UserSettingStorage LoadDefault() { DontPromptUpdateMsg = false; diff --git a/Wox.Core/Wox.Core.csproj b/Wox.Core/Wox.Core.csproj index b9b40bb80a..570038c14c 100644 --- a/Wox.Core/Wox.Core.csproj +++ b/Wox.Core/Wox.Core.csproj @@ -83,8 +83,8 @@ - - + + diff --git a/Wox.Infrastructure/Storage/BinaryStorage.cs b/Wox.Infrastructure/Storage/BinaryStorage.cs index 7561ba1149..7651ca770c 100644 --- a/Wox.Infrastructure/Storage/BinaryStorage.cs +++ b/Wox.Infrastructure/Storage/BinaryStorage.cs @@ -6,6 +6,7 @@ using System.Reflection; using System.Runtime.Serialization.Formatters; using System.Runtime.Serialization.Formatters.Binary; using System.Text; +using System.Threading; using Wox.Infrastructure.Logger; namespace Wox.Infrastructure.Storage @@ -18,6 +19,7 @@ namespace Wox.Infrastructure.Storage [Serializable] public abstract class BinaryStorage : BaseStorage where T : class, IStorage, new() { + private static object syncObject = new object(); protected override string FileSuffix { get { return ".dat"; } @@ -87,25 +89,31 @@ namespace Wox.Infrastructure.Storage protected override void SaveInternal() { - try + ThreadPool.QueueUserWorkItem(o => { - FileStream fileStream = new FileStream(ConfigPath, FileMode.Create); - BinaryFormatter binaryFormatter = new BinaryFormatter + lock (syncObject) { - AssemblyFormat = FormatterAssemblyStyle.Simple - }; - binaryFormatter.Serialize(fileStream, serializedObject); - fileStream.Close(); - } - catch (Exception e) - { - Log.Error(e.Message); + try + { + FileStream fileStream = new FileStream(ConfigPath, FileMode.Create); + BinaryFormatter binaryFormatter = new BinaryFormatter + { + AssemblyFormat = FormatterAssemblyStyle.Simple + }; + binaryFormatter.Serialize(fileStream, serializedObject); + fileStream.Close(); + } + catch (Exception e) + { + Log.Error(e); #if (DEBUG) - { - throw; - } + { + throw; + } #endif - } + } + } + }); } } } diff --git a/Wox.Infrastructure/Storage/JsonStorage.cs b/Wox.Infrastructure/Storage/JsonStorage.cs index 4a4525bd3e..ca6c0fea09 100644 --- a/Wox.Infrastructure/Storage/JsonStorage.cs +++ b/Wox.Infrastructure/Storage/JsonStorage.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using System.Threading; using Newtonsoft.Json; namespace Wox.Infrastructure.Storage @@ -12,6 +13,7 @@ namespace Wox.Infrastructure.Storage /// public abstract class JsonStrorage : BaseStorage where T : class, IStorage, new() { + private static object syncObject = new object(); protected override string FileSuffix { get { return ".json"; } @@ -39,8 +41,14 @@ namespace Wox.Infrastructure.Storage protected override void SaveInternal() { - string json = JsonConvert.SerializeObject(serializedObject, Formatting.Indented); - File.WriteAllText(ConfigPath, json); + ThreadPool.QueueUserWorkItem(o => + { + lock (syncObject) + { + string json = JsonConvert.SerializeObject(serializedObject, Formatting.Indented); + File.WriteAllText(ConfigPath, json); + } + }); } } } diff --git a/Wox/ActionKeyword.xaml b/Wox/ActionKeyword.xaml index 27ed9ad171..bdc7b6000a 100644 --- a/Wox/ActionKeyword.xaml +++ b/Wox/ActionKeyword.xaml @@ -6,15 +6,16 @@ ResizeMode="NoResize" Loaded="ActionKeyword_OnLoaded" WindowStartupLocation="CenterScreen" - Height="200" Width="674.766"> + Height="200" Width="600"> + - + @@ -24,8 +25,10 @@ + + - +