mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -14,6 +14,10 @@ namespace Orchard.Tests.Stubs {
|
||||
return Directory.GetDirectories(path);
|
||||
}
|
||||
|
||||
public IEnumerable<string> ListFiles(string path, bool recursive) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool FileExists(string virtualPath) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@@ -20,10 +20,10 @@ namespace Orchard.CodeGeneration.Commands {
|
||||
private readonly ISchemaCommandGenerator _schemaCommandGenerator;
|
||||
|
||||
private static readonly string[] _ignoredExtensions = new [] {
|
||||
"dll", "obj", "pdb", "exclude"
|
||||
"obj", "pdb", "exclude"
|
||||
};
|
||||
private static readonly string[] _ignoredPaths = new [] {
|
||||
"/bin/", "/obj/"
|
||||
"/obj/"
|
||||
};
|
||||
private static readonly string[] _themeDirectories = new [] {
|
||||
"", "Content", "Styles", "Scripts", "Views", "Zones"
|
||||
|
@@ -38,7 +38,7 @@ namespace Orchard.Packaging.Commands {
|
||||
}
|
||||
|
||||
[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) {
|
||||
if (!File.Exists(filename)) {
|
||||
Context.Output.WriteLine(T("File \"{0}\" does not exist.", filename));
|
||||
|
@@ -5,6 +5,8 @@ using System.IO.Packaging;
|
||||
using System.Linq;
|
||||
using System.Net.Mime;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
@@ -16,6 +18,19 @@ namespace Orchard.Packaging.Services {
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
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) {
|
||||
_extensionManager = extensionManager;
|
||||
_webSiteFolder = webSiteFolder;
|
||||
@@ -27,7 +42,7 @@ namespace Orchard.Packaging.Services {
|
||||
var context = new CreateContext();
|
||||
BeginPackage(context);
|
||||
try {
|
||||
EstablishPaths(context, _webSiteFolder, extensionDescriptor.Location, extensionDescriptor.Name);
|
||||
EstablishPaths(context, _webSiteFolder, extensionDescriptor.Location, extensionDescriptor.Name, extensionDescriptor.ExtensionType);
|
||||
SetCoreProperties(context, extensionDescriptor);
|
||||
|
||||
string projectFile = extensionDescriptor.Name + ".csproj";
|
||||
@@ -36,6 +51,10 @@ namespace Orchard.Packaging.Services {
|
||||
EmbedProjectFiles(context, "Compile", "Content", "None", "EmbeddedResource");
|
||||
EmbedReferenceFiles(context);
|
||||
}
|
||||
else if (extensionDescriptor.ExtensionType == "Theme") {
|
||||
// this is a simple theme with no csproj
|
||||
EmbedThemeFiles(context);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
EndPackage(context);
|
||||
@@ -110,6 +129,21 @@ namespace Orchard.Packaging.Services {
|
||||
}
|
||||
}
|
||||
|
||||
private void EmbedThemeFiles(CreateContext context) {
|
||||
var basePath = context.SourcePath;
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
|
||||
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.SourcePath = "~/Modules/" + moduleName + "/";
|
||||
if (moduleType == "Theme") {
|
||||
context.SourcePath = "~/Themes/" + moduleName + "/";
|
||||
}
|
||||
else {
|
||||
context.SourcePath = "~/Modules/" + moduleName + "/";
|
||||
}
|
||||
context.TargetPath = "\\" + moduleName + "\\";
|
||||
}
|
||||
|
||||
|
@@ -38,6 +38,10 @@ namespace Orchard.Packaging.Services {
|
||||
ExtractProjectFiles(context, "Compile", "Content", "None", "EmbeddedResource");
|
||||
ExtractReferenceFiles(context);
|
||||
}
|
||||
else if (context.ExtensionType == "Theme") {
|
||||
// this is a simple theme with no csproj
|
||||
ExtractThemeFiles(context);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
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) {
|
||||
Uri projectUri = PackUriHelper.CreatePartUri(new Uri(context.SourcePath + relativePath, UriKind.Relative));
|
||||
return context.Package.PartExists(projectUri);
|
||||
|
@@ -8,6 +8,7 @@ namespace Orchard.FileSystems.WebSite {
|
||||
/// </summary>
|
||||
public interface IWebSiteFolder : IVolatileProvider {
|
||||
IEnumerable<string> ListDirectories(string virtualPath);
|
||||
IEnumerable<string> ListFiles(string virtualPath, bool recursive);
|
||||
|
||||
bool FileExists(string virtualPath);
|
||||
string ReadFile(string virtualPath);
|
||||
|
@@ -4,7 +4,6 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web.Hosting;
|
||||
using Orchard.Caching;
|
||||
using Orchard.Environment;
|
||||
using Orchard.FileSystems.VirtualPath;
|
||||
|
||||
namespace Orchard.FileSystems.WebSite {
|
||||
@@ -18,18 +17,26 @@ namespace Orchard.FileSystems.WebSite {
|
||||
}
|
||||
|
||||
public IEnumerable<string> ListDirectories(string virtualPath) {
|
||||
if (!HostingEnvironment.VirtualPathProvider.DirectoryExists(virtualPath))
|
||||
if (!_virtualPathProvider.DirectoryExists(virtualPath)) {
|
||||
return Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
return HostingEnvironment.VirtualPathProvider
|
||||
.GetDirectory(virtualPath)
|
||||
.Directories.OfType<VirtualDirectory>()
|
||||
.Select(d => d.VirtualPath)
|
||||
.ToArray();
|
||||
return _virtualPathProvider.ListDirectories(virtualPath);
|
||||
}
|
||||
|
||||
private IEnumerable<string> ListFiles(IEnumerable<string> directories) {
|
||||
return directories.SelectMany(d => ListFiles(d, true));
|
||||
}
|
||||
|
||||
public IEnumerable<string> ListFiles(string virtualPath, bool recursive) {
|
||||
if (!recursive) {
|
||||
return _virtualPathProvider.ListFiles(virtualPath);
|
||||
}
|
||||
return _virtualPathProvider.ListFiles(virtualPath).Concat(ListFiles(ListDirectories(virtualPath)));
|
||||
}
|
||||
|
||||
public bool FileExists(string virtualPath) {
|
||||
return HostingEnvironment.VirtualPathProvider.FileExists(virtualPath);
|
||||
return _virtualPathProvider.FileExists(virtualPath);
|
||||
}
|
||||
|
||||
public string ReadFile(string virtualPath) {
|
||||
@@ -37,8 +44,9 @@ namespace Orchard.FileSystems.WebSite {
|
||||
}
|
||||
|
||||
public string ReadFile(string virtualPath, bool actualContent) {
|
||||
if (!HostingEnvironment.VirtualPathProvider.FileExists(virtualPath))
|
||||
if (!_virtualPathProvider.FileExists(virtualPath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (actualContent) {
|
||||
var physicalPath = _virtualPathProvider.MapPath(virtualPath);
|
||||
@@ -49,7 +57,7 @@ namespace Orchard.FileSystems.WebSite {
|
||||
}
|
||||
}
|
||||
else {
|
||||
using (var stream = VirtualPathProvider.OpenFile(Normalize(virtualPath))) {
|
||||
using (var stream = _virtualPathProvider.OpenFile(Normalize(virtualPath))) {
|
||||
using (var reader = new StreamReader(stream)) {
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
@@ -74,7 +82,7 @@ namespace Orchard.FileSystems.WebSite {
|
||||
}
|
||||
}
|
||||
else {
|
||||
using (var stream = VirtualPathProvider.OpenFile(Normalize(virtualPath))) {
|
||||
using (var stream = _virtualPathProvider.OpenFile(Normalize(virtualPath))) {
|
||||
stream.CopyTo(destination);
|
||||
}
|
||||
}
|
||||
@@ -85,6 +93,8 @@ namespace Orchard.FileSystems.WebSite {
|
||||
}
|
||||
|
||||
static string Normalize(string virtualPath) {
|
||||
// todo: use IVirtualPathProvider instance instead of static.
|
||||
// Currently IVirtualPathProvider has no way of doing normalization like this
|
||||
return HostingEnvironment.VirtualPathProvider.GetFile(virtualPath).VirtualPath;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user