diff --git a/src/Umbraco.Core/IO/MediaFileSystem.cs b/src/Umbraco.Core/IO/MediaFileSystem.cs index b6ef6f7bf5..9dd0a8fda1 100644 --- a/src/Umbraco.Core/IO/MediaFileSystem.cs +++ b/src/Umbraco.Core/IO/MediaFileSystem.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Media; namespace Umbraco.Core.IO { @@ -26,6 +27,8 @@ namespace Umbraco.Core.IO _contentConfig = contentConfig; } + // none of the methods below are used in Core anymore + [Obsolete("This low-level method should NOT exist.")] public string GetRelativePath(int propertyId, string fileName) { @@ -36,7 +39,7 @@ namespace Umbraco.Core.IO return propertyId.ToString(CultureInfo.InvariantCulture) + sep + fileName; } - [Obsolete("This low-level method should NOT exist.")] + [Obsolete("This low-level method should NOT exist.", false)] public string GetRelativePath(string subfolder, string fileName) { var sep = _contentConfig.UploadAllowDirectories @@ -46,50 +49,28 @@ namespace Umbraco.Core.IO return subfolder + sep + fileName; } - // what's below is weird - // we are not deleting custom thumbnails - // MediaFileSystem is not just IFileSystem - // etc - - [Obsolete("", true)] + [Obsolete("Use ImageHelper.GetThumbnails instead.", false)] public IEnumerable GetThumbnails(string path) - { - var parentDirectory = Path.GetDirectoryName(path); - var extension = Path.GetExtension(path); - - return GetFiles(parentDirectory) - .Where(x => x.StartsWith(path.TrimEnd(extension) + "_thumb") || x.StartsWith(path.TrimEnd(extension) + "_big-thumb")) - .ToList(); + { + return ImageHelper.GetThumbnails(this, path); } - [Obsolete("", true)] + [Obsolete("Use ImageHelper.DeleteFile instead.", false)] public void DeleteFile(string path, bool deleteThumbnails) { - DeleteFile(path); - - if (deleteThumbnails == false) - return; - - DeleteThumbnails(path); + ImageHelper.DeleteFile(this, path, deleteThumbnails); } - [Obsolete("", true)] + [Obsolete("Use ImageHelper.DeleteThumbnails instead.", false)] public void DeleteThumbnails(string path) { - GetThumbnails(path) - .ForEach(DeleteFile); + ImageHelper.DeleteThumbnails(this, path); } - [Obsolete("", true)] + [Obsolete("Use ImageHelper.CopyThumbnails instead.", false)] public void CopyThumbnails(string sourcePath, string targetPath) { - var targetPathBase = Path.GetDirectoryName(targetPath) ?? ""; - foreach (var sourceThumbPath in GetThumbnails(sourcePath)) - { - var sourceThumbFilename = Path.GetFileName(sourceThumbPath) ?? ""; - var targetThumbPath = Path.Combine(targetPathBase, sourceThumbFilename); - this.CopyFile(sourceThumbPath, targetThumbPath); - } + ImageHelper.CopyThumbnails(this, sourcePath, targetPath); } } } diff --git a/src/Umbraco.Core/Media/ImageHelper.cs b/src/Umbraco.Core/Media/ImageHelper.cs index a9775321e8..61d786a1fa 100644 --- a/src/Umbraco.Core/Media/ImageHelper.cs +++ b/src/Umbraco.Core/Media/ImageHelper.cs @@ -91,6 +91,8 @@ namespace Umbraco.Core.Media #region Manage thumbnails + // note: this does not find 'custom' thumbnails? + // will find _thumb and _big-thumb but NOT _custom? public static IEnumerable GetThumbnails(IFileSystem fs, string path) { var parentDirectory = Path.GetDirectoryName(path); diff --git a/src/Umbraco.Core/Media/MediaHelper.cs b/src/Umbraco.Core/Media/MediaHelper.cs index 5367455a43..4b7133cce0 100644 --- a/src/Umbraco.Core/Media/MediaHelper.cs +++ b/src/Umbraco.Core/Media/MediaHelper.cs @@ -41,6 +41,7 @@ namespace Umbraco.Core.Media /// The unique identifier of the content/media owning the file. /// The unique identifier of the property type owning the file. /// The filesystem-relative path to the media file. + /// With the old media path scheme, this CREATES a new media path each time it is invoked. public static string GetMediaPath(string filename, Guid cuid, Guid puid) { filename = Path.GetFileName(filename); @@ -79,7 +80,7 @@ namespace Umbraco.Core.Media /// The unique identifier of the property type owning the file. /// The filesystem-relative path to the media file. /// In the old, legacy, number-based scheme, we try to re-use the media folder - /// specified by . Else, we create a new one. + /// specified by . Else, we CREATE a new one. Each time we are invoked. public static string GetMediaPath(string filename, string prevpath, Guid cuid, Guid puid) { if (UseTheNewMediaPathScheme || string.IsNullOrWhiteSpace(prevpath)) @@ -112,14 +113,14 @@ namespace Umbraco.Core.Media /// Gets the next media folder in the original number-based scheme. /// /// + /// Should be private, is internal for legacy FileHandlerData which is obsolete. internal static string GetNextFolder() { lock (FolderCounterLock) { if (_folderCounterInitialized == false) { - // fixme - seed was not respected in MediaSubfolderCounter? - _folderCounter = 1000; // seed + _folderCounter = 1000; // seed - was not respected in MediaSubfolderCounter? var fs = FileSystemProviderManager.Current.GetFileSystemProvider(); var directories = fs.GetDirectories(""); foreach (var directory in directories) @@ -163,7 +164,7 @@ namespace Umbraco.Core.Media // clear the old file, if any var fs = FileSystem; if (string.IsNullOrWhiteSpace(oldpath)) - fs.DeleteFile(oldpath, true); + ImageHelper.DeleteFile(fs, oldpath, true); // get the filepath, store the data // use oldpath as "prevpath" to try and reuse the folder, in original number-based scheme @@ -178,7 +179,7 @@ namespace Umbraco.Core.Media /// The filesystem-relative path to the media file. public static void DeleteFile(string filepath) { - FileSystem.DeleteFile(filepath, true); + ImageHelper.DeleteFile(FileSystem, filepath, true); } /// @@ -202,7 +203,7 @@ namespace Umbraco.Core.Media var filename = Path.GetFileName(sourcepath); var filepath = GetMediaPath(filename, content.Key, propertyType.Key); fs.CopyFile(sourcepath, filepath); - fs.CopyThumbnails(sourcepath, filepath); + ImageHelper.CopyThumbnails(fs, sourcepath, filepath); return filepath; } diff --git a/src/Umbraco.Core/Media/UploadAutoFillProperties.cs b/src/Umbraco.Core/Media/UploadAutoFillProperties.cs index 553c994599..625bdc4e47 100644 --- a/src/Umbraco.Core/Media/UploadAutoFillProperties.cs +++ b/src/Umbraco.Core/Media/UploadAutoFillProperties.cs @@ -11,7 +11,7 @@ using Umbraco.Core.Models; namespace Umbraco.Core.Media { /// - /// Provides extension methods to manage auto-fill properties for upload fields. + /// Provides methods to manage auto-fill properties for upload fields. /// internal static class UploadAutoFillProperties { diff --git a/src/Umbraco.Core/Models/ContentExtensions.cs b/src/Umbraco.Core/Models/ContentExtensions.cs index 863f6b197a..e54653ea29 100644 --- a/src/Umbraco.Core/Models/ContentExtensions.cs +++ b/src/Umbraco.Core/Models/ContentExtensions.cs @@ -450,11 +450,11 @@ namespace Umbraco.Core.Models #region SetValue for setting file contents /// - /// Sets and uploads the file from a HttpPostedFileBase object as the property value + /// Stores and sets an uploaded HttpPostedFileBase as a property value. /// - /// to add property value to - /// Alias of the property to save the value on - /// The containing the file that will be uploaded + /// A content item. + /// The property alias. + /// The uploaded . public static void SetValue(this IContentBase content, string propertyTypeAlias, HttpPostedFileBase value) { // ensure we get the filename without the path in IE in intranet mode @@ -478,37 +478,37 @@ namespace Umbraco.Core.Models } /// - /// Sets and uploads the file from a HttpPostedFile object as the property value + /// Stores and sets an uploaded HttpPostedFile as a property value. /// - /// to add property value to - /// Alias of the property to save the value on - /// The containing the file that will be uploaded + /// A content item. + /// The property alias. + /// The uploaded . public static void SetValue(this IContentBase content, string propertyTypeAlias, HttpPostedFile value) { - SetValue(content, propertyTypeAlias, (HttpPostedFileBase)new HttpPostedFileWrapper(value)); + SetValue(content, propertyTypeAlias, (HttpPostedFileBase) new HttpPostedFileWrapper(value)); } /// - /// Sets and uploads the file from a HttpPostedFileWrapper object as the property value + /// Stores and sets an uploaded HttpPostedFileWrapper as a property value. /// - /// to add property value to - /// Alias of the property to save the value on - /// The containing the file that will be uploaded + /// A content item. + /// The property alias. + /// The uploaded . [Obsolete("There is no reason for this overload since HttpPostedFileWrapper inherits from HttpPostedFileBase")] public static void SetValue(this IContentBase content, string propertyTypeAlias, HttpPostedFileWrapper value) { - SetValue(content, propertyTypeAlias, (HttpPostedFileBase)value); + SetValue(content, propertyTypeAlias, (HttpPostedFileBase) value); } /// - /// Sets a content item property value with a file coming from a stream. + /// Stores and sets a file as a property value. /// - /// The content item. - /// The property type alias. - /// Name of the file - /// The stream containing the file data. + /// A content item. + /// The property alias. + /// The name of the file. + /// A stream containing the file data. /// This really is for FileUpload fields only, and should be obsoleted. For anything else, - /// you need to store the file by yourself using and then figure out + /// you need to store the file by yourself using Store and then figure out /// how to deal with auto-fill properties (if any) and thumbnails (if any) by yourself. public static void SetValue(this IContentBase content, string propertyTypeAlias, string filename, Stream filestream) { @@ -522,12 +522,28 @@ namespace Umbraco.Core.Models MediaHelper.SetUploadFile(content, propertyTypeAlias, filename, filestream); } - public static string StoreFile(this IContentBase content, string propertyTypeAlias, string filename, Stream filestream, string oldpath) + /// + /// Stores a file. + /// + /// A content item. + /// The property alias. + /// The name of the file. + /// A stream containing the file data. + /// The original file path, if any. + /// The path to the file, relative to the media filesystem. + /// + /// Does NOT set the property value, so one should probably store the file and then do + /// something alike: property.Value = MediaHelper.FileSystem.GetUrl(filepath). + /// The original file path is used, in the old media file path scheme, to try and reuse + /// the "folder number" that was assigned to the previous file referenced by the property, + /// if any. + /// + public static string StoreFile(this IContentBase content, string propertyTypeAlias, string filename, Stream filestream, string filepath) { var propertyType = content.GetContentType() .CompositionPropertyTypes.FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias)); if (propertyType == null) throw new ArgumentException("Invalid property type alias " + propertyTypeAlias + "."); - return MediaHelper.StoreFile(content, propertyType, filename, filestream, oldpath); + return MediaHelper.StoreFile(content, propertyType, filename, filestream, filepath); } #endregion diff --git a/src/Umbraco.Core/Models/File.cs b/src/Umbraco.Core/Models/File.cs index da093f792a..8ead6da5f8 100644 --- a/src/Umbraco.Core/Models/File.cs +++ b/src/Umbraco.Core/Models/File.cs @@ -25,21 +25,6 @@ namespace Umbraco.Core.Models private string _content; internal Func GetFileContent { get; set; } - // whether to use whatever already exists on filesystem - internal bool _useExistingContent; - - /// - /// Indicates that the file should use whatever content already - /// exists on the filesystem which manages the file, bypassing content - /// management entirely. - /// - /// Only for the next save. Is resetted when the file is saved. - public void UseExistingContent() - { - _useExistingContent = true; - _content = null; // force content to be loaded - } - protected File(string path, Func getFileContent = null) { _path = SanitizePath(path); diff --git a/src/Umbraco.Core/Models/IFile.cs b/src/Umbraco.Core/Models/IFile.cs index 0d1cf24cdd..de900c50ec 100644 --- a/src/Umbraco.Core/Models/IFile.cs +++ b/src/Umbraco.Core/Models/IFile.cs @@ -39,14 +39,6 @@ namespace Umbraco.Core.Models /// string Content { get; set; } - /// - /// Indicates that the file should use whatever content already - /// exists on the filesystem which manages the file, bypassing content - /// management entirely. - /// - /// Only for the next save. Is resetted when the file is saved. - void UseExistingContent(); - /// /// Gets or sets the file's virtual path (i.e. the file path relative to the root of the website) /// diff --git a/src/Umbraco.Core/Models/Template.cs b/src/Umbraco.Core/Models/Template.cs index 1c8b44b674..6a271ad7ab 100644 --- a/src/Umbraco.Core/Models/Template.cs +++ b/src/Umbraco.Core/Models/Template.cs @@ -15,7 +15,7 @@ using Umbraco.Core.Strings; namespace Umbraco.Core.Models { /// - /// Represents a Template file + /// Represents a Template file. /// [Serializable] [DataContract(IsReference = true)] diff --git a/src/Umbraco.Core/Models/TemplateOnDisk.cs b/src/Umbraco.Core/Models/TemplateOnDisk.cs new file mode 100644 index 0000000000..7f89b47e34 --- /dev/null +++ b/src/Umbraco.Core/Models/TemplateOnDisk.cs @@ -0,0 +1,52 @@ +using System; +using System.Runtime.Serialization; + +namespace Umbraco.Core.Models +{ + /// + /// Represents a Template file that can have its content on disk. + /// + [Serializable] + [DataContract(IsReference = true)] + public class TemplateOnDisk : Template + { + /// + /// Initializes a new instance of the class. + /// + /// The name of the template. + /// The alias of the template. + public TemplateOnDisk(string name, string alias) + : base(name, alias) + { + IsOnDisk = true; + } + + /// + /// Gets or sets a value indicating whether the content is on disk already. + /// + public bool IsOnDisk { get; set; } + + /// + /// Gets or sets the content. + /// + /// + /// Getting the content while the template is "on disk" throws, + /// the template must be saved before its content can be retrieved. + /// Setting the content means it is not "on disk" anymore, and the + /// template becomes (and behaves like) a normal template. + /// + public override string Content + { + get + { + if (IsOnDisk) throw new InvalidOperationException("On-disk template do not have content until saved."); + return base.Content; + } + set + { + base.Content = value; + IsOnDisk = false; + } + } + } +} diff --git a/src/Umbraco.Core/Persistence/Repositories/Interfaces/ITemplateRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Interfaces/ITemplateRepository.cs index 48b0cf66b7..11ac404f5d 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Interfaces/ITemplateRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Interfaces/ITemplateRepository.cs @@ -64,13 +64,13 @@ namespace Umbraco.Core.Persistence.Repositories /// /// The filesystem path to the template. /// The content of the template. - Stream GetFileStream(string filepath); + Stream GetFileContent(string filepath); /// /// Sets the content of a template. /// /// The filesystem path to the template. /// The content of the template. - void SetFile(string filepath, Stream content); + void SetFileContent(string filepath, Stream content); } } \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs b/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs index 0242d9d222..34cbd30df7 100644 --- a/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs @@ -251,13 +251,15 @@ namespace Umbraco.Core.Persistence.Repositories { string content; - if (template._useExistingContent) + var templateOnDisk = template as TemplateOnDisk; + if (templateOnDisk != null && templateOnDisk.IsOnDisk) { - content = _viewHelper.GetFileContents(template); // BUT the template does not exist yet?! - template._useExistingContent = false; // reset + // if "template on disk" load content from disk + content = _viewHelper.GetFileContents(template); } else { + // else, create or write template.Content to disk if (DetermineTemplateRenderingEngine(template) == RenderingEngine.Mvc) { content = originalAlias == null @@ -272,6 +274,7 @@ namespace Umbraco.Core.Persistence.Repositories } } + // once content has been set, "template on disk" are not "on disk" anymore template.Content = content; if (dto.Design == content) return; @@ -449,12 +452,12 @@ namespace Umbraco.Core.Persistence.Repositories } } - public Stream GetFileStream(string filepath) + public Stream GetFileContent(string filepath) { return GetFileSystem(filepath).OpenFile(filepath); } - public void SetFile(string filepath, Stream content) + public void SetFileContent(string filepath, Stream content) { GetFileSystem(filepath).AddFile(filepath, content, true); } diff --git a/src/Umbraco.Core/Persistence/Repositories/VersionableRepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/VersionableRepositoryBase.cs index 56b0b63ad5..6ffa692fa0 100644 --- a/src/Umbraco.Core/Persistence/Repositories/VersionableRepositoryBase.cs +++ b/src/Umbraco.Core/Persistence/Repositories/VersionableRepositoryBase.cs @@ -22,6 +22,7 @@ using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; using Umbraco.Core.Dynamics; using Umbraco.Core.IO; +using Umbraco.Core.Media; namespace Umbraco.Core.Persistence.Repositories { @@ -579,7 +580,7 @@ WHERE EXISTS( } else { - fs.DeleteFile(file, true); + ImageHelper.DeleteFile(fs, file, true); } } catch (Exception e) diff --git a/src/Umbraco.Core/Services/FileService.cs b/src/Umbraco.Core/Services/FileService.cs index 1dae926c6a..06ab3c5229 100644 --- a/src/Umbraco.Core/Services/FileService.cs +++ b/src/Umbraco.Core/Services/FileService.cs @@ -558,19 +558,19 @@ namespace Umbraco.Core.Services } } - public Stream GetTemplateFileStream(string filepath) + public Stream GetTemplateFileContent(string filepath) { - using (var repository = _repositoryFactory.CreateTemplateRepository(_dataUowProvider.GetUnitOfWork())) + using (var repository = RepositoryFactory.CreateTemplateRepository(UowProvider.GetUnitOfWork())) { - return repository.GetFileStream(filepath); + return repository.GetFileContent(filepath); } } - public void SetTemplateFile(string filepath, Stream content) + public void SetTemplateFileContent(string filepath, Stream content) { - using (var repository = _repositoryFactory.CreateTemplateRepository(_dataUowProvider.GetUnitOfWork())) + using (var repository = RepositoryFactory.CreateTemplateRepository(UowProvider.GetUnitOfWork())) { - repository.SetFile(filepath, content); + repository.SetFileContent(filepath, content); } } diff --git a/src/Umbraco.Core/Services/IFileService.cs b/src/Umbraco.Core/Services/IFileService.cs index 8ea1d9b23b..010dd7067f 100644 --- a/src/Umbraco.Core/Services/IFileService.cs +++ b/src/Umbraco.Core/Services/IFileService.cs @@ -242,13 +242,13 @@ namespace Umbraco.Core.Services /// /// The filesystem path to the template. /// The content of the template. - Stream GetTemplateFileStream(string filepath); + Stream GetTemplateFileContent(string filepath); /// /// Sets the content of a template. /// /// The filesystem path to the template. /// The content of the template. - void SetTemplateFile(string filepath, Stream content); + void SetTemplateFileContent(string filepath, Stream content); } } \ No newline at end of file diff --git a/src/Umbraco.Core/Services/IMediaService.cs b/src/Umbraco.Core/Services/IMediaService.cs index 83c815c78d..3fcad5f32e 100644 --- a/src/Umbraco.Core/Services/IMediaService.cs +++ b/src/Umbraco.Core/Services/IMediaService.cs @@ -377,14 +377,14 @@ namespace Umbraco.Core.Services /// /// The filesystem path to the media. /// The content of the media. - Stream GetMediaFileStream(string filepath); + Stream GetMediaFileContent(string filepath); /// /// Sets the content of a media. /// /// The filesystem path to the media. /// The content of the media. - void SetMediaFile(string filepath, Stream content); + void SetMediaFileContent(string filepath, Stream content); /// /// Deletes a media file and all thumbnails. diff --git a/src/Umbraco.Core/Services/MediaService.cs b/src/Umbraco.Core/Services/MediaService.cs index 5240c5c9b3..121b7f508e 100644 --- a/src/Umbraco.Core/Services/MediaService.cs +++ b/src/Umbraco.Core/Services/MediaService.cs @@ -1259,19 +1259,19 @@ namespace Umbraco.Core.Services } } - public Stream GetMediaFileStream(string filepath) + public Stream GetMediaFileContent(string filepath) { return MediaHelper.FileSystem.OpenFile(filepath); } - public void SetMediaFile(string filepath, Stream stream) + public void SetMediaFileContent(string filepath, Stream stream) { MediaHelper.FileSystem.AddFile(filepath, stream, true); } public void DeleteMediaFile(string filepath) { - MediaHelper.FileSystem.DeleteFile(filepath, true); + ImageHelper.DeleteFile(MediaHelper.FileSystem, filepath, true); } public void GenerateThumbnails(string filepath, PropertyType propertyType) diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index f329fab881..1ebd25cda5 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -403,6 +403,7 @@ + diff --git a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs index 857f2860b2..1bba10c7a3 100644 --- a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs @@ -75,7 +75,7 @@ namespace Umbraco.Web.PropertyEditors if (clears) { foreach (var pathToRemove in currentPaths) - fs.DeleteFile(pathToRemove, true); + ImageHelper.DeleteFile(fs, pathToRemove, true); return string.Empty; // no more files } @@ -136,7 +136,7 @@ namespace Umbraco.Web.PropertyEditors // remove files that are not there anymore foreach (var pathToRemove in currentPaths.Except(newPaths)) - fs.DeleteFile(pathToRemove, true); + ImageHelper.DeleteFile(fs, pathToRemove, true); return string.Join(",", newPaths.Select(x => fs.GetUrl(x))); diff --git a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs index cf46037402..f1f26f003b 100644 --- a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs @@ -122,7 +122,7 @@ namespace Umbraco.Web.PropertyEditors // value is unchanged. if (string.IsNullOrWhiteSpace(editorFile) && string.IsNullOrWhiteSpace(currentPath) == false) { - fs.DeleteFile(currentPath, true); + ImageHelper.DeleteFile(fs, currentPath, true); return null; // clear } @@ -138,7 +138,7 @@ namespace Umbraco.Web.PropertyEditors // remove current file if replaced if (currentPath != filepath && string.IsNullOrWhiteSpace(currentPath) == false) - fs.DeleteFile(currentPath, true); + ImageHelper.DeleteFile(fs, currentPath, true); // update json and return if (editorJson == null) return null; diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/channels/UmbracoMetaWeblogAPI.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/channels/UmbracoMetaWeblogAPI.cs index 6eefec8ab0..b4fa6ed573 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/channels/UmbracoMetaWeblogAPI.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/channels/UmbracoMetaWeblogAPI.cs @@ -450,7 +450,7 @@ namespace umbraco.presentation.channels Property fileObject = m.getProperty(userChannel.MediaTypeFileProperty); var filename = file.name.Replace("/", "_"); - var relativeFilePath = _fs.GetRelativePath(fileObject.Id, filename); + var relativeFilePath = UmbracoMediaFactory.GetRelativePath(fileObject.Id, filename); fileObject.Value = _fs.GetUrl(relativeFilePath); fileUrl.url = fileObject.Value.ToString(); diff --git a/src/umbraco.cms/businesslogic/Content.cs b/src/umbraco.cms/businesslogic/Content.cs index f014ddae93..e7b9d7fe66 100644 --- a/src/umbraco.cms/businesslogic/Content.cs +++ b/src/umbraco.cms/businesslogic/Content.cs @@ -13,6 +13,7 @@ using umbraco.DataLayer; using System.Runtime.CompilerServices; using umbraco.cms.helpers; using umbraco.cms.businesslogic.datatype.controls; +using Umbraco.Core.Media; using File = System.IO.File; using Property = umbraco.cms.businesslogic.property.Property; using PropertyType = umbraco.cms.businesslogic.propertytype.PropertyType; @@ -631,7 +632,7 @@ namespace umbraco.cms.businesslogic } else { - fs.DeleteFile(relativeFilePath, true); + ImageHelper.DeleteFile(fs, relativeFilePath, true); } } } diff --git a/src/umbraco.cms/businesslogic/media/UmbracoFileMediaFactory.cs b/src/umbraco.cms/businesslogic/media/UmbracoFileMediaFactory.cs index 0c265d8b07..dc13f83ea6 100644 --- a/src/umbraco.cms/businesslogic/media/UmbracoFileMediaFactory.cs +++ b/src/umbraco.cms/businesslogic/media/UmbracoFileMediaFactory.cs @@ -29,7 +29,7 @@ namespace umbraco.cms.businesslogic.media var propertyId = media.getProperty(Constants.Conventions.Media.File).Id; // Get paths - var destFilePath = FileSystem.GetRelativePath(propertyId, uploadedFile.FileName); + var destFilePath = GetRelativePath(propertyId, uploadedFile.FileName); var ext = Path.GetExtension(destFilePath).Substring(1); //var absoluteDestPath = HttpContext.Current.Server.MapPath(destPath); diff --git a/src/umbraco.cms/businesslogic/media/UmbracoMediaFactory.cs b/src/umbraco.cms/businesslogic/media/UmbracoMediaFactory.cs index 54d8dfa770..8cdf519a09 100644 --- a/src/umbraco.cms/businesslogic/media/UmbracoMediaFactory.cs +++ b/src/umbraco.cms/businesslogic/media/UmbracoMediaFactory.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.IO; using System.Linq; using System.Text.RegularExpressions; using System.Threading; @@ -99,7 +100,7 @@ namespace umbraco.cms.businesslogic.media if (int.TryParse(subfolder, out subfolderId)) { - var destFilePath = FileSystem.GetRelativePath(subfolderId, fileName); + var destFilePath = GetRelativePath(subfolderId, fileName); var destFileUrl = FileSystem.GetUrl(destFilePath); if (prop.Value.ToString() == destFileUrl) @@ -154,6 +155,17 @@ namespace umbraco.cms.businesslogic.media return friendlyName; } + public static string GetRelativePath(int propertyId, string fileName) + { + var contentConfig = UmbracoConfig.For.UmbracoSettings().Content; + + var sep = contentConfig.UploadAllowDirectories + ? Path.DirectorySeparatorChar + : '-'; + + return propertyId.ToString(CultureInfo.InvariantCulture) + sep + fileName; + } + #endregion } }