-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add existing code for HelpConvert project.
- Loading branch information
Showing
6 changed files
with
254 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
|
||
<supportedRuntime version="v2.0.50727"/></startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{469806C9-9B3B-4AA2-94D9-35A2143FC585}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>HelpConvert</RootNamespace> | ||
<AssemblyName>HelpConvert</AssemblyName> | ||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<TargetFrameworkProfile /> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\QuickHelp\QuickHelp.csproj"> | ||
<Project>{c18c4ed1-e4b6-4dc3-b7cf-55053fec165b}</Project> | ||
<Name>QuickHelp</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using QuickHelp; | ||
using QuickHelp.Converters; | ||
using QuickHelp.Serialization; | ||
|
||
namespace HelpConvert | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Convert(args, false); | ||
|
||
#if DEBUG | ||
Console.WriteLine("Press any key to continue..."); | ||
Console.ReadKey(); | ||
#endif | ||
} | ||
|
||
static void PrintUsage() | ||
{ | ||
Console.WriteLine("HelpConvert input-file [input-file ...]"); | ||
} | ||
|
||
static void Convert(string[] fileNames, bool isDryRun) | ||
{ | ||
HelpSystem system = new HelpSystem(); | ||
BatchHtmlConverter converter = new BatchHtmlConverter(system); | ||
|
||
foreach (string fileName in fileNames) | ||
{ | ||
var decoder = new DatabaseDecoder(); | ||
foreach (HelpDatabase database in decoder.LoadDatabases(fileName)) | ||
system.Databases.Add(database); | ||
} | ||
|
||
// export HTML | ||
foreach (HelpDatabase database in system.Databases) | ||
{ | ||
// TODO: check invalid chars in database name | ||
string htmlPath = database.Name.Replace('.', '_'); | ||
Directory.CreateDirectory(htmlPath); | ||
|
||
int topicIndex = 0; | ||
foreach (HelpTopic topic in database.Topics) | ||
{ | ||
string html = converter.ConvertTopic(topic); | ||
string htmlFileName = Path.Combine(htmlPath, string.Format("T{0:X4}.html", topicIndex)); | ||
if (!isDryRun) | ||
{ | ||
using (StreamWriter writer = new StreamWriter(htmlFileName, false, Encoding.UTF8)) | ||
{ | ||
writer.Write(html); | ||
} | ||
} | ||
topicIndex++; | ||
} | ||
|
||
// Create contents.html. | ||
HelpTopic topic1 = system.ResolveUri(database, new HelpUri("h.contents")); | ||
if (topic1 != null && topic1.Database == database) | ||
{ | ||
if (!isDryRun) | ||
{ | ||
using (StreamWriter writer = new StreamWriter(Path.Combine(htmlPath, "Contents.html"))) | ||
{ | ||
writer.WriteLine("<meta http-equiv=\"refresh\" content=\"0; url=T{0:X4}.html\">", | ||
topic1.TopicIndex); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
static string GetDatabasePath(HelpDatabase database) | ||
{ | ||
string path = database.Name.Replace('.', '_'); | ||
Directory.CreateDirectory(path); | ||
return path; | ||
} | ||
} | ||
|
||
class BatchHtmlConverter : HtmlConverter | ||
{ | ||
readonly HelpSystem system; | ||
|
||
public BatchHtmlConverter(HelpSystem system) | ||
{ | ||
base.AutoFixHyperlinks = true; | ||
this.system = system; | ||
} | ||
|
||
protected override string ConvertUri(HelpTopic source, HelpUri uri) | ||
{ | ||
switch (uri.Type) | ||
{ | ||
case HelpUriType.Context: | ||
case HelpUriType.GlobalContext: | ||
case HelpUriType.LocalContext: | ||
{ | ||
HelpTopic target = system.ResolveUri(source.Database, uri); | ||
if (target != null) | ||
{ | ||
if (target.Database == source.Database) | ||
{ | ||
return string.Format("T{0:X4}.html", target.TopicIndex); | ||
} | ||
else | ||
{ | ||
return string.Format("../{0}/T{1:X4}.html", | ||
GetDatabasePath(target.Database), | ||
target.TopicIndex); | ||
} | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Warning: cannot resolve context string '{0}'", uri); | ||
} | ||
} | ||
break; | ||
|
||
case HelpUriType.TopicIndex: | ||
return string.Format("T{0:X4}.html", uri.TopicIndex); | ||
|
||
case HelpUriType.Command: | ||
case HelpUriType.File: | ||
default: | ||
// TODO: would be better if we have the source location. | ||
Console.WriteLine("Warning: cannot convert link: {0}", uri); | ||
break; | ||
} | ||
return "?" + uri.ToString(); | ||
} | ||
|
||
static string GetDatabasePath(HelpDatabase database) | ||
{ | ||
string path = database.Name.Replace('.', '_'); | ||
Directory.CreateDirectory(path); | ||
return path; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("HelpConvert")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("HelpConvert")] | ||
[assembly: AssemblyCopyright("Copyright © 2014")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("a2d32d66-6dd2-4bbf-a238-e9e719544a6b")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters