Added source code.

This commit is contained in:
2018-02-06 01:24:46 +02:00
parent 1d9f2990c8
commit 8b28da5b80
367 changed files with 22964 additions and 0 deletions

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Help.HelpSystem
{
public class HelpChapter
{
private List<HelpTopic> topics = new List<HelpTopic>();
public List<HelpTopic> Topics { get { return topics; } }
public string Application { get; set; }
public string Title { get; set; }
public string Filename { get; set; }
public HelpChapter(string app = "", string title = "", string filename = "")
{
Application = app; Title = title; Filename = filename;
}
}
}

View File

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Help.HelpSystem
{
public static class HelpHtmlWrapper
{
public static void Find(object Document, string text)
{
var doc = Document as mshtml.IHTMLDocument2;
if (doc == null || doc.body == null || text == "") return;
string html = doc.body.innerHTML;
string temp = "";
int index = html.IndexOf(text, StringComparison.CurrentCultureIgnoreCase);
while (index != -1)
{
int min = html.IndexOf('<', index);
int max = html.IndexOf('>', index);
if (min <= max)
{
temp = "<span style=\"background: magenta;\">" + html.Substring(index, text.Length) + "</span>";
html = html.Substring(0, index) + temp + html.Substring(index + text.Length);
index += temp.Length - text.Length;
}
index = html.IndexOf(text, index + 1, StringComparison.CurrentCultureIgnoreCase);
}
doc.body.innerHTML = html;
}
public static string GetHtml(object document)
{
var doc = document as mshtml.IHTMLDocument2;
if (doc == null || doc.body == null) return "";
return doc.body.innerHTML;
}
public static void SetHtml(object document, string html)
{
var doc = document as mshtml.IHTMLDocument2;
if (doc == null || doc.body == null) return;
doc.body.innerHTML = html;
}
}
}

View File

@ -0,0 +1,134 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace Help.HelpSystem
{
static class HelpManager
{
public static List<HelpChapter> Chapters = new List<HelpChapter>();
public static string DocumentationPath = "";
public static string GetFullPath(string relative)
{
return System.IO.Path.Combine(DocumentationPath, relative);
}
public static void Load(string indexfile)
{
XmlTextReader reader = new XmlTextReader(indexfile);
HelpChapter currentChapter = new HelpChapter();
HelpTopic currentTopic = new HelpTopic();
bool isTopic = false;
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
if (reader.Name == "chapter")
{
isTopic = false;
currentChapter = new HelpChapter();
}
else if (reader.Name == "topic")
{
isTopic = true;
currentTopic = new HelpTopic();
}
while (reader.MoveToNextAttribute())
{
switch (reader.Name)
{
case "application": if (!isTopic) currentChapter.Application = reader.Value; break;
case "title":
if (isTopic) currentTopic.Title = reader.Value;
else currentChapter.Title = reader.Value;
break;
case "filename":
if (isTopic) currentTopic.Filename = reader.Value;
else currentChapter.Filename = reader.Value;
break;
}
}
if (isTopic) currentChapter.Topics.Add(currentTopic);
break;
case XmlNodeType.EndElement:
if (reader.Name == "topic") currentChapter.Topics.Add(currentTopic);
else if (reader.Name == "chapter") Chapters.Add(currentChapter);
break;
}
}
reader.Close();
DocumentationPath = System.IO.Path.GetDirectoryName(indexfile);
}
private static string[] FindInFile(string file, string q)
{
int min, max;
string text = System.IO.File.ReadAllText(file);
List<string> ret = new List<string>();
// Remove html tags
min = text.IndexOf('<');
max = text.IndexOf('>');
while (min != -1 && max != -1 && min < max)
{
text = text.Remove(min, max - min + 1);
min = text.IndexOf('<');
max = text.IndexOf('>');
}
// Search each line
foreach (var line in text.Split('\n', '\r'))
if (line.ToLower().Contains(q.ToLower())) ret.Add(line.TrimStart(' ', '\t', '\n', '\r'));
return ret.ToArray();
}
public static HelpTopic[] SearchText(string text, HelpChapter chapter)
{
var list = new List<HelpTopic>();
// Make a list of files to be checked
var temp = new List<HelpTopic>();
temp.Add(new HelpTopic(chapter.Title, chapter.Filename));
temp.AddRange(chapter.Topics);
// Search
foreach (var top in temp)
{
string[] f = FindInFile(GetFullPath(top.Filename), text);
foreach (var i in f)
list.Add(new HelpTopic()
{
Title = top.Title,
Filename = top.Filename,
Context = i,
IsSearchResult = true
});
}
return list.ToArray();
}
public static HelpTopic[] SearchTitle(string text, HelpChapter chapter)
{
return chapter.Topics.Where(x => x.Title.ToLower().Contains(text.ToLower())).ToArray();
}
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Help.HelpSystem
{
public class HelpTopic
{
public string Title { get; set; }
public string Filename { get; set; }
public string Context { get; set; }
public bool IsSearchResult { get; set; }
public HelpTopic(string title = "", string filename = "", string context = "")
{
Title = title; Filename = filename;
Context = context;
IsSearchResult = (context != "");
}
}
}