@@ -0,0 +1,39 @@ | |||||
using System; | |||||
using System.Windows.Forms; | |||||
using Microsoft.Win32; | |||||
namespace Shadowsocks.Controller { | |||||
class AutoStartup { | |||||
public static bool Set(bool enabled) { | |||||
try { | |||||
string path = Application.ExecutablePath; | |||||
RegistryKey runKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true); | |||||
if (enabled) { | |||||
runKey.SetValue("Shadowsocks", path); | |||||
} else { | |||||
runKey.DeleteValue("Shadowsocks"); | |||||
} | |||||
runKey.Close(); | |||||
return true; | |||||
} catch (Exception) { | |||||
return false; | |||||
} | |||||
} | |||||
public static bool Check() { | |||||
try { | |||||
string path = Application.ExecutablePath; | |||||
RegistryKey runKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run"); | |||||
string[] runList = runKey.GetValueNames(); | |||||
runKey.Close(); | |||||
foreach (string item in runList) { | |||||
if (item.Equals("Shadowsocks")) | |||||
return true; | |||||
} | |||||
return false; | |||||
} catch (Exception) { | |||||
return false; | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -379,47 +379,15 @@ namespace Shadowsocks.View | |||||
qrCodeForm.Show(); | qrCodeForm.Show(); | ||||
} | } | ||||
private bool setAutoStartup(bool enabled) { | |||||
try { | |||||
string path = Application.ExecutablePath; | |||||
RegistryKey runKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true); | |||||
if (enabled) { | |||||
runKey.SetValue("Shadowsocks-CSharp", path); | |||||
} else { | |||||
runKey.DeleteValue("Shadowsocks-CSharp"); | |||||
} | |||||
runKey.Close(); | |||||
return true; | |||||
} catch (Exception e) { | |||||
return false; | |||||
} | |||||
} | |||||
private bool checkAutoStartup() { | |||||
try { | |||||
string path = Application.ExecutablePath; | |||||
RegistryKey runKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run"); | |||||
string[] runList = runKey.GetValueNames(); | |||||
runKey.Close(); | |||||
foreach(string item in runList){ | |||||
if (item.Equals("Shadowsocks-CSharp")) | |||||
return true; | |||||
} | |||||
return false; | |||||
} catch (Exception e) { | |||||
return false; | |||||
} | |||||
} | |||||
private void autoStartup_Click(object sender, EventArgs e) { | private void autoStartup_Click(object sender, EventArgs e) { | ||||
autoStartup.Checked = !autoStartup.Checked; | autoStartup.Checked = !autoStartup.Checked; | ||||
if (!setAutoStartup(autoStartup.Checked)) { | |||||
//MessageBox.Show("Failed to edit registry"); | |||||
if (!AutoStartup.Set(autoStartup.Checked)) { | |||||
MessageBox.Show("Failed to edit registry"); | |||||
} | } | ||||
} | } | ||||
private void contextMenu1_Popup(object sender, EventArgs e) { | private void contextMenu1_Popup(object sender, EventArgs e) { | ||||
autoStartup.Checked = checkAutoStartup(); | |||||
autoStartup.Checked = AutoStartup.Check(); | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -70,6 +70,7 @@ | |||||
<ItemGroup> | <ItemGroup> | ||||
<Compile Include="3rd\QRCodeCS.cs" /> | <Compile Include="3rd\QRCodeCS.cs" /> | ||||
<Compile Include="3rd\SimpleJson.cs" /> | <Compile Include="3rd\SimpleJson.cs" /> | ||||
<Compile Include="Controller\AutoStartup.cs" /> | |||||
<Compile Include="Controller\FileManager.cs" /> | <Compile Include="Controller\FileManager.cs" /> | ||||
<Compile Include="Controller\Logging.cs" /> | <Compile Include="Controller\Logging.cs" /> | ||||
<Compile Include="Controller\UpdateChecker.cs" /> | <Compile Include="Controller\UpdateChecker.cs" /> | ||||