Add start Wox on system startup config & code refactorying.

This commit is contained in:
qianlifeng
2014-02-06 22:22:02 +08:00
parent 9e1980f843
commit 67f14d6a62
33 changed files with 818 additions and 811 deletions

View File

@@ -1,11 +1,18 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Microsoft.Win32;
using Wox.Helper;
using Wox.Infrastructure;
using Wox.Infrastructure.UserSettings;
using MessageBox = System.Windows.MessageBox;
namespace Wox
{
@@ -13,6 +20,11 @@ namespace Wox
{
private MainWindow mainWindow;
public SettingWidow()
{
InitializeComponent();
}
public SettingWidow(MainWindow mainWindow)
{
this.mainWindow = mainWindow;
@@ -98,5 +110,47 @@ namespace Wox
MessageBox.Show("Please select a web search");
}
}
private void CbStartWithWindows_OnChecked(object sender, RoutedEventArgs e)
{
OnStartWithWindowsChecked();
}
private void CbStartWithWindows_OnUnchecked(object sender, RoutedEventArgs e)
{
OnStartWithWindowUnChecked();
}
[MethodImpl(MethodImplOptions.NoInlining)]
private void OnStartWithWindowUnChecked()
{
UAC.ExecuteAdminMethod(() => SetStartup(false));
}
[MethodImpl(MethodImplOptions.NoInlining)]
private void OnStartWithWindowsChecked()
{
UAC.ExecuteAdminMethod(() => SetStartup(true));
}
private void SetStartup(bool startup)
{
RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (rk != null)
{
if (startup)
{
rk.SetValue("Wox",Path.Combine(Directory.GetCurrentDirectory(),"Wox.exe startHide"));
}
else
{
rk.DeleteValue("Wox", false);
}
}
}
}
}