- Portable mode ON: executable file's folder - Portable mode OFF: current user's temp foldertags/4.1.0
@@ -175,16 +175,11 @@ namespace Shadowsocks.Controller | |||||
return plugin.LocalEndPoint; | return plugin.LocalEndPoint; | ||||
} | } | ||||
public void SaveServers(List<Server> servers, int localPort) | |||||
public void SaveServers(List<Server> servers, int localPort, bool portableMode) | |||||
{ | { | ||||
_config.configs = servers; | _config.configs = servers; | ||||
_config.localPort = localPort; | _config.localPort = localPort; | ||||
Configuration.Save(_config); | |||||
} | |||||
public void SaveTempFolder(string tempFolder) | |||||
{ | |||||
_config.tempFolder = tempFolder; | |||||
_config.portableMode = portableMode; | |||||
Configuration.Save(_config); | Configuration.Save(_config); | ||||
} | } | ||||
@@ -55,6 +55,8 @@ Plugin Program=プラグインプログラム | |||||
Plugin Options=プラグインのオプション | Plugin Options=プラグインのオプション | ||||
Plugin Arguments=プラグインの引数 | Plugin Arguments=プラグインの引数 | ||||
Proxy Port=プロキシポート | Proxy Port=プロキシポート | ||||
Portable Mode=ポータブルモード | |||||
Restart required=再起動SSが必要 | |||||
Remarks=付記 | Remarks=付記 | ||||
Timeout(Sec)=タイムアウト (秒) | Timeout(Sec)=タイムアウト (秒) | ||||
OK=OK | OK=OK | ||||
@@ -55,6 +55,8 @@ Plugin Program=插件程序 | |||||
Plugin Options=插件选项 | Plugin Options=插件选项 | ||||
Plugin Arguments=插件参数 | Plugin Arguments=插件参数 | ||||
Proxy Port=代理端口 | Proxy Port=代理端口 | ||||
Portable Mode=便携模式 | |||||
Restart required=需要重新启动SS | |||||
Remarks=备注 | Remarks=备注 | ||||
Timeout(Sec)=超时(秒) | Timeout(Sec)=超时(秒) | ||||
OK=确定 | OK=确定 | ||||
@@ -62,7 +64,6 @@ Cancel=取消 | |||||
New server=未配置的服务器 | New server=未配置的服务器 | ||||
Move &Up=上移(&U) | Move &Up=上移(&U) | ||||
Move D&own=下移(&O) | Move D&own=下移(&O) | ||||
Temp Folder=临时文件夹 | |||||
# Proxy Form | # Proxy Form | ||||
@@ -55,6 +55,8 @@ Plugin Program=外掛程式 | |||||
Plugin Options=外掛程式選項 | Plugin Options=外掛程式選項 | ||||
Plugin Arguments=外掛程式參數 | Plugin Arguments=外掛程式參數 | ||||
Proxy Port=Proxy 連接埠 | Proxy Port=Proxy 連接埠 | ||||
Portable Mode=便攜模式 | |||||
Restart required=需要重新啟動SS | |||||
Remarks=註解 | Remarks=註解 | ||||
Timeout(Sec)=逾時 (秒) | Timeout(Sec)=逾時 (秒) | ||||
OK=確定 | OK=確定 | ||||
@@ -62,7 +64,6 @@ Cancel=取消 | |||||
New server=新伺服器 | New server=新伺服器 | ||||
Move &Up=上移 (&U) | Move &Up=上移 (&U) | ||||
Move D&own=下移 (&O) | Move D&own=下移 (&O) | ||||
Temp Folder=臨時資料夾 | |||||
# Proxy Form | # Proxy Form | ||||
@@ -20,6 +20,7 @@ namespace Shadowsocks.Model | |||||
public bool shareOverLan; | public bool shareOverLan; | ||||
public bool isDefault; | public bool isDefault; | ||||
public int localPort; | public int localPort; | ||||
public bool portableMode = true; | |||||
public string pacUrl; | public string pacUrl; | ||||
public bool useOnlinePac; | public bool useOnlinePac; | ||||
public bool secureLocalPac = true; | public bool secureLocalPac = true; | ||||
@@ -30,7 +31,6 @@ namespace Shadowsocks.Model | |||||
public LogViewerConfig logViewer; | public LogViewerConfig logViewer; | ||||
public ProxyConfig proxy; | public ProxyConfig proxy; | ||||
public HotkeyConfig hotkey; | public HotkeyConfig hotkey; | ||||
public string tempFolder; | |||||
private static string CONFIG_FILE = "gui-config.json"; | private static string CONFIG_FILE = "gui-config.json"; | ||||
@@ -146,13 +146,6 @@ namespace Shadowsocks.Model | |||||
throw new ArgumentException(I18N.GetString("Port can't be 8123")); | throw new ArgumentException(I18N.GetString("Port can't be 8123")); | ||||
} | } | ||||
public static void CheckTempFolder(string tempPath) | |||||
{ | |||||
if (string.IsNullOrWhiteSpace(tempPath)) | |||||
return; | |||||
Path.GetFullPath(tempPath); | |||||
} | |||||
private static void CheckPassword(string password) | private static void CheckPassword(string password) | ||||
{ | { | ||||
if (password.IsNullOrEmpty()) | if (password.IsNullOrEmpty()) | ||||
@@ -2,7 +2,6 @@ | |||||
using System.Diagnostics; | using System.Diagnostics; | ||||
using System.IO; | using System.IO; | ||||
using System.IO.Compression; | using System.IO.Compression; | ||||
using System.Linq; | |||||
using System.Runtime.InteropServices; | using System.Runtime.InteropServices; | ||||
using System.Windows.Forms; | using System.Windows.Forms; | ||||
using Microsoft.Win32; | using Microsoft.Win32; | ||||
@@ -28,45 +27,24 @@ namespace Shadowsocks.Util | |||||
public static class Utils | public static class Utils | ||||
{ | { | ||||
private static string _tempPath = null; | private static string _tempPath = null; | ||||
private const string TEMP_LOG = "temp.log"; | |||||
private static readonly string[] COMMON_ENV = | |||||
{ | |||||
"%Tmp%", | |||||
"%Temp%", | |||||
"%AppData%", | |||||
"%LocalAppData%", | |||||
"%Home%", | |||||
"%UserProfile%", | |||||
"%Public%", | |||||
"%CommonProgramFiles%", | |||||
"%CommonProgramFiles(x86)%", | |||||
"%CommonProgramW6432%", | |||||
"%ProgramFiles%", | |||||
"%ProgramFiles(x86)%", | |||||
"%ProgramW6432%", | |||||
"%ProgramData%", | |||||
}; | |||||
// return path to store temporary files | // return path to store temporary files | ||||
public static string GetTempPath() | public static string GetTempPath() | ||||
{ | { | ||||
if (_tempPath == null) | if (_tempPath == null) | ||||
{ | { | ||||
bool isPortableMode = Configuration.Load().portableMode; | |||||
try | try | ||||
{ | { | ||||
var tempFolder = Configuration.Load().tempFolder; | |||||
if (string.IsNullOrWhiteSpace(tempFolder)) | |||||
if (isPortableMode) | |||||
{ | |||||
_tempPath = Directory.CreateDirectory(Path.Combine(Application.StartupPath, "ss_win_temp")).FullName; | |||||
// don't use "/", it will fail when we call explorer /select xxx/ss_win_temp\xxx.log | // don't use "/", it will fail when we call explorer /select xxx/ss_win_temp\xxx.log | ||||
tempFolder = "ss_win_temp"; | |||||
else if (COMMON_ENV.Contains(tempFolder, StringComparer.OrdinalIgnoreCase)) | |||||
// add subfolder for these common folders | |||||
tempFolder += (@"\Shadowsocks\ss_win_temp_" + Application.ExecutablePath.GetHashCode()); | |||||
tempFolder = Environment.ExpandEnvironmentVariables(tempFolder); | |||||
// If `tempFolder` is an absolute path, `Application.StartupPath` will be ignored. | |||||
var tempDirectory = Directory.CreateDirectory(Path.Combine(Application.StartupPath, tempFolder)); | |||||
_tempPath = tempDirectory.FullName; | |||||
File.AppendAllText(Path.Combine(_tempPath, TEMP_LOG), $"[{DateTimeOffset.Now.ToString("u")}] Temp folder used by \"{Application.ExecutablePath}\"{Environment.NewLine}"); | |||||
} | |||||
else | |||||
{ | |||||
_tempPath = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), @"Shadowsocks\ss_win_temp_" + Application.ExecutablePath.GetHashCode())).FullName; | |||||
} | |||||
} | } | ||||
catch (Exception e) | catch (Exception e) | ||||
{ | { | ||||
@@ -63,8 +63,7 @@ | |||||
this.tableLayoutPanel5 = new System.Windows.Forms.TableLayoutPanel(); | this.tableLayoutPanel5 = new System.Windows.Forms.TableLayoutPanel(); | ||||
this.ProxyPortTextBox = new System.Windows.Forms.TextBox(); | this.ProxyPortTextBox = new System.Windows.Forms.TextBox(); | ||||
this.ProxyPortLabel = new System.Windows.Forms.Label(); | this.ProxyPortLabel = new System.Windows.Forms.Label(); | ||||
this.TempFolderLabel = new System.Windows.Forms.Label(); | |||||
this.TempFolderTextBox = new System.Windows.Forms.TextBox(); | |||||
this.PortableModeCheckBox = new System.Windows.Forms.CheckBox(); | |||||
this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel(); | this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel(); | ||||
this.tableLayoutPanel4 = new System.Windows.Forms.TableLayoutPanel(); | this.tableLayoutPanel4 = new System.Windows.Forms.TableLayoutPanel(); | ||||
this.DuplicateButton = new System.Windows.Forms.Button(); | this.DuplicateButton = new System.Windows.Forms.Button(); | ||||
@@ -506,26 +505,21 @@ | |||||
this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); | this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); | ||||
this.tableLayoutPanel5.Controls.Add(this.ProxyPortTextBox, 1, 0); | this.tableLayoutPanel5.Controls.Add(this.ProxyPortTextBox, 1, 0); | ||||
this.tableLayoutPanel5.Controls.Add(this.ProxyPortLabel, 0, 0); | this.tableLayoutPanel5.Controls.Add(this.ProxyPortLabel, 0, 0); | ||||
this.tableLayoutPanel5.Controls.Add(this.TempFolderLabel, 0, 1); | |||||
this.tableLayoutPanel5.Controls.Add(this.TempFolderTextBox, 1, 1); | |||||
this.tableLayoutPanel5.Controls.Add(this.PortableModeCheckBox, 0, 1); | |||||
this.tableLayoutPanel5.Location = new System.Drawing.Point(166, 308); | this.tableLayoutPanel5.Location = new System.Drawing.Point(166, 308); | ||||
this.tableLayoutPanel5.Margin = new System.Windows.Forms.Padding(0); | this.tableLayoutPanel5.Margin = new System.Windows.Forms.Padding(0); | ||||
this.tableLayoutPanel5.Name = "tableLayoutPanel5"; | this.tableLayoutPanel5.Name = "tableLayoutPanel5"; | ||||
this.tableLayoutPanel5.Padding = new System.Windows.Forms.Padding(3); | this.tableLayoutPanel5.Padding = new System.Windows.Forms.Padding(3); | ||||
this.tableLayoutPanel5.RowCount = 2; | this.tableLayoutPanel5.RowCount = 2; | ||||
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle()); | this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle()); | ||||
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); | |||||
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 58F)); | |||||
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 58F)); | |||||
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 58F)); | |||||
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 58F)); | |||||
this.tableLayoutPanel5.Size = new System.Drawing.Size(202, 64); | |||||
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle()); | |||||
this.tableLayoutPanel5.Size = new System.Drawing.Size(196, 64); | |||||
this.tableLayoutPanel5.TabIndex = 9; | this.tableLayoutPanel5.TabIndex = 9; | ||||
// | // | ||||
// ProxyPortTextBox | // ProxyPortTextBox | ||||
// | // | ||||
this.ProxyPortTextBox.Anchor = System.Windows.Forms.AnchorStyles.Left; | this.ProxyPortTextBox.Anchor = System.Windows.Forms.AnchorStyles.Left; | ||||
this.ProxyPortTextBox.Location = new System.Drawing.Point(83, 6); | |||||
this.ProxyPortTextBox.Location = new System.Drawing.Point(77, 6); | |||||
this.ProxyPortTextBox.MaxLength = 10; | this.ProxyPortTextBox.MaxLength = 10; | ||||
this.ProxyPortTextBox.Name = "ProxyPortTextBox"; | this.ProxyPortTextBox.Name = "ProxyPortTextBox"; | ||||
this.ProxyPortTextBox.Size = new System.Drawing.Size(113, 21); | this.ProxyPortTextBox.Size = new System.Drawing.Size(113, 21); | ||||
@@ -536,29 +530,24 @@ | |||||
// | // | ||||
this.ProxyPortLabel.Anchor = System.Windows.Forms.AnchorStyles.Right; | this.ProxyPortLabel.Anchor = System.Windows.Forms.AnchorStyles.Right; | ||||
this.ProxyPortLabel.AutoSize = true; | this.ProxyPortLabel.AutoSize = true; | ||||
this.ProxyPortLabel.Location = new System.Drawing.Point(12, 10); | |||||
this.ProxyPortLabel.Location = new System.Drawing.Point(6, 10); | |||||
this.ProxyPortLabel.Name = "ProxyPortLabel"; | this.ProxyPortLabel.Name = "ProxyPortLabel"; | ||||
this.ProxyPortLabel.Size = new System.Drawing.Size(65, 12); | this.ProxyPortLabel.Size = new System.Drawing.Size(65, 12); | ||||
this.ProxyPortLabel.TabIndex = 10; | this.ProxyPortLabel.TabIndex = 10; | ||||
this.ProxyPortLabel.Text = "Proxy Port"; | this.ProxyPortLabel.Text = "Proxy Port"; | ||||
// | // | ||||
// TempFolderLabel | |||||
// | |||||
this.TempFolderLabel.Anchor = System.Windows.Forms.AnchorStyles.Right; | |||||
this.TempFolderLabel.AutoSize = true; | |||||
this.TempFolderLabel.Location = new System.Drawing.Point(6, 39); | |||||
this.TempFolderLabel.Name = "TempFolderLabel"; | |||||
this.TempFolderLabel.Size = new System.Drawing.Size(71, 12); | |||||
this.TempFolderLabel.TabIndex = 9; | |||||
this.TempFolderLabel.Text = "Temp Folder"; | |||||
// | |||||
// TempFolderTextBox | |||||
// PortableModeCheckBox | |||||
// | // | ||||
this.TempFolderTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); | |||||
this.TempFolderTextBox.Location = new System.Drawing.Point(83, 35); | |||||
this.TempFolderTextBox.Name = "TempFolderTextBox"; | |||||
this.TempFolderTextBox.Size = new System.Drawing.Size(113, 21); | |||||
this.TempFolderTextBox.TabIndex = 11; | |||||
this.PortableModeCheckBox.Anchor = System.Windows.Forms.AnchorStyles.Left; | |||||
this.PortableModeCheckBox.AutoSize = true; | |||||
this.tableLayoutPanel5.SetColumnSpan(this.PortableModeCheckBox, 2); | |||||
this.PortableModeCheckBox.Location = new System.Drawing.Point(6, 37); | |||||
this.PortableModeCheckBox.Name = "PortableModeCheckBox"; | |||||
this.PortableModeCheckBox.Size = new System.Drawing.Size(102, 16); | |||||
this.PortableModeCheckBox.TabIndex = 11; | |||||
this.PortableModeCheckBox.Text = "Portable Mode"; | |||||
this.toolTip1.SetToolTip(this.PortableModeCheckBox, "restart required"); | |||||
this.PortableModeCheckBox.UseVisualStyleBackColor = true; | |||||
// | // | ||||
// tableLayoutPanel3 | // tableLayoutPanel3 | ||||
// | // | ||||
@@ -686,11 +675,10 @@ | |||||
private System.Windows.Forms.TextBox PluginOptionsTextBox; | private System.Windows.Forms.TextBox PluginOptionsTextBox; | ||||
private System.Windows.Forms.CheckBox ShowPasswdCheckBox; | private System.Windows.Forms.CheckBox ShowPasswdCheckBox; | ||||
private System.Windows.Forms.TextBox PasswordTextBox; | private System.Windows.Forms.TextBox PasswordTextBox; | ||||
private System.Windows.Forms.Label TempFolderLabel; | |||||
private System.Windows.Forms.TextBox PluginArgumentsTextBox; | private System.Windows.Forms.TextBox PluginArgumentsTextBox; | ||||
private System.Windows.Forms.Label PluginArgumentsLabel; | private System.Windows.Forms.Label PluginArgumentsLabel; | ||||
private System.Windows.Forms.ToolTip toolTip1; | private System.Windows.Forms.ToolTip toolTip1; | ||||
private System.Windows.Forms.TextBox TempFolderTextBox; | |||||
private System.Windows.Forms.CheckBox PortableModeCheckBox; | |||||
} | } | ||||
} | } | ||||
@@ -54,7 +54,8 @@ namespace Shadowsocks.View | |||||
PluginOptionsLabel.Text = I18N.GetString("Plugin Options"); | PluginOptionsLabel.Text = I18N.GetString("Plugin Options"); | ||||
PluginArgumentsLabel.Text = I18N.GetString("Plugin Arguments"); | PluginArgumentsLabel.Text = I18N.GetString("Plugin Arguments"); | ||||
ProxyPortLabel.Text = I18N.GetString("Proxy Port"); | ProxyPortLabel.Text = I18N.GetString("Proxy Port"); | ||||
TempFolderLabel.Text = I18N.GetString("Temp Folder"); | |||||
PortableModeCheckBox.Text = I18N.GetString("Portable Mode"); | |||||
toolTip1.SetToolTip(this.PortableModeCheckBox, I18N.GetString("Restart required")); | |||||
RemarksLabel.Text = I18N.GetString("Remarks"); | RemarksLabel.Text = I18N.GetString("Remarks"); | ||||
TimeoutLabel.Text = I18N.GetString("Timeout(Sec)"); | TimeoutLabel.Text = I18N.GetString("Timeout(Sec)"); | ||||
ServerGroupBox.Text = I18N.GetString("Server"); | ServerGroupBox.Text = I18N.GetString("Server"); | ||||
@@ -112,11 +113,11 @@ namespace Shadowsocks.View | |||||
return false; | return false; | ||||
} | } | ||||
int localPort = int.Parse(ProxyPortTextBox.Text); | int localPort = int.Parse(ProxyPortTextBox.Text); | ||||
Configuration.CheckTempFolder(TempFolderTextBox.Text); | |||||
Configuration.CheckServer(server); | Configuration.CheckServer(server); | ||||
Configuration.CheckLocalPort(localPort); | Configuration.CheckLocalPort(localPort); | ||||
_modifiedConfiguration.configs[_lastSelectedIndex] = server; | _modifiedConfiguration.configs[_lastSelectedIndex] = server; | ||||
_modifiedConfiguration.localPort = localPort; | _modifiedConfiguration.localPort = localPort; | ||||
_modifiedConfiguration.portableMode = PortableModeCheckBox.Checked; | |||||
return true; | return true; | ||||
} | } | ||||
@@ -167,7 +168,7 @@ namespace Shadowsocks.View | |||||
ServersListBox.SelectedIndex = _lastSelectedIndex; | ServersListBox.SelectedIndex = _lastSelectedIndex; | ||||
UpdateMoveUpAndDownButton(); | UpdateMoveUpAndDownButton(); | ||||
LoadSelectedServer(); | LoadSelectedServer(); | ||||
TempFolderTextBox.Text = _modifiedConfiguration.tempFolder; | |||||
PortableModeCheckBox.Checked = _modifiedConfiguration.portableMode; | |||||
} | } | ||||
private void ConfigForm_Load(object sender, EventArgs e) | private void ConfigForm_Load(object sender, EventArgs e) | ||||
@@ -191,7 +192,7 @@ namespace Shadowsocks.View | |||||
MessageBox.Show(I18N.GetString("Please add at least one server")); | MessageBox.Show(I18N.GetString("Please add at least one server")); | ||||
return; | return; | ||||
} | } | ||||
controller.SaveServers(_modifiedConfiguration.configs, _modifiedConfiguration.localPort); | |||||
controller.SaveServers(_modifiedConfiguration.configs, _modifiedConfiguration.localPort, _modifiedConfiguration.portableMode); | |||||
controller.SelectServerIndex(_modifiedConfiguration.configs.IndexOf(server)); | controller.SelectServerIndex(_modifiedConfiguration.configs.IndexOf(server)); | ||||
} | } | ||||
@@ -279,8 +280,7 @@ namespace Shadowsocks.View | |||||
MessageBox.Show(I18N.GetString("Please add at least one server")); | MessageBox.Show(I18N.GetString("Please add at least one server")); | ||||
return; | return; | ||||
} | } | ||||
controller.SaveServers(_modifiedConfiguration.configs, _modifiedConfiguration.localPort); | |||||
controller.SaveTempFolder(TempFolderTextBox.Text); | |||||
controller.SaveServers(_modifiedConfiguration.configs, _modifiedConfiguration.localPort, _modifiedConfiguration.portableMode); | |||||
// SelectedIndex remains valid | // SelectedIndex remains valid | ||||
// We handled this in event handlers, e.g. Add/DeleteButton, SelectedIndexChanged | // We handled this in event handlers, e.g. Add/DeleteButton, SelectedIndexChanged | ||||
// and move operations | // and move operations | ||||
@@ -120,4 +120,7 @@ | |||||
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | <metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | ||||
<value>17, 17</value> | <value>17, 17</value> | ||||
</metadata> | </metadata> | ||||
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | |||||
<value>17, 17</value> | |||||
</metadata> | |||||
</root> | </root> |