-
Notifications
You must be signed in to change notification settings - Fork 1
/
ImageHunter.cs
87 lines (75 loc) · 3.05 KB
/
ImageHunter.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
using System.Collections;
using System.IO;
namespace CSharp_Image_Action
{
public class ImageHunter
{
public int NumberImagesFound
{get{ return ImagesFound;}}
public ArrayList ImageList { get => imageList;}
protected System.Collections.ArrayList imageList = new System.Collections.ArrayList();
protected int ImagesFound = 0;
protected int MaxImages = 32768;
protected int MaxDirectoryDepth = 4;
protected string[] ValidImageExtensions;
public ImageHunter(ref DirectoryDescriptor dd, System.IO.DirectoryInfo directory, System.String[] Extensions, int Max_Images = 32768, int Directory_Depth = 4)
{
MaxDirectoryDepth = Directory_Depth;
MaxImages = Max_Images;
ValidImageExtensions = Extensions;
RecurseDirectory(ref dd, directory,0);
}
protected void MatchImages(ref DirectoryDescriptor dd, System.IO.DirectoryInfo directory, System.IO.FileInfo fi)
{
if(fi.Name.StartsWith(ImageDescriptor.thumbnail) || fi.Name.StartsWith(ImageDescriptor.resized))
{
System.Console.WriteLine("Not Adding " + fi.Name + " to file list");
return;
}
++ImagesFound;
var p = new ImageDescriptor(directory,fi);
imageList.Add(p);
dd.Images.Add(p);
}
protected void RecurseDirectory(ref DirectoryDescriptor dd, System.IO.DirectoryInfo directory, int CurrentDepth)
{
if(ImagesFound > MaxImages)
{
System.Console.WriteLine("//would be good to log an error");
return;
}
if(CurrentDepth == MaxDirectoryDepth)
{
System.Console.WriteLine("//would be good to log an error");
}else{
// Get all the sub directories, and dive into them
foreach(System.IO.DirectoryInfo di in directory.GetDirectories())
{
if(di.Name != Program.THUMBNAILS)
{
DirectoryDescriptor dd2 = new DirectoryDescriptor(di.Name,di.FullName);
dd.Directories.Add(dd2);
RecurseDirectory(ref dd2,di, CurrentDepth + 1);
}
}
}
foreach(System.IO.FileInfo fi in directory.GetFiles())
{
//optimize this later, it's slow and ugly
bool ValidExtension = false;
// Get all the images if a valid extension
foreach(string s in ValidImageExtensions)
{
if(fi.Extension == s)
ValidExtension = true;
}
if(ValidExtension)
{
MatchImages(ref dd, directory,fi);
}else{
System.Console.WriteLine("Info: " + fi.Name + " with " + fi.Extension + " invalid");
}
}
}
}
}