mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Ability to create and install packages of simple themes.
--HG-- branch : dev
This commit is contained in:
@@ -14,6 +14,10 @@ namespace Orchard.Tests.Stubs {
|
|||||||
return Directory.GetDirectories(path);
|
return Directory.GetDirectories(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<string> ListFiles(string path, bool recursive) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
public bool FileExists(string virtualPath) {
|
public bool FileExists(string virtualPath) {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
@@ -38,7 +38,7 @@ namespace Orchard.Packaging.Commands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[CommandHelp("package install <filename>\r\n\t" + "Install a module from a package <filename>.")]
|
[CommandHelp("package install <filename>\r\n\t" + "Install a module from a package <filename>.")]
|
||||||
[CommandName("package install ")]
|
[CommandName("package install")]
|
||||||
public void InstallPackage(string filename) {
|
public void InstallPackage(string filename) {
|
||||||
if (!File.Exists(filename)) {
|
if (!File.Exists(filename)) {
|
||||||
Context.Output.WriteLine(T("File \"{0}\" does not exist.", filename));
|
Context.Output.WriteLine(T("File \"{0}\" does not exist.", filename));
|
||||||
|
@@ -5,6 +5,8 @@ using System.IO.Packaging;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Hosting;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
using Orchard.Environment.Extensions.Models;
|
using Orchard.Environment.Extensions.Models;
|
||||||
@@ -16,6 +18,19 @@ namespace Orchard.Packaging.Services {
|
|||||||
private readonly IExtensionManager _extensionManager;
|
private readonly IExtensionManager _extensionManager;
|
||||||
private readonly IWebSiteFolder _webSiteFolder;
|
private readonly IWebSiteFolder _webSiteFolder;
|
||||||
|
|
||||||
|
private static readonly string[] _ignoredThemeExtensions = new[] {
|
||||||
|
"obj", "pdb", "exclude"
|
||||||
|
};
|
||||||
|
private static readonly string[] _ignoredThemePaths = new[] {
|
||||||
|
"/obj/"
|
||||||
|
};
|
||||||
|
|
||||||
|
private static bool IgnoreFile(string filePath) {
|
||||||
|
return String.IsNullOrEmpty(filePath) ||
|
||||||
|
_ignoredThemePaths.Any(filePath.Contains) ||
|
||||||
|
_ignoredThemeExtensions.Contains(Path.GetExtension(filePath) ?? "");
|
||||||
|
}
|
||||||
|
|
||||||
public PackageBuilder(IExtensionManager extensionManager, IWebSiteFolder webSiteFolder) {
|
public PackageBuilder(IExtensionManager extensionManager, IWebSiteFolder webSiteFolder) {
|
||||||
_extensionManager = extensionManager;
|
_extensionManager = extensionManager;
|
||||||
_webSiteFolder = webSiteFolder;
|
_webSiteFolder = webSiteFolder;
|
||||||
@@ -27,7 +42,7 @@ namespace Orchard.Packaging.Services {
|
|||||||
var context = new CreateContext();
|
var context = new CreateContext();
|
||||||
BeginPackage(context);
|
BeginPackage(context);
|
||||||
try {
|
try {
|
||||||
EstablishPaths(context, _webSiteFolder, extensionDescriptor.Location, extensionDescriptor.Name);
|
EstablishPaths(context, _webSiteFolder, extensionDescriptor.Location, extensionDescriptor.Name, extensionDescriptor.ExtensionType);
|
||||||
SetCoreProperties(context, extensionDescriptor);
|
SetCoreProperties(context, extensionDescriptor);
|
||||||
|
|
||||||
string projectFile = extensionDescriptor.Name + ".csproj";
|
string projectFile = extensionDescriptor.Name + ".csproj";
|
||||||
@@ -36,6 +51,10 @@ namespace Orchard.Packaging.Services {
|
|||||||
EmbedProjectFiles(context, "Compile", "Content", "None", "EmbeddedResource");
|
EmbedProjectFiles(context, "Compile", "Content", "None", "EmbeddedResource");
|
||||||
EmbedReferenceFiles(context);
|
EmbedReferenceFiles(context);
|
||||||
}
|
}
|
||||||
|
else if (extensionDescriptor.ExtensionType == "Theme") {
|
||||||
|
// this is a simple theme with no csproj
|
||||||
|
EmbedThemeFiles(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
EndPackage(context);
|
EndPackage(context);
|
||||||
@@ -110,6 +129,21 @@ namespace Orchard.Packaging.Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void EmbedThemeFiles(CreateContext context) {
|
||||||
|
var basePath = HostingEnvironment.VirtualPathProvider.GetDirectory(context.SourcePath).VirtualPath;
|
||||||
|
foreach (var virtualPath in context.SourceFolder.ListFiles(context.SourcePath, true)) {
|
||||||
|
// ignore dlls, etc
|
||||||
|
if (IgnoreFile(virtualPath)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// full virtual path given but we need the relative path so it can be put into
|
||||||
|
// the package that way (the package itself is the logical base path).
|
||||||
|
// Get it by stripping the basePath off including the slash.
|
||||||
|
var relativePath = virtualPath.Replace(basePath, "");
|
||||||
|
EmbedVirtualFile(context, relativePath, MediaTypeNames.Application.Octet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private XName Ns(string localName) {
|
private XName Ns(string localName) {
|
||||||
return XName.Get(localName, "http://schemas.microsoft.com/developer/msbuild/2003");
|
return XName.Get(localName, "http://schemas.microsoft.com/developer/msbuild/2003");
|
||||||
}
|
}
|
||||||
@@ -120,9 +154,14 @@ namespace Orchard.Packaging.Services {
|
|||||||
context.Package = Package.Open(context.Stream, FileMode.Create, FileAccess.ReadWrite);
|
context.Package = Package.Open(context.Stream, FileMode.Create, FileAccess.ReadWrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void EstablishPaths(CreateContext context, IWebSiteFolder webSiteFolder, string locationPath, string moduleName) {
|
private static void EstablishPaths(CreateContext context, IWebSiteFolder webSiteFolder, string locationPath, string moduleName, string moduleType) {
|
||||||
context.SourceFolder = webSiteFolder;
|
context.SourceFolder = webSiteFolder;
|
||||||
context.SourcePath = "~/Modules/" + moduleName + "/";
|
if (moduleType == "Theme") {
|
||||||
|
context.SourcePath = "~/Themes/" + moduleName + "/";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
context.SourcePath = "~/Modules/" + moduleName + "/";
|
||||||
|
}
|
||||||
context.TargetPath = "\\" + moduleName + "\\";
|
context.TargetPath = "\\" + moduleName + "\\";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,6 +38,10 @@ namespace Orchard.Packaging.Services {
|
|||||||
ExtractProjectFiles(context, "Compile", "Content", "None", "EmbeddedResource");
|
ExtractProjectFiles(context, "Compile", "Content", "None", "EmbeddedResource");
|
||||||
ExtractReferenceFiles(context);
|
ExtractReferenceFiles(context);
|
||||||
}
|
}
|
||||||
|
else if (context.ExtensionType == "Theme") {
|
||||||
|
// this is a simple theme with no csproj
|
||||||
|
ExtractThemeFiles(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
EndPackage(context);
|
EndPackage(context);
|
||||||
@@ -108,6 +112,14 @@ namespace Orchard.Packaging.Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ExtractThemeFiles(ExpandContext context) {
|
||||||
|
foreach (var relativePath in from p in context.Package.GetParts()
|
||||||
|
where p.Uri.ToString().StartsWith("/" + context.ExtensionName + "/", StringComparison.OrdinalIgnoreCase)
|
||||||
|
select p.Uri.ToString().Substring(("/" + context.ExtensionName + "/").Length)) {
|
||||||
|
ExtractFile(context, relativePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private bool PartExists(ExpandContext context, string relativePath) {
|
private bool PartExists(ExpandContext context, string relativePath) {
|
||||||
Uri projectUri = PackUriHelper.CreatePartUri(new Uri(context.SourcePath + relativePath, UriKind.Relative));
|
Uri projectUri = PackUriHelper.CreatePartUri(new Uri(context.SourcePath + relativePath, UriKind.Relative));
|
||||||
return context.Package.PartExists(projectUri);
|
return context.Package.PartExists(projectUri);
|
||||||
|
@@ -8,6 +8,7 @@ namespace Orchard.FileSystems.WebSite {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IWebSiteFolder : IVolatileProvider {
|
public interface IWebSiteFolder : IVolatileProvider {
|
||||||
IEnumerable<string> ListDirectories(string virtualPath);
|
IEnumerable<string> ListDirectories(string virtualPath);
|
||||||
|
IEnumerable<string> ListFiles(string virtualPath, bool recursive);
|
||||||
|
|
||||||
bool FileExists(string virtualPath);
|
bool FileExists(string virtualPath);
|
||||||
string ReadFile(string virtualPath);
|
string ReadFile(string virtualPath);
|
||||||
|
@@ -27,6 +27,36 @@ namespace Orchard.FileSystems.WebSite {
|
|||||||
.Select(d => d.VirtualPath)
|
.Select(d => d.VirtualPath)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerable<string> ListFiles(IEnumerable<string> directories) {
|
||||||
|
return from dir in directories
|
||||||
|
from file in ListFiles(dir, true)
|
||||||
|
select file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<string> ListFiles(string virtualPath, bool recursive) {
|
||||||
|
if (!recursive) {
|
||||||
|
return from VirtualFile file in HostingEnvironment.VirtualPathProvider.GetDirectory(virtualPath).Files
|
||||||
|
select file.VirtualPath;
|
||||||
|
}
|
||||||
|
return (from VirtualFile file in HostingEnvironment.VirtualPathProvider.GetDirectory(virtualPath).Files
|
||||||
|
select file.VirtualPath).Concat(ListFiles(ListDirectories(virtualPath)));
|
||||||
|
/*
|
||||||
|
|
||||||
|
var path = HostingEnvironment.MapPath(virtualPath);
|
||||||
|
if (path == null || !Directory.Exists(path)) {
|
||||||
|
return Enumerable.Empty<string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!path.EndsWith("\\")) {
|
||||||
|
path += "\\";
|
||||||
|
}
|
||||||
|
|
||||||
|
var files = Directory.GetFiles(path, searchPattern, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
|
||||||
|
// strip base path to make it relative and replace '\' with '/'
|
||||||
|
return from file in files
|
||||||
|
select "~/" + file.Replace(path, "").Replace("\\", "/");*/
|
||||||
|
}
|
||||||
|
|
||||||
public bool FileExists(string virtualPath) {
|
public bool FileExists(string virtualPath) {
|
||||||
return HostingEnvironment.VirtualPathProvider.FileExists(virtualPath);
|
return HostingEnvironment.VirtualPathProvider.FileExists(virtualPath);
|
||||||
|
Reference in New Issue
Block a user