From e3c69f8fff7cd43be0be0fa6e8829f2db15583aa Mon Sep 17 00:00:00 2001 From: Victor Jiang Date: Tue, 10 Mar 2015 10:00:36 +0800 Subject: [PATCH] Add command line support to specify folder for ss_polipo --- shadowsocks-csharp/Controller/PolipoRunner.cs | 48 +++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/shadowsocks-csharp/Controller/PolipoRunner.cs b/shadowsocks-csharp/Controller/PolipoRunner.cs index bbff1c20..c3e098d9 100755 --- a/shadowsocks-csharp/Controller/PolipoRunner.cs +++ b/shadowsocks-csharp/Controller/PolipoRunner.cs @@ -19,8 +19,33 @@ namespace Shadowsocks.Controller static PolipoRunner() { - // temppath = Path.GetTempPath(); - temppath = Environment.CurrentDirectory; + temppath = Path.GetTempPath(); + string[] commandLineArgs = Environment.GetCommandLineArgs(); + for (int i = 0; i < commandLineArgs.Length; i++) + { + string commandLineArg = commandLineArgs[i]; + if (commandLineArg.ToLower() == "/SameFolderForPolipo".ToLower()) + { + temppath = Environment.CurrentDirectory; + } + if (commandLineArg.ToLower() == "/PolipoFolder".ToLower()) + { + if (i == commandLineArgs.Length - 1) + { + System.Windows.Forms.MessageBox.Show("Polipo folder not specified.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); + throw new Exception("Polipo folder not specified"); + } + else if (!IsDirectoryValid(commandLineArgs[i + 1])) + { + System.Windows.Forms.MessageBox.Show("Polipo folder not valid.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); + throw new Exception("Polipo folder not valid"); + } + else + { + temppath = commandLineArgs[i + 1]; + } + } + } try { FileManager.UncompressFile(temppath + "/ss_polipo.exe", Resources.polipo_exe); @@ -123,5 +148,24 @@ namespace Shadowsocks.Controller } throw new Exception("No free port found."); } + + public static bool IsDirectoryValid(string path) + { + try + { + if (new DirectoryInfo(path).Exists == true) + { + return true; + } + else + { + return false; + } + } + catch (Exception e) + { + return false; + } + } } }