mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 03:25:23 +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) {
|
||||
var basePath = HostingEnvironment.VirtualPathProvider.GetDirectory(context.SourcePath).VirtualPath;
|
||||
var basePath = context.SourcePath;
|
||||
foreach (var virtualPath in context.SourceFolder.ListFiles(context.SourcePath, true)) {
|
||||
// ignore dlls, etc
|
||||
if (IgnoreFile(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,33 +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 from dir in directories
|
||||
from file in ListFiles(dir, true)
|
||||
select file;
|
||||
return directories.SelectMany(d => ListFiles(d, true));
|
||||
}
|
||||
|
||||
public IEnumerable<string> ListFiles(string virtualPath, bool recursive) {
|
||||
if (!recursive) {
|
||||
return from VirtualFile file in HostingEnvironment.VirtualPathProvider.GetDirectory(virtualPath).Files
|
||||
select file.VirtualPath;
|
||||
return _virtualPathProvider.ListFiles(virtualPath);
|
||||
}
|
||||
return (from VirtualFile file in HostingEnvironment.VirtualPathProvider.GetDirectory(virtualPath).Files
|
||||
select file.VirtualPath).Concat(ListFiles(ListDirectories(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) {
|
||||
@@ -52,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);
|
||||
@@ -64,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();
|
||||
}
|
||||
@@ -89,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);
|
||||
}
|
||||
}
|
||||
@@ -100,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