diff --git a/src/chocolatey.console/Program.cs b/src/chocolatey.console/Program.cs index ab64b5bf0d..77458b5a9a 100644 --- a/src/chocolatey.console/Program.cs +++ b/src/chocolatey.console/Program.cs @@ -183,7 +183,7 @@ private static void remove_old_chocolatey_exe(IFileSystem fileSystem) { try { - fileSystem.delete_file(Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", string.Empty) + ".old"); + fileSystem.delete_file(fileSystem.get_current_assembly_path() + ".old"); fileSystem.delete_file(fileSystem.combine_paths(AppDomain.CurrentDomain.BaseDirectory, "choco.exe.old")); } catch (Exception ex) diff --git a/src/chocolatey.tests.integration/NUnitSetup.cs b/src/chocolatey.tests.integration/NUnitSetup.cs index 4b3aa1a965..f887003ed0 100644 --- a/src/chocolatey.tests.integration/NUnitSetup.cs +++ b/src/chocolatey.tests.integration/NUnitSetup.cs @@ -57,7 +57,7 @@ private static void fix_application_parameter_variables(Container container) { var fileSystem = container.GetInstance<IFileSystem>(); - var applicationLocation = fileSystem.get_directory_name(Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", string.Empty)); + var applicationLocation = fileSystem.get_directory_name(fileSystem.get_current_assembly_path()); var field = typeof (ApplicationParameters).GetField("InstallLocation"); field.SetValue(null, applicationLocation); diff --git a/src/chocolatey.tests.integration/Scenario.cs b/src/chocolatey.tests.integration/Scenario.cs index 08fa4ae024..f96983da99 100644 --- a/src/chocolatey.tests.integration/Scenario.cs +++ b/src/chocolatey.tests.integration/Scenario.cs @@ -35,7 +35,7 @@ public class Scenario public static string get_top_level() { - return _fileSystem.get_directory_name(Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", string.Empty)); + return _fileSystem.get_directory_name(_fileSystem.get_current_assembly_path()); } public static string get_package_install_path() diff --git a/src/chocolatey.tests.integration/infrastructure/cryptography/CrytpoHashProviderSpecs.cs b/src/chocolatey.tests.integration/infrastructure/cryptography/CrytpoHashProviderSpecs.cs index 20aa0947e7..60f822664a 100644 --- a/src/chocolatey.tests.integration/infrastructure/cryptography/CrytpoHashProviderSpecs.cs +++ b/src/chocolatey.tests.integration/infrastructure/cryptography/CrytpoHashProviderSpecs.cs @@ -35,7 +35,7 @@ public override void Context() { FileSystem = new DotNetFileSystem(); Provider = new CrytpoHashProvider(FileSystem,CryptoHashProviderType.Md5); - ContextDirectory = FileSystem.combine_paths(FileSystem.get_directory_name(Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", string.Empty)), "context"); + ContextDirectory = FileSystem.combine_paths(FileSystem.get_directory_name(FileSystem.get_current_assembly_path()), "context"); } } diff --git a/src/chocolatey/infrastructure.app/ApplicationParameters.cs b/src/chocolatey/infrastructure.app/ApplicationParameters.cs index a546a87287..8b550c8573 100644 --- a/src/chocolatey/infrastructure.app/ApplicationParameters.cs +++ b/src/chocolatey/infrastructure.app/ApplicationParameters.cs @@ -30,12 +30,12 @@ public static class ApplicationParameters public static readonly string ChocolateyInstallEnvironmentVariableName = "ChocolateyInstall"; public static readonly string Name = "Chocolatey"; #if DEBUG - public static readonly string InstallLocation = _fileSystem.get_directory_name(Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", string.Empty)); + public static readonly string InstallLocation = _fileSystem.get_directory_name(_fileSystem.get_current_assembly_path()); #else - public static readonly string InstallLocation = Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName) ?? _fileSystem.get_directory_name(Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", string.Empty)); + public static readonly string InstallLocation = System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName) ?? _fileSystem.get_directory_name(_fileSystem.get_current_assembly_path()); #endif - public static readonly string CommonAppDataChocolatey = _fileSystem.combine_paths(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), Name); + public static readonly string CommonAppDataChocolatey = _fileSystem.combine_paths(System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData), Name); public static readonly string LoggingLocation = _fileSystem.combine_paths(InstallLocation, "logs"); public static readonly string LoggingFile = @"chocolatey.log"; public static readonly string Log4NetConfigurationAssembly = @"chocolatey"; diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUnpackSelfCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUnpackSelfCommand.cs index 49c257fc76..5b7b9e7a23 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUnpackSelfCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUnpackSelfCommand.cs @@ -98,7 +98,7 @@ public void run(ChocolateyConfiguration configuration) AssemblyFileExtractor.extract_all_resources_to_relative_directory( _fileSystem, assembly, - _fileSystem.get_directory_name(Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", string.Empty)), + _fileSystem.get_directory_name(_fileSystem.get_current_assembly_path()), folders, ApplicationParameters.ChocolateyFileResources, overwriteExisting: configuration.Force, diff --git a/src/chocolatey/infrastructure/commands/CommandExecutor.cs b/src/chocolatey/infrastructure/commands/CommandExecutor.cs index 05f6eb39d9..fd9ed43c3a 100644 --- a/src/chocolatey/infrastructure/commands/CommandExecutor.cs +++ b/src/chocolatey/infrastructure/commands/CommandExecutor.cs @@ -49,7 +49,7 @@ public static void initialize_with(Lazy<IFileSystem> file_system, Func<IProcess> public int execute(string process, string arguments, int waitForExitInSeconds) { - return execute(process, arguments, waitForExitInSeconds, file_system.get_directory_name(Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", string.Empty))); + return execute(process, arguments, waitForExitInSeconds, file_system.get_directory_name(file_system.get_current_assembly_path())); } public int execute( @@ -64,7 +64,7 @@ public int execute( return execute(process, arguments, waitForExitInSeconds, - file_system.get_directory_name(Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", string.Empty)), + file_system.get_directory_name(file_system.get_current_assembly_path()), stdOutAction, stdErrAction, updateProcessPath diff --git a/src/chocolatey/infrastructure/commands/PowershellExecutor.cs b/src/chocolatey/infrastructure/commands/PowershellExecutor.cs index 1a630310aa..ef44dc84d9 100644 --- a/src/chocolatey/infrastructure/commands/PowershellExecutor.cs +++ b/src/chocolatey/infrastructure/commands/PowershellExecutor.cs @@ -50,7 +50,7 @@ Action<object, DataReceivedEventArgs> stdErrAction _powershell, arguments, waitForExitSeconds, - workingDirectory: fileSystem.get_directory_name(Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", string.Empty)), + workingDirectory: fileSystem.get_directory_name(fileSystem.get_current_assembly_path()), stdOutAction: stdOutAction, stdErrAction: stdErrAction, updateProcessPath: true diff --git a/src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs b/src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs index f2dc91eaec..f78064b550 100644 --- a/src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs +++ b/src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs @@ -81,6 +81,11 @@ public char get_path_directory_separator_char() return Path.DirectorySeparatorChar; } + public string get_current_assembly_path() + { + return Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", string.Empty); + } + #endregion #region File diff --git a/src/chocolatey/infrastructure/filesystem/IFileSystem.cs b/src/chocolatey/infrastructure/filesystem/IFileSystem.cs index 959a9205c9..971990e475 100644 --- a/src/chocolatey/infrastructure/filesystem/IFileSystem.cs +++ b/src/chocolatey/infrastructure/filesystem/IFileSystem.cs @@ -53,6 +53,12 @@ public interface IFileSystem /// <returns></returns> char get_path_directory_separator_char(); + /// <summary> + /// Gets the location of the executing assembly + /// </summary> + /// <returns>The path to the executing assembly</returns> + string get_current_assembly_path(); + #endregion #region File