5
5
// </copyright>
6
6
// --------------------------------------------------------------------------------------------------------------------
7
7
8
+ using System ;
8
9
using System . IO ;
9
10
using System . Reflection ;
10
11
using Autofac ;
@@ -27,8 +28,31 @@ public static class Bootstrapper
27
28
// as it will be returning the path to the choco.exe executable instead.
28
29
public static readonly string ChocolateyGuiInstallLocation = _fileSystem . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . CodeBase . Replace ( "file:///" , string . Empty ) ) ;
29
30
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 ( ) ) ;
31
38
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
32
56
33
57
public static readonly string ChocolateyGuiCommonAssemblyLocation = _fileSystem . CombinePaths ( ChocolateyGuiInstallLocation , "ChocolateyGui.Common.dll" ) ;
34
58
public static readonly string ChocolateyGuiCommonWindowsAssemblyLocation = _fileSystem . CombinePaths ( ChocolateyGuiInstallLocation , "ChocolateyGui.Common.Windows.dll" ) ;
0 commit comments