55// </copyright>
66// --------------------------------------------------------------------------------------------------------------------
77
8+ using System ;
89using System . IO ;
910using System . Reflection ;
1011using Autofac ;
@@ -27,8 +28,31 @@ public static class Bootstrapper
2728 // as it will be returning the path to the choco.exe executable instead.
2829 public static readonly string ChocolateyGuiInstallLocation = _fileSystem . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . CodeBase . Replace ( "file:///" , string . Empty ) ) ;
2930 public static readonly string ChocolateyInstallEnvironmentVariableName = "ChocolateyInstall" ;
30- public static readonly string ChocolateyInstallLocation = System . Environment . GetEnvironmentVariable ( ChocolateyInstallEnvironmentVariableName ) ?? _fileSystem . GetDirectoryName ( _fileSystem . GetCurrentAssemblyPath ( ) ) ;
31+
32+ #if FORCE_CHOCOLATEY_OFFICIAL_KEY
33+ // always look at the official location of the machine installation
34+ public static readonly string ChocolateyInstallLocation = Environment . GetEnvironmentVariable ( ChocolateyInstallEnvironmentVariableName ) ?? _fileSystem . GetDirectoryName ( _fileSystem . GetCurrentAssemblyPath ( ) ) ;
35+ public static readonly string LicensedGuiAssemblyLocation = _fileSystem . CombinePaths ( ChocolateyInstallLocation , "extensions" , "chocolateygui" , "chocolateygui.licensed.dll" ) ;
36+ #elif DEBUG
37+ public static readonly string ChocolateyInstallLocation = _fileSystem . GetDirectoryName ( _fileSystem . GetCurrentAssemblyPath ( ) ) ;
3138 public static readonly string LicensedGuiAssemblyLocation = _fileSystem . CombinePaths ( ChocolateyInstallLocation , "extensions" , "chocolateygui" , "chocolateygui.licensed.dll" ) ;
39+ #else
40+ // Install locations is Chocolatey.dll or choco.exe - In Release mode
41+ // we might be testing on a server or in the local debugger. Either way,
42+ // start from the assembly location and if unfound, head to the machine
43+ // locations instead. This is a merge of official and Debug modes.
44+ private static Assembly _assemblyForLocation = Assembly . GetEntryAssembly ( ) != null ? Assembly . GetEntryAssembly ( ) : Assembly . GetExecutingAssembly ( ) ;
45+ public static readonly string ChocolateyInstallLocation = _fileSystem . FileExists ( _fileSystem . CombinePaths ( _fileSystem . GetDirectoryName ( _assemblyForLocation . CodeBase ) , "chocolatey.dll" ) ) ||
46+ _fileSystem . FileExists ( _fileSystem . CombinePaths ( _fileSystem . GetDirectoryName ( _assemblyForLocation . CodeBase ) , "choco.exe" ) ) ?
47+ _fileSystem . GetDirectoryName ( _assemblyForLocation . CodeBase ) :
48+ ! string . IsNullOrWhiteSpace ( Environment . GetEnvironmentVariable ( ChocolateyInstallEnvironmentVariableName ) ) ?
49+ Environment . GetEnvironmentVariable ( ChocolateyInstallEnvironmentVariableName ) :
50+ @"C:\ProgramData\Chocolatey"
51+ ;
52+
53+ // when being used as a reference, start by looking next to Chocolatey, then in a subfolder.
54+ public static readonly string LicensedGuiAssemblyLocation = _fileSystem . FileExists ( _fileSystem . CombinePaths ( ChocolateyInstallLocation , "chocolateygui.licensed.dll" ) ) ? _fileSystem . CombinePaths ( ChocolateyInstallLocation , "chocolateygui.licensed.dll" ) : _fileSystem . CombinePaths ( ChocolateyInstallLocation , "extensions" , "chocolateygui" , "chocolateygui.licensed.dll" ) ;
55+ #endif
3256
3357 public static readonly string ChocolateyGuiCommonAssemblyLocation = _fileSystem . CombinePaths ( ChocolateyGuiInstallLocation , "ChocolateyGui.Common.dll" ) ;
3458 public static readonly string ChocolateyGuiCommonWindowsAssemblyLocation = _fileSystem . CombinePaths ( ChocolateyGuiInstallLocation , "ChocolateyGui.Common.Windows.dll" ) ;
0 commit comments