using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Text; using System.Windows.Forms; using Microsoft.Win32; namespace FontPreview; internal class SystemFontExportDialog : Form { private CheckedListBox lst; private TextBox txtDir; private Label lblSum; private List> fonts = new List>(); public SystemFontExportDialog() { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown ((Control)this).Text = "导出系统字体"; ((Control)this).Width = 680; ((Control)this).Height = 560; ((Form)this).StartPosition = (FormStartPosition)4; ((Control)this).Font = new Font("Microsoft YaHei UI", 9f); Build(); LoadFonts(); } private void Build() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Expected O, but got Unknown //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Expected O, but got Unknown //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Expected O, but got Unknown //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Expected O, but got Unknown //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Expected O, but got Unknown //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Expected O, but got Unknown //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_022c: Expected O, but got Unknown //IL_0280: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Expected O, but got Unknown //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02ee: Expected O, but got Unknown Label val = new Label(); ((Control)val).Text = "勾选需要导出的系统字体(从注册表读取,含字体文件路径),导出的副本不会影响系统原字体。"; ((Control)val).SetBounds(12, 10, 650, 34); ((Control)val).ForeColor = Color.DimGray; ((Control)this).Controls.Add((Control)(object)val); lst = new CheckedListBox(); ((Control)lst).SetBounds(12, 48, 650, 320); lst.CheckOnClick = true; lst.ItemCheck += (ItemCheckEventHandler)delegate { UpdateSum(); }; ((Control)this).Controls.Add((Control)(object)lst); Button val2 = new Button(); ((Control)val2).Text = "全选"; ((Control)val2).SetBounds(12, 376, 76, 28); ((Control)val2).Click += delegate { for (int j = 0; j < lst.Items.Count; j++) { lst.SetItemChecked(j, true); } UpdateSum(); }; Button val3 = new Button(); ((Control)val3).Text = "全不选"; ((Control)val3).SetBounds(94, 376, 84, 28); ((Control)val3).Click += delegate { for (int i = 0; i < lst.Items.Count; i++) { lst.SetItemChecked(i, false); } UpdateSum(); }; Button val4 = new Button(); ((Control)val4).Text = "刷新"; ((Control)val4).SetBounds(184, 376, 76, 28); ((Control)val4).Click += delegate { LoadFonts(); }; ((Control)this).Controls.Add((Control)(object)val2); ((Control)this).Controls.Add((Control)(object)val3); ((Control)this).Controls.Add((Control)(object)val4); Label val5 = new Label(); ((Control)val5).Text = "导出到:"; ((Control)val5).SetBounds(12, 414, 56, 26); txtDir = new TextBox(); ((Control)txtDir).SetBounds(66, 411, 476, 26); Button val6 = new Button(); ((Control)val6).Text = "浏览…"; ((Control)val6).SetBounds(548, 410, 100, 28); ((Control)val6).Click += delegate { string text = NativeFolderDialog.PickFolder(((Control)this).Handle, "选择导出的目标目录", ((Control)txtDir).Text.Trim()); if (text != null) { ((Control)txtDir).Text = text; NormalizeDir(); } }; ((Control)this).Controls.Add((Control)(object)val5); ((Control)this).Controls.Add((Control)(object)txtDir); ((Control)this).Controls.Add((Control)(object)val6); lblSum = new Label(); ((Control)lblSum).Text = "已选 0 / 0 个字体"; ((Control)lblSum).SetBounds(12, 448, 400, 20); ((Control)lblSum).ForeColor = Color.FromArgb(43, 58, 85); ((Control)this).Controls.Add((Control)(object)lblSum); Button val7 = new Button(); ((Control)val7).Text = "开始导出"; ((Control)val7).BackColor = Color.FromArgb(43, 58, 85); ((Control)val7).ForeColor = Color.White; ((ButtonBase)val7).FlatStyle = (FlatStyle)0; ((Control)val7).SetBounds(12, 478, 130, 36); ((Control)val7).Click += delegate { DoExport(); }; Button val8 = new Button(); ((Control)val8).Text = "关闭"; val8.DialogResult = (DialogResult)2; ((Control)val8).SetBounds(560, 478, 90, 36); ((Control)this).Controls.Add((Control)(object)val7); ((Control)this).Controls.Add((Control)(object)val8); ((Form)this).AcceptButton = (IButtonControl)(object)val8; } internal static string NormalizeDir(string s) { if (string.IsNullOrEmpty(s)) { return s; } if (s.Length == 2 && s[1] == ':') { s += "\\"; } return s; } private void LoadFonts() { //IL_0146: Unknown result type (might be due to invalid IL or missing references) fonts.Clear(); try { string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Fonts); using RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"); if (registryKey != null) { string[] valueNames = registryKey.GetValueNames(); Array.Sort(valueNames, (IComparer?)StringComparer.OrdinalIgnoreCase); string[] array = valueNames; foreach (string text in array) { string text2 = registryKey.GetValue(text) as string; if (string.IsNullOrEmpty(text2)) { continue; } string extension = Path.GetExtension(text2); if (extension.Equals(".ttf", StringComparison.OrdinalIgnoreCase) || extension.Equals(".otf", StringComparison.OrdinalIgnoreCase) || extension.Equals(".ttc", StringComparison.OrdinalIgnoreCase)) { string text3 = (Path.IsPathRooted(text2) ? text2 : Path.Combine(folderPath, text2)); if (File.Exists(text3)) { fonts.Add(new KeyValuePair(text, text3)); } } } } } catch (Exception ex) { MessageBox.Show((IWin32Window)(object)this, "读取系统字体失败:" + ex.Message, "提示", (MessageBoxButtons)0, (MessageBoxIcon)48); } lst.Items.Clear(); foreach (KeyValuePair font in fonts) { lst.Items.Add((object)(font.Key + " —— " + Path.GetFileName(font.Value)), false); } UpdateSum(); } private void UpdateSum() { int num = 0; for (int i = 0; i < lst.Items.Count; i++) { if (lst.GetItemChecked(i)) { num++; } } ((Control)lblSum).Text = "已选 " + num + " / " + fonts.Count + " 个字体"; } private void NormalizeDir() { string text = ((Control)txtDir).Text.Trim().Trim(new char[1] { '"' }); if (text.Length == 2 && text[1] == ':') { text += "\\"; } ((Control)txtDir).Text = text; } private void DoExport() { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_031f: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) string text = ((Control)txtDir).Text.Trim().Trim(new char[1] { '"' }); if (text.Length == 0) { MessageBox.Show((IWin32Window)(object)this, "请先选择导出目录", "提示"); return; } string text2 = text; if (MainForm.DiagnosePath(text2) != null) { string text3 = MainForm.DriveToUnc(text2); if (text3 == null || !MainForm.TryReconnect(text2) || MainForm.DiagnosePath(text2) != null) { if (text3 == null || MainForm.DiagnosePath(text3) != null) { MessageBox.Show((IWin32Window)(object)this, "目标目录不可访问:" + text, "提示", (MessageBoxButtons)0, (MessageBoxIcon)48); return; } text2 = text3; } } int num = 0; int num2 = 0; int num3 = 0; List list = new List(); List list2 = new List(); for (int i = 0; i < lst.Items.Count; i++) { if (!lst.GetItemChecked(i)) { continue; } num++; string value = fonts[i].Value; try { string text4 = Path.Combine(text2, Path.GetFileName(value)); if (!File.Exists(value)) { list.Add(value); continue; } if (File.Exists(text4)) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(value); string extension = Path.GetExtension(value); int num4 = 1; string text5 = text4; while (File.Exists(text5)) { text5 = Path.Combine(text2, fileNameWithoutExtension + "_" + num4 + extension); num4++; } text4 = text5; } File.Copy(value, text4, overwrite: false); num2++; } catch (Exception) { list2.Add(value); } } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("导出完成:成功 " + num2 + " / " + num + " 个\r\n"); if (num3 > 0) { stringBuilder.Append("跳过 " + num3 + " 个\r\n"); } if (list.Count > 0) { stringBuilder.Append("源文件缺失 " + list.Count + " 个\r\n"); } if (list2.Count > 0) { stringBuilder.Append("失败 " + list2.Count + " 个\r\n"); } stringBuilder.Append("\r\n目标目录: " + text2); MessageBox.Show((IWin32Window)(object)this, stringBuilder.ToString(), "导出结果", (MessageBoxButtons)0, (MessageBoxIcon)64); } }