Add TorInstallator class.
ADD
WalletWasabi/Tor/TorInstallator.cs
+using System.IO;
+using System.Runtime.InteropServices;
+using System.Threading.Tasks;
+using WalletWasabi.Helpers;
+using WalletWasabi.Logging;
+
+namespace WalletWasabi.Tor
+{
+ /// <summary>
+ /// Installs Tor from <c>data-folder.zip</c> and <c>tor-PLATFORM.zip</c> files which are part of Wasabi Wallet distribution.
+ /// </summary>
+ public class TorInstallator
+ {
+ public static async Task InstallAsync(string torDir)
+ {
+ string torDaemonsDir = Path.Combine(EnvironmentHelpers.GetFullBaseDirectory(), "TorDaemons");
+
+ string dataZip = Path.Combine(torDaemonsDir, "data-folder.zip");
+ await IoHelpers.BetterExtractZipToDirectoryAsync(dataZip, torDir).ConfigureAwait(false);
+ Logger.LogInfo($"Extracted {dataZip} to {torDir}.");
+
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ string torWinZip = Path.Combine(torDaemonsDir, "tor-win64.zip");
+ await IoHelpers.BetterExtractZipToDirectoryAsync(torWinZip, torDir).ConfigureAwait(false);
+ Logger.LogInfo($"Extracted {torWinZip} to {torDir}.");
+ }
+ else // Linux or OSX
+ {
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+ {
+ string torLinuxZip = Path.Combine(torDaemonsDir, "tor-linux64.zip");
+ await IoHelpers.BetterExtractZipToDirectoryAsync(torLinuxZip, torDir).ConfigureAwait(false);
+ Logger.LogInfo($"Extracted {torLinuxZip} to {torDir}.");
+ }
+ else // OSX
+ {
+ string torOsxZip = Path.Combine(torDaemonsDir, "tor-osx64.zip");
+ await IoHelpers.BetterExtractZipToDirectoryAsync(torOsxZip, torDir).ConfigureAwait(false);
+ Logger.LogInfo($"Extracted {torOsxZip} to {torDir}.");
+ }
+
+ // Make sure there's sufficient permission.
+ string chmodTorDirCmd = $"chmod -R 750 {torDir}";
+ await EnvironmentHelpers.ShellExecAsync(chmodTorDirCmd, waitForExit: true).ConfigureAwait(false);
+ Logger.LogInfo($"Shell command executed: {chmodTorDirCmd}.");
+ }
+ }
+ }
+}

MODIFY
WalletWasabi/Tor/TorProcessManager.cs
WalletWasabi/Tor/TorProcessManager.cs
@@ -95,7 +95,7 @@ namespace WalletWasabi.Tor
if (!File.Exists(settings.TorPath))
{
Logger.LogInfo($"Tor instance NOT found at '{settings.TorPath}'. Attempting to acquire it ...");
- InstallTor(settings.TorDir);
+ TorInstallator.InstallAsync(settings.TorDir).GetAwaiter().GetResult();
}
else if (!IoHelpers.CheckExpectedHash(settings.HashSourcePath, Path.Combine(fullBaseDirectory, "TorDaemons")))
{
@@ -108,7 +108,7 @@ namespace WalletWasabi.Tor
}
Directory.Move(settings.TorDir, backupTorDir);
- InstallTor(settings.TorDir);
+ TorInstallator.InstallAsync(settings.TorDir).GetAwaiter().GetResult();
}
else
{
@@ -165,42 +165,6 @@ namespace WalletWasabi.Tor
}).Start();
}
- private static void InstallTor(string torDir)
- {
- string torDaemonsDir = Path.Combine(EnvironmentHelpers.GetFullBaseDirectory(), "TorDaemons");
-
- string dataZip = Path.Combine(torDaemonsDir, "data-folder.zip");
- IoHelpers.BetterExtractZipToDirectoryAsync(dataZip, torDir).GetAwaiter().GetResult();
- Logger.LogInfo($"Extracted {dataZip} to {torDir}.");
-
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- string torWinZip = Path.Combine(torDaemonsDir, "tor-win64.zip");
- IoHelpers.BetterExtractZipToDirectoryAsync(torWinZip, torDir).GetAwaiter().GetResult();
- Logger.LogInfo($"Extracted {torWinZip} to {torDir}.");
- }
- else // Linux or OSX
- {
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
- {
- string torLinuxZip = Path.Combine(torDaemonsDir, "tor-linux64.zip");
- IoHelpers.BetterExtractZipToDirectoryAsync(torLinuxZip, torDir).GetAwaiter().GetResult();
- Logger.LogInfo($"Extracted {torLinuxZip} to {torDir}.");
- }
- else // OSX
- {
- string torOsxZip = Path.Combine(torDaemonsDir, "tor-osx64.zip");
- IoHelpers.BetterExtractZipToDirectoryAsync(torOsxZip, torDir).GetAwaiter().GetResult();
- Logger.LogInfo($"Extracted {torOsxZip} to {torDir}.");
- }
-
- // Make sure there's sufficient permission.
- string chmodTorDirCmd = $"chmod -R 750 {torDir}";
- EnvironmentHelpers.ShellExecAsync(chmodTorDirCmd, waitForExit: true).GetAwaiter().GetResult();
- Logger.LogInfo($"Shell command executed: {chmodTorDirCmd}.");
- }
- }
-
/// <param name="torSocks5EndPoint">Opt out Tor with null.</param>
public static async Task<bool> IsTorRunningAsync(EndPoint torSocks5EndPoint)
{

Add TorInstallator class.