/// <summary>
        /// Create a new instance
        /// </summary>
        /// <param name="fileInfo">File info</param>
        /// <param name="rootVolume">Root volume</param>
        /// <returns>Result instance</returns>
        public static ImageEntryObjectModel Create(FileInfo fileInfo, FileSystemRootVolume rootVolume)
        {
            // Get paths
            var parentPath   = fileInfo.Directory?.FullName.Substring(rootVolume.Directory.FullName.Length);
            var relativePath = fileInfo.FullName.Substring(rootVolume.Directory.FullName.Length);

            // Get image size
            var imageSize = ImagingUtils.GetImageSize(fileInfo.FullName);

            // Create new instance
            var objectModel = new ImageEntryObjectModel
            {
                Read          = true,
                Write         = !rootVolume.IsReadOnly,
                Locked        = rootVolume.IsLocked,
                Name          = fileInfo.Name,
                Size          = fileInfo.Length,
                UnixTimeStamp = (long)(fileInfo.LastWriteTimeUtc - UnixOrigin).TotalSeconds,
                Mime          = UrlPathUtils.GetMimeType(fileInfo),
                Hash          = rootVolume.VolumeId + UrlPathUtils.EncodePath(relativePath),
                ParentHash    =
                    rootVolume.VolumeId +
                    UrlPathUtils.EncodePath(!string.IsNullOrEmpty(parentPath) ? parentPath : fileInfo.Directory?.Name),
                Tmb       = rootVolume.GetExistingThumbHash(fileInfo) ?? "",
                Dimension = $"{imageSize.Width}x{imageSize.Height}"
            };

            // Return it
            return(objectModel);
        }
Esempio n. 2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }

            if (!string.IsNullOrEmpty(value.ToString()))
            {
                return(ImagingUtils.BitmapFromPath(value.ToString()));
            }

            return(null);
        }
Esempio n. 3
0
        private void Button_OK(object sender, RoutedEventArgs e)
        {
            var view = new ViewPoint(!Issue.Viewpoints.Any());

            if (!Directory.Exists(Path.Combine(TempFolder, Issue.Topic.Guid)))
            {
                Directory.CreateDirectory(Path.Combine(TempFolder, Issue.Topic.Guid));
            }


            if (!string.IsNullOrEmpty(CommentBox.Text))
            {
                var c = new Comment
                {
                    Comment1     = CommentBox.Text,
                    Author       = Utils.GetUsername(),
                    Status       = comboStatuses.SelectedValue.ToString(),
                    VerbalStatus = VerbalStatus.Text,
                    Date         = DateTime.Now,
                    Viewpoint    = new CommentViewpoint {
                        Guid = view.Guid
                    }
                };
                Issue.Comment.Add(c);
            }
            //first save the image, then update path
            var path = Path.Combine(TempFolder, Issue.Topic.Guid, view.Snapshot);

            ImagingUtils.SaveImageSource(SnapshotImg.Source, path);
            view.SnapshotPath = path;

            //neede for UI binding
            Issue.Viewpoints.Add(view);

            var win = Window.GetWindow(this);

            if (win != null)
            {
                win.DialogResult = true;
            }
        }
        /// <summary>
        /// Search accessible files and directories in given volume
        /// </summary>
        /// <typeparam name="TVolume">Volume type</typeparam>
        /// <param name="volume">Volume</param>
        /// <param name="root">Root path</param>
        /// <param name="searchTerm">Search term</param>
        /// <returns>Result list</returns>
        public static IEnumerable <EntryObjectModel> SearchAccessibleFilesAndDirectories <TVolume>(this TVolume volume, string root,
                                                                                                   string searchTerm)
            where TVolume : FileSystemRootVolume
        {
            var entries = new List <EntryObjectModel>();

            foreach (var directory in Directory.EnumerateDirectories(root).Where(m => m.Contains(searchTerm)))
            {
                entries.Add(DirectoryEntryObjectModel.Create(new DirectoryInfo(directory), volume));
            }
            foreach (var file in Directory.EnumerateFiles(root).Where(m => m.Contains(searchTerm)))
            {
                // Check if file refers to an image or not
                if (ImagingUtils.CanProcessFile(file))
                {
                    // Add image to added entries
                    entries.Add(
                        ImageEntryObjectModel.Create(new FileInfo(file), volume));
                }
                else
                {
                    // Add file to added entries
                    entries.Add(
                        FileEntryObjectModel.Create(new FileInfo(file), volume));
                }
            }
            foreach (var subDir in Directory.EnumerateDirectories(root))
            {
                try
                {
                    entries.AddRange(volume.SearchAccessibleFilesAndDirectories(subDir, searchTerm));
                }
                catch (UnauthorizedAccessException)
                {
                    // Do nothing
                }
            }

            return(entries);
        }
Esempio n. 5
0
        /// <summary>
        /// Open file
        /// </summary>
        /// <param name="target">Target</param>
        /// <param name="includeRootSubFolders">Include subfolders of root directories</param>
        /// <returns>Response result</returns>
        OpenCommandResult IConnectorDriver.Open(string target, bool includeRootSubFolders)
        {
            // Get directory target path info
            var fullPath = ParseDirectoryPath(target);

            // Create command result
            var commandResult = new OpenCommandResult(
                fullPath.CreateTargetEntryObjectModel(),
                new OptionsResultData(fullPath));

            // Add visible files
            foreach (var fileItem in fullPath.Directory.GetVisibleFiles())
            {
                // Check if file is supported for imaging
                if (ImagingUtils.CanProcessFile(fileItem))
                {
                    // Is supported
                    // Add file item as image entry
                    commandResult.Files.Add(
                        ImageEntryObjectModel.Create(fileItem, fullPath.Root));
                }
                else
                {
                    // Not supported
                    // Add file item as standard entry
                    commandResult.Files.Add(
                        FileEntryObjectModel.Create(fileItem, fullPath.Root));
                }
            }

            // Add visible directories
            foreach (var directoryItem in fullPath.Directory.GetVisibleDirectories())
            {
                commandResult.Files.Add(DirectoryEntryObjectModel.Create(directoryItem, fullPath.Root));
            }

            // Return it
            return(commandResult);
        }
Esempio n. 6
0
        private void EditSnapshot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string editSnap = "mspaint";
                string tempImg  = Path.Combine(Path.GetTempPath(), "BCFier", Path.GetTempFileName() + ".png");
                ImagingUtils.SaveImageSource(SnapshotImg.Source, tempImg);

                if (!File.Exists(tempImg))
                {
                    MessageBox.Show("Snapshot is not a valit image, please try again.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                string customeditor = UserSettings.Get("editSnap");
                if (!string.IsNullOrEmpty(customeditor) && File.Exists(customeditor))
                {
                    editSnap = customeditor;
                }



                var paint     = new Process();
                var paintInfo = new ProcessStartInfo(editSnap, "\"" + tempImg + "\"");
                paintInfo.UseShellExecute = false;
                paint.StartInfo           = paintInfo;
                paint.Start();
                paint.WaitForExit();


                AddViewpoint(tempImg);
                File.Delete(tempImg);
            }
            catch (System.Exception ex1)
            {
                MessageBox.Show("exception: " + ex1);
            }
        }
Esempio n. 7
0
 internal void AddViewpoint(string imagePath)
 {
     SnapshotImg.Source = ImagingUtils.ImageSourceFromPath(imagePath);
 }
Esempio n. 8
0
        /// <summary>
        /// Generate thumbnail for image
        /// </summary>
        /// <param name="originalImage">Image</param>
        /// <returns>Thumbnail generated result</returns>
        public ThumbnailGeneratedResult GenerateThumbnail(FileSystemVolumeFileInfo originalImage)
        {
            // Normalize file name
            var name =
                originalImage.File.Name.Substring(0,
                                                  originalImage.File.Name.LastIndexOf(
                                                      ConnectorFileSystemDriverConstants.VolumeSeparator,
                                                      StringComparison.InvariantCulture));

            // Compute full path
            var fullPath = $@"{originalImage.File.DirectoryName}\{name}{originalImage.File.Extension}";

            // Check that thumbnails directory is set
            if (ThumbnailsDirectory != null)
            {
                // Is set

                // Get thumbnail path
                var thumbPath = originalImage.File.FullName.StartsWith(ThumbnailsDirectory.FullName)
                    ? originalImage.File
                    : new FileInfo(Path.Combine(ThumbnailsDirectory.FullName, originalImage.RelativePath));

                // Check if it exists
                if (!thumbPath.Exists)
                {
                    // Doesn't exist

                    // Check if directory exists
                    if (thumbPath.Directory != null && !thumbPath.Directory.Exists)
                    {
                        // Doesn't exist, create it
                        System.IO.Directory.CreateDirectory(thumbPath.Directory.FullName);
                    }

                    // Generate thumbnail
                    byte[] thumbBytes;

                    using (var thumbFile = thumbPath.Create())
                    {
                        // Get thumnail bytes
                        thumbBytes = ImagingUtils.GenerateThumbnail(File.ReadAllBytes(fullPath), ThumbnailsSize, true);

                        // Write thumbnail bytes to file
                        thumbFile.Write(thumbBytes, 0, thumbBytes.Length);
                    }

                    // Return result
                    return(new ThumbnailGeneratedResult(new FileInfo(thumbPath.FullName), thumbBytes));
                }

                // Exists
                return(new ThumbnailGeneratedResult(thumbPath, File.ReadAllBytes(thumbPath.FullName)));
            }

            // Is not set

            // Return thumbnail bytes
            return(new ThumbnailGeneratedResult(
                       new FileInfo(fullPath),
                       ImagingUtils.GenerateThumbnail(File.ReadAllBytes(fullPath), ThumbnailsSize, true)
                       ));
        }
Esempio n. 9
0
 /// <summary>
 /// Get if thumnail can be created for file
 /// </summary>
 /// <param name="fileInfo">File info</param>
 /// <returns>True/False, based on result</returns>
 public bool CanCreateThumbnail(FileInfo fileInfo)
 {
     return(!string.IsNullOrEmpty(ThumbnailsUrl) &&
            ImagingUtils.CanProcessFile(fileInfo.Extension));
 }
 /// <summary>
 /// Get if file system volume path info refers to an image
 /// </summary>
 /// <param name="info">Info</param>
 /// <returns>True/False, based on result</returns>
 public static bool IsImage(this FileSystemVolumePathInfo info)
 {
     return(info.IsFile() &&
            ImagingUtils.CanProcessFile(info.Info.Extension));
 }
Esempio n. 11
0
 public BitmapImage LoadBitmap()
 {
     using (var stream = OpenStream())
         return(ImagingUtils.LoadPremultipliedBitmapImageFromStream(stream));
 }
 private static BitmapImage LoadImage(ThemeBitmap oldValue)
 {
     using (var stream = oldValue.OpenStream())
         return(ImagingUtils.LoadBitmapImageFromStream(stream));
 }
Esempio n. 13
0
        /// <summary>
        /// Upload files
        /// </summary>
        /// <param name="target">Target</param>
        /// <param name="files">Files</param>
        /// <returns>Response result</returns>
        UploadCommandResult IConnectorDriver.Upload(string target, IEnumerable <IFileStream> files)
        {
            // Parse target path
            var dest = ParsePath(target);

            // Create command result
            var commandResult = new UploadCommandResult();

            // Normalize file streams
            var fileStreams = files as IFileStream[] ?? files.ToArray();

            // Check if max upload size is set and that no files exceeds it
            if (dest.Root.MaxUploadSizeKb.HasValue &&
                fileStreams.Any(x => (x.Stream.Length / 1024) > dest.Root.MaxUploadSizeKb))
            {
                // Max upload size exceeded
                commandResult.SetMaxUploadFileSizeError();

                // End processing
                return(commandResult);
            }

            // Loop files
            foreach (var file in fileStreams)
            {
                // Validate file name
                if (string.IsNullOrWhiteSpace(file.FileName))
                {
                    throw new ArgumentNullException(nameof(IFileStream.FileName));
                }

                // Get path
                var path = new FileInfo(Path.Combine(dest.Info.FullName, Path.GetFileName(file.FileName)));

                // Check if it already exists
                if (path.Exists)
                {
                    // Check if overwrite on upload is supported
                    if (dest.Root.UploadOverwrite)
                    {
                        // If file already exist we rename the current file.
                        // If upload is successful, delete temp file. Otherwise, we restore old file.
                        var tmpPath = path.FullName + Guid.NewGuid();

                        // Save file
                        var fileSaved = false;
                        try
                        {
                            file.SaveAs(tmpPath);
                            fileSaved = true;
                        }
                        catch (Exception) { }
                        finally
                        {
                            // Check that file was saved correctly
                            if (fileSaved)
                            {
                                // Delete file
                                File.Delete(path.FullName);

                                // Move file
                                File.Move(tmpPath, path.FullName);

                                // Remove thumbnails
                                dest.RemoveThumbs();
                            }
                            else
                            {
                                // Delete temporary file
                                File.Delete(tmpPath);
                            }
                        }
                    }
                    else
                    {
                        // Ensure directy name is set
                        if (string.IsNullOrEmpty(path.DirectoryName))
                        {
                            throw new ArgumentNullException(nameof(FileInfo.DirectoryName));
                        }

                        // Save file
                        file.SaveAs(Path.Combine(path.DirectoryName, FileSystemUtils.GetDuplicatedName(path)));
                    }
                }
                else
                {
                    // Save file
                    file.SaveAs(path.FullName);
                }

                // Check if file refers to an image or not
                if (ImagingUtils.CanProcessFile(path))
                {
                    // Add image to added entries
                    commandResult.Added.Add(
                        ImageEntryObjectModel.Create(new FileInfo(path.FullName), dest.Root));
                }
                else
                {
                    // Add file to added entries
                    commandResult.Added.Add(
                        FileEntryObjectModel.Create(new FileInfo(path.FullName), dest.Root));
                }
            }

            // Return result
            return(commandResult);
        }
Esempio n. 14
0
        /// <summary>
        /// Paste items
        /// </summary>
        /// <param name="source">Source</param>
        /// <param name="dest">Destination</param>
        /// <param name="targets">Targets</param>
        /// <param name="isCut">Is cut</param>
        /// <returns>Response result</returns>
        PasteCommandResult IConnectorDriver.Paste(string source, string dest, IEnumerable <string> targets, bool isCut)
        {
            // Parse destination path
            var destPath = ParsePath(dest);

            // Create command result
            var commandResult = new PasteCommandResult();

            // Loop target items
            foreach (var item in targets)
            {
                // Parse target item path, which will be the source
                var src = ParsePath(item);

                // Proceed if it's a file or directory
                if (src.IsDirectory())
                {
                    // Directory

                    // Compute new directory
                    var newDir = new DirectoryInfo(Path.Combine(destPath.Info.FullName, src.Info.Name));

                    // Check if it already exists
                    if (newDir.Exists)
                    {
                        // Exists
                        Directory.Delete(newDir.FullName, true);
                    }

                    // Check if content is being cut
                    if (isCut)
                    {
                        // Remove thumbnails
                        src.RemoveThumbs();

                        // Move directory
                        src.GetDirectory().MoveTo(newDir.FullName);

                        // Add to removed entries
                        commandResult.Removed.Add(item);
                    }
                    else
                    {
                        // Copy directory
                        FileSystemUtils.DirectoryCopy(src.GetDirectory(), newDir.FullName, true);
                    }

                    // Add it to added items
                    commandResult.Added.Add(
                        DirectoryEntryObjectModel.Create(newDir, destPath.Root));
                }
                else if (src.IsFile())
                {
                    // File

                    // Compute new file path
                    var newFilePath = Path.Combine(destPath.Info.FullName, src.Info.Name);

                    // Check if file exists
                    if (File.Exists(newFilePath))
                    {
                        // Exists
                        File.Delete(newFilePath);
                    }

                    // Check if content is being cut
                    if (isCut)
                    {
                        // Remove thumbnails
                        src.RemoveThumbs();

                        // Move file
                        File.Move(src.Info.FullName, newFilePath);

                        // Add it to removed items
                        commandResult.Removed.Add(item);
                    }
                    else
                    {
                        // Copy file
                        File.Copy(src.Info.FullName, newFilePath);
                    }

                    // Check if file refers to an image or not
                    if (ImagingUtils.CanProcessFile(newFilePath))
                    {
                        // Add image to added entries
                        commandResult.Added.Add(
                            ImageEntryObjectModel.Create(new FileInfo(newFilePath), destPath.Root));
                    }
                    else
                    {
                        // Add file to added entries
                        commandResult.Added.Add(
                            FileEntryObjectModel.Create(new FileInfo(newFilePath), destPath.Root));
                    }
                }
                else
                {
                    // Not supported
                    throw new NotSupportedException();
                }
            }

            // Return result
            return(commandResult);
        }
Esempio n. 15
0
        /// <summary>
        /// Duplicate items
        /// </summary>
        /// <param name="targets">Targets</param>
        /// <returns>Response result</returns>
        DuplicateCommandResult IConnectorDriver.Duplicate(IEnumerable <string> targets)
        {
            // Create command result
            var commandResult = new DuplicateCommandResult();

            // Loop targets
            foreach (var targetItem in targets)
            {
                // Parse target path
                var fullPath = ParsePath(targetItem);

                // Proceed if it's a file or directory
                if (fullPath.IsDirectory())
                {
                    // Directory

                    // Remove thumbnails
                    fullPath.RemoveThumbs();

                    // Get path info
                    var parentPath = fullPath.GetParentDirectory().FullName;
                    var name       = fullPath.GetDirectory().Name;

                    // Compute new name
                    var newName = $@"{parentPath}\{name} copy";

                    // Check if directory already exists
                    if (!Directory.Exists(newName))
                    {
                        // Doesn't exist
                        FileSystemUtils.DirectoryCopy(fullPath.GetDirectory(), newName, true);
                    }
                    else
                    {
                        // Already exists, create numbered copy
                        var newNameFound = false;
                        for (var i = 1; i < 100; i++)
                        {
                            // Compute new name
                            newName = $@"{parentPath}\{name} copy {i}";

                            // Test that it doesn't exist
                            if (!Directory.Exists(newName))
                            {
                                FileSystemUtils.DirectoryCopy(fullPath.GetDirectory(), newName, true);
                                newNameFound = true;
                                break;
                            }
                        }

                        // Check if new name was found
                        if (!newNameFound)
                        {
                            throw new ELFinderNewNameSelectionException($@"{parentPath}\{name} copy");
                        }
                    }

                    // Add entry to added items
                    commandResult.Added.Add(
                        DirectoryEntryObjectModel.Create(new DirectoryInfo(newName), fullPath.Root));
                }
                else if (fullPath.IsFile())
                {
                    // File

                    // Remove thumbnails
                    fullPath.RemoveThumbs();

                    // Get path info
                    var parentPath = fullPath.GetDirectory().FullName;
                    var name       = fullPath.Info.Name.Substring(0, fullPath.Info.Name.Length - fullPath.Info.Extension.Length);
                    var ext        = fullPath.Info.Extension;

                    // Compute new name
                    var newName = $@"{parentPath}\{name} copy{ext}";

                    // Check if file already exists
                    if (!File.Exists(newName))
                    {
                        // Doesn't exist
                        ((FileSystemVolumeFileInfo)fullPath).File.CopyTo(newName);
                    }
                    else
                    {
                        // Already exists, create numbered copy
                        var newNameFound = false;
                        for (var i = 1; i < 100; i++)
                        {
                            // Compute new name
                            newName = $@"{parentPath}\{name} copy {i}{ext}";

                            // Test that it doesn't exist
                            if (!File.Exists(newName))
                            {
                                ((FileSystemVolumeFileInfo)fullPath).File.CopyTo(newName);
                                newNameFound = true;
                                break;
                            }
                        }

                        // Check if new name was found
                        if (!newNameFound)
                        {
                            throw new ELFinderNewNameSelectionException($@"{parentPath}\{name} copy{ext}");
                        }
                    }

                    // Check if file refers to an image or not
                    if (ImagingUtils.CanProcessFile(newName))
                    {
                        // Add image to added entries
                        commandResult.Added.Add(
                            ImageEntryObjectModel.Create(new FileInfo(newName), fullPath.Root));
                    }
                    else
                    {
                        // Add file to added entries
                        commandResult.Added.Add(
                            FileEntryObjectModel.Create(new FileInfo(newName), fullPath.Root));
                    }
                }
                else
                {
                    // Not supported
                    throw new NotSupportedException();
                }
            }

            // Return result
            return(commandResult);
        }
Esempio n. 16
0
        /// <summary>
        /// Initialize file/directory open
        /// </summary>
        /// <param name="target">Target</param>
        /// <returns>Response result</returns>
        InitCommandResult IConnectorDriver.Init(string target)
        {
            // Declare target directory path info
            FileSystemVolumeDirectoryInfo fullPath;

            // Check if target was defined
            if (string.IsNullOrEmpty(target))
            {
                // Target not defined

                // Get startup volume
                var startupVolume = RootVolumes.GetStartupVolume();

                // Get directory target path info
                fullPath = new FileSystemVolumeDirectoryInfo(
                    startupVolume, startupVolume.StartDirectory ?? startupVolume.Directory);
            }
            else
            {
                // Target defined

                // Get directory target path info
                fullPath = ParseDirectoryPath(target);
            }

            // Create command result
            var commandResult = new InitCommandResult(
                fullPath.CreateTargetEntryObjectModel(),
                new OptionsResultData(fullPath));

            // Add visible files
            foreach (var fileItem in fullPath.Directory.GetVisibleFiles())
            {
                // Check if file is supported for imaging
                if (ImagingUtils.CanProcessFile(fileItem))
                {
                    // Is supported
                    // Add file item as image entry
                    commandResult.Files.Add(
                        ImageEntryObjectModel.Create(fileItem, fullPath.Root));
                }
                else
                {
                    // Not supported
                    // Add file item as standard entry
                    commandResult.Files.Add(
                        FileEntryObjectModel.Create(fileItem, fullPath.Root));
                }
            }

            // Add visible directories
            foreach (var directoryItem in fullPath.Directory.GetVisibleDirectories())
            {
                commandResult.Files.Add(DirectoryEntryObjectModel.Create(directoryItem, fullPath.Root));
            }

            // Add root directories
            foreach (var rootVolume in RootVolumes)
            {
                commandResult.Files.Add(RootDirectoryEntryObjectModel.Create(rootVolume.Directory, rootVolume));
            }

            // Add root directories, if different from root
            if (!fullPath.IsDirectorySameAsRoot)
            {
                foreach (var directoryItem in fullPath.Root.Directory.GetVisibleDirectories())
                {
                    commandResult.Files.Add(DirectoryEntryObjectModel.Create(directoryItem, fullPath.Root));
                }
            }

            // Set max upload size
            if (fullPath.Root.MaxUploadSizeKb.HasValue)
            {
                commandResult.UploadMaxSize = $"{fullPath.Root.MaxUploadSizeKb.Value}K";
            }

            // Return it
            return(commandResult);
        }