Example #1
0
        private void ProcessDirectory(LocalDirectory parentDirectory, IO.DirectoryInfo directoryInfo)
        {
            if (parentDirectory == null) {
                throw new ArgumentNullException("parentDirectory");
            }
            if (directoryInfo == null) {
                throw new ArgumentNullException("directoryInfo");
            }

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

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

                    foreach (IO.FileInfo fileInfo in directoryInfo.GetFiles()) {
                        if (fileInfo.Name.StartsWith(".") == false) {

                            if (IndexingFile != null)
                                IndexingFile(this, 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)) {
                                Core.ShareHasher.HashFile(file);
                            }
                        }
                    }

                    foreach (IO.DirectoryInfo 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, ex);
                }
            }
        }