Skip to content

Commit

Permalink
(GH-1318) Extractor option to not throw error
Browse files Browse the repository at this point in the history
Add an option for not throwing an error on extracting resources.
  • Loading branch information
ferventcoder committed Jun 2, 2017
1 parent 2d5b438 commit eccabb2
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/chocolatey/infrastructure/extractors/AssemblyFileExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace chocolatey.infrastructure.extractors
using System.Text;
using adapters;
using filesystem;
using tolerance;

/// <summary>
/// Extracts resources from an assembly.
Expand Down Expand Up @@ -65,16 +66,26 @@ public static void extract_text_file_from_assembly(IFileSystem fileSystem, IAsse
/// <param name="overwriteExisting">
/// if set to <c>true</c> [overwrite existing].
/// </param>
public static void extract_binary_file_from_assembly(IFileSystem fileSystem, IAssembly assembly, string manifestLocation, string filePath, bool overwriteExisting = false)
/// <param name="throwEror">Throw an error if there are issues</param>
public static void extract_binary_file_from_assembly(IFileSystem fileSystem, IAssembly assembly, string manifestLocation, string filePath, bool overwriteExisting = false, bool throwEror = true)
{
if (overwriteExisting || !fileSystem.file_exists(filePath))
{
fileSystem.create_directory_if_not_exists(fileSystem.get_directory_name(filePath));
fileSystem.write_file(filePath, () => assembly.get_manifest_stream(manifestLocation));
FaultTolerance.try_catch_with_logging_exception(
() =>
{
fileSystem.create_directory_if_not_exists(fileSystem.get_directory_name(filePath));
fileSystem.write_file(filePath, () => assembly.get_manifest_stream(manifestLocation));
},
errorMessage:"Unable to extract binary",
throwError: throwEror,
logWarningInsteadOfError: false,
logDebugInsteadOfError: !throwEror,
isSilent: !throwEror);
}
}

public static void extract_all_resources_to_relative_directory(IFileSystem fileSystem, IAssembly assembly, string directoryPath, IList<string> relativeDirectories, string resourcesToInclude, bool overwriteExisting = false, bool logOutput = false)
public static void extract_all_resources_to_relative_directory(IFileSystem fileSystem, IAssembly assembly, string directoryPath, IList<string> relativeDirectories, string resourcesToInclude, bool overwriteExisting = false, bool logOutput = false, bool throwError = true)
{
var resourceString = new StringBuilder();
foreach (var resourceName in assembly.GetManifestResourceNames())
Expand Down Expand Up @@ -102,7 +113,7 @@ public static void extract_all_resources_to_relative_directory(IFileSystem fileS

var filePath = fileSystem.combine_paths(directoryPath, fileLocation);
if (logOutput) "chocolatey".Log().Debug("Unpacking {0} to '{1}'".format_with(fileLocation, filePath));
extract_binary_file_from_assembly(fileSystem, assembly, resourceName, filePath, overwriteExisting);
extract_binary_file_from_assembly(fileSystem, assembly, resourceName, filePath, overwriteExisting, throwError);
}
}
}
Expand Down

0 comments on commit eccabb2

Please sign in to comment.