Skip to content

Commit

Permalink
Merge branch 'hotfix/0.17.2' into develop
Browse files Browse the repository at this point in the history
* hotfix/0.17.2:
  (GH-785) Reverted StyleCop change
  (GH-785) Fix stylecop and dupfinder errors
  (GH-785) Add assembly resolver to CLI and GUI
  (GH-785) Add additonal project/nuget references
  (GH-785) Remove ApplicationParameters class
  (GH-747) add txt extension to the LICENSE file
  (build) Update to latest Cake.Recipe

# Conflicts:
#	recipe.cake
  • Loading branch information
gep13 committed Jul 13, 2020
2 parents 6329bf9 + fc690e0 commit b4fbb73
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 65 deletions.
29 changes: 26 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,28 @@ namespace ChocolateyGui.Common.Windows
{
public class Bootstrapper : BootstrapperBase
{
private static readonly IFileSystem _fileSystem = new DotNetFileSystem();

#pragma warning disable SA1202
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";
#pragma warning restore SA1202

public Bootstrapper()
{
Initialize();
Expand All @@ -47,9 +70,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 +97,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 @@ -107,7 +107,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
45 changes: 45 additions & 0 deletions Source/ChocolateyGui/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
// --------------------------------------------------------------------------------------------------------------------

using System;
using System.Reflection;
using System.Windows;
using Autofac;
using chocolatey;
using chocolatey.infrastructure.registration;
using ChocolateyGui.Common.Services;
using ChocolateyGui.Common.Windows;

Expand All @@ -20,10 +23,52 @@ public partial class App
{
private static readonly App _application = new App();

#region DupFinder Exclusion
public App()
{
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
var requestedAssembly = new AssemblyName(args.Name);

#if FORCE_CHOCOLATEY_OFFICIAL_KEY
var chocolateyGuiPublicKey = Bootstrapper.OfficialChocolateyPublicKey;
#else
var chocolateyGuiPublicKey = Bootstrapper.UnofficialChocolateyPublicKey;
#endif

try
{
if (requestedAssembly.get_public_key_token().is_equal_to(chocolateyGuiPublicKey)
&& requestedAssembly.Name.is_equal_to(Bootstrapper.ChocolateyGuiCommonAssemblySimpleName))
{
return AssemblyResolution.resolve_or_load_assembly(
Bootstrapper.ChocolateyGuiCommonAssemblySimpleName,
requestedAssembly.get_public_key_token(),
Bootstrapper.ChocolateyGuiCommonAssemblyLocation).UnderlyingType;
}

if (requestedAssembly.get_public_key_token().is_equal_to(chocolateyGuiPublicKey)
&& requestedAssembly.Name.is_equal_to(Bootstrapper.ChocolateyGuiCommonWindowsAssemblySimpleName))
{
return AssemblyResolution.resolve_or_load_assembly(
Bootstrapper.ChocolateyGuiCommonWindowsAssemblySimpleName,
requestedAssembly.get_public_key_token(),
Bootstrapper.ChocolateyGuiCommonWindowsAssemblyLocation).UnderlyingType;
}
}
catch (Exception ex)
{
var errorMessage = string.Format("Unable to load Chocolatey GUI assembly. {0}", ex.Message);
MessageBox.Show(errorMessage);
throw new ApplicationException(errorMessage);
}

return null;
};

InitializeComponent();
}
#endregion

internal static SplashScreen SplashScreen { get; set; }

Expand Down
29 changes: 26 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,35 @@ namespace ChocolateyGuiCli
{
public static class Bootstrapper
{
private static readonly IFileSystem _fileSystem = new DotNetFileSystem();

#pragma warning disable SA1202
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";
#pragma warning restore SA1202

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 +64,7 @@ internal static void Configure()

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

Container = AutoFacConfiguration.RegisterAutoFac();
Container = AutoFacConfiguration.RegisterAutoFac(LicensedChocolateyGuiAssemblySimpleName, LicensedGuiAssemblyLocation);
}
}
}
16 changes: 16 additions & 0 deletions Source/ChocolateyGuiCli/ChocolateyGuiCli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
<Reference Include="Autofac, Version=4.6.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.4.6.1\lib\net45\Autofac.dll</HintPath>
</Reference>
<Reference Include="Caliburn.Micro, Version=3.2.0.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL">
<HintPath>..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll</HintPath>
</Reference>
<Reference Include="Caliburn.Micro.Platform, Version=3.2.0.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL">
<HintPath>..\packages\Caliburn.Micro.3.2.0\lib\net45\Caliburn.Micro.Platform.dll</HintPath>
</Reference>
<Reference Include="Caliburn.Micro.Platform.Core, Version=3.2.0.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL">
<HintPath>..\packages\Caliburn.Micro.3.2.0\lib\net45\Caliburn.Micro.Platform.Core.dll</HintPath>
</Reference>
<Reference Include="chocolatey, Version=0.10.15.0, Culture=neutral, PublicKeyToken=79d02ea9cad655eb, processorArchitecture=MSIL">
<HintPath>..\packages\chocolatey.lib.0.10.15\lib\chocolatey.dll</HintPath>
</Reference>
Expand All @@ -78,6 +87,9 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Caliburn.Micro.3.2.0\lib\net45\System.Windows.Interactivity.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -109,6 +121,10 @@
<Analyzer Include="..\packages\StyleCop.Analyzers.1.0.2\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ChocolateyGui.Common.Windows\ChocolateyGui.Common.Windows.csproj">
<Project>{4c2e05fe-3f4d-40be-873c-5d07c8729741}</Project>
<Name>ChocolateyGui.Common.Windows</Name>
</ProjectReference>
<ProjectReference Include="..\ChocolateyGui.Common\ChocolateyGui.Common.csproj">
<Project>{a3a40034-4e31-4d05-832a-351c416dccbb}</Project>
<Name>ChocolateyGui.Common</Name>
Expand Down
Loading

0 comments on commit b4fbb73

Please sign in to comment.