public MainWindow() { File.Create(filePath).Close(); addLog("Started!"); if (!File.Exists(ValuesPath)) { File.Create(ValuesPath).Close(); UpToDate = false; addLog("Created winver.json"); } else { addLog("winver.json already exists"); string JsonList = File.ReadAllText(ValuesPath); if (JsonList == "") { UpToDate = false; } else { vals = JsonConvert.DeserializeObject <Values>(JsonList); double check = current.DayOfYear / 7; int checkInt = Convert.ToInt32(Math.Round(check)); if (vals.WeekOfYear != checkInt || vals.WeekOfYear == -1 || vals.RAMSpeed == null) { UpToDate = false; } } } // ////////////////////////////// // // Gets new values for everything // // ////////////////////////////// // if (UpToDate == false) { buttonRefresh_Click(null, null); addLog("Initial loading complete"); } else { addLog("Creating pages"); LoadedAboutPage = new AboutPage(); LoadedSystemPage = new SystemPage(); LoadedThemePage = new ThemePage(); LoadedAdvancedPage = new AdvancedPage(); addLog("Page creation complete"); } InitializeComponent(); addLog("Initialised MAIN"); }
public MainWindow() { if (!File.Exists(ValuesPath)) { File.Create(ValuesPath).Close(); UpToDate = false; } else { string JsonList = File.ReadAllText(ValuesPath); if (JsonList == "") { UpToDate = false; } else { vals = JsonConvert.DeserializeObject <Values>(JsonList); double check = current.DayOfYear / 7; int checkInt = Convert.ToInt32(Math.Round(check)); if (vals.WeekOfYear != checkInt || vals.WeekOfYear == -1 || vals.RAMSpeed == null) { UpToDate = false; } } } // ////////////////////////////// // // Gets new values for everything // // ////////////////////////////// // if (UpToDate == false) { buttonRefresh_Click(null, null); } else { LoadedAboutPage = new AboutPage(); LoadedSystemPage = new SystemPage(); LoadedThemePage = new ThemePage(); LoadedAdvancedPage = new AdvancedPage(); } InitializeComponent(); }
private void buttonRefresh_Click(object sender, RoutedEventArgs e) { //refreshProgress.IsActive = true; RegistryKey CurrentVersionKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"); RegistryKey CentralProcessorKey = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DESCRIPTION\System\CentralProcessor\0"); // Easy stuff vals.WeekOfYear = current.DayOfYear / 7; vals.CopyrightYear = current.Year.ToString(); vals.Version = (string)CurrentVersionKey.GetValue("DisplayVersion"); if (vals.Version == "") { vals.Version = (string)CurrentVersionKey.GetValue("ReleaseId"); if (vals.Version == "2009") { vals.Version = "20H2"; } } vals.Build = (string)CurrentVersionKey.GetValue("CurrentBuild") + "." + CurrentVersionKey.GetValue("UBR").ToString(); vals.User = (string)CurrentVersionKey.GetValue("RegisteredOwner"); vals.SystemName = ExecuteCommandSync("hostname").Replace("\r\n", ""); vals.Workgroup = (string)CurrentVersionKey.GetValue("RegisteredOrganization"); vals.CPU = (string)CentralProcessorKey.GetValue("ProcessorNameString"); vals.Arch = SysInfo("Win32_Processor", "Architecture"); vals.RAM = GetTotalMemoryInGibibytes(); vals.RAMType = RamType(); vals.RAMSpeed = SysInfo("Win32_PhysicalMemory", "Speed"); vals.Path = @"C:\Windows"; //(string)CurrentVersionKey.GetValue("PathName"); TODO: find a proper way to get this because im lazy vals.FreeSpace = GetTotalFreeSpace(); vals.Storage = GetTotalSpace(); switch (SysInfo("Win32_Processor", "Architecture")) { case "0": vals.Arch = "x86"; break; case "1": vals.Arch = "MIPS"; break; case "2": vals.Arch = "Alpha"; break; case "3": vals.Arch = "PowerPC"; break; case "5": vals.Arch = "ARM"; break; case "6": vals.Arch = "ia64"; break; case "9": vals.Arch = "AMD64"; break; default: vals.Arch = "Real"; break; } // Get edition of Windows 10 because apparently that's bloody impossible any other way and the registry returns me wrong values try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_OperatingSystem"); foreach (ManagementObject queryObj in searcher.Get()) { vals.Edition = ((string)queryObj["Caption"]).Replace("Microsoft ", ""); if (vals.Edition.Contains("Insider Preview") && vals.Version != "Dev") { vals.Version = "vNext"; } vals.Edition = vals.Edition.Replace("Insider Preview", ""); } } catch (ManagementException ex) { MessageBox.Show("An error occurred while querying for WMI data: " + ex.Message); } // This just prevents you from having a blank username if (vals.User == "" || vals.User == "user name") { vals.User = "******"; } // If in org, show org name, else show hostname if (vals.Workgroup == "" || vals.Workgroup == "org name") { vals.IsLocal = true; } else { vals.IsLocal = false; } // Writes files File.Create(ValuesPath).Close(); File.WriteAllText(ValuesPath, JsonConvert.SerializeObject(vals, Formatting.Indented)); // Reloads pages LoadedAboutPage = new AboutPage(); LoadedSystemPage = new SystemPage(); LoadedThemePage = new ThemePage(); LoadedAdvancedPage = new AdvancedPage(); if (ContentFrame != null) { ContentFrame.Navigate(LoadedAboutPage); NavView.SelectedItem = NavView.MenuItems[0]; } //refreshProgress.IsActive = false; }