From b1ebfe77724533996c36981b48c1ce0ff8890270 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Wed, 19 Aug 2015 19:35:37 -0700 Subject: [PATCH 1/3] prevent moving up and down when unsaved --- shadowsocks-csharp/View/ConfigForm.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shadowsocks-csharp/View/ConfigForm.cs b/shadowsocks-csharp/View/ConfigForm.cs index edcb405e..6e4e98ef 100755 --- a/shadowsocks-csharp/View/ConfigForm.cs +++ b/shadowsocks-csharp/View/ConfigForm.cs @@ -269,6 +269,10 @@ namespace Shadowsocks.View private void MoveUpButton_Click(object sender, EventArgs e) { + if (!SaveOldSelectedServer()) + { + return; + } if (ServersListBox.SelectedIndex > 0) { MoveConfigItem(-1); // -1 means move backward @@ -277,6 +281,10 @@ namespace Shadowsocks.View private void MoveDownButton_Click(object sender, EventArgs e) { + if (!SaveOldSelectedServer()) + { + return; + } if (ServersListBox.SelectedIndex < ServersListBox.Items.Count - 1) { MoveConfigItem(+1); // +1 means move forward From c767f55b3c3612b751caed8f94b4c048f5e31190 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Wed, 19 Aug 2015 21:39:06 -0700 Subject: [PATCH 2/3] add portable mode --- shadowsocks-csharp/Controller/Logging.cs | 5 +++-- .../Service/AvailabilityStatistics.cs | 5 +++-- .../Controller/Service/PolipoRunner.cs | 3 ++- shadowsocks-csharp/Encryption/PolarSSL.cs | 3 ++- shadowsocks-csharp/Encryption/Sodium.cs | 3 ++- shadowsocks-csharp/Util/Util.cs | 18 ++++++++++++++++++ 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/shadowsocks-csharp/Controller/Logging.cs b/shadowsocks-csharp/Controller/Logging.cs index 126dab70..d77a3fbe 100755 --- a/shadowsocks-csharp/Controller/Logging.cs +++ b/shadowsocks-csharp/Controller/Logging.cs @@ -1,4 +1,5 @@ -using System; +using Shadowsocks.Util; +using System; using System.Collections.Generic; using System.IO; using System.Net.Sockets; @@ -14,7 +15,7 @@ namespace Shadowsocks.Controller { try { - string temppath = Path.GetTempPath(); + string temppath = Utils.GetTempPath(); LogFile = Path.Combine(temppath, "shadowsocks.log"); FileStream fs = new FileStream(LogFile, FileMode.Append); StreamWriterWithTimestamp sw = new StreamWriterWithTimestamp(fs); diff --git a/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs b/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs index 0d8463a6..f3d088c5 100644 --- a/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs +++ b/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs @@ -6,7 +6,8 @@ using System.Net.NetworkInformation; using System.Threading; using Shadowsocks.Model; using System.Reflection; - +using Shadowsocks.Util; + namespace Shadowsocks.Controller { class AvailabilityStatistics @@ -25,7 +26,7 @@ namespace Shadowsocks.Controller //static constructor to initialize every public static fields before refereced static AvailabilityStatistics() { - string temppath = Path.GetTempPath(); + string temppath = Utils.GetTempPath(); AvailabilityStatisticsFile = Path.Combine(temppath, StatisticsFilesName); } diff --git a/shadowsocks-csharp/Controller/Service/PolipoRunner.cs b/shadowsocks-csharp/Controller/Service/PolipoRunner.cs index 3b3a5a4c..5b784bcd 100644 --- a/shadowsocks-csharp/Controller/Service/PolipoRunner.cs +++ b/shadowsocks-csharp/Controller/Service/PolipoRunner.cs @@ -9,6 +9,7 @@ using System.Text; using System.Net.NetworkInformation; using System.Net; using System.Runtime.InteropServices; +using Shadowsocks.Util; namespace Shadowsocks.Controller { @@ -20,7 +21,7 @@ namespace Shadowsocks.Controller static PolipoRunner() { - temppath = Path.GetTempPath(); + temppath = Utils.GetTempPath(); try { FileManager.UncompressFile(temppath + "/ss_privoxy.exe", Resources.privoxy_exe); diff --git a/shadowsocks-csharp/Encryption/PolarSSL.cs b/shadowsocks-csharp/Encryption/PolarSSL.cs index f5c2626d..42ce5bf7 100755 --- a/shadowsocks-csharp/Encryption/PolarSSL.cs +++ b/shadowsocks-csharp/Encryption/PolarSSL.cs @@ -1,5 +1,6 @@ using Shadowsocks.Controller; using Shadowsocks.Properties; +using Shadowsocks.Util; using System; using System.Collections.Generic; using System.IO; @@ -18,7 +19,7 @@ namespace Shadowsocks.Encryption static PolarSSL() { - string tempPath = Path.GetTempPath(); + string tempPath = Utils.GetTempPath(); string dllPath = tempPath + "/libsscrypto.dll"; try { diff --git a/shadowsocks-csharp/Encryption/Sodium.cs b/shadowsocks-csharp/Encryption/Sodium.cs index 9bc72d32..564aaeda 100755 --- a/shadowsocks-csharp/Encryption/Sodium.cs +++ b/shadowsocks-csharp/Encryption/Sodium.cs @@ -1,5 +1,6 @@ using Shadowsocks.Controller; using Shadowsocks.Properties; +using Shadowsocks.Util; using System; using System.Collections.Generic; using System.IO; @@ -14,7 +15,7 @@ namespace Shadowsocks.Encryption static Sodium() { - string tempPath = Path.GetTempPath(); + string tempPath = Utils.GetTempPath(); string dllPath = tempPath + "/libsscrypto.dll"; try { diff --git a/shadowsocks-csharp/Util/Util.cs b/shadowsocks-csharp/Util/Util.cs index 004128af..8cbdb31d 100755 --- a/shadowsocks-csharp/Util/Util.cs +++ b/shadowsocks-csharp/Util/Util.cs @@ -5,11 +5,29 @@ using System.IO; using System.IO.Compression; using System.Runtime.InteropServices; using System.Text; +using System.Windows.Forms; namespace Shadowsocks.Util { public class Utils { + // return path to store temporary files + public static string GetTempPath() + { + if (File.Exists(Application.StartupPath + "/shadowsocks_portable_mode.txt")) + { + try + { + Directory.CreateDirectory(Application.StartupPath + "/temp"); + } catch (Exception e) + { + Console.WriteLine(e); + } + return Application.StartupPath + "/temp"; + } + return Path.GetTempPath(); + } + public static void ReleaseMemory(bool removePages) { // release any unused pages From 765720dbd944f9dea5c1b076b6efc743cda86756 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Wed, 19 Aug 2015 21:51:28 -0700 Subject: [PATCH 3/3] small fix --- CHANGES | 9 +++++++++ shadowsocks-csharp/Util/Util.cs | 7 ++++--- shadowsocks-csharp/View/LogForm.cs | 3 ++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 2ddecc94..647c146f 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,12 @@ +2.5.6 2015-08-19 +- Add portable mode +- Support server reorder + +2.5.5 2015-08-17 +- Fix crash when enabling Availability Statistics and some servers can not be resolved +- Allow multiple instances +- Other fixes + 2.5.4 2015-08-16 - Hide Privoxy icon diff --git a/shadowsocks-csharp/Util/Util.cs b/shadowsocks-csharp/Util/Util.cs index 8cbdb31d..1858ee90 100755 --- a/shadowsocks-csharp/Util/Util.cs +++ b/shadowsocks-csharp/Util/Util.cs @@ -14,16 +14,17 @@ namespace Shadowsocks.Util // return path to store temporary files public static string GetTempPath() { - if (File.Exists(Application.StartupPath + "/shadowsocks_portable_mode.txt")) + if (File.Exists(Application.StartupPath + "\\shadowsocks_portable_mode.txt")) { try { - Directory.CreateDirectory(Application.StartupPath + "/temp"); + Directory.CreateDirectory(Application.StartupPath + "\\temp"); } catch (Exception e) { Console.WriteLine(e); } - return Application.StartupPath + "/temp"; + // don't use "/", it will fail when we call explorer /select xxx/temp\xxx.log + return Application.StartupPath + "\\temp"; } return Path.GetTempPath(); } diff --git a/shadowsocks-csharp/View/LogForm.cs b/shadowsocks-csharp/View/LogForm.cs index bdb9ad5c..d9255853 100644 --- a/shadowsocks-csharp/View/LogForm.cs +++ b/shadowsocks-csharp/View/LogForm.cs @@ -91,7 +91,8 @@ namespace Shadowsocks.View private void menuItem2_Click(object sender, EventArgs e) { - string argument = @"/select, " + filename; + string argument = "/select, \"" + filename + "\""; + Console.WriteLine(argument); System.Diagnostics.Process.Start("explorer.exe", argument); }