mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
Code review improvements. Fix base path resolution.
--HG-- branch : dev
This commit is contained in:
@@ -130,7 +130,7 @@ namespace Orchard.Packaging.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void EmbedThemeFiles(CreateContext context) {
|
private void EmbedThemeFiles(CreateContext context) {
|
||||||
var basePath = HostingEnvironment.VirtualPathProvider.GetDirectory(context.SourcePath).VirtualPath;
|
var basePath = context.SourcePath;
|
||||||
foreach (var virtualPath in context.SourceFolder.ListFiles(context.SourcePath, true)) {
|
foreach (var virtualPath in context.SourceFolder.ListFiles(context.SourcePath, true)) {
|
||||||
// ignore dlls, etc
|
// ignore dlls, etc
|
||||||
if (IgnoreFile(virtualPath)) {
|
if (IgnoreFile(virtualPath)) {
|
||||||
|
@@ -4,7 +4,6 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Hosting;
|
using System.Web.Hosting;
|
||||||
using Orchard.Caching;
|
using Orchard.Caching;
|
||||||
using Orchard.Environment;
|
|
||||||
using Orchard.FileSystems.VirtualPath;
|
using Orchard.FileSystems.VirtualPath;
|
||||||
|
|
||||||
namespace Orchard.FileSystems.WebSite {
|
namespace Orchard.FileSystems.WebSite {
|
||||||
@@ -18,33 +17,26 @@ namespace Orchard.FileSystems.WebSite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> ListDirectories(string virtualPath) {
|
public IEnumerable<string> ListDirectories(string virtualPath) {
|
||||||
if (!HostingEnvironment.VirtualPathProvider.DirectoryExists(virtualPath))
|
if (!_virtualPathProvider.DirectoryExists(virtualPath)) {
|
||||||
return Enumerable.Empty<string>();
|
return Enumerable.Empty<string>();
|
||||||
|
}
|
||||||
|
|
||||||
return HostingEnvironment.VirtualPathProvider
|
return _virtualPathProvider.ListDirectories(virtualPath);
|
||||||
.GetDirectory(virtualPath)
|
|
||||||
.Directories.OfType<VirtualDirectory>()
|
|
||||||
.Select(d => d.VirtualPath)
|
|
||||||
.ToArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<string> ListFiles(IEnumerable<string> directories) {
|
private IEnumerable<string> ListFiles(IEnumerable<string> directories) {
|
||||||
return from dir in directories
|
return directories.SelectMany(d => ListFiles(d, true));
|
||||||
from file in ListFiles(dir, true)
|
|
||||||
select file;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> ListFiles(string virtualPath, bool recursive) {
|
public IEnumerable<string> ListFiles(string virtualPath, bool recursive) {
|
||||||
if (!recursive) {
|
if (!recursive) {
|
||||||
return from VirtualFile file in HostingEnvironment.VirtualPathProvider.GetDirectory(virtualPath).Files
|
return _virtualPathProvider.ListFiles(virtualPath);
|
||||||
select file.VirtualPath;
|
|
||||||
}
|
}
|
||||||
return (from VirtualFile file in HostingEnvironment.VirtualPathProvider.GetDirectory(virtualPath).Files
|
return _virtualPathProvider.ListFiles(virtualPath).Concat(ListFiles(ListDirectories(virtualPath)));
|
||||||
select file.VirtualPath).Concat(ListFiles(ListDirectories(virtualPath)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool FileExists(string virtualPath) {
|
public bool FileExists(string virtualPath) {
|
||||||
return HostingEnvironment.VirtualPathProvider.FileExists(virtualPath);
|
return _virtualPathProvider.FileExists(virtualPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ReadFile(string virtualPath) {
|
public string ReadFile(string virtualPath) {
|
||||||
@@ -52,8 +44,9 @@ namespace Orchard.FileSystems.WebSite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string ReadFile(string virtualPath, bool actualContent) {
|
public string ReadFile(string virtualPath, bool actualContent) {
|
||||||
if (!HostingEnvironment.VirtualPathProvider.FileExists(virtualPath))
|
if (!_virtualPathProvider.FileExists(virtualPath)) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (actualContent) {
|
if (actualContent) {
|
||||||
var physicalPath = _virtualPathProvider.MapPath(virtualPath);
|
var physicalPath = _virtualPathProvider.MapPath(virtualPath);
|
||||||
@@ -64,7 +57,7 @@ namespace Orchard.FileSystems.WebSite {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
using (var stream = VirtualPathProvider.OpenFile(Normalize(virtualPath))) {
|
using (var stream = _virtualPathProvider.OpenFile(Normalize(virtualPath))) {
|
||||||
using (var reader = new StreamReader(stream)) {
|
using (var reader = new StreamReader(stream)) {
|
||||||
return reader.ReadToEnd();
|
return reader.ReadToEnd();
|
||||||
}
|
}
|
||||||
@@ -89,7 +82,7 @@ namespace Orchard.FileSystems.WebSite {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
using (var stream = VirtualPathProvider.OpenFile(Normalize(virtualPath))) {
|
using (var stream = _virtualPathProvider.OpenFile(Normalize(virtualPath))) {
|
||||||
stream.CopyTo(destination);
|
stream.CopyTo(destination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,6 +93,8 @@ namespace Orchard.FileSystems.WebSite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static string Normalize(string virtualPath) {
|
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;
|
return HostingEnvironment.VirtualPathProvider.GetFile(virtualPath).VirtualPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user