Пример #1
0
        public List <FileIndexItem> Delete(string f, bool collections)
        {
            var inputFilePaths = PathHelper.SplitInputFilePaths(f);

            // the result list
            var fileIndexResultsList             = new List <FileIndexItem>();
            var collectionAndInsideDirectoryList = new List <string>();

            foreach (var subPath in inputFilePaths)
            {
                var detailView =
                    _query.SingleItem(subPath, null, collections, false);

                if (detailView?.FileIndexItem == null)
                {
                    StatusCodesHelper.ReturnExifStatusError(
                        new FileIndexItem(subPath),
                        FileIndexItem.ExifStatus.NotFoundNotInIndex,
                        fileIndexResultsList);
                    continue;
                }

                if (_iStorage.IsFolderOrFile(detailView.FileIndexItem
                                             .FilePath) ==
                    FolderOrFileModel.FolderOrFileTypeList.Deleted)
                {
                    StatusCodesHelper.ReturnExifStatusError(
                        detailView.FileIndexItem,
                        FileIndexItem.ExifStatus.NotFoundSourceMissing,
                        fileIndexResultsList);
                    continue;
                }

                // Dir is readonly / don't delete
                if (_statusCodeHelper.IsReadOnlyStatus(detailView)
                    == FileIndexItem.ExifStatus.ReadOnly)
                {
                    StatusCodesHelper.ReturnExifStatusError(
                        detailView.FileIndexItem,
                        FileIndexItem.ExifStatus.ReadOnly,
                        fileIndexResultsList);
                    continue;
                }

                // Status should be deleted before you can delete the item
                if (StatusCodesHelper.IsDeletedStatus(detailView)
                    != FileIndexItem.ExifStatus.Deleted)
                {
                    StatusCodesHelper.ReturnExifStatusError(
                        detailView.FileIndexItem,
                        FileIndexItem.ExifStatus.OperationNotSupported,
                        fileIndexResultsList);
                    continue;
                }

                collectionAndInsideDirectoryList.AddRange(DetailView.GetCollectionSubPathList(detailView.FileIndexItem, collections, subPath));

                // For deleting content of an entire directory
                if (detailView.FileIndexItem.IsDirectory != true)
                {
                    continue;
                }

                // when deleting a folder the collections setting does nothing
                collectionAndInsideDirectoryList.AddRange(
                    _query.GetAllFiles(detailView.FileIndexItem.FilePath).Select(itemInDirectory => itemInDirectory.FilePath)
                    );
            }

            // collectionAndInsideDirectoryList should not have duplicate items
            foreach (var collectionSubPath in new HashSet <string>(collectionAndInsideDirectoryList))
            {
                var detailViewItem = _query.SingleItem(collectionSubPath,
                                                       null, false, false);

                // null only happens when some other process also delete this item
                if (detailViewItem == null)
                {
                    continue;
                }

                // return a Ok, which means the file is deleted
                detailViewItem.FileIndexItem.Status = FileIndexItem.ExifStatus.Ok;

                // remove thumbnail from disk
                _thumbnailStorage.FileDelete(detailViewItem.FileIndexItem.FileHash);

                fileIndexResultsList.Add(detailViewItem.FileIndexItem.Clone());

                // remove item from db
                _query.RemoveItem(detailViewItem.FileIndexItem);

                RemoveXmpSideCarFile(detailViewItem);
                RemoveJsonSideCarFile(detailViewItem);
                RemoveFileOrFolderFromDisk(detailViewItem);

                // the child directories are still stored in the database
                if (detailViewItem.FileIndexItem.IsDirectory != true)
                {
                    continue;
                }

                foreach (var item in _query.GetAllRecursive(collectionSubPath).Where(p => p.IsDirectory == true))
                {
                    item.Status = FileIndexItem.ExifStatus.Deleted;
                    fileIndexResultsList.Add(item.Clone());
                    _query.RemoveItem(item);
                }
            }
            return(fileIndexResultsList);
        }
Пример #2
0
        public List <FileIndexItem> GetInfo(List <string> inputFilePaths, bool collections)
        {
            // the result list
            var fileIndexResultsList = new List <FileIndexItem>();

            foreach (var subPath in inputFilePaths)
            {
                var detailView = _query.SingleItem(subPath, null, collections, false);

                if (detailView?.FileIndexItem == null)
                {
                    StatusCodesHelper.ReturnExifStatusError(new FileIndexItem(subPath),
                                                            FileIndexItem.ExifStatus.NotFoundNotInIndex,
                                                            fileIndexResultsList);
                    continue;
                }

                if (!_iStorage.ExistFile(detailView.FileIndexItem.FilePath))
                {
                    StatusCodesHelper.ReturnExifStatusError(detailView.FileIndexItem,
                                                            FileIndexItem.ExifStatus.NotFoundSourceMissing,
                                                            fileIndexResultsList);
                    continue;
                }

                // Check if extension is supported for ExtensionExifToolSupportedList
                // Not all files are able to write with exifTool
                if (!ExtensionRolesHelper.IsExtensionExifToolSupported(detailView.FileIndexItem.FileName))
                {
                    StatusCodesHelper.ReturnExifStatusError(
                        new FileIndexItemJsonParser(_iStorage).Read(detailView.FileIndexItem),
                        FileIndexItem.ExifStatus.ExifWriteNotSupported,
                        fileIndexResultsList);
                    continue;
                }

                var statusResults = StatusCodesHelper.IsDeletedStatus(detailView);
                // only when default status to avoid unneeded checks
                if (statusResults == FileIndexItem.ExifStatus.Default)
                {
                    statusResults = _statusCodeHelper.IsReadOnlyStatus(detailView);
                }
                // when everything is checked, it should be good
                if (statusResults == FileIndexItem.ExifStatus.Default)
                {
                    statusResults = FileIndexItem.ExifStatus.Ok;
                }

                var collectionSubPathList = DetailView.GetCollectionSubPathList(detailView.FileIndexItem, collections, subPath);

                foreach (var collectionSubPath in collectionSubPathList)
                {
                    var collectionItem = _readMeta.ReadExifAndXmpFromFile(collectionSubPath);

                    collectionItem.Status          = statusResults;
                    collectionItem.CollectionPaths = collectionSubPathList;
                    collectionItem.ImageFormat     =
                        ExtensionRolesHelper.MapFileTypesToExtension(collectionSubPath);
                    collectionItem.Size = _iStorage.Info(collectionSubPath).Size;
                    fileIndexResultsList.Add(collectionItem);
                }
            }

            return(fileIndexResultsList);
        }