comparison Tools/DocGen/Program.Chm.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using System.Diagnostics;
3 using System.IO;
4
5 namespace DocGen
6 {
7 partial class Program
8 {
9 static readonly string _template = Path.GetFullPath(@"..\..\content\ChmTemplate.html");
10
11 static FileAction FilterFile(string fileName)
12 {
13 var name = Path.GetFileName(fileName).ToLower();
14
15 switch (name)
16 {
17 case "download.htm" :
18 case "robots.txt" : return FileAction.Skip;
19 default :
20 if (fileName.ToLower().EndsWith("\\content\\index.htm"))
21 return FileAction.Skip;
22
23 return FileAction.Process;
24 }
25 }
26
27 static void CreateTarget(FileItem root)
28 {
29 CreateProjectFile(root);
30 CreateIndexFile ();
31 CreateContentFile(root);
32
33 var hcc = ProgramFilesx86() + @"\HTML Help Workshop\hhc.exe";
34
35 Process.Start(hcc, destPath + "BLToolkit.hhp").WaitForExit();
36 Process.Start(Path.GetFullPath(@"..\..\..\..\Source\Doc\") + "BLToolkit.chm");
37 }
38
39 static string ProgramFilesx86()
40 {
41 if (IntPtr.Size == 8 || !String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432")))
42 return Environment.GetEnvironmentVariable("ProgramFiles(x86)");
43
44 return Environment.GetEnvironmentVariable("ProgramFiles");
45 }
46
47 static void CreateProjectFile(FileItem root)
48 {
49 using (var sw = File.CreateText(destPath + "BLToolkit.hhp"))
50 {
51 sw.WriteLine("[FILES]");
52
53 foreach (var file in root.GetFiles())
54 {
55 var s = file.Path;
56 sw.WriteLine(s);
57 }
58
59 var path = Path.GetFullPath(@"..\..\..\..\Source\Doc\");
60
61 sw.WriteLine(@"
62 [OPTIONS]
63 Title=BLToolkit
64 Auto Index=Yes
65 Compatibility=1.1 or later
66 Compiled file={0}BLToolkit.chm
67 Default Window=MsdnHelp
68 Default topic=Home.htm
69 Display compile progress=No
70 Error log file=BLToolkit.log
71 Full-text search=Yes
72 Index file=BLToolkit.hhk
73 Language=0x409 English (United States)
74 Contents file=BLToolkit.hhc
75
76 [WINDOWS]
77 MsdnHelp=""Business Logic Toolkit for .NET Help"",""BLToolkit.hhc"",""BLToolkit.hhk"",""Home.htm"",""Home.htm"",,,,,0x63520,250,0x387e,[50,25,850,625],0x1020000,,,,,,0
78
79 [INFOTYPES]
80 ",
81 path);
82 }
83 }
84
85 private static void CreateIndexFile()
86 {
87 using (var sw = File.CreateText(destPath + "BLToolkit.hhk"))
88 {
89 sw.WriteLine("<HTML><HEAD></HEAD><BODY><UL>");
90
91 foreach (var index in IndexItem.Index)
92 {
93 sw.WriteLine(
94 @"<LI><OBJECT type=""text/sitemap""><param name=""Name"" value=""{0}"">",
95 index.Name);
96
97 if (index.Files.Count == 0)
98 throw new InvalidDataException(string.Format("Index '{0}' is empty.", index.Name));
99
100 foreach (var file in index.Files)
101 {
102 if (file.Path == "Home.htm")
103 continue;
104
105 sw.WriteLine(@"
106 <param name=""Name"" value=""{0}"">
107 <param name=""Local"" value=""{1}"">",
108 file.Title, file.Path);
109 }
110
111 sw.WriteLine("</OBJECT>");
112 }
113
114 sw.WriteLine("</UL></BODY></HTML>");
115 }
116 }
117
118 private static void CreateContent(FileItem dir, TextWriter sw)
119 {
120 if (dir.Items == null)
121 return;
122
123 var index = dir.Items.Find(i => i.Name.ToLower().EndsWith("index.htm"));
124
125 if (index == null)
126 {
127 sw.WriteLine(
128 @"
129 <LI><OBJECT type=""text/sitemap"">
130 <param name=""Name"" value=""{0}"">
131 </OBJECT>
132 <UL>",
133 dir.Title);
134 }
135 else
136 {
137 sw.WriteLine(
138 @"
139 <LI><OBJECT type=""text/sitemap"">
140 <param name=""Name"" value=""{0}"">
141 <param name=""Local"" value=""{1}"">
142 </OBJECT>
143 <UL>",
144 index.Title, index.Name);
145 }
146
147 foreach (var file in dir.Items)
148 {
149 if (file.Name.ToLower().EndsWith("index.htm"))
150 continue;
151
152 if (file.IsFile)
153 {
154 sw.WriteLine(@"
155 <LI><OBJECT type=""text/sitemap"">
156 <param name=""Name"" value=""{0}"">
157 <param name=""Local"" value=""{1}"">
158 </OBJECT>",
159 file.Title, file.Name);
160
161 }
162 else
163 CreateContent(file, sw);
164 }
165
166 sw.WriteLine("</UL>");
167 }
168
169 private static void CreateContentFile(FileItem root)
170 {
171 using (var sw = File.CreateText(destPath + "BLToolkit.hhc"))
172 {
173 sw.WriteLine(@"
174 <HTML>
175 <HEAD>
176 </HEAD><BODY>
177 <UL>
178 <LI> <OBJECT type=""text/sitemap"">
179 <param name=""Name"" value=""Home"">
180 <param name=""Local"" value=""Home.htm"">
181 </OBJECT>
182 <LI> <OBJECT type=""text/sitemap"">
183 <param name=""Name"" value=""License"">
184 <param name=""Local"" value=""License.htm"">
185 </OBJECT>");
186
187 foreach (var file in root.Items)
188 {
189 if (!file.IsFile && file.Name == "Doc")
190 {
191 file.Title = "Documentation";
192 CreateContent(file, sw);
193 break;
194 }
195 }
196
197 sw.WriteLine(@"
198 </UL>
199 </BODY></HTML>
200 ");
201 }
202 }
203 }
204 }