This repository has been archived by the owner on Oct 15, 2020. It is now read-only.
forked from nmaier/simpleDLNA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlainFolder.cs
101 lines (91 loc) · 2.26 KB
/
PlainFolder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using NMaier.SimpleDlna.Server;
using NMaier.SimpleDlna.Server.Metadata;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace NMaier.SimpleDlna.FileMediaServer
{
internal class PlainFolder : VirtualFolder, IMetaInfo
{
private readonly DirectoryInfo dir;
private PlainFolder(FileServer server, DlnaMediaTypes types,
VirtualFolder parent, DirectoryInfo dir,
IEnumerable<string> exts)
: base(parent, dir.Name)
{
Server = server;
this.dir = dir;
folders = (from d in dir.GetDirectories()
let m = TryGetFolder(server, types, d)
where m != null && m.ChildCount > 0
select m as IMediaFolder).ToList();
var rawfiles = from f in dir.GetFiles("*.*")
select f;
var files = new List<BaseFile>();
foreach (var f in rawfiles) {
var ext = f.Extension;
if (string.IsNullOrEmpty(ext) ||
!exts.Contains(ext.Substring(1), StringComparer.OrdinalIgnoreCase)) {
continue;
}
try {
files.Add(server.GetFile(this, f));
}
catch (Exception ex) {
server.Warn(f, ex);
}
}
resources.AddRange(files);
}
protected PlainFolder(FileServer server, DlnaMediaTypes types,
VirtualFolder parent, DirectoryInfo dir)
: this(server, types, parent, dir, types.GetExtensions())
{
}
public DateTime InfoDate
{
get
{
return dir.LastWriteTimeUtc;
}
}
public long? InfoSize
{
get
{
return null;
}
}
public override string Path
{
get
{
return dir.FullName;
}
}
public FileServer Server
{
get;
protected set;
}
public override string Title
{
get
{
return dir.Name;
}
}
private PlainFolder TryGetFolder(FileServer server, DlnaMediaTypes types,
DirectoryInfo d)
{
try {
return new PlainFolder(server, types, this, d);
}
catch (Exception ex) {
server.Warn("Failed to access folder", ex);
return null;
}
}
}
}