-
Notifications
You must be signed in to change notification settings - Fork 0
/
homePage.xaml.cs
378 lines (303 loc) · 13.8 KB
/
homePage.xaml.cs
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
using Microsoft.UI.Xaml.Controls;
using Microsoft.Win32;
using System;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Xml;
using CommunityToolkit.WinUI.Controls;
using Microsoft.UI.Xaml.Documents;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI;
using System.Threading.Tasks;
using Microsoft.UI.Dispatching;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace changeWindows
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
///
///
/// CLASSES
///
[DataContract]
public class fetchedBuild // The system's fetched build.
{
public fetchedBuild(string buildNum, int installDate, string buildBranch, string buildTag)
{
this.buildNum = buildNum;
this.installDate = installDate;
this.buildBranch = buildBranch;
this.buildTag = buildTag;
}
[DataMember]
public string buildNum; // The build #
[DataMember]
public int installDate; // The install date (converted from UNIX)
[DataMember]
public string buildBranch; // The insider channel (dev; canary)
[DataMember]
public string buildTag; // The build tag (23020.ni_prerelease.240118-1056)
public string getBuildNum()
{
return buildNum;
}
public int getInstallDate()
{
return installDate; // ?
}
public string getBuildBranch()
{
return buildBranch;
}
public string getBuildTag()
{
return buildTag;
}
public override string ToString() // This function is what prints out all the build details.
{
string returnString = "Build: " + buildNum + " UNIX: " + installDate + " (Branch: " + buildBranch + ")" + " (" + buildTag + ")";
return returnString;
}
}
public sealed partial class homePage : Page
{
///
/// VARIABLES
///
// The app's root folder.
private string baseDirectory = AppDomain.CurrentDomain.BaseDirectory + @"\";
// These are the current working elements.
private Run installDateElem;
private Run buildBranchElem;
private Run buildTagElem;
RegistryKey registryDev = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\WindowsSelfHost\Applicability");
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
private int run = 0;
///
/// FUNCTIONS
///
static void SaveViaDataContractSerialization<T>(T serializableObject, string filepath)
{
var serializer = new DataContractSerializer(typeof(T));
var settings = new XmlWriterSettings()
{
Indent = true,
IndentChars = "\t",
};
var writer = XmlWriter.Create(filepath, settings);
serializer.WriteObject(writer, serializableObject);
writer.Close();
}
// This function handles serializing the XML. (Read/Write?)
static T LoadViaDataContractSerialization<T>(string filepath)
{
var fileStream = new FileStream(filepath, FileMode.Open);
var reader = XmlDictionaryReader.CreateTextReader(fileStream, new XmlDictionaryReaderQuotas());
var serializer = new DataContractSerializer(typeof(T));
T serializableObject = (T)serializer.ReadObject(reader, true);
reader.Close();
fileStream.Close();
return serializableObject;
}
private void setVer()
{
// App Version
var ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
appVer.Text = ver;
}
// Determines what Insider channel (branch) the user is in and sets metadata.
private void determineBranch(string buildBranch, bool isFirstTime)
{
if (isFirstTime)
{
switch (buildBranch)
{
case null: // Null means that the user is not in a branch. (GAC)
buildBranchC.Foreground = new SolidColorBrush(Colors.Green);
buildBranchC.Text = "GAC";
break;
case "CanaryChannel":
buildBranchC.Foreground = new SolidColorBrush(Colors.Yellow);
buildBranchC.Text = "Canary";
break;
case "Dev":
buildBranchC.Foreground = new SolidColorBrush(Colors.Orange);
buildBranchC.Text = "Dev";
break;
case "Beta":
buildBranchC.Foreground = new SolidColorBrush(Colors.GreenYellow);
buildBranchC.Text = "Beta";
break;
case "ReleasePreview":
buildBranchC.Foreground = new SolidColorBrush(Colors.Green);
buildBranchC.Text = "Release Preview";
break;
};
}
else
{
switch (buildBranch)
{
case null: // Null means that the user is not in a branch. (GAC)
buildBranchElem.Foreground = new SolidColorBrush(Colors.Green);
buildBranchElem.Text = "GAC";
break;
case "CanaryChannel":
buildBranchElem.Foreground = new SolidColorBrush(Colors.Yellow);
buildBranchElem.Text = "Canary";
break;
case "Dev":
buildBranchElem.Foreground = new SolidColorBrush(Colors.Orange);
buildBranchElem.Text = "Dev";
break;
case "Beta":
buildBranchElem.Foreground = new SolidColorBrush(Colors.GreenYellow);
buildBranchElem.Text = "Beta";
break;
case "ReleasePreview":
buildBranchElem.Foreground = new SolidColorBrush(Colors.Green);
buildBranchElem.Text = "Release Preview";
break;
};
}
}
private void updateLog(List<fetchedBuild> loadedBuild)
{
var sysBuild = registryKey.GetValue("CurrentBuild").ToString();
var sysBuildLab = registryKey.GetValue("BuildLab").ToString();
var sysBuildBranch = registryDev.GetValue("BranchName").ToString();
var sysInstallDate = registryKey.GetValue("InstallDate");
List<fetchedBuild> currentWorkingBuilds = new List<fetchedBuild>
{
new fetchedBuild(sysBuild, (int)sysInstallDate, sysBuildBranch, sysBuildLab)
};
XmlDocument buildLog = new XmlDocument();
buildLog.Load(baseDirectory + "buildLog.xml");
XmlElement systemBuild = buildLog.CreateElement("fetchedBuild");
XmlElement root = buildLog.DocumentElement;
root.PrependChild(systemBuild);
XmlElement sysBuildBranchX = buildLog.CreateElement("buildBranch");
sysBuildBranchX.InnerText = sysBuildBranch;
systemBuild.AppendChild(sysBuildBranchX);
XmlElement sysBuildX = buildLog.CreateElement("buildNum");
sysBuildX.InnerText = sysBuild;
systemBuild.AppendChild(sysBuildX);
XmlElement sysBuildLabX = buildLog.CreateElement("buildTag");
sysBuildLabX.InnerText = sysBuildLab;
systemBuild.AppendChild(sysBuildLabX);
XmlElement sysInstallDateX = buildLog.CreateElement("installDate");
sysInstallDateX.InnerText = sysInstallDate.ToString();
systemBuild.AppendChild(sysInstallDateX);
loadedBuild.Insert(0, new fetchedBuild(sysBuild, (int)sysInstallDate, sysBuildBranch, sysBuildLab));
SaveViaDataContractSerialization(loadedBuild, baseDirectory + "buildLog.xml"); // Save (pls no override)
}
///
/// MAIN FUNCTIONS
///
public homePage()
{
this.InitializeComponent();
// Set the app's version.
setVer();
// Check the log.
if (File.Exists(baseDirectory + "buildLog.xml"))
{
var loadedBuild = LoadViaDataContractSerialization<List<fetchedBuild>>(baseDirectory + "buildLog.xml");
foreach (var a in loadedBuild)
{
var buildNumber = a.getBuildNum();
var systemBuildNumber = registryKey.GetValue("CurrentBuild").ToString();
var systemBuildNumberC = int.Parse(systemBuildNumber);
var buildNumberC = int.Parse(buildNumber);
//
// UPDATE CHECK
//
if (systemBuildNumberC > buildNumberC) // If the build number is higher (update)
{
updateLog(loadedBuild);
}
break;
}
foreach (var a in loadedBuild)
{
//
// The first run.
//
run += 1;
var buildNumber = a.getBuildNum();
var installDate = a.getInstallDate();
var buildBranch = a.getBuildBranch();
var buildTag = a.getBuildTag();
installDateElem = this.FindName("buildInstallDate") as Run;
buildBranchElem = this.FindName("buildBranchC") as Run;
buildTagElem = this.FindName("buildTag") as Run;
// The other runs, checks all the other builds. (If applicable)
if (run >= 2 && run <= 9)
{
SettingsCard pastWorkingBuild = this.FindName("pastBuild" + run) as SettingsCard;
// This runs through the past builds.
installDateElem = this.FindName("pastBuild" + run + "Install") as Run;
buildBranchElem = this.FindName("pastBuild" + run + "Branch") as Run;
buildTagElem = this.FindName("pastBuild" + run + "Tag") as Run;
// Set metadata
pastWorkingBuild.Header = "Build " + buildNumber;
pastWorkingBuild.Visibility = Visibility.Visible;
installDateElem.Text = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(installDate).ToString() + " //";
determineBranch(buildBranch, false);
buildTagElem.Text = "- " + buildTag;
}
//
// Current Build
//
else
{
currentBuild.Header = "Build " + buildNumber;
installDateElem.Text = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(installDate).ToString() + " //";
determineBranch(buildBranch, false);
buildTagElem.Text = "- " + buildTag;
}
}
} else
{
// Inherited from WinUISys.
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
RegistryKey registryDev = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\WindowsSelfHost\Applicability");
var build = registryKey.GetValue("CurrentBuild").ToString();
var buildLab = registryKey.GetValue("BuildLab").ToString();
var buildBranch = registryDev.GetValue("BranchName").ToString();
var installDate = registryKey.GetValue("InstallDate");
// This is what fills in information.
// build: #
// buildLab: The full build tag.
// buildBranch: Self
// commonBuildName: Ex. "22H2"
// editionID: "Enterprise" or etc.
currentBuild.Header = "Build " + build;
// Gets the install date.
int uInstall = (int)installDate;
buildInstallDate.Text = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(uInstall).ToString() + " //";
determineBranch(buildBranch, true);
// Gets the build tag.
buildTag.Text = "- " + buildLab;
List<fetchedBuild> currentWorkingBuilds = new List<fetchedBuild>
{
new fetchedBuild(build, (int)installDate, buildBranch, buildLab)
};
SaveViaDataContractSerialization(currentWorkingBuilds, baseDirectory + "buildLog.xml"); // Save
currentWorkingBuilds = null; // This "deletes" or rather sets everything to null to the object.
currentWorkingBuilds = LoadViaDataContractSerialization<List<fetchedBuild>>(baseDirectory + "buildLog.xml");
foreach (var a in currentWorkingBuilds) // Go thru index.
Debug.WriteLine(a.ToString());
}
}
private void settingsButton_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(settingsPage));
}
}
}