2012-11-08 08:27:38 +05:00
|
|
|
|
using System.Collections.Generic;
|
2013-09-13 18:11:20 +10:00
|
|
|
|
using System.Globalization;
|
2012-11-08 08:27:38 +05:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Umbraco.Core.Configuration;
|
2013-09-13 18:11:20 +10:00
|
|
|
|
using Umbraco.Core.Configuration.UmbracoSettings;
|
2012-11-07 09:30:40 +05:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.IO
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// A custom file system provider for media
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[FileSystemProvider("media")]
|
2013-01-15 01:19:51 +03:00
|
|
|
|
public class MediaFileSystem : FileSystemWrapper
|
2012-11-07 09:30:40 +05:00
|
|
|
|
{
|
2013-09-16 15:52:59 +10:00
|
|
|
|
private readonly IContentSection _contentConfig;
|
2013-09-13 18:11:20 +10:00
|
|
|
|
|
|
|
|
|
|
public MediaFileSystem(IFileSystem wrapped)
|
2013-09-25 19:23:41 +10:00
|
|
|
|
: this(wrapped, UmbracoConfig.For.UmbracoSettings().Content)
|
2012-11-07 09:30:40 +05:00
|
|
|
|
{
|
|
|
|
|
|
}
|
2012-11-08 08:27:38 +05:00
|
|
|
|
|
2013-09-16 15:52:59 +10:00
|
|
|
|
public MediaFileSystem(IFileSystem wrapped, IContentSection contentConfig) : base(wrapped)
|
2013-09-13 18:11:20 +10:00
|
|
|
|
{
|
|
|
|
|
|
_contentConfig = contentConfig;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string GetRelativePath(int propertyId, string fileName)
|
2012-11-08 08:27:38 +05:00
|
|
|
|
{
|
2013-09-13 18:11:20 +10:00
|
|
|
|
var seperator = _contentConfig.UploadAllowDirectories
|
2012-11-08 08:27:38 +05:00
|
|
|
|
? Path.DirectorySeparatorChar
|
|
|
|
|
|
: '-';
|
|
|
|
|
|
|
2013-09-13 18:11:20 +10:00
|
|
|
|
return propertyId.ToString(CultureInfo.InvariantCulture) + seperator + fileName;
|
2012-11-08 08:27:38 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-02-19 11:06:00 -01:00
|
|
|
|
public string GetRelativePath(string subfolder, string fileName)
|
|
|
|
|
|
{
|
2013-09-13 18:11:20 +10:00
|
|
|
|
var seperator = _contentConfig.UploadAllowDirectories
|
2013-02-19 11:06:00 -01:00
|
|
|
|
? Path.DirectorySeparatorChar
|
|
|
|
|
|
: '-';
|
|
|
|
|
|
|
|
|
|
|
|
return subfolder + seperator + fileName;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-08 08:27:38 +05:00
|
|
|
|
public IEnumerable<string> GetThumbnails(string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
var parentDirectory = System.IO.Path.GetDirectoryName(path);
|
|
|
|
|
|
var extension = System.IO.Path.GetExtension(path);
|
|
|
|
|
|
|
|
|
|
|
|
return GetFiles(parentDirectory)
|
|
|
|
|
|
.Where(x => x.StartsWith(path.TrimEnd(extension) + "_thumb"))
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void DeleteFile(string path, bool deleteThumbnails)
|
|
|
|
|
|
{
|
|
|
|
|
|
DeleteFile(path);
|
|
|
|
|
|
|
|
|
|
|
|
if (!deleteThumbnails)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
DeleteThumbnails(path);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void DeleteThumbnails(string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
GetThumbnails(path)
|
|
|
|
|
|
.ForEach(DeleteFile);
|
|
|
|
|
|
}
|
2012-11-07 09:30:40 +05:00
|
|
|
|
}
|
|
|
|
|
|
}
|