Пример #1
0
        private void ProcessDirectory(LocalDirectory parentDirectory, IO.DirectoryInfo directoryInfo)
        {
            if (parentDirectory == null)
            {
                throw new ArgumentNullException(nameof(parentDirectory));
            }

            if (directoryInfo == null)
            {
                throw new ArgumentNullException(nameof(directoryInfo));
            }

            try
            {
                LocalDirectory directory = (LocalDirectory)parentDirectory.GetSubdirectory(directoryInfo.Name);

                if (directory == null)
                {
                    directory = parentDirectory.CreateSubDirectory(directoryInfo.Name, directoryInfo.FullName);
                }

                foreach (var fileInfo in directoryInfo.EnumerateFiles().Where(f => !f.Name.StartsWith(".")))
                {
                    IndexingFile?.Invoke(this, new FilenameEventArgs(fileInfo.FullName));

                    LocalFile file = (LocalFile)directory.GetFile(fileInfo.Name);
                    if (file == null)
                    {
                        file = directory.CreateFile(fileInfo);
                    }
                    else
                    {
                        // XXX: Update file info
                    }

                    if (string.IsNullOrEmpty(file.InfoHash))
                    {
                        this.hasher.HashFile(file);
                    }
                }

                foreach (var subDirectoryInfo in directoryInfo.EnumerateDirectories().Where(d => !d.Name.StartsWith(".")))
                {
                    //ProcessDirectory(directory, subDirectoryInfo);
                    this.queue.Add(new QueueItem(directory, subDirectoryInfo), this.cancellation.Token);
                }
            }
            catch (ThreadAbortException)
            {
                // Canceled, ignore error.
            }
            catch (Exception ex)
            {
                this.loggingService.LogError("Error while re-indexing shared files:", ex);

                ErrorIndexing?.Invoke(this, new ErrorEventArgs(ex));
            }
        }
Пример #2
0
        private void ProcessDirectory(LocalDirectory parentDirectory, DirectoryInfo directoryInfo)
        {
            if (parentDirectory == null)
            {
                throw new ArgumentNullException("parentDirectory");
            }
            if (directoryInfo == null)
            {
                throw new ArgumentNullException("directoryInfo");
            }

            try {
                if (directoryInfo.Name.StartsWith(".") == false)
                {
                    var directory = (LocalDirectory)parentDirectory.GetSubdirectory(directoryInfo.Name);

                    if (directory == null)
                    {
                        directory = parentDirectory.CreateSubDirectory(core.FileSystem, directoryInfo.Name, directoryInfo.FullName);
                    }

                    foreach (var fileInfo in directoryInfo.GetFiles())
                    {
                        if (fileInfo.Name.StartsWith(".") == false)
                        {
                            if (IndexingFile != null)
                            {
                                IndexingFile(this, fileInfo.FullName);
                            }

                            var file = (LocalFile)directory.GetFile(fileInfo.Name);
                            if (file == null)
                            {
                                file = directory.CreateFile(fileInfo);
                            }
                            if (string.IsNullOrEmpty(file.InfoHash))
                            {
                                core.ShareHasher.HashFile(file);
                            }
                        }
                    }

                    foreach (var subDirectoryInfo in directoryInfo.GetDirectories())
                    {
                        ProcessDirectory(directory, subDirectoryInfo);
                    }
                }
            } catch (ThreadAbortException) {
                // Canceled, ignore error.
            } catch (Exception ex) {
                LoggingService.LogError("Error while re-indexing shared files:", ex);
                if (ErrorIndexing != null)
                {
                    ErrorIndexing(this, new ErrorEventArgs(ex));
                }
            }
        }