字体预览工具 v1.0.0 初始版本
This commit is contained in:
@@ -0,0 +1,277 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace FontPreview;
|
||||
|
||||
internal class MoveInstallDialog : Form
|
||||
{
|
||||
private List<FontItem> items;
|
||||
|
||||
public bool Moved;
|
||||
|
||||
private TextBox txtDir;
|
||||
|
||||
private CheckBox chkShortcut;
|
||||
|
||||
private ListBox lst;
|
||||
|
||||
public MoveInstallDialog(List<FontItem> list)
|
||||
{
|
||||
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_0050: Expected O, but got Unknown
|
||||
items = list;
|
||||
((Control)this).Text = "移动字体 + 快捷方式安装";
|
||||
((Control)this).Width = 700;
|
||||
((Control)this).Height = 560;
|
||||
((Form)this).StartPosition = (FormStartPosition)4;
|
||||
((Control)this).Font = new Font("Microsoft YaHei UI", 9f);
|
||||
Build();
|
||||
}
|
||||
|
||||
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_0059: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_0063: Expected O, but got Unknown
|
||||
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_0100: Expected O, but got Unknown
|
||||
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_0129: Expected O, but got Unknown
|
||||
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_0149: Expected O, but got Unknown
|
||||
//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_01b4: Expected O, but got Unknown
|
||||
//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_0205: Expected O, but got Unknown
|
||||
//IL_0265: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_026c: Expected O, but got Unknown
|
||||
//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_02c4: Expected O, but got Unknown
|
||||
Label val = new Label();
|
||||
((Control)val).Text = "将把 " + items.Count + " 个字体文件移动到指定目录;可选『以快捷方式安装』:\r\n在系统字体中创建指向新位置的快捷方式(字体不复制进系统盘,需管理员权限)。";
|
||||
((Control)val).SetBounds(12, 10, 664, 46);
|
||||
((Control)val).ForeColor = Color.DimGray;
|
||||
((Control)this).Controls.Add((Control)(object)val);
|
||||
lst = new ListBox();
|
||||
((Control)lst).SetBounds(12, 62, 664, 260);
|
||||
lst.HorizontalScrollbar = true;
|
||||
foreach (FontItem item in items)
|
||||
{
|
||||
lst.Items.Add((object)(item.Name + " <- " + item.Path));
|
||||
}
|
||||
((Control)this).Controls.Add((Control)(object)lst);
|
||||
Label val2 = new Label();
|
||||
((Control)val2).Text = "目标目录:";
|
||||
((Control)val2).SetBounds(12, 330, 64, 26);
|
||||
txtDir = new TextBox();
|
||||
((Control)txtDir).SetBounds(76, 327, 470, 26);
|
||||
Button val3 = new Button();
|
||||
((Control)val3).Text = "浏览…";
|
||||
((Control)val3).SetBounds(552, 326, 124, 28);
|
||||
((Control)val3).Click += delegate
|
||||
{
|
||||
string text = NativeFolderDialog.PickFolder(((Control)this).Handle, "选择目标目录", ((Control)txtDir).Text.Trim());
|
||||
if (text != null)
|
||||
{
|
||||
((Control)txtDir).Text = text;
|
||||
}
|
||||
};
|
||||
((Control)this).Controls.Add((Control)(object)val2);
|
||||
((Control)this).Controls.Add((Control)(object)txtDir);
|
||||
((Control)this).Controls.Add((Control)(object)val3);
|
||||
chkShortcut = new CheckBox();
|
||||
((Control)chkShortcut).Text = "移动后以快捷方式安装到系统字体(需管理员权限,不复制进系统盘)";
|
||||
((Control)chkShortcut).SetBounds(12, 366, 664, 26);
|
||||
chkShortcut.Checked = true;
|
||||
((Control)this).Controls.Add((Control)(object)chkShortcut);
|
||||
Button val4 = new Button();
|
||||
((Control)val4).Text = "执行移动";
|
||||
((Control)val4).BackColor = Color.FromArgb(43, 58, 85);
|
||||
((Control)val4).ForeColor = Color.White;
|
||||
((ButtonBase)val4).FlatStyle = (FlatStyle)0;
|
||||
((Control)val4).SetBounds(12, 408, 130, 36);
|
||||
((Control)val4).Click += delegate
|
||||
{
|
||||
DoMove();
|
||||
};
|
||||
Button val5 = new Button();
|
||||
((Control)val5).Text = "关闭";
|
||||
val5.DialogResult = (DialogResult)2;
|
||||
((Control)val5).SetBounds(576, 408, 100, 36);
|
||||
((Control)this).Controls.Add((Control)(object)val4);
|
||||
((Control)this).Controls.Add((Control)(object)val5);
|
||||
((Form)this).AcceptButton = (IButtonControl)(object)val5;
|
||||
Label val6 = new Label();
|
||||
((Control)val6).Text = "提示:移动会从原目录移除字体文件;移动正在使用的字体可能影响引用它的程序显示。";
|
||||
((Control)val6).SetBounds(12, 456, 664, 30);
|
||||
((Control)val6).ForeColor = Color.FromArgb(191, 90, 60);
|
||||
((Control)this).Controls.Add((Control)(object)val6);
|
||||
}
|
||||
|
||||
private void DoMove()
|
||||
{
|
||||
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_00bc: Invalid comparison between Unknown and I4
|
||||
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_00ce: Invalid comparison between Unknown and I4
|
||||
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_0196: Invalid comparison between Unknown and I4
|
||||
//IL_05b4: 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;
|
||||
}
|
||||
if (text.Length == 2 && text[1] == ':')
|
||||
{
|
||||
text += "\\";
|
||||
}
|
||||
string path = MainForm.DriveToUnc(text) ?? text;
|
||||
if (chkShortcut.Checked && !FontManagerEx.IsAdmin())
|
||||
{
|
||||
DialogResult val = MessageBox.Show((IWin32Window)(object)this, "『以快捷方式安装』需要管理员权限,当前未以管理员身份运行。\r\n\r\n选择『是』:用管理员身份重启本工具(会自动恢复上次目录,请重启后重新执行本次移动+安装);\r\n选择『否』:仅移动字体,跳过快捷方式安装。", "需要管理员权限", (MessageBoxButtons)3, (MessageBoxIcon)48);
|
||||
if ((int)val == 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ((int)val == 6)
|
||||
{
|
||||
try
|
||||
{
|
||||
ProcessStartInfo processStartInfo = new ProcessStartInfo();
|
||||
processStartInfo.FileName = Application.ExecutablePath;
|
||||
processStartInfo.Verb = "runas";
|
||||
Process.Start(processStartInfo);
|
||||
return;
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show((IWin32Window)(object)this, "提权启动失败(已取消,请手动以管理员身份运行本工具重试)。", "提示");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
string text2 = "将把 " + items.Count + " 个字体文件移动到:\r\n " + text + (chkShortcut.Checked ? "\r\n\r\n并在系统字体中创建快捷方式安装(指向移动后的位置)。" : "") + "\r\n\r\n确认执行?";
|
||||
if ((int)MessageBox.Show((IWin32Window)(object)this, text2, "确认操作", (MessageBoxButtons)1, (MessageBoxIcon)32) != 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int num = 0;
|
||||
int num2 = 0;
|
||||
int num3 = 0;
|
||||
int num4 = 0;
|
||||
List<string> list = new List<string>();
|
||||
List<string> list2 = new List<string>();
|
||||
List<string> list3 = new List<string>();
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
try
|
||||
{
|
||||
HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
string text3 = MainForm.DriveToUnc(items[i].Path) ?? items[i].Path;
|
||||
if (!File.Exists(text3))
|
||||
{
|
||||
num2++;
|
||||
list.Add(items[i].Name);
|
||||
continue;
|
||||
}
|
||||
string text4 = items[i].Name;
|
||||
string text5 = Path.Combine(path, text4);
|
||||
if (hashSet.Contains(text4) || File.Exists(text5))
|
||||
{
|
||||
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text4);
|
||||
string extension = Path.GetExtension(text4);
|
||||
int num5 = 1;
|
||||
do
|
||||
{
|
||||
text4 = fileNameWithoutExtension + "_" + num5 + extension;
|
||||
text5 = Path.Combine(path, text4);
|
||||
num5++;
|
||||
}
|
||||
while (hashSet.Contains(text4) || File.Exists(text5));
|
||||
}
|
||||
hashSet.Add(text4);
|
||||
try
|
||||
{
|
||||
MoveFileSafe(text3, text5);
|
||||
num++;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
num2++;
|
||||
list.Add(items[i].Name);
|
||||
continue;
|
||||
}
|
||||
if (chkShortcut.Checked)
|
||||
{
|
||||
string fontFullPath = Path.Combine(text, text4);
|
||||
if (FontManagerEx.InstallAsShortcut(fontFullPath, out var lnkPath, out var regName))
|
||||
{
|
||||
num3++;
|
||||
list2.Add(lnkPath + " | " + regName);
|
||||
}
|
||||
else
|
||||
{
|
||||
num2++;
|
||||
list.Add(items[i].Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Cursor.Current = Cursors.Default;
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append("移动完成:成功 " + num + " / " + items.Count);
|
||||
if (num2 > 0)
|
||||
{
|
||||
stringBuilder.Append(",失败 " + num2);
|
||||
}
|
||||
stringBuilder.Append("\r\n");
|
||||
if (chkShortcut.Checked)
|
||||
{
|
||||
stringBuilder.Append("快捷方式安装成功 " + num3 + " 个");
|
||||
if (num3 > 0)
|
||||
{
|
||||
stringBuilder.Append("\r\n\r\n已写入:");
|
||||
foreach (string item in list2)
|
||||
{
|
||||
stringBuilder.Append("\r\n " + item);
|
||||
}
|
||||
stringBuilder.Append("\r\n\r\n说明:快捷方式(.lnk)存放在 C:\\Windows\\Fonts,并在注册表 HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts 登记。");
|
||||
stringBuilder.Append("\r\n若在『字体设置 / 控制面板-字体』或 Word、PS 等软件中未立即出现,请注销后重新登录或重启系统再查看。");
|
||||
}
|
||||
}
|
||||
if (num2 > 0 && list.Count <= 20)
|
||||
{
|
||||
stringBuilder.Append("\r\n\r\n失败项:");
|
||||
foreach (string item2 in list)
|
||||
{
|
||||
stringBuilder.Append("\r\n " + item2);
|
||||
}
|
||||
}
|
||||
if (num > 0)
|
||||
{
|
||||
Moved = true;
|
||||
}
|
||||
MessageBox.Show((IWin32Window)(object)this, stringBuilder.ToString(), "移动结果", (MessageBoxButtons)0, (MessageBoxIcon)64);
|
||||
}
|
||||
|
||||
private static void MoveFileSafe(string src, string dest)
|
||||
{
|
||||
File.Copy(src, dest, overwrite: false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user