Skip to content

Commit

Permalink
merge of PR #60
Browse files Browse the repository at this point in the history
  • Loading branch information
thoemmi committed Jun 6, 2020
2 parents 5ec6563 + 8c0b81f commit baa5105
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
12 changes: 8 additions & 4 deletions 7Zip4Powershell/7Zip4Powershell.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,24 @@
</ItemGroup>

<ItemGroup>
<Reference Include="System.Management.Automation">
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll</HintPath>
<SpecificVersion>false</SpecificVersion>
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libs\System.Management.Automation.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="GitVersionTask">
<Version>5.2.4</Version>
<Version>5.3.4</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" />
<PackageReference Include="SevenZipSharp.Net45" Version="1.0.19" />
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3" />
<PackageReference Include="Squid-Box.SevenZipSharp" Version="1.2.265" />
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" />
<PackageReference Include="SevenZipSharp.Net45" Version="1.0.19" />
<PackageReference Include="System.Management" Version="4.7.0" />
</ItemGroup>
</Project>
22 changes: 21 additions & 1 deletion 7Zip4Powershell/Compress7Zip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class Compress7Zip : ThreadedCmdlet {
[Parameter(Position = 2, Mandatory = false, HelpMessage = "The filter to be applied if Path points to a directory")]
public string Filter { get; set; } = "*";

[Parameter(HelpMessage = "Output path for a compressed archive")]
public string OutputPath { get; set; }

private List<string> _directoryOrFilesFromPipeline;

[Parameter]
Expand Down Expand Up @@ -183,9 +186,26 @@ public override void Execute() {
};
}

// Final path for the archive
var outputPath = !string.IsNullOrEmpty(_cmdlet.OutputPath)
? _cmdlet.OutputPath
: _cmdlet.SessionState.Path.CurrentFileSystemLocation.Path;

// Check whether the output path is a path to the file
// The folder and file name cannot be the same in the same folder
if (File.Exists(outputPath)) {
throw new ArgumentException("The output path is a file, not a directory");
}

// If the directory doesn't exist, create it
if (!Directory.Exists(outputPath)) {
Directory.CreateDirectory(outputPath);
}

var directoryOrFiles = _cmdlet._directoryOrFilesFromPipeline
// Don't put outputPath here, it will break the relative path
.Select(path => new FileInfo(System.IO.Path.Combine(_cmdlet.SessionState.Path.CurrentFileSystemLocation.Path, path)).FullName).ToArray();
var archiveFileName = new FileInfo(System.IO.Path.Combine(_cmdlet.SessionState.Path.CurrentFileSystemLocation.Path, _cmdlet.ArchiveFileName)).FullName;
var archiveFileName = new FileInfo(System.IO.Path.Combine(outputPath, _cmdlet.ArchiveFileName)).FullName;

var activity = directoryOrFiles.Length > 1
? $"Compressing {directoryOrFiles.Length} Files to {archiveFileName}"
Expand Down
Binary file added Libs/System.Management.Automation.dll
Binary file not shown.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ A list of all custom parameters can be found [here](https://sevenzip.osdn.jp/chm
### vNext

* Replaces *SevenZipSharp.Net45* with *Squid-Box.SevenZipSharp* library.
([#57](https://github.com/thoemmi/7Zip4Powershell/pull/57), contributed by [@kborowinski](https://github.com/kborowinski))
([#57](https://github.com/thoemmi/7Zip4Powershell/pull/57), contributed by [@kborowinski](https://github.com/kborowinski))
* Adds new a parameter `OutputPath` for `Compress-7Zip`
([#60](https://github.com/thoemmi/7Zip4Powershell/pull/60), contributed by [@iRebbok](https://github.com/iRebbok))

### [v1.10](https://github.com/thoemmi/7Zip4Powershell/releases/tag/v1.10)

Expand Down

0 comments on commit baa5105

Please sign in to comment.