Browse Source

close #17

tags/2.3
clowwindy 10 years ago
parent
commit
3d6ee55f5a
2 changed files with 62 additions and 29 deletions
  1. +44
    -29
      shadowsocks-csharp/Program.cs
  2. +18
    -0
      shadowsocks-csharp/View/ConfigForm.cs

+ 44
- 29
shadowsocks-csharp/Program.cs View File

@@ -3,8 +3,11 @@ using Shadowsocks.Properties;
using Shadowsocks.View; using Shadowsocks.View;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
namespace Shadowsocks namespace Shadowsocks
@@ -20,39 +23,51 @@ namespace Shadowsocks
[STAThread] [STAThread]
static void Main() static void Main()
{ {
string tempPath = Path.GetTempPath();
string dllPath = tempPath + "/polarssl.dll";
try
using (Mutex mutex = new Mutex(false, "Global\\" + Assembly.GetExecutingAssembly().GetType().GUID.ToString()))
{ {
FileManager.UncompressFile(dllPath, Resources.polarssl_dll);
}
catch (IOException e)
{
Console.WriteLine(e.ToString());
}
LoadLibrary(dllPath);
if (!mutex.WaitOne(0, false))
{
Process[] oldProcesses = Process.GetProcessesByName("Shadowsocks");
if (oldProcesses.Length > 0)
{
Process oldProcess = oldProcesses[0];
}
MessageBox.Show("Shadowsocks is already running.\n\nFind Shadowsocks icon in your notify tray.");
return;
}
string tempPath = Path.GetTempPath();
string dllPath = tempPath + "/polarssl.dll";
try
{
FileManager.UncompressFile(dllPath, Resources.polarssl_dll);
}
catch (IOException e)
{
Console.WriteLine(e.ToString());
}
LoadLibrary(dllPath);
try
{
FileStream fs = new FileStream("shadowsocks.log", FileMode.Append);
TextWriter tmp = Console.Out;
StreamWriter sw = new StreamWriter(fs);
sw.AutoFlush = true;
Console.SetOut(sw);
Console.SetError(sw);
}
catch (IOException e)
{
Console.WriteLine(e.ToString());
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
ShadowsocksController controller = new ShadowsocksController();
// TODO run without a main form to save RAM
Application.Run(new ConfigForm(controller));
try
{
FileStream fs = new FileStream("shadowsocks.log", FileMode.Append);
TextWriter tmp = Console.Out;
StreamWriter sw = new StreamWriter(fs);
sw.AutoFlush = true;
Console.SetOut(sw);
Console.SetError(sw);
}
catch (IOException e)
{
Console.WriteLine(e.ToString());
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
ShadowsocksController controller = new ShadowsocksController();
// TODO run without a main form to save RAM
Application.Run(new ConfigForm(controller));
}
} }
} }
} }

+ 18
- 0
shadowsocks-csharp/View/ConfigForm.cs View File

@@ -17,6 +17,7 @@ namespace Shadowsocks.View
// this is a copy of configuration that we are working on // this is a copy of configuration that we are working on
private Configuration modifiedConfiguration; private Configuration modifiedConfiguration;
private int oldSelectedIndex = -1; private int oldSelectedIndex = -1;
private bool isFirstRun;
public ConfigForm(ShadowsocksController controller) public ConfigForm(ShadowsocksController controller)
{ {
@@ -162,6 +163,10 @@ namespace Shadowsocks.View
this.Hide(); this.Hide();
})); }));
} }
else
{
isFirstRun = true;
}
} }
private void ServersListBox_SelectedIndexChanged(object sender, EventArgs e) private void ServersListBox_SelectedIndexChanged(object sender, EventArgs e)
@@ -222,6 +227,17 @@ namespace Shadowsocks.View
this.Close(); this.Close();
} }
private void showFirstTimeBalloon()
{
if (isFirstRun)
{
notifyIcon1.BalloonTipTitle = "Shadowsocks is here";
notifyIcon1.BalloonTipText = "You can find turn on/off Shadowsocks in the context menu";
notifyIcon1.ShowBalloonTip(0);
isFirstRun = false;
}
}
private void OKButton_Click(object sender, EventArgs e) private void OKButton_Click(object sender, EventArgs e)
{ {
if (!saveOldSelectedServer()) if (!saveOldSelectedServer())
@@ -235,12 +251,14 @@ namespace Shadowsocks.View
} }
controller.SaveConfig(modifiedConfiguration); controller.SaveConfig(modifiedConfiguration);
this.Hide(); this.Hide();
showFirstTimeBalloon();
} }
private void CancelButton_Click(object sender, EventArgs e) private void CancelButton_Click(object sender, EventArgs e)
{ {
this.Hide(); this.Hide();
loadCurrentConfiguration(); loadCurrentConfiguration();
showFirstTimeBalloon();
} }
private void ConfigForm_FormClosed(object sender, FormClosedEventArgs e) private void ConfigForm_FormClosed(object sender, FormClosedEventArgs e)


Loading…
Cancel
Save