using System; using System.Windows.Forms; using System.IO; using System.Net; using System.IO.Compression; using System.Diagnostics; namespace TorInstallerApp { public partial class Form1 : Form { static string bundle_url = "https://www.torproject.org/dist/torbrowser/10.0.18/tor-win32-0.4.5.9.zip"; static string bundle_location = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\TorBundle"; static string bundle_temp_dl_path = bundle_location + "/bundle.zip"; static string tor_data = bundle_location + @"\Data\Tor"; static string torrc_path = bundle_location + @"\Data\Tor\torrc"; static string tor_geoip_path = bundle_location + @"\Data\Tor\geoip"; static string tor_geoip6_path = bundle_location + @"\Data\Tor\geoip6"; public static void ExecuteAsAdmin(string Filename, string FileArgs) { Process proc = new Process(); proc.StartInfo.FileName = Filename; proc.StartInfo.Arguments = FileArgs; proc.StartInfo.Verb = "runas"; proc.Start(); } public static void DownloadandUnpack() { WebClient webClient = new WebClient(); webClient.Proxy = null; webClient.DownloadFile(bundle_url, bundle_temp_dl_path); ZipFile.ExtractToDirectory(bundle_temp_dl_path, bundle_location); } public static void MakeTorConfig() { string text = "DataDirectory " + tor_data + "\n" + "GeoIPFile " + tor_geoip_path + "\n" + "GeoIPv6File " + tor_geoip6_path + "\n" + "AvoidDiskWrites 1\n" + "SocksPort 127.0.0.1:9160\n"; File.WriteAllText(torrc_path, text); } public static void InstallasService() { ExecuteAsAdmin("sc.exe", "create TorBundle binPath= " + "\"" + bundle_location + "\\Tor\\tor.exe" + " --nt-service -f " + torrc_path + "\"" + " start= auto"); ExecuteAsAdmin("sc.exe", "start TorBundle"); } public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { if (Directory.Exists(bundle_location)) { button1.Enabled = false; } else { button2.Enabled = false; } } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start("https://nova.ws"); } private void button1_Click(object sender, EventArgs e) { Directory.CreateDirectory(bundle_location); DownloadandUnpack(); MakeTorConfig(); InstallasService(); MessageBox.Show("Setup is finished, you can close app."); button1.Enabled = false; button2.Enabled = true; } private void button2_Click(object sender, EventArgs e) { ExecuteAsAdmin("sc.exe", "stop TorBundle"); ExecuteAsAdmin("sc.exe", "delete TorBundle"); Directory.Delete(bundle_location, true); MessageBox.Show("Delete TorBundle sucess, you can close app"); button1.Enabled = true; button2.Enabled = false; } } }