add portable mode

This commit is contained in:
clowwindy
2015-08-19 21:39:06 -07:00
parent 7ab5eae64c
commit c767f55b3c
6 changed files with 30 additions and 7 deletions
+3 -2
View File
@@ -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);
@@ -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);
}
@@ -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);
+2 -1
View File
@@ -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
{
+2 -1
View File
@@ -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
{
+18
View File
@@ -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