⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cs

📁 c#源代码
💻 CS
字号:
using System;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using System.IO;
using System.Xml;

class MainClass
{
	public static int Main(string[] args)
	{
		try {
			InstallHelp();
			return 0;
		} catch (Exception ex) {
			Console.WriteLine(ex);
			return 1;
		}
	}
	
	static DateTime Max(DateTime a, DateTime b)
	{
		return a > b ? a : b;
	}
	
	static DateTime GetHelpTime()
	{
		DateTime a = File.GetLastWriteTime("register.xml");
		XmlDocument doc = new XmlDocument();
		doc.Load("register.xml");
		return Max(a, GetHelpTime(doc.DocumentElement));
	}
	
	static DateTime GetHelpTime(XmlElement e)
	{
		DateTime a = DateTime.MinValue;
		if (e.HasAttribute("file")) {
			a = File.GetLastWriteTime(e.GetAttribute("file"));
		}
		if (e.HasAttribute("HxS")) {
			a = Max(a, File.GetLastWriteTime(e.GetAttribute("HxS")));
		}
		if (e.HasAttribute("HxI")) {
			a = Max(a, File.GetLastWriteTime(e.GetAttribute("HxI")));
		}
		foreach (XmlNode n in e) {
			if (n is XmlElement) {
				a = Max(a, GetHelpTime((XmlElement)n));
			}
		}
		return a;
	}
	
	static void InstallHelp()
	{
		DateTime helptime = GetHelpTime();
		if (File.Exists("helptime.txt")) {
			DateTime oldhelptime;
			using (StreamReader r = new StreamReader("helptime.txt")) {
				oldhelptime = DateTime.Parse(r.ReadLine(), CultureInfo.InvariantCulture);
			}
			// times aren't equal because saving/loading strips the millisecond part
			if (oldhelptime.Subtract(helptime).TotalSeconds < 1) {
				Console.WriteLine("Current help is already registered, skipping register.exe");
				Console.WriteLine("Use a clean build to force re-registering the help!");
				return;
			}
		}
		Console.WriteLine("Registering help...");
		UpdateHelp(helptime);
	}
	
	static void UpdateHelp(DateTime helptime)
	{
		Process p = Process.Start("Help2Register.exe", "/r register.xml");
		p.WaitForExit();
		if (p.ExitCode == -1 || p.ExitCode == 0) {
			try {
				using (StreamWriter w = new StreamWriter("helptime.txt")) {
					w.WriteLine(helptime.ToString(CultureInfo.InvariantCulture));
				}
			} catch (IOException ex) {
				Console.WriteLine(ex);
				// ignore error
			}
		} /* else {
			Console.WriteLine();
			Console.WriteLine("==========================");
			if (p.ExitCode == 2) {
				Console.WriteLine("MSXML 4.0 is not installed. It is required to register the documentation.");
			}
			if (p.ExitCode == 3) {
				Console.WriteLine("MSHelp 2.0 is not installed. You should install the .NET Framework SDK!");
			}
			if (p.ExitCode == 4) {
				Console.WriteLine("You need administrator rights or power user rights to register the help!");
			}
			Console.WriteLine();
			Console.WriteLine("Build continues, but help is not available");
			Console.WriteLine("==========================");
			Console.WriteLine();
			//throw new ApplicationException("register.exe exit code was " + p.ExitCode);
		} */
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -