2012-11-08 08:27:38 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
2012-11-07 09:30:40 +05:00
|
|
|
|
using System.Text;
|
2012-11-08 08:27:38 +05:00
|
|
|
|
using Umbraco.Core.CodeAnnotations;
|
|
|
|
|
|
using Umbraco.Core.Configuration;
|
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
|
|
|
|
{
|
|
|
|
|
|
public MediaFileSystem(IFileSystem wrapped)
|
|
|
|
|
|
: base(wrapped)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
2012-11-08 08:27:38 +05:00
|
|
|
|
|
|
|
|
|
|
public string GetRelativePath(int propertyId, string fileName)
|
|
|
|
|
|
{
|
|
|
|
|
|
var seperator = UmbracoSettings.UploadAllowDirectories
|
|
|
|
|
|
? Path.DirectorySeparatorChar
|
|
|
|
|
|
: '-';
|
|
|
|
|
|
|
|
|
|
|
|
return propertyId.ToString() + seperator + fileName;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|