-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenericDriveScan.cs
68 lines (56 loc) · 2.27 KB
/
GenericDriveScan.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
using System.Runtime.ExceptionServices;
using Newtonsoft.Json.Serialization;
namespace GDrive_test;
// TODO Add scan options (folder, mimetype, filesize min, file ext, wildcard)
// put in a dict pour extended options, beware not all options have the same type (string, int64, bool)
public abstract class GenericDriveScan
{
// scan options management settings
// TODO Add settings and var for managing mimetype filtering, wildcard, ext filtering
protected List<string>? MimeTypesFilter = null; // Init with empty list instead ?
protected HashSet<string>? ExtensionsFilter = null; // Init with empty list instead ?
protected bool UseExtensionFilter = false;
protected bool UseWildcardFilter = false;
// generic scan options
/// <value>Indicates if only folders should be retrieved from the scan</value>
public bool ScanFoldersOnly { get ; set; } = false;
public bool ScanRecursive { get ; set; } = false;
public Int64 MinFileSize { get ; set; } = Int64.MaxValue; // put max(int64) to ease tests or -1 ?
// Information set during scan
public int FileCount { get ; protected set; } = 0;
public int FolderCount { get ; protected set; } = 0;
protected void SetExentions(List<string>? extslist)
{
if (extslist == null)
{
// TODO BEWARE of side effect with mime types filter
UseExtensionFilter = false;
}
else
{
UseExtensionFilter = true;
//TODO compute
}
}
public abstract GenericFolder? ScanFolder(string startingId);
// TODO Add a helper method to check scan options over a file name and filesize
// TODO Rename
protected bool MatchScanOptions(string filename, string extension, Int64 filesize)
{
if (this.ScanFoldersOnly)
return false;
if (this.MinFileSize > filesize)
return false;
// check extensions
if (this.UseExtensionFilter)
{
if (this.ExtensionsFilter != null)
if (! this.ExtensionsFilter.Contains(extension))
return false;
}
// check wildcard
// https://www.codeproject.com/Articles/11556/Converting-Wildcards-to-Regexes
// check mimetypes
return true;
}
}