コード例 #1
0
        private void FileWatcherRenamedEventHandlers(object sender, RenamedEventArgs args)
        {
            lock (watcherLock)
            {
                var attr = File.GetAttributes(args.FullPath);
                if (attr.HasFlag(FileAttributes.Directory))
                {
                    if (TryGetDirectoryFromFullPath(args.OldFullPath, out var directory))
                    {
                        var newParentDirectory = ParentDirectoryForEntry(args.FullPath);
                        var newDirectoryInfo   = new DirectoryInfo(args.FullPath);

                        directory.Parent.Directories.internalList.Remove(directory);
                        newParentDirectory.Directories.internalList.Add(directory);

                        directory.Name = newDirectoryInfo.Name;

                        OnEntryChanged?.Invoke(new ArchiveEventParameters()
                        {
                            ActionType = ArchiveActionType.Changed,
                            Entry      = directory,
                        });
                    }
                }
                else
                {
                    if (TryGetFileFromFullPath(args.OldFullPath, out var file))
                    {
                        var newParentDirectory = ParentDirectoryForEntry(args.FullPath);
                        var newFileInfo        = new FileInfo(args.FullPath);

                        file.Parent.Files.internalList.Remove(file);
                        newParentDirectory.Files.internalList.Add(file);

                        file.MoveAndRename(file.Parent, newFileInfo);

                        OnEntryChanged?.Invoke(new ArchiveEventParameters()
                        {
                            ActionType = ArchiveActionType.Changed,
                            Entry      = file,
                        });
                    }
                }
            }
        }
コード例 #2
0
        private void FileWatcherEventHandler(object sender, FileSystemEventArgs args)
        {
            lock (watcherLock)
            {
                if (args.ChangeType.HasFlag(WatcherChangeTypes.Created))
                {
                    var attr = File.GetAttributes(args.FullPath);

                    var parentDirectory = ParentDirectoryForEntry(args.FullPath);

                    if (attr.HasFlag(FileAttributes.Directory))
                    {
                        var newDirectory = new FileSystemArchiveDirectory(this, parentDirectory, new DirectoryInfo(args.FullPath));
                        parentDirectory.Directories.internalList.Add(newDirectory);

                        OnEntryChanged?.Invoke(new ArchiveEventParameters()
                        {
                            ActionType = ArchiveActionType.Created,
                            Entry      = newDirectory,
                        });
                    }
                    else
                    {
                        var newFile = new FileSystemArchiveFile(this, parentDirectory, new FileInfo(args.FullPath));
                        parentDirectory.Files.internalList.Add(newFile);

                        OnEntryChanged?.Invoke(new ArchiveEventParameters()
                        {
                            ActionType = ArchiveActionType.Created,
                            Entry      = newFile,
                        });
                    }
                }

                if (args.ChangeType.HasFlag(WatcherChangeTypes.Changed))
                {
                    if (TryGetFileFromFullPath(args.FullPath, out var file))
                    {
                        OnEntryChanged?.Invoke(new ArchiveEventParameters()
                        {
                            ActionType = ArchiveActionType.Changed,
                            Entry      = file,
                        });
                    }
                }

                if (args.ChangeType.HasFlag(WatcherChangeTypes.Deleted))
                {
                    if (TryGetFileFromFullPath(args.FullPath, out var file))
                    {
                        file.Parent.Files.internalList.Remove(file);

                        OnEntryChanged?.Invoke(new ArchiveEventParameters()
                        {
                            ActionType = ArchiveActionType.Deleted,
                            Entry      = file,
                        });
                    }
                    else if (TryGetDirectoryFromFullPath(args.FullPath, out var directory))
                    {
                        directory.Parent.Directories.internalList.Remove(directory);

                        OnEntryChanged?.Invoke(new ArchiveEventParameters()
                        {
                            ActionType = ArchiveActionType.Deleted,
                            Entry      = directory,
                        });
                    }
                }
            }
        }