mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
- Extensions: Install extensions from zip files.
- Themes: installing new themes from the themes admin. --HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043816
This commit is contained in:
@@ -56,7 +56,7 @@ namespace Orchard.Tests.Environment {
|
||||
return Enumerable.Empty<ExtensionEntry>();
|
||||
}
|
||||
|
||||
public void InstallExtension(HttpPostedFileBase extensionBundle) {
|
||||
public void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ namespace Orchard.Tests.Mvc.Routes {
|
||||
};
|
||||
}
|
||||
|
||||
public void InstallExtension(HttpPostedFileBase extensionBundle) {
|
||||
public void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Core.Themes.ViewModels;
|
||||
using Orchard.Localization;
|
||||
@@ -51,6 +52,10 @@ namespace Orchard.Core.Themes.Controllers {
|
||||
[AcceptVerbs(HttpVerbs.Post)]
|
||||
public ActionResult Install(FormCollection input) {
|
||||
try {
|
||||
foreach (string fileName in Request.Files) {
|
||||
HttpPostedFileBase file = Request.Files[fileName];
|
||||
_themeService.InstallTheme(file);
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using Orchard.Extensions;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Models;
|
||||
@@ -71,6 +72,10 @@ namespace Orchard.Core.Themes.Services {
|
||||
}
|
||||
}
|
||||
|
||||
public void InstallTheme(HttpPostedFileBase file) {
|
||||
_extensionManager.InstallExtension("Theme", file);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using Orchard.Extensions.Helpers;
|
||||
using Orchard.Extensions.Loaders;
|
||||
using Yaml.Grammar;
|
||||
using System.Web;
|
||||
@@ -9,7 +12,7 @@ namespace Orchard.Extensions {
|
||||
public interface IExtensionManager {
|
||||
IEnumerable<ExtensionDescriptor> AvailableExtensions();
|
||||
IEnumerable<ExtensionEntry> ActiveExtensions();
|
||||
void InstallExtension(HttpPostedFileBase extensionBundle);
|
||||
void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle);
|
||||
}
|
||||
|
||||
public class ExtensionManager : IExtensionManager {
|
||||
@@ -68,8 +71,42 @@ namespace Orchard.Extensions {
|
||||
return _activeExtensions;
|
||||
}
|
||||
|
||||
public void InstallExtension(HttpPostedFileBase extensionBundle) {
|
||||
throw new NotImplementedException();
|
||||
public void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle) {
|
||||
if (String.IsNullOrEmpty(extensionType)) {
|
||||
throw new ArgumentException("extensionType");
|
||||
}
|
||||
string targetFolder;
|
||||
if (String.Equals(extensionType, "Theme", StringComparison.OrdinalIgnoreCase)) {
|
||||
targetFolder = PathHelpers.GetPhysicalPath("~/Themes");
|
||||
}
|
||||
else if (String.Equals(extensionType, "Package", StringComparison.OrdinalIgnoreCase)) {
|
||||
targetFolder = PathHelpers.GetPhysicalPath("~/Packages");
|
||||
}
|
||||
else {
|
||||
throw new ArgumentException("extensionType");
|
||||
}
|
||||
int postedFileLength = extensionBundle.ContentLength;
|
||||
Stream postedFileStream = extensionBundle.InputStream;
|
||||
byte[] postedFileData = new byte[postedFileLength];
|
||||
postedFileStream.Read(postedFileData, 0, postedFileLength);
|
||||
|
||||
using (var memoryStream = new MemoryStream(postedFileData)) {
|
||||
var fileInflater = new ZipInputStream(memoryStream);
|
||||
ZipEntry entry;
|
||||
while ((entry = fileInflater.GetNextEntry()) != null) {
|
||||
string directoryName = Path.GetDirectoryName(entry.Name);
|
||||
if (!Directory.Exists(Path.Combine(targetFolder, directoryName))) {
|
||||
Directory.CreateDirectory(Path.Combine(targetFolder, directoryName));
|
||||
}
|
||||
|
||||
if (!entry.IsDirectory && entry.Name.Length > 0) {
|
||||
var len = Convert.ToInt32(entry.Size);
|
||||
var extractedBytes = new byte[len];
|
||||
fileInflater.Read(extractedBytes, 0, len);
|
||||
File.WriteAllBytes(Path.Combine(targetFolder, entry.Name), extractedBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<ExtensionEntry> BuildActiveExtensions() {
|
||||
|
@@ -47,6 +47,10 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\fluentnhibernate\FluentNHibernate.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\sharpziplib\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<Reference Include="Microsoft.VisualStudio.TeamSystem.Data.UnitTesting, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<Reference Include="NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
|
||||
namespace Orchard.Themes {
|
||||
public interface IThemeService : IDependency {
|
||||
@@ -6,5 +7,6 @@ namespace Orchard.Themes {
|
||||
ITheme GetThemeByName(string themeName);
|
||||
IEnumerable<ITheme> GetInstalledThemes();
|
||||
void SetCurrentTheme(string themeName);
|
||||
void InstallTheme(HttpPostedFileBase file);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user