遇到doxygen生成的chm文档目录如果有中文是乱码?
原因不在于doxygen,它没有问题,问题出在微软的HTML Help Workshop的hhc.exe不支持utf8.所以要解决这个问题,需要做两个额外的步骤:
1.将html/index.hhp中的Language=0x409 English (United States)换成Language=0x804 中文 (中国),并将文本存成UTF8格式。
2.将html/index.hhc整个文件从UTF8编码换成gb2312,再次手动调用hhc.exe去处理这个hhp文件即可生成不是乱码的中文chm帮助文档。
我自己用C#写了个小工具来处理这个过程,源代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics; namespace Generator
{
class Program
{ static void Main(string[] args)
{
if(args.Length <=)
{
Console.WriteLine("Error:缺少目标配置文件");
return;
} string path = args[]; if(!File.Exists(path))
{
Console.WriteLine(string.Format("{0}不存在", path));
return;
} using(ChmGenerator generator = new ChmGenerator(path))
{
generator.Generate();
}
}
} public class ChmGenerator : IDisposable
{
static readonly string HHC_CONFIG_LOCATION = "HHC_LOCATION = \"C:/Program Files (x86)/HTML Help Workshop/hhc.exe\""; string WorkDirectory;
string InputFile;
string ConfigText;
string NewHHCConfig;
string NewConfigText;
string NewConfigPath; string HHCLocation;
string DoxygenPath; string IntermediatePath;
string IntermediateHHP;
string IntermediateHHC; public ChmGenerator(string inputFile)
{
InputFile = inputFile; string Directory = Path.GetDirectoryName(InputFile);
WorkDirectory = Directory; System.IO.Directory.SetCurrentDirectory(WorkDirectory); HHCLocation = Path.Combine(Directory, "hhc.exe");
DoxygenPath = Path.Combine(Directory, "doxygen.exe");
IntermediatePath = Path.Combine(Directory, "Intermediate");
IntermediateHHP = Path.Combine(IntermediatePath, @"html/index.hhp");
IntermediateHHC = Path.Combine(IntermediatePath, @"html/index.hhc");
NewHHCConfig = string.Format("HHC_LOCATION = \"{0}\"", HHCLocation);
} public void Dispose()
{
try
{
if (!string.IsNullOrEmpty(NewConfigPath) && File.Exists(NewConfigPath))
{
File.Delete(NewConfigPath);
}
}
finally
{ }
} public void Generate()
{
ConfigText = File.ReadAllText(InputFile, Encoding.UTF8); NewConfigPath = Path.Combine(WorkDirectory, Guid.NewGuid().ToString() + ".doxygenProj");
NewConfigText = ConfigText.Replace(HHC_CONFIG_LOCATION, NewHHCConfig); File.WriteAllText(NewConfigPath, NewConfigText, Encoding.UTF8); // 调用doxygen来生成
StartProc(DoxygenPath, string.Format(" {0}", NewConfigPath)); if(!PrepareInputFiles())
{
Console.WriteLine("无法正确生成chm");
return;
} // 调用hhc生成chm
StartProc(HHCLocation, string.Format(" {0}", IntermediateHHP)); } private bool PrepareInputFiles()
{
// 替换Language
if (File.Exists(IntermediateHHP))
{
ReplaceFileText(IntermediateHHP, "Language=0x409 English (United States)", "Language=0x804 中文 (中国)", Encoding.UTF8); if (File.Exists(IntermediateHHC))
{
ChangeFileToAnsi(IntermediateHHC, Encoding.UTF8, Encoding.GetEncoding("gb2312")); return true;
}
else
{
Console.WriteLine(string.Format("Error:{0}不存在", IntermediateHHC));
}
}
else
{
Console.WriteLine(string.Format("Error:{0}不存在", IntermediateHHP));
} return false;
} private void ChangeFileToAnsi(string inputPath, Encoding sourceEncoding, Encoding destEncoding)
{
var text = File.ReadAllText(inputPath, sourceEncoding);
byte[] bytes = sourceEncoding.GetBytes(text); // convert to win bytes
var destBytes = Encoding.Convert(
sourceEncoding, destEncoding, bytes); File.WriteAllBytes(inputPath, destBytes);
} private void ReplaceFileText(string inputPath, string sourceText, string destText, Encoding encoding)
{
var text = File.ReadAllText(inputPath, Encoding.UTF8);
text = text.Replace(sourceText, destText);
File.WriteAllText(inputPath, text, encoding);
} static void StartProc(string application, string command)
{
Debug.Assert(File.Exists(application)); var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = application,
Arguments = " " + command,
RedirectStandardOutput = true,
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
StandardOutputEncoding = Encoding.UTF8
}
}; process.Start(); while (!process.StandardOutput.EndOfStream)
{
string line = process.StandardOutput.ReadLine(); Console.WriteLine(line);
// Debug.WriteLine(line);
} process.WaitForExit();
}
}
}
另外为了确保目标机器没有安装doxygen或者hhc都不影响我生成文档,因此我将这些执行档都复制了一份放到了doxygen项目下,代码中的一些额外步骤就是强行将原始project文件中的hhc路径改成当前目录下的hhc。
目录结构如下:

遇到doxygen生成的chm文档目录如果有中文是乱码?的更多相关文章
- 使用Doxygen生成net帮助文档
一. 什么是Doxygen? Doxygen 是一个程序的文件产生工具,可将程序中的特定批注转换成为说明文件.通常我们在写程序时,或多或少都会写上批注,但是对于其它人而言,要直接探索程序里的批注,与打 ...
- 使用Doxygen生成C#帮助文档
一. 什么是Doxygen? Doxygen 是一个程序的文件产生工具,可将程序中的特定批注转换成为说明文件.通常我们在写程序时,或多或少都会写上批注,但是对于其它人而言,要直接探索程序里的批注,与打 ...
- Doxygen生成美丽注释文档(1):初体验
Chapter 1 - 准备工作 (Windows环境) 1.1 程序包下载 1. Doxygen * 源码: git clone https://github.com/doxygen/doxygen ...
- YUIDoc example代码高亮错误、生成API文档目录不按源文件注释顺序
1.如果发现yuidoc命令用不了,那就重装nodejs吧 昨天不知道是清扫电脑的原因,yuidoc命令用不了(命令不存在),也没有找到好的解决方法,怒重装YUIDoc也不行.最后想了想,怒重装了no ...
- 制作Aspose CHM文档的过程记录
欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...
- 用doxygen风格注释代码生成文档
目录 用doxygen风格注释代码生成文档 1. 说明 2. 具体操作 2.1 生成头部注释 2.2 安装doxygen 2.3 工程配置 3. 总结 用doxygen风格注释代码生成文档 1. 说明 ...
- 安装doxygen(一个自动文档生成工具)+Graphviz图形可视化软件
参考文章: http://www.fmddlmyy.cn/text21.html http://www.cnblogs.com/duguguiyu/archive/2008/06/29/1231852 ...
- 生成chm文档工具- Sandcastle -摘自网络
Sandcastle是微软官方的文档生成工具,NDoc开发停止后,这个貌似也是唯一的一个这方面的工具.它从dll文件及其xml注释文件能够 生成完整的帮助文档,支持多种生成格式(Helpe1x:chm ...
- IDEA生成doc文档-生成chm文档
首先,打开IDEA,并找到Tools -> Generate JavaDoc- 可供查询的chm比那些HTML页面好看多了. 如果您用过JDK API的chm文档,那么您一定不会拒绝接受其它第三 ...
随机推荐
- 面试被问:如果系统 CPU 突然飙升且 GC 频繁,你该如何排查?
出自:开源中国 原文:系统运行缓慢,CPU 100%,以及Full GC次数过多问题的排查思路 处理过线上问题的同学基本上都会遇到系统突然运行缓慢,CPU 100%,以及Full GC次数过多的问题. ...
- 18、Memento 备忘录模式
例如:用于记录快照(顺势状态).存盘 1.Memento Memento设计模式是一种软件设计模式,用于将对象回滚到其先前状态.它是行为设计模式的一部分,与算法和对象之间的职责分配有关. 行为模式描述 ...
- Prometheus监控神器-Rules篇
本章主要对如何使用Prometheus与Alertmanager组件集成配置,以及对警报规则 Rules 的俩种类型及其模板内容进行讲解. 与Alertmanager集成 Prometheus把产生的 ...
- db2 创建function报错
create function fun_fw_sfyczy(pi_operunitid varchar(2)) returns varchar(2)LANGUAGE SQL BEGIN ATOMIC ...
- C#设计模式之13-职责链模式
职责链模式(Chain of Responsibility Pattern) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archive ...
- C#LeetCode刷题之#69-x 的平方根(Sqrt(x))
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3848 访问. 实现 int sqrt(int x) 函数. 计算 ...
- volatile的特性代码验证
一 . 可见性(visibility) volatile关键字修饰的变量,如果值发生了改变,其他线程会立刻获取到,从而避免了出现脏读的情况. public class TestVolatile { p ...
- storcli 命令(更新Ing)
help [root@centos7]# storcli -h Storage Command Line Tool Ver 007.0606.0000.0000 Mar , (c)Copyright ...
- day1 linux常用命令(一)
- Java引用类型之软引用(2)
下面接着上一篇介绍第2阶段和第3阶段的处理逻辑. 2.process_phase2() 第2个阶段移除所有的referent还存活的Reference,也就是从refs_list中移除Referenc ...