| 0 | 1 using System; | 
|  | 2 using System.Collections.Generic; | 
|  | 3 | 
|  | 4 namespace DocGen | 
|  | 5 { | 
|  | 6 	class FileItem | 
|  | 7 	{ | 
|  | 8 		public bool           IsFile; | 
|  | 9 		public string         Name; | 
|  | 10 		public List<FileItem> Items; | 
|  | 11 		public FileItem       Parent; | 
|  | 12 		public string         Group; | 
|  | 13 		public List<string>   Indexes   = new List<string>(); | 
|  | 14 		public List<string>   NoIndexes = new List<string>(); | 
|  | 15 		public bool           NoIndex; | 
|  | 16 | 
|  | 17 		private string _title; | 
|  | 18 		public  string  Title | 
|  | 19 		{ | 
|  | 20 			get { return _title ?? System.IO.Path.GetFileNameWithoutExtension(Name); } | 
|  | 21 			set { _title = value; } | 
|  | 22 		} | 
|  | 23 | 
|  | 24 		private int _sortOrder; | 
|  | 25 		public  int  SortOrder | 
|  | 26 		{ | 
|  | 27 			get | 
|  | 28 			{ | 
|  | 29 				if (_sortOrder == 0 && Items != null) | 
|  | 30 					return Items[0].SortOrder; | 
|  | 31 | 
|  | 32 				return _sortOrder; | 
|  | 33 			} | 
|  | 34 | 
|  | 35 			set { _sortOrder = value; } | 
|  | 36 		} | 
|  | 37 | 
|  | 38 		public string Path | 
|  | 39 		{ | 
|  | 40 			get | 
|  | 41 			{ | 
|  | 42 				return Name.Replace(Program.destPath, "").Replace("\\", "/"); | 
|  | 43 			} | 
|  | 44 		} | 
|  | 45 | 
|  | 46 		public IEnumerable<FileItem> GetFiles() | 
|  | 47 		{ | 
|  | 48 			if (Items != null) | 
|  | 49 			{ | 
|  | 50 				foreach (var item in Items) | 
|  | 51 				{ | 
|  | 52 					if (item.IsFile) | 
|  | 53 						yield return item; | 
|  | 54 | 
|  | 55 					if (item.Items != null) | 
|  | 56 						foreach (var i in item.GetFiles()) | 
|  | 57 							yield return i; | 
|  | 58 				} | 
|  | 59 			} | 
|  | 60 		} | 
|  | 61 | 
|  | 62 		public void Add(FileItem item) | 
|  | 63 		{ | 
|  | 64 			item.Parent = this; | 
|  | 65 | 
|  | 66 			if (Items == null) | 
|  | 67 				Items = new List<FileItem>(); | 
|  | 68 | 
|  | 69 			Items.Add(item); | 
|  | 70 		} | 
|  | 71 | 
|  | 72 		public void Prepare() | 
|  | 73 		{ | 
|  | 74 			if (Items != null) | 
|  | 75 			{ | 
|  | 76 				var groups = new List<FileItem>(); | 
|  | 77 | 
|  | 78 				for (var i = 0; i < Items.Count; i++) | 
|  | 79 				{ | 
|  | 80 					var item = Items[i]; | 
|  | 81 | 
|  | 82 					if (item.Group != null && item.Group != Name) | 
|  | 83 					{ | 
|  | 84 						var group = groups.Find(file => file.Name == item.Group); | 
|  | 85 | 
|  | 86 						if (group == null) | 
|  | 87 							groups.Add(group = new FileItem { Name = item.Group, SortOrder = item.SortOrder }); | 
|  | 88 | 
|  | 89 						group.Add(item); | 
|  | 90 						Items.RemoveAt(i); | 
|  | 91 | 
|  | 92 						i--; | 
|  | 93 					} | 
|  | 94 				} | 
|  | 95 | 
|  | 96 				Items.AddRange(groups); | 
|  | 97 | 
|  | 98 				foreach (var item in Items) | 
|  | 99 					item.Prepare(); | 
|  | 100 | 
|  | 101 				Items.Sort((x, y) => | 
|  | 102 				{ | 
|  | 103 					var xname = x.Title.ToLower(); | 
|  | 104 					var yname = y.Title.ToLower(); | 
|  | 105 | 
|  | 106 					if (xname == yname)                         return  0; | 
|  | 107 					if (x.Name.ToLower().EndsWith("index.htm")) return -1; | 
|  | 108 					if (y.Name.ToLower().EndsWith("index.htm")) return  1; | 
|  | 109 | 
|  | 110 					if (x.SortOrder != 0 && y.SortOrder != 0) | 
|  | 111 						return x.SortOrder - y.SortOrder; | 
|  | 112 | 
|  | 113 					if (x.SortOrder != 0) return -1; | 
|  | 114 					if (y.SortOrder != 0) return  1; | 
|  | 115 | 
|  | 116 					return string.Compare(xname, yname); | 
|  | 117 				}); | 
|  | 118 			} | 
|  | 119 		} | 
|  | 120 	} | 
|  | 121 } |