Streamed implementation. Limited input buffer.
[LanSpider.git] / src / AltSpider / AltSpider.cs
bloba3b5297505e13d518017ab199991b6feb0ba7aec
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4 using System.Linq;
6 using ShareDiscoveryService;
8 namespace AltSpider
10 public class AltSpider
12 public static DiscoveryTreeNode IndexFolder( string directoryName )
14 FileInfo dirinfo = new FileInfo( directoryName );
16 DiscoveryTreeNode dir
17 = new DiscoveryTreeNode
19 Path = directoryName,
20 Name = Path.GetFileName( directoryName ),
21 CreatedAt = dirinfo.CreationTime,
22 LastAccessedAt = dirinfo.LastAccessTime,
23 LastModifiedAt = dirinfo.LastWriteTime
26 List<DiscoveryTreeNode> listing = new List<DiscoveryTreeNode>();
28 try
30 string[] subdirs = Directory.GetDirectories( directoryName );
31 string[] subfiles = Directory.GetFiles( directoryName );
33 if ( subdirs.Length == 0 && subfiles.Length == 0 )
35 return null;
38 dir.ChildNodes
39 = (
41 from directory in subdirs
42 let child = IndexFolder( directory )
43 where child != null
44 select child
45 ).Union(
46 from fileName in subfiles
47 let info = new FileInfo( fileName )
48 select
49 new DiscoveryTreeNode
51 Path = fileName,
52 Name = info.Name,
53 Size = info.Length,
54 CreatedAt = info.CreationTime,
55 LastAccessedAt = info.LastAccessTime,
56 LastModifiedAt = info.LastWriteTime
59 ).ToList();
61 catch ( UnauthorizedAccessException ex )
63 Console.Error.WriteLine( "Access denied to {0}", directoryName );
65 catch ( IOException ex )
67 Console.Error.WriteLine( "Cannot read {0}: {1}", directoryName, ex.Message );
70 return dir;