Skip to content

Commit

Permalink
Some progress made witht he create install zip package msbuild task. #15
Browse files Browse the repository at this point in the history
  • Loading branch information
dazinator committed Jul 19, 2015
1 parent 1cd67db commit 7f27836
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 18 deletions.
Binary file added lib/SharpZipLib.0.86.0/SharpZipLib.0.86.0.nupkg
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions lib/repositories.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<repositories>
<repository path="..\src\DnnPackager.Tasks\packages.config" />
<repository path="..\src\DnnPackager.Tests\packages.config" />
<repository path="..\src\DnnPackager\packages.config" />
</repositories>
107 changes: 90 additions & 17 deletions src/DnnPackager.Tasks/CreateDnnExtensionInstallationZip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Text;
using System.Xml.Linq;
using DnnPackager.Util;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Core;

namespace DnnPackager.Tasks
{
Expand Down Expand Up @@ -68,8 +70,94 @@ public CreateDnnExtensionInstallationZip(IFileSystem fileSystem)
public override bool ExecuteTask()
{
var packagingDir = CreateEmptyOutputDirectory("dnnpackager");
//todo: finish
string outputZipFileName = Path.Combine(packagingDir, "resources.zip");
CreateResourcesZip(outputZipFileName);

//todo: finish below
// copy the manifest to packaging dir

// copy assemblies to packagingdir\bin

// copy symbols to packagingdir\bin

// copy AdditionalFiles to packagingdir (keeping same relative path from new parent dir)

// find any .sqldataprovider files in project and copy them to packagingdir (keeping same relative path from new parent dir)

// find any .lic files in project and copy them to packagingdir (keeping same relative path from new parent dir)

// find any ReleaseNotes.txt file in project and copy it to packagingdir (keeping same relative path from parent dir)


// otpional: check that if a lic file is referenced in manifest that it exists in packagingdir
// otpional: check that if a releasenotes file is referenced in manifest that it exists in packagingdir
// otpional: run variable substitution against manifest?
// otpional: ensure manifest has a ResourceFile component that references Resources.zip?

// zip up packagingdir to OutputDirectory\OutputZipFileName
throw new NotImplementedException();

}

public void CreateResourcesZip(string outputZipFileName)
{
// var outputFileName = Path.Combine(outputPathForZip, OutputZipFileName);
using (var fsOut = File.Create(outputZipFileName))
{
using (var zipStream = new ZipOutputStream(fsOut))
{
zipStream.SetLevel(9); //0-9, 9 being the highest level of compression
// zipStream.Password = password; // optional. Null is the same as not setting. Required if using AES.
CompressFileItems(ProjectDirectory, zipStream, ResourcesZipContent);
zipStream.IsStreamOwner = true; // Makes the Close also Close the underlying stream
zipStream.Close();
}
}
}

private void CompressFileItems(string baseDir, ZipOutputStream zipStream, ITaskItem[] items)
{
// string[] files = Directory.GetFiles(path);
int folderOffset = baseDir.Length + (baseDir.EndsWith("\\") ? 0 : 1);
foreach (var contentItem in ResourcesZipContent)
{
var sourceFilePath = Path.Combine(baseDir, contentItem.ItemSpec);
sourceFilePath = Path.GetFullPath(sourceFilePath);

var fi = new FileInfo(sourceFilePath);
if (!fi.Exists)
{
LogMessage("The source file '" + sourceFilePath + "' does not exist, so it will not be included in the package", MessageImportance.High);
continue;
}

string entryName = sourceFilePath.Substring(folderOffset); // Makes the name in zip based on the folder
entryName = ZipEntry.CleanName(entryName); // Removes drive from name and fixes slash direction
ZipEntry newEntry = new ZipEntry(entryName);
newEntry.DateTime = fi.LastWriteTime; // Note the zip format stores 2 second granularity

// Specifying the AESKeySize triggers AES encryption. Allowable values are 0 (off), 128 or 256.
// A password on the ZipOutputStream is required if using AES.
// newEntry.AESKeySize = 256;

// To permit the zip to be unpacked by built-in extractor in WinXP and Server2003, WinZip 8, Java, and other older code,
// you need to do one of the following: Specify UseZip64.Off, or set the Size.
// If the file may be bigger than 4GB, or you do not need WinXP built-in compatibility, you do not need either,
// but the zip will be in Zip64 format which not all utilities can understand.
// zipStream.UseZip64 = UseZip64.Off;
newEntry.Size = fi.Length;

zipStream.PutNextEntry(newEntry);

// Zip the file in buffered chunks
// the "using" will close the stream even if an exception occurs
byte[] buffer = new byte[4096];
using (FileStream streamReader = File.OpenRead(fi.FullName))
{
StreamUtils.Copy(streamReader, zipStream, buffer);
}
zipStream.CloseEntry();
}
}

private string CreateEmptyOutputDirectory(string name)
Expand All @@ -81,22 +169,7 @@ private string CreateEmptyOutputDirectory(string name)
_fileSystem.EnsureDirectoryExists(temp);
_fileSystem.EnsureDiskHasEnoughFreeSpace(temp);
return temp;
}

private void Copy(IEnumerable<string> sourceFiles, string baseDirectory, string destinationDirectory)
{
foreach (var source in sourceFiles)
{
var relativePath = _fileSystem.GetPathRelativeTo(source, baseDirectory);
var destination = Path.Combine(destinationDirectory, relativePath);

LogMessage("Copy file: " + source, importance: MessageImportance.Normal);

var relativeDirectory = Path.GetDirectoryName(destination);
_fileSystem.EnsureDirectoryExists(relativeDirectory);
_fileSystem.CopyFile(source, destination);
}
}
}


}
Expand Down
8 changes: 8 additions & 0 deletions src/DnnPackager.Tasks/DnnPackager.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ICSharpCode.SharpZipLib">
<HintPath>..\..\lib\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -54,6 +59,9 @@
<Name>DnnPackager</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
4 changes: 4 additions & 0 deletions src/DnnPackager.Tasks/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="SharpZipLib" version="0.86.0" targetFramework="net451" />
</packages>
5 changes: 4 additions & 1 deletion src/DnnPackager.Tests/DnnPackager.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ICSharpCode.SharpZipLib">
<HintPath>..\..\lib\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Utilities.v4.0" />
<Reference Include="nunit.core">
Expand Down Expand Up @@ -78,7 +81,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="TestPackageContent\Stylesheet1.css" />
<Content Include="TestPackageContent\TestTextFile1.txt" />
<None Include="TestPackageContent\TestTextFile1.txt" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/DnnPackager.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<package id="NUnit" version="2.6.4" targetFramework="net451" />
<package id="NUnitTestAdapter" version="2.0.0" targetFramework="net451" />
<package id="RhinoMocks" version="3.6.1" targetFramework="net451" />
<package id="SharpZipLib" version="0.86.0" targetFramework="net451" />
</packages>
Binary file modified src/DnnPackager.v12.suo
Binary file not shown.

0 comments on commit 7f27836

Please sign in to comment.