-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
122 lines (121 loc) · 6.17 KB
/
Program.cs
File metadata and controls
122 lines (121 loc) · 6.17 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Threading;
namespace LTSC_Toolkit
{
internal class Program
{
static void Main(string[] args)
{
while (true)
{
Console.WriteLine("LTSC Toolkit\n\n 1) Install \"OneDrive\" with patch.\n 2) Install \"Microsoft Store\" with patch.\n 3) Install \"OneDrive\" and \"Microsoft Store\" with patch.\n"); // "Tips: Add \"-\" at the end of number to install with out patch (may not work)."
Console.Write("Enter a number to start install: ");
int choice = 0;
try
{
choice = int.Parse(Console.ReadLine());
}
catch
{
Console.WriteLine("Wrong number. Please try again.");
Thread.Sleep(3000);
Console.Clear();
continue;
}
switch (choice)
{
case 1:
InstallOneDrive(true);
break;
case 2:
InstallMicrosoftStore(true);
break;
case 3:
Console.WriteLine("3");
break;
default:
Console.WriteLine("Wrong number. Please try again.");
break;
}
if (choice < 1 || choice > 3)
{
Thread.Sleep(3000);
Console.Clear();
continue;
}
break;
}
}
static void InstallOneDrive(bool withPatch)
{
string tempFile = Path.GetTempPath() + @"\LTSC Toolkit\OneDriveSetup.exe";
Console.WriteLine("Downloading \"OneDrive\"...");
DownLoadFile("https://go.microsoft.com/fwlink/p/?LinkID=2182910", tempFile);
Console.WriteLine("Installing \"OneDrive\"...");
Process.Start(tempFile).WaitForExit();
Console.WriteLine("Patching \"OneDrive\"...");
PatchOneDrive();
File.Delete(tempFile);
Console.WriteLine("\"OneDrive\" installed and patched successfully.");
}
static void PatchOneDrive()
{
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Desktop\\NameSpace");
string[] keys = registryKey.GetSubKeyNames();
foreach (string key in keys)
{
Console.WriteLine(key);
RegistryKey subKey = registryKey.OpenSubKey(key);
if (subKey.GetValue(string.Empty) == "OneDrive")
{
subKey.Close();
registryKey.DeleteSubKey(key);
registryKey.Close();
}
}
RegistryKey path = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FolderDescriptions\\{A52BBA46-E9E1-435f-B3D9-28DAA648C0F6}");
path.SetValue("Attributes", 1, RegistryValueKind.DWord);
path.SetValue("Category", 4, RegistryValueKind.DWord);
path.SetValue("DefinitionFlags", 40, RegistryValueKind.DWord);
byte[] iconBytes = { 0x25, 0x00, 0x53, 0x00, 0x79, 0x00, 0x73, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x52, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x74, 0x00, 0x25, 0x00, 0x5c, 0x00, 0x73, 0x00, 0x79, 0x00, 0x73, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x33, 0x00, 0x32, 0x00, 0x5c, 0x00, 0x69, 0x00, 0x6d, 0x00, 0x61, 0x00, 0x67, 0x00, 0x65, 0x00, 0x72, 0x00, 0x65, 0x00, 0x73, 0x00, 0x2e, 0x00, 0x64, 0x00, 0x6c, 0x00, 0x6c, 0x00, 0x2c, 0x00, 0x2d, 0x00, 0x31, 0x00, 0x30, 0x00, 0x34, 0x00, 0x30, 0x00, 0x00, 0x00 };
path.SetValue("Icon", iconBytes, RegistryValueKind.Binary);
byte[] nameBytes = { 0x40, 0x00, 0x25, 0x00, 0x53, 0x00, 0x79, 0x00, 0x73, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x52, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x74, 0x00, 0x25, 0x00, 0x5c, 0x00, 0x53, 0x00, 0x79, 0x00, 0x73, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x33, 0x00, 0x32, 0x00, 0x5c, 0x00, 0x53, 0x00, 0x65, 0x00, 0x74, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x67, 0x00, 0x53, 0x00, 0x79, 0x00, 0x6e, 0x00, 0x63, 0x00, 0x43, 0x00, 0x6f, 0x00, 0x72, 0x00, 0x65, 0x00, 0x2e, 0x00, 0x64, 0x00, 0x6c, 0x00, 0x6c, 0x00, 0x2c, 0x00, 0x2d, 0x00, 0x31, 0x00, 0x30, 0x00, 0x32, 0x00, 0x34, 0x00, 0x00, 0x00 };
path.SetValue("LocalizedName", nameBytes, RegistryValueKind.Binary);
path.SetValue("LocalRedirectOnly", 1, RegistryValueKind.DWord);
path.SetValue("Name", "OneDrive", RegistryValueKind.String);
path.SetValue("ParentFolder", "{5E6C858F-0E22-4760-9AFE-EA3317B67173}", RegistryValueKind.String);
path.SetValue("ParsingName", "shell:::{018D5C66-4533-4307-9B53-224DE2ED1FE6}", RegistryValueKind.String);
path.SetValue("RelativePath", "OneDrive", RegistryValueKind.String);
path.Close();
}
static void InstallMicrosoftStore(bool withPatch)
{
DownLoadFile("https://github.com/kkkgo/LTSC-Add-MicrosoftStore/archive/refs/heads/master.zip", "MicrosoftStore.zip");
}
static bool DownLoadFile(string url, string localFileName)
{
Uri uri = new Uri(url);
string path = Path.GetDirectoryName(localFileName);
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
HttpClient httpClient = new HttpClient();
HttpResponseMessage responseMessage = httpClient.GetAsync(uri).Result;
if (responseMessage.IsSuccessStatusCode)
{
using (FileStream fileStream = File.Create(localFileName))
{
Stream stream = responseMessage.Content.ReadAsStreamAsync().Result;
stream.CopyTo(fileStream);
return true;
}
}
else
{
return false;
}
}
}
}