/// <summary> /// Get picture (thumb) local path /// </summary> /// <param name="thumbFileName">Filename</param> /// <returns>Local picture thumb path</returns> protected virtual string GetThumbLocalPath(string thumbFileName) { var thumbsDirectoryPath = _fileProvider.GetAbsolutePath(SmiMediaDefaults.ImageThumbsPath); if (_mediaSettings.MultipleThumbDirectories) { //get the first two letters of the file name var fileNameWithoutExtension = _fileProvider.GetFileNameWithoutExtension(thumbFileName); if (fileNameWithoutExtension != null && fileNameWithoutExtension.Length > SmiMediaDefaults.MultipleThumbDirectoriesLength) { var subDirectoryName = fileNameWithoutExtension.Substring(0, SmiMediaDefaults.MultipleThumbDirectoriesLength); thumbsDirectoryPath = _fileProvider.GetAbsolutePath(SmiMediaDefaults.ImageThumbsPath, subDirectoryName); _fileProvider.CreateDirectory(thumbsDirectoryPath); } } var thumbFilePath = _fileProvider.Combine(thumbsDirectoryPath, thumbFileName); return(thumbFilePath); }
/// <summary> /// Get the unique name of the file (add -copy-(N) to the file name if there is already a file with that name in the directory) /// </summary> /// <param name="directoryPath">Path to the file directory</param> /// <param name="fileName">Original file name</param> /// <returns>Unique name of the file</returns> protected virtual string GetUniqueFileName(string directoryPath, string fileName) { var uniqueFileName = fileName; var i = 0; while (_fileProvider.FileExists(_fileProvider.Combine(directoryPath, uniqueFileName))) { uniqueFileName = $"{_fileProvider.GetFileNameWithoutExtension(fileName)}-Copy-{++i}{_fileProvider.GetFileExtension(fileName)}"; } return(uniqueFileName); }