-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
107 lines (91 loc) · 4.08 KB
/
Program.cs
File metadata and controls
107 lines (91 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Win32;
namespace Fix_FontLink
{
class RegistryValue
{
public string Key { get; set; }
public string Value { get; set; }
}
internal class Program
{
static void Main()
{
// Registry key path
string registryKeyPath = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink";
// Define the custom sorting order
List<string> sortingOrder = (new string[] { "MSYH.TTC", "MSJH.TTC", "MEIRYO.TTC", "MALGUN.TTF", "TAHOMA.TTF" }).ToList();
using (FileStream fs = File.OpenWrite(String.Format("{0}-regbackup.reg", DateTime.Now.ToString("yyyyMMddHHmmss"))))
{
using (TextWriter writer = new StreamWriter(fs))
{
writer.WriteLine("Windows Registry Editor Version 5.00");
writer.WriteLine();
writer.WriteLine("[{0}]", registryKeyPath);
// Registry key to inspect
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKeyPath, true))
{
if (key == null)
{
Console.WriteLine("Registry key not found {0}", registryKeyPath);
return;
}
// Get all the value names under the registry key
string[] valueNames = key.GetValueNames().Where(p => p.StartsWith("Segoe UI")).ToArray();
// Iterate through the value names and add them to the list
List<RegistryValue> registryValues = new List<RegistryValue>();
foreach (string valueName in valueNames)
{
// Create a list of RegistryValue objects to store key and value pairs
List<string> values = (key.GetValue(valueName) as string[]).ToList();
Console.WriteLine("Backing up {0}", valueName);
// Backup registry value
writer.WriteLine("\"{0}\"=hex(7):{1}", valueName, ToHex7(values));
writer.Flush();
// Custom sorting
values.Sort((v1, v2) =>
{
int i1 = sortingOrder.FindIndex(p => v1.StartsWith(p));
int i2 = sortingOrder.FindIndex(p => v2.StartsWith(p));
if (i1 != -1 && i2 != -1)
{
return i1.CompareTo(i2);
}
if (i2 != -1)
{
return 1;
}
if (i1 != -1)
{
return -1;
}
return 0;
});
Console.WriteLine("Applying changes to {0}", valueName);
key.SetValue(valueName, values.ToArray());
}
}
}
}
Console.WriteLine("Press any key to close.");
Console.ReadKey(true);
}
static string ToHex7(List<string> values)
{
UnicodeEncoding unicodeEncoding = new UnicodeEncoding();
values = new List<string>(values);
values.Add("");
return String.Join(",", values.Select(p =>
{
List<byte> arr = unicodeEncoding.GetBytes(p).ToList();
arr.Add(0);
arr.Add(0);
return String.Join(",", BitConverter.ToString(arr.ToArray()).Replace('-', ',').ToLower());
}));
}
}
}