Skip to content

Commit a2a976c

Browse files
authored
Merge pull request chocolatey#1024 from gep13/allow-debugging
2 parents d2dbe95 + 987b7bf commit a2a976c

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

Source/ChocolateyGui.Common.Windows/Bootstrapper.cs

+24-1
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,31 @@ public class Bootstrapper : BootstrapperBase
3939
#pragma warning disable SA1202
4040
public static readonly string ChocolateyGuiInstallLocation = _fileSystem.GetDirectoryName(_fileSystem.GetCurrentAssemblyPath());
4141
public static readonly string ChocolateyInstallEnvironmentVariableName = "ChocolateyInstall";
42-
public static readonly string ChocolateyInstallLocation = System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName) ?? _fileSystem.GetDirectoryName(_fileSystem.GetCurrentAssemblyPath());
42+
43+
#if FORCE_CHOCOLATEY_OFFICIAL_KEY
44+
// always look at the official location of the machine installation
45+
public static readonly string ChocolateyInstallLocation = Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName) ?? _fileSystem.GetDirectoryName(_fileSystem.GetCurrentAssemblyPath());
46+
public static readonly string LicensedGuiAssemblyLocation = _fileSystem.CombinePaths(ChocolateyInstallLocation, "extensions", "chocolateygui", "chocolateygui.licensed.dll");
47+
#elif DEBUG
48+
public static readonly string ChocolateyInstallLocation = _fileSystem.GetDirectoryName(_fileSystem.GetCurrentAssemblyPath());
4349
public static readonly string LicensedGuiAssemblyLocation = _fileSystem.CombinePaths(ChocolateyInstallLocation, "extensions", "chocolateygui", "chocolateygui.licensed.dll");
50+
#else
51+
// Install locations is Chocolatey.dll or choco.exe - In Release mode
52+
// we might be testing on a server or in the local debugger. Either way,
53+
// start from the assembly location and if unfound, head to the machine
54+
// locations instead. This is a merge of official and Debug modes.
55+
private static Assembly _assemblyForLocation = Assembly.GetEntryAssembly() != null ? Assembly.GetEntryAssembly() : Assembly.GetExecutingAssembly();
56+
public static readonly string ChocolateyInstallLocation = _fileSystem.FileExists(_fileSystem.CombinePaths(_fileSystem.GetDirectoryName(_assemblyForLocation.CodeBase), "chocolatey.dll")) ||
57+
_fileSystem.FileExists(_fileSystem.CombinePaths(_fileSystem.GetDirectoryName(_assemblyForLocation.CodeBase), "choco.exe")) ?
58+
_fileSystem.GetDirectoryName(_assemblyForLocation.CodeBase) :
59+
!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName)) ?
60+
Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName) :
61+
@"C:\ProgramData\Chocolatey"
62+
;
63+
64+
// when being used as a reference, start by looking next to Chocolatey, then in a subfolder.
65+
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");
66+
#endif
4467

4568
public static readonly string ChocolateyGuiCommonAssemblyLocation = _fileSystem.CombinePaths(ChocolateyGuiInstallLocation, "ChocolateyGui.Common.dll");
4669
public static readonly string ChocolateyGuiCommonWindowsAssemblyLocation = _fileSystem.CombinePaths(ChocolateyGuiInstallLocation, "ChocolateyGui.Common.Windows.dll");

Source/ChocolateyGuiCli/Bootstrapper.cs

+25-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// </copyright>
66
// --------------------------------------------------------------------------------------------------------------------
77

8+
using System;
89
using System.IO;
910
using System.Reflection;
1011
using 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

Comments
 (0)