Skip to content

Commit 91ad649

Browse files
committed
Add existing code for HelpConvert project.
1 parent de7e0ef commit 91ad649

File tree

6 files changed

+254
-3
lines changed

6 files changed

+254
-3
lines changed

DosHelp.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickHelp", "QuickHelp\Quic
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelpBrowser", "HelpBrowser\HelpBrowser.csproj", "{00E978CD-7420-40EA-91A2-18E0F3CFF5C1}"
99
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelpConvert", "HelpConvert\HelpConvert.csproj", "{469806C9-9B3B-4AA2-94D9-35A2143FC585}"
11+
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1214
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
2123
{00E978CD-7420-40EA-91A2-18E0F3CFF5C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
2224
{00E978CD-7420-40EA-91A2-18E0F3CFF5C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
2325
{00E978CD-7420-40EA-91A2-18E0F3CFF5C1}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{469806C9-9B3B-4AA2-94D9-35A2143FC585}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{469806C9-9B3B-4AA2-94D9-35A2143FC585}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{469806C9-9B3B-4AA2-94D9-35A2143FC585}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{469806C9-9B3B-4AA2-94D9-35A2143FC585}.Release|Any CPU.Build.0 = Release|Any CPU
2430
EndGlobalSection
2531
GlobalSection(SolutionProperties) = preSolution
2632
HideSolutionNode = FALSE

HelpConvert/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
5+
<supportedRuntime version="v2.0.50727"/></startup>
6+
</configuration>

HelpConvert/HelpConvert.csproj

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{469806C9-9B3B-4AA2-94D9-35A2143FC585}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>HelpConvert</RootNamespace>
11+
<AssemblyName>HelpConvert</AssemblyName>
12+
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="System" />
37+
</ItemGroup>
38+
<ItemGroup>
39+
<Compile Include="Program.cs" />
40+
<Compile Include="Properties\AssemblyInfo.cs" />
41+
</ItemGroup>
42+
<ItemGroup>
43+
<None Include="App.config" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<ProjectReference Include="..\QuickHelp\QuickHelp.csproj">
47+
<Project>{c18c4ed1-e4b6-4dc3-b7cf-55053fec165b}</Project>
48+
<Name>QuickHelp</Name>
49+
</ProjectReference>
50+
</ItemGroup>
51+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
52+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
53+
Other similar extension points exist, see Microsoft.Common.targets.
54+
<Target Name="BeforeBuild">
55+
</Target>
56+
<Target Name="AfterBuild">
57+
</Target>
58+
-->
59+
</Project>

HelpConvert/Program.cs

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
using System;
2+
using System.IO;
3+
using System.Text;
4+
using QuickHelp;
5+
using QuickHelp.Converters;
6+
using QuickHelp.Serialization;
7+
8+
namespace HelpConvert
9+
{
10+
class Program
11+
{
12+
static void Main(string[] args)
13+
{
14+
Convert(args, false);
15+
16+
#if DEBUG
17+
Console.WriteLine("Press any key to continue...");
18+
Console.ReadKey();
19+
#endif
20+
}
21+
22+
static void PrintUsage()
23+
{
24+
Console.WriteLine("HelpConvert input-file [input-file ...]");
25+
}
26+
27+
static void Convert(string[] fileNames, bool isDryRun)
28+
{
29+
HelpSystem system = new HelpSystem();
30+
BatchHtmlConverter converter = new BatchHtmlConverter(system);
31+
32+
foreach (string fileName in fileNames)
33+
{
34+
var decoder = new DatabaseDecoder();
35+
foreach (HelpDatabase database in decoder.LoadDatabases(fileName))
36+
system.Databases.Add(database);
37+
}
38+
39+
// export HTML
40+
foreach (HelpDatabase database in system.Databases)
41+
{
42+
// TODO: check invalid chars in database name
43+
string htmlPath = database.Name.Replace('.', '_');
44+
Directory.CreateDirectory(htmlPath);
45+
46+
int topicIndex = 0;
47+
foreach (HelpTopic topic in database.Topics)
48+
{
49+
string html = converter.ConvertTopic(topic);
50+
string htmlFileName = Path.Combine(htmlPath, string.Format("T{0:X4}.html", topicIndex));
51+
if (!isDryRun)
52+
{
53+
using (StreamWriter writer = new StreamWriter(htmlFileName, false, Encoding.UTF8))
54+
{
55+
writer.Write(html);
56+
}
57+
}
58+
topicIndex++;
59+
}
60+
61+
// Create contents.html.
62+
HelpTopic topic1 = system.ResolveUri(database, new HelpUri("h.contents"));
63+
if (topic1 != null && topic1.Database == database)
64+
{
65+
if (!isDryRun)
66+
{
67+
using (StreamWriter writer = new StreamWriter(Path.Combine(htmlPath, "Contents.html")))
68+
{
69+
writer.WriteLine("<meta http-equiv=\"refresh\" content=\"0; url=T{0:X4}.html\">",
70+
topic1.TopicIndex);
71+
}
72+
}
73+
}
74+
}
75+
}
76+
77+
static string GetDatabasePath(HelpDatabase database)
78+
{
79+
string path = database.Name.Replace('.', '_');
80+
Directory.CreateDirectory(path);
81+
return path;
82+
}
83+
}
84+
85+
class BatchHtmlConverter : HtmlConverter
86+
{
87+
readonly HelpSystem system;
88+
89+
public BatchHtmlConverter(HelpSystem system)
90+
{
91+
base.AutoFixHyperlinks = true;
92+
this.system = system;
93+
}
94+
95+
protected override string ConvertUri(HelpTopic source, HelpUri uri)
96+
{
97+
switch (uri.Type)
98+
{
99+
case HelpUriType.Context:
100+
case HelpUriType.GlobalContext:
101+
case HelpUriType.LocalContext:
102+
{
103+
HelpTopic target = system.ResolveUri(source.Database, uri);
104+
if (target != null)
105+
{
106+
if (target.Database == source.Database)
107+
{
108+
return string.Format("T{0:X4}.html", target.TopicIndex);
109+
}
110+
else
111+
{
112+
return string.Format("../{0}/T{1:X4}.html",
113+
GetDatabasePath(target.Database),
114+
target.TopicIndex);
115+
}
116+
}
117+
else
118+
{
119+
Console.WriteLine("Warning: cannot resolve context string '{0}'", uri);
120+
}
121+
}
122+
break;
123+
124+
case HelpUriType.TopicIndex:
125+
return string.Format("T{0:X4}.html", uri.TopicIndex);
126+
127+
case HelpUriType.Command:
128+
case HelpUriType.File:
129+
default:
130+
// TODO: would be better if we have the source location.
131+
Console.WriteLine("Warning: cannot convert link: {0}", uri);
132+
break;
133+
}
134+
return "?" + uri.ToString();
135+
}
136+
137+
static string GetDatabasePath(HelpDatabase database)
138+
{
139+
string path = database.Name.Replace('.', '_');
140+
Directory.CreateDirectory(path);
141+
return path;
142+
}
143+
}
144+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("HelpConvert")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("HelpConvert")]
13+
[assembly: AssemblyCopyright("Copyright © 2014")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("a2d32d66-6dd2-4bbf-a238-e9e719544a6b")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

QuickHelp/Converters/HtmlConverter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private void FormatLine(StringBuilder html, HelpTopic topic, HelpLine line)
9797
if (newAttrs.Link != null)
9898
{
9999
html.AppendFormat("<a href=\"{0}\">",
100-
ConvertLink(topic, newAttrs.Link));
100+
ConvertUri(topic, newAttrs.Link));
101101
}
102102
}
103103
html.Append(Escape("" + line.Text[i]));
@@ -113,9 +113,9 @@ private void FormatLine(StringBuilder html, HelpTopic topic, HelpLine line)
113113
html.AppendLine();
114114
}
115115

116-
protected virtual string ConvertLink(HelpTopic topic, HelpUri link)
116+
protected virtual string ConvertUri(HelpTopic topic, HelpUri uri)
117117
{
118-
return "?" + Escape(link.ToString());
118+
return "?" + Escape(uri.ToString());
119119
}
120120

121121
private static void FormatAddedStyles(

0 commit comments

Comments
 (0)