private string GetUniqueFileName(string folder, string fileName)
        {
            var    result    = fileName;
            var    copy      = T("Admin.Common.Copy");
            string name      = null;
            string extension = null;

            for (var i = 1; i < 999999; ++i)
            {
                var path = _fileSystem.Combine(folder, result);

                if (!_fileSystem.FileExists(path))
                {
                    return(result);
                }

                if (name == null || extension == null)
                {
                    var file = _fileSystem.GetFile(path);
                    extension = file.FileType;
                    // this assumes that a storage file name always ends with its file type
                    name = file.Name.EmptyNull().Substring(0, file.Name.EmptyNull().Length - extension.Length);
                }

                result = "{0} - {1} {2}{3}".FormatInvariant(name, copy, i, extension);
            }

            return(result);
        }
        protected string GetPath(MediaFile mediaFile)
        {
            var ext = mediaFile.Extension.NullEmpty() ?? MimeTypes.MapMimeTypeToExtension(mediaFile.MimeType);

            var fileName  = mediaFile.Id.ToString(ImageCache.IdFormatString).Grow(ext, ".");
            var subfolder = fileName.Substring(0, ImageCache.MaxDirLength);
            var path      = _fileSystem.Combine(subfolder, fileName);

            return(_fileSystem.Combine(MediaRootPath, path));
        }
        private void RenameFile(string oldPath, string name)
        {
            oldPath = GetRelativePath(oldPath);

            if (!_fileSystem.FileExists(oldPath))
            {
                throw new Exception(LangRes("E_RenameFileInvalidPath"));
            }

            var fileType = Path.GetExtension(name);

            if (!IsAllowedFileType(fileType))
            {
                throw new Exception(LangRes("E_FileExtensionForbidden"));
            }

            try
            {
                var folder  = _fileSystem.GetFolderForFile(oldPath);
                var newPath = _fileSystem.Combine(folder.Path, name);

                _fileSystem.RenameFile(oldPath, newPath);

                Response.Write(GetResultString());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message + "; " + LangRes("E_RenameFile") + " \"" + oldPath + "\"");
            }
        }
Пример #4
0
        protected string GetPath(MediaItem media)
        {
            var fileName = media.GetFileName();

            var picture = media.Entity as Picture;

            if (picture != null)
            {
                var subfolder = fileName.Substring(0, ImageCache.MaxDirLength);
                fileName = _fileSystem.Combine(subfolder, fileName);
            }

            return(_fileSystem.Combine(media.Path, fileName));
        }
        protected string GetPath(MediaFile mediaFile)
        {
            Guard.NotNull(mediaFile, nameof(mediaFile));

            if (_pathCache.TryGetValue(mediaFile.Id, out var path))
            {
                return(path);
            }

            var ext = mediaFile.Extension.NullEmpty() ?? MimeTypes.MapMimeTypeToExtension(mediaFile.MimeType);

            var fileName  = mediaFile.Id.ToString(ImageCache.IdFormatString).Grow(ext, ".");
            var subfolder = fileName.Substring(0, ImageCache.MaxDirLength);

            path = _fileSystem.Combine(subfolder, fileName);
            path = _fileSystem.Combine(MediaRootPath, path);

            _pathCache[mediaFile.Id] = path;

            return(path);
        }
Пример #6
0
        /// <summary>
        /// Returns the images thumb path as is plus query (required for uploaded images)
        /// </summary>
        /// <param name="file">Image file to get thumbnail for</param>
        /// <param name="query"></param>
        /// <returns></returns>
        private string GetCachedImagePath(IFile file, ProcessImageQuery query)
        {
            if (!_imageProcessor.IsSupportedImage(file.Name))
            {
                throw new InvalidOperationException("Thumbnails for '{0}' files are not supported".FormatInvariant(file.Extension));
            }

            // TODO: (mc) prevent creating thumbs for thumbs AND check equality of source and target

            var imageFileName = String.Concat(file.Title, query.CreateHash());
            var extension     = (query.GetResultExtension() ?? file.Extension).EnsureStartsWith(".").ToLower();
            var path          = _fileSystem.Combine(file.Directory, imageFileName + extension);

            return(path.TrimStart('/', '\\'));
        }
Пример #7
0
 private void RenameDir(string path, string name)
 {
     try
     {
         path = GetRelativePath(path);
         var newPath = _fileSystem.Combine(Path.GetDirectoryName(path), name);
         _fileSystem.RenameFolder(path, newPath);
         Response.Write(GetResultString());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #8
0
 protected string GetPicturePath(MediaItem media)
 {
     return(_fileSystem.Combine(media.Path, media.GetFileName()));
 }