mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-11-24 08:46:48 +08:00
Using System.IO.Compression instead of DotNetZip
This commit is contained in:
@@ -52,12 +52,6 @@ Website: http://dlr.codeplex.com
|
||||
Copyright: Copyright (c) Microsoft Corporation
|
||||
License: Apache Software Foundation License 2.0
|
||||
|
||||
DotNetZip
|
||||
-----
|
||||
Website: http://dotnetzip.codeplex.com/
|
||||
Copyright:
|
||||
License: MS-PL
|
||||
|
||||
Eric Meyer's Reset CSS
|
||||
-----
|
||||
Website: http://meyerweb.com/eric/tools/css/reset/
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using Ionic.Zip;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.FileSystems.Media;
|
||||
@@ -53,10 +53,10 @@ namespace Orchard.Tests.Modules.Media.Services {
|
||||
[Test]
|
||||
public void GetMediaFoldersTest() {
|
||||
StorageProvider.ListFoldersPredicate = path => {
|
||||
return string.IsNullOrEmpty(path) ? new[] {new StubStorageFolder(FolderName1)}
|
||||
: string.Equals(path, FolderName1) ? new[] {new StubStorageFolder(FolderName2), new StubStorageFolder(FolderName3)}
|
||||
return string.IsNullOrEmpty(path) ? new[] { new StubStorageFolder(FolderName1) }
|
||||
: string.Equals(path, FolderName1) ? new[] { new StubStorageFolder(FolderName2), new StubStorageFolder(FolderName3) }
|
||||
: new StubStorageFolder[] { };
|
||||
};
|
||||
};
|
||||
|
||||
IEnumerable<MediaFolder> mediaFolders = MediaService.GetMediaFolders(null);
|
||||
Assert.That(mediaFolders.Count(), Is.EqualTo(1), "Root path only has 1 sub directory");
|
||||
@@ -94,7 +94,7 @@ namespace Orchard.Tests.Modules.Media.Services {
|
||||
Assert.That(StorageProvider.SavedStreams.Contains(StorageProvider.Combine(FolderName1, FinalDottedWebconfigFileName)), Is.False, "no extension files are never allowed");
|
||||
Assert.That(StorageProvider.SavedStreams.Contains(StorageProvider.Combine(FolderName1, PaddedWebconfigFileName)), Is.False, "no extension files are never allowed");
|
||||
Assert.That(StorageProvider.SavedStreams.Contains(StorageProvider.Combine(FolderName1, FinalDottedTextFileName)), Is.False, "no extension files are never allowed");
|
||||
|
||||
|
||||
Assert.That(StorageProvider.SavedStreams.Count, Is.EqualTo(3));
|
||||
}
|
||||
|
||||
@@ -160,29 +160,30 @@ namespace Orchard.Tests.Modules.Media.Services {
|
||||
}
|
||||
|
||||
private MemoryStream CreateZipMemoryStream() {
|
||||
var entries = new List<string> {
|
||||
TextFileName, WebconfigFileName, DllFileName, ZipFileName, NoExtensionFileName, PaddedWebconfigFileName,
|
||||
FinalDottedWebconfigFileName, PaddedTextFileName, FinalDottedTextFileName
|
||||
};
|
||||
|
||||
// Setup memory stream with zip archive for more complex scenarios
|
||||
MemoryStream memoryStream = new MemoryStream();
|
||||
using (ZipFile zipOut = new ZipFile()) {
|
||||
|
||||
zipOut.AddEntry(TextFileName, new byte[] { 0x01 });
|
||||
zipOut.AddEntry(WebconfigFileName, new byte[] { 0x02 });
|
||||
zipOut.AddEntry(DllFileName, new byte[] { 0x03 });
|
||||
zipOut.AddEntry(ZipFileName, new byte[] { 0x04 });
|
||||
zipOut.AddEntry(NoExtensionFileName, new byte[] { 0x05 });
|
||||
zipOut.AddEntry(PaddedWebconfigFileName, new byte[] { 0x06 });
|
||||
zipOut.AddEntry(FinalDottedWebconfigFileName, new byte[] { 0x07 });
|
||||
zipOut.AddEntry(PaddedTextFileName, new byte[] { 0x08 });
|
||||
zipOut.AddEntry(FinalDottedTextFileName, new byte[] { 0x09 });
|
||||
|
||||
zipOut.Save(memoryStream);
|
||||
using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, leaveOpen: true)) {
|
||||
var content = new byte[] { 0x01 };
|
||||
foreach (var entry in entries) {
|
||||
var zipEntry = archive.CreateEntry(entry);
|
||||
using (var zipStream = zipEntry.Open()) {
|
||||
zipStream.Write(content, 0, 1);
|
||||
}
|
||||
++content[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return new MemoryStream(memoryStream.ToArray());
|
||||
}
|
||||
|
||||
private class MediaServiceAccessor : MediaService {
|
||||
public MediaServiceAccessor(IStorageProvider storageProvider, IOrchardServices orchardServices)
|
||||
: base (storageProvider, orchardServices) {}
|
||||
: base(storageProvider, orchardServices) { }
|
||||
|
||||
public void UnzipMediaFileArchiveAccessor(string targetFolder, Stream zipStream) {
|
||||
UnzipMediaFileArchive(targetFolder, zipStream);
|
||||
|
||||
@@ -64,9 +64,6 @@
|
||||
<Reference Include="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Castle.Core.3.3.1\lib\net45\Castle.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DotNetZip, Version=1.12.0.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DotNetZip.1.12.0\lib\net20\DotNetZip.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FluentNHibernate, Version=2.0.3.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentNHibernate.2.0.3.0\lib\net40\FluentNHibernate.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -134,6 +131,7 @@
|
||||
<HintPath>..\..\lib\sqlce\System.Data.SqlServerCe.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Abstractions">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
<packages>
|
||||
<package id="Autofac" version="3.5.2" targetFramework="net48" />
|
||||
<package id="Castle.Core" version="3.3.1" targetFramework="net48" />
|
||||
<package id="DotNetZip" version="1.12.0" targetFramework="net48" />
|
||||
<package id="FluentNHibernate" version="2.0.3.0" targetFramework="net48" />
|
||||
<package id="Iesi.Collections" version="4.0.1.4000" targetFramework="net48" />
|
||||
<package id="IronRuby" version="1.1.3" targetFramework="net48" />
|
||||
|
||||
@@ -52,9 +52,6 @@
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="DotNetZip, Version=1.12.0.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\DotNetZip.1.12.0\lib\net20\DotNetZip.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\lib\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -64,6 +61,7 @@
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.ApplicationServices" />
|
||||
<Reference Include="System.Web.DynamicData" />
|
||||
@@ -204,4 +202,4 @@
|
||||
</FlavorProperties>
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Ionic.Zip;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.FileSystems.Media;
|
||||
using Orchard.Localization;
|
||||
@@ -194,7 +194,7 @@ namespace Orchard.Media.Services {
|
||||
/// <param name="bytes">The array of bytes with the file's contents.</param>
|
||||
/// <param name="extractZip">Boolean value indicating weather zip files should be extracted.</param>
|
||||
/// <returns>The path to the uploaded file.</returns>
|
||||
public string UploadMediaFile(string folderPath, string fileName, byte [] bytes, bool extractZip) {
|
||||
public string UploadMediaFile(string folderPath, string fileName, byte[] bytes, bool extractZip) {
|
||||
Argument.ThrowIfNullOrEmpty(folderPath, "folderPath");
|
||||
Argument.ThrowIfNullOrEmpty(fileName, "fileName");
|
||||
Argument.ThrowIfNull(bytes, "bytes");
|
||||
@@ -274,16 +274,16 @@ namespace Orchard.Media.Services {
|
||||
|
||||
// must be in the whitelist
|
||||
MediaSettingsPart mediaSettings = currentSite.As<MediaSettingsPart>();
|
||||
|
||||
|
||||
if (mediaSettings == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(String.IsNullOrWhiteSpace(mediaSettings.UploadAllowedFileTypeWhitelist)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!mediaSettings.UploadAllowedFileTypeWhitelist.ToUpperInvariant().Split(' ').Contains(extension.ToUpperInvariant())) {
|
||||
if (String.IsNullOrWhiteSpace(mediaSettings.UploadAllowedFileTypeWhitelist)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!mediaSettings.UploadAllowedFileTypeWhitelist.ToUpperInvariant().Split(' ').Contains(extension.ToUpperInvariant())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -305,28 +305,26 @@ namespace Orchard.Media.Services {
|
||||
Argument.ThrowIfNullOrEmpty(targetFolder, "targetFolder");
|
||||
Argument.ThrowIfNull(zipStream, "zipStream");
|
||||
|
||||
using (var fileInflater = ZipFile.Read(zipStream)) {
|
||||
using (var fileInflater = new ZipArchive(zipStream)) {
|
||||
// We want to preserve whatever directory structure the zip file contained instead
|
||||
// of flattening it.
|
||||
// The API below doesn't necessarily return the entries in the zip file in any order.
|
||||
// That means the files in subdirectories can be returned as entries from the stream
|
||||
// before the directories that contain them, so we create directories as soon as first
|
||||
// file below their path is encountered.
|
||||
foreach (ZipEntry entry in fileInflater) {
|
||||
foreach (var entry in fileInflater.Entries) {
|
||||
if (entry == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!entry.IsDirectory && !string.IsNullOrEmpty(entry.FileName)) {
|
||||
|
||||
if (!string.IsNullOrEmpty(entry.Name)) {
|
||||
// skip disallowed files
|
||||
if (FileAllowed(entry.FileName, false)) {
|
||||
string fullFileName = _storageProvider.Combine(targetFolder, entry.FileName);
|
||||
if (FileAllowed(entry.Name, false)) {
|
||||
string fullFileName = _storageProvider.Combine(targetFolder, entry.FullName);
|
||||
|
||||
using (var stream = entry.OpenReader()) {
|
||||
using (var stream = entry.Open()) {
|
||||
// the call will return false if the file already exists
|
||||
if (!_storageProvider.TrySaveStream(fullFileName, stream)) {
|
||||
|
||||
// try to delete the file and save again
|
||||
try {
|
||||
_storageProvider.DeleteFile(fullFileName);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="DotNetZip" version="1.12.0" targetFramework="net48" />
|
||||
<package id="Microsoft.AspNet.Mvc" version="5.2.7" targetFramework="net48" />
|
||||
<package id="Microsoft.AspNet.Razor" version="3.2.7" targetFramework="net48" />
|
||||
<package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net48" />
|
||||
|
||||
Reference in New Issue
Block a user