Skip to content

Commit

Permalink
(GH-785) Remove ApplicationParameters class
Browse files Browse the repository at this point in the history
Due to problems with using an assembly before it has been correctly
resolved, using the concept of a shared ApplicationParameters class
won't work going forward.  Instead, the required information needs to
be duplicated in both the Chocolatey GUI and the Chocolatey CLI
projects.  This may cause problems later with StyleCop when we come to
create a release build, but we will cross that bridge when we come to
it.
  • Loading branch information
gep13 committed Jul 13, 2020
1 parent ebd6fd6 commit c4db2d9
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 60 deletions.
27 changes: 24 additions & 3 deletions Source/ChocolateyGui.Common.Windows/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using AutoMapper;
using Caliburn.Micro;
using chocolatey;
using chocolatey.infrastructure.filesystem;
using ChocolateyGui.Common.Models;
using ChocolateyGui.Common.Properties;
using ChocolateyGui.Common.Services;
Expand All @@ -32,6 +33,26 @@ namespace ChocolateyGui.Common.Windows
{
public class Bootstrapper : BootstrapperBase
{
private static readonly IFileSystem _fileSystem = new DotNetFileSystem();

public static readonly string ChocolateyGuiInstallLocation = _fileSystem.get_directory_name(_fileSystem.get_current_assembly_path());
public static readonly string ChocolateyInstallEnvironmentVariableName = "ChocolateyInstall";
public static readonly string ChocolateyInstallLocation = System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName) ?? _fileSystem.get_directory_name(_fileSystem.get_current_assembly_path());
public static readonly string LicensedGuiAssemblyLocation = _fileSystem.combine_paths(ChocolateyInstallLocation, "extensions", "chocolateygui", "chocolateygui.licensed.dll");

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

public static readonly string ChocolateyGuiCommonAssemblySimpleName = "ChocolateyGui.Common";
public static readonly string ChocolateyGuiCommonWindowsAssemblySimpleName = "ChocolateyGui.Common.Windows";

public static readonly string UnofficialChocolateyPublicKey = "ffc115b9f4eb5c26";
public static readonly string OfficialChocolateyPublicKey = "dfd1909b30b79d8b";

public static readonly string Name = "Chocolatey GUI";

public static readonly string LicensedChocolateyGuiAssemblySimpleName = "chocolateygui.licensed";

public Bootstrapper()
{
Initialize();
Expand All @@ -47,9 +68,9 @@ public Bootstrapper()

internal static string ApplicationFilesPath { get; } = Path.GetDirectoryName((Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly()).Location);

internal static string AppDataPath { get; } = LogSetup.GetAppDataPath(ApplicationParameters.Name);
internal static string AppDataPath { get; } = LogSetup.GetAppDataPath(Name);

internal static string LocalAppDataPath { get; } = LogSetup.GetLocalAppDataPath(ApplicationParameters.Name);
internal static string LocalAppDataPath { get; } = LogSetup.GetLocalAppDataPath(Name);

public Task OnExitAsync()
{
Expand All @@ -74,7 +95,7 @@ protected override void Configure()

Logger = Log.Logger = logConfig.CreateLogger();

Container = AutoFacConfiguration.RegisterAutoFac();
Container = AutoFacConfiguration.RegisterAutoFac(LicensedChocolateyGuiAssemblySimpleName, LicensedGuiAssemblyLocation);

Internationalization.Initialize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ChocolateyService(IMapper mapper, IProgressService progressService, IChoc
_configService = configService;
_choco = Lets.GetChocolatey().SetCustomLogging(new SerilogLogger(Logger, _progressService));

_localAppDataPath = _fileSystem.combine_paths(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify), ApplicationParameters.Name);
_localAppDataPath = _fileSystem.combine_paths(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify), "Chocolatey GUI");
}

public Task<bool> IsElevated()
Expand Down
39 changes: 0 additions & 39 deletions Source/ChocolateyGui.Common/ApplicationParameters.cs

This file was deleted.

1 change: 0 additions & 1 deletion Source/ChocolateyGui.Common/ChocolateyGui.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
<Compile Include="..\SolutionInfo.cs">
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
<Compile Include="ApplicationParameters.cs" />
<Compile Include="Attributes\ConfigAttribute.cs" />
<Compile Include="Attributes\FeatureAttribute.cs" />
<Compile Include="Attributes\LocalizedCommandForAttribute.cs" />
Expand Down
2 changes: 1 addition & 1 deletion Source/ChocolateyGui.Common/Commands/GenericRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void Run(ChocolateyGuiConfiguration configuration, IContainer container,

if (command != null)
{
Logger.Debug("_ {0}:{1} - Normal Run Mode _".format_with(ApplicationParameters.Name, command.GetType().Name));
Logger.Debug("_ {0}:{1} - Normal Run Mode _".format_with("Chocolatey GUI", command.GetType().Name));
command.Run(configuration);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ChocolateyGuiCacheService(IFileStorageService fileStorageService, IFileSy
_fileStorageService = fileStorageService;
_fileSystem = fileSystem;

_localAppDataPath = _fileSystem.combine_paths(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify), ApplicationParameters.Name);
_localAppDataPath = _fileSystem.combine_paths(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify), "Chocolatey GUI");
}

public void PurgeIcons()
Expand Down
2 changes: 1 addition & 1 deletion Source/ChocolateyGui.Common/Services/VersionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public string Version

public string DisplayVersion
{
get { return string.Format("{0} v{1}", ApplicationParameters.Name, Version); }
get { return string.Format("{0} v{1}", "Chocolatey GUI", Version); }
}
}
}
8 changes: 4 additions & 4 deletions Source/ChocolateyGui.Common/Startup/AutoFacConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ public static class AutoFacConfiguration
"Microsoft.Maintainability",
"CA1506:AvoidExcessiveClassCoupling",
Justification = "This is really a requirement due to required registrations.")]
public static IContainer RegisterAutoFac()
public static IContainer RegisterAutoFac(string chocolateyGuiAssemblySimpleName, string licensedGuiAssemblyLocation)
{
var builder = new ContainerBuilder();
builder.RegisterAssemblyModules(System.Reflection.Assembly.GetCallingAssembly());

var license = License.validate_license();
if (license.IsValid)
{
if (File.Exists(ApplicationParameters.LicensedGuiAssemblyLocation))
if (File.Exists(licensedGuiAssemblyLocation))
{
var licensedGuiAssembly = AssemblyResolution.resolve_or_load_assembly(
ApplicationParameters.LicensedChocolateyGuiAssemblySimpleName,
chocolateyGuiAssemblySimpleName,
chocolatey.infrastructure.app.ApplicationParameters.OfficialChocolateyPublicKey,
ApplicationParameters.LicensedGuiAssemblyLocation);
licensedGuiAssemblyLocation);

if (licensedGuiAssembly != null)
{
Expand Down
27 changes: 24 additions & 3 deletions Source/ChocolateyGuiCli/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System.IO;
using Autofac;
using chocolatey.infrastructure.filesystem;
using ChocolateyGui.Common;
using ChocolateyGui.Common.Startup;
using ChocolateyGui.Common.Utilities;
Expand All @@ -17,13 +18,33 @@ namespace ChocolateyGuiCli
{
public static class Bootstrapper
{
private static readonly IFileSystem _fileSystem = new DotNetFileSystem();

public static readonly string ChocolateyGuiInstallLocation = _fileSystem.get_directory_name(_fileSystem.get_current_assembly_path());
public static readonly string ChocolateyInstallEnvironmentVariableName = "ChocolateyInstall";
public static readonly string ChocolateyInstallLocation = System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName) ?? _fileSystem.get_directory_name(_fileSystem.get_current_assembly_path());
public static readonly string LicensedGuiAssemblyLocation = _fileSystem.combine_paths(ChocolateyInstallLocation, "extensions", "chocolateygui", "chocolateygui.licensed.dll");

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

public static readonly string ChocolateyGuiCommonAssemblySimpleName = "ChocolateyGui.Common";
public static readonly string ChocolateyGuiCommonWindowsAssemblySimpleName = "ChocolateyGui.Common.Windows";

public static readonly string UnofficialChocolateyPublicKey = "ffc115b9f4eb5c26";
public static readonly string OfficialChocolateyPublicKey = "dfd1909b30b79d8b";

public static readonly string Name = "Chocolatey GUI";

public static readonly string LicensedChocolateyGuiAssemblySimpleName = "chocolateygui.licensed";

internal static ILogger Logger { get; private set; }

internal static IContainer Container { get; private set; }

internal static string AppDataPath { get; } = LogSetup.GetAppDataPath(ApplicationParameters.Name);
internal static string AppDataPath { get; } = LogSetup.GetAppDataPath(Name);

internal static string LocalAppDataPath { get; } = LogSetup.GetLocalAppDataPath(ApplicationParameters.Name);
internal static string LocalAppDataPath { get; } = LogSetup.GetLocalAppDataPath(Name);

internal static void Configure()
{
Expand All @@ -41,7 +62,7 @@ internal static void Configure()

Logger = Log.Logger = logConfig.CreateLogger();

Container = AutoFacConfiguration.RegisterAutoFac();
Container = AutoFacConfiguration.RegisterAutoFac(LicensedChocolateyGuiAssemblySimpleName, LicensedGuiAssemblyLocation);
}
}
}
4 changes: 2 additions & 2 deletions Source/ChocolateyGuiCli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public static void Main(string[] args)
if (configuration.RegularOutput)
{
#if DEBUG
Bootstrapper.Logger.Information("{0} v{1} (DEBUG BUILD)".format_with(ApplicationParameters.Name, configuration.Information.ChocolateyGuiProductVersion));
Bootstrapper.Logger.Information("{0} v{1} (DEBUG BUILD)".format_with("Chocolatey GUI", configuration.Information.ChocolateyGuiProductVersion));
#else
Bootstrapper.Logger.Information("{0} v{1}".format_with(ApplicationParameters.Name, configuration.Information.ChocolateyGuiProductVersion));
Bootstrapper.Logger.Information("{0} v{1}".format_with("Chocolatey GUI", configuration.Information.ChocolateyGuiProductVersion));
#endif

if (args.Length == 0)
Expand Down
11 changes: 7 additions & 4 deletions Source/ChocolateyGuiCli/Startup/ChocolateyGuiCliModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using chocolatey.infrastructure.app.services;
using chocolatey.infrastructure.filesystem;
using chocolatey.infrastructure.services;
using ChocolateyGui.Common;
using ChocolateyGui.Common.Commands;
using ChocolateyGui.Common.Properties;
using ChocolateyGui.Common.Providers;
Expand All @@ -23,6 +22,10 @@ namespace ChocolateyGuiCli.Startup
{
internal class ChocolateyGuiCliModule : Module
{
private static readonly string FeatureCommandName = "Feature";
private static readonly string ConfigCommandName = "Config";
private static readonly string PurgeCommandName = "Purge";

protected override void Load(ContainerBuilder builder)
{
// Register Providers
Expand Down Expand Up @@ -55,9 +58,9 @@ protected override void Load(ContainerBuilder builder)
// These are using Named registrations to aid with the "finding" of these components
// within the Container. As suggested in this Stack Overflow question:
// https://stackoverflow.com/questions/4999000/replace-registration-in-autofac
builder.RegisterType<FeatureCommand>().As<ICommand>().SingleInstance().Named<ICommand>(ApplicationParameters.FeatureCommandName);
builder.RegisterType<ConfigCommand>().As<ICommand>().SingleInstance().Named<ICommand>(ApplicationParameters.ConfigCommandName);
builder.RegisterType<PurgeCommand>().As<ICommand>().SingleInstance().Named<ICommand>(ApplicationParameters.PurgeCommandName);
builder.RegisterType<FeatureCommand>().As<ICommand>().SingleInstance().Named<ICommand>(FeatureCommandName);
builder.RegisterType<ConfigCommand>().As<ICommand>().SingleInstance().Named<ICommand>(ConfigCommandName);
builder.RegisterType<PurgeCommand>().As<ICommand>().SingleInstance().Named<ICommand>(PurgeCommandName);
}
}
}

0 comments on commit c4db2d9

Please sign in to comment.