Merge branch 'kookxiang-master'
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Shadowsocks.Model
|
||||
{
|
||||
@@ -10,6 +11,7 @@ namespace Shadowsocks.Model
|
||||
{
|
||||
public Configuration()
|
||||
{
|
||||
Configuration.CONFIG_FILE = Application.StartupPath + @"\gui-config.json";
|
||||
}
|
||||
|
||||
public List<Server> configs;
|
||||
|
||||
+20
-10
@@ -65,6 +65,7 @@
|
||||
this.AddButton = new System.Windows.Forms.Button();
|
||||
this.ServerGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.ServersListBox = new System.Windows.Forms.ListBox();
|
||||
this.autoStartup = new System.Windows.Forms.MenuItem();
|
||||
this.tableLayoutPanel1.SuspendLayout();
|
||||
this.panel1.SuspendLayout();
|
||||
this.panel3.SuspendLayout();
|
||||
@@ -299,6 +300,7 @@
|
||||
//
|
||||
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
||||
this.enableItem,
|
||||
this.autoStartup,
|
||||
this.ShareOverLANItem,
|
||||
this.ServersItem,
|
||||
this.menuItem4,
|
||||
@@ -308,6 +310,7 @@
|
||||
this.aboutItem,
|
||||
this.menuItem3,
|
||||
this.quitItem});
|
||||
this.contextMenu1.Popup += new System.EventHandler(this.contextMenu1_Popup);
|
||||
//
|
||||
// enableItem
|
||||
//
|
||||
@@ -317,13 +320,13 @@
|
||||
//
|
||||
// ShareOverLANItem
|
||||
//
|
||||
this.ShareOverLANItem.Index = 1;
|
||||
this.ShareOverLANItem.Index = 2;
|
||||
this.ShareOverLANItem.Text = "Share over LAN";
|
||||
this.ShareOverLANItem.Click += new System.EventHandler(this.ShareOverLANItem_Click);
|
||||
//
|
||||
// ServersItem
|
||||
//
|
||||
this.ServersItem.Index = 2;
|
||||
this.ServersItem.Index = 3;
|
||||
this.ServersItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
||||
this.SeperatorItem,
|
||||
this.ConfigItem});
|
||||
@@ -342,41 +345,41 @@
|
||||
//
|
||||
// menuItem4
|
||||
//
|
||||
this.menuItem4.Index = 3;
|
||||
this.menuItem4.Index = 4;
|
||||
this.menuItem4.Text = "-";
|
||||
//
|
||||
// editPACFileItem
|
||||
//
|
||||
this.editPACFileItem.Index = 4;
|
||||
this.editPACFileItem.Index = 5;
|
||||
this.editPACFileItem.Text = "Edit &PAC File...";
|
||||
this.editPACFileItem.Click += new System.EventHandler(this.EditPACFileItem_Click);
|
||||
//
|
||||
// QRCodeItem
|
||||
//
|
||||
this.QRCodeItem.Index = 5;
|
||||
this.QRCodeItem.Index = 6;
|
||||
this.QRCodeItem.Text = "Show &QRCode...";
|
||||
this.QRCodeItem.Click += new System.EventHandler(this.QRCodeItem_Click);
|
||||
//
|
||||
// ShowLogItem
|
||||
//
|
||||
this.ShowLogItem.Index = 6;
|
||||
this.ShowLogItem.Index = 7;
|
||||
this.ShowLogItem.Text = "Show Logs...";
|
||||
this.ShowLogItem.Click += new System.EventHandler(this.ShowLogItem_Click);
|
||||
//
|
||||
// aboutItem
|
||||
//
|
||||
this.aboutItem.Index = 7;
|
||||
this.aboutItem.Index = 8;
|
||||
this.aboutItem.Text = "About...";
|
||||
this.aboutItem.Click += new System.EventHandler(this.AboutItem_Click);
|
||||
//
|
||||
// menuItem3
|
||||
//
|
||||
this.menuItem3.Index = 8;
|
||||
this.menuItem3.Index = 9;
|
||||
this.menuItem3.Text = "-";
|
||||
//
|
||||
// quitItem
|
||||
//
|
||||
this.quitItem.Index = 9;
|
||||
this.quitItem.Index = 10;
|
||||
this.quitItem.Text = "&Quit";
|
||||
this.quitItem.Click += new System.EventHandler(this.Quit_Click);
|
||||
//
|
||||
@@ -435,7 +438,13 @@
|
||||
this.ServersListBox.Size = new System.Drawing.Size(286, 264);
|
||||
this.ServersListBox.TabIndex = 5;
|
||||
this.ServersListBox.SelectedIndexChanged += new System.EventHandler(this.ServersListBox_SelectedIndexChanged);
|
||||
//
|
||||
//
|
||||
// autoStartup
|
||||
//
|
||||
this.autoStartup.Index = 1;
|
||||
this.autoStartup.Text = "Start on boot";
|
||||
this.autoStartup.Click += new System.EventHandler(this.autoStartup_Click);
|
||||
//
|
||||
// ConfigForm
|
||||
//
|
||||
this.AcceptButton = this.OKButton;
|
||||
@@ -508,6 +517,7 @@
|
||||
private System.Windows.Forms.MenuItem QRCodeItem;
|
||||
private System.Windows.Forms.MenuItem ShowLogItem;
|
||||
private System.Windows.Forms.MenuItem ShareOverLANItem;
|
||||
private System.Windows.Forms.MenuItem autoStartup;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Win32;
|
||||
using Shadowsocks.Controller;
|
||||
using Shadowsocks.Model;
|
||||
using Shadowsocks.Properties;
|
||||
@@ -377,5 +378,16 @@ namespace Shadowsocks.View
|
||||
qrCodeForm.Icon = this.Icon;
|
||||
qrCodeForm.Show();
|
||||
}
|
||||
|
||||
private void autoStartup_Click(object sender, EventArgs e) {
|
||||
autoStartup.Checked = !autoStartup.Checked;
|
||||
if (!AutoStartup.Set(autoStartup.Checked)) {
|
||||
MessageBox.Show("Failed to edit registry");
|
||||
}
|
||||
}
|
||||
|
||||
private void contextMenu1_Popup(object sender, EventArgs e) {
|
||||
autoStartup.Checked = AutoStartup.Check();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="3rd\QRCodeCS.cs" />
|
||||
<Compile Include="3rd\SimpleJson.cs" />
|
||||
<Compile Include="Controller\AutoStartup.cs" />
|
||||
<Compile Include="Controller\FileManager.cs" />
|
||||
<Compile Include="Controller\Logging.cs" />
|
||||
<Compile Include="Controller\UpdateChecker.cs" />
|
||||
|
||||
Reference in New Issue
Block a user