diff --git a/OneMore/AddIn.cs b/OneMore/AddIn.cs index e129ebd572..6b5653d174 100644 --- a/OneMore/AddIn.cs +++ b/OneMore/AddIn.cs @@ -65,10 +65,11 @@ public AddIn() thread.CurrentUICulture = Culture; var (cpu, ram) = GetMachineProps(); + var uram = ram > ulong.MaxValue ? ">GB" : ((ulong)ram).ToBytes(); logger.WriteLine(); logger.Start( - $"Starting {process.ProcessName} {process.Id}, {cpu} Mhz, {ram.ToBytes()}, " + + $"Starting {process.ProcessName} {process.Id}, {cpu} Mhz, {uram}, " + $"{thread.CurrentCulture.Name}/{thread.CurrentUICulture.Name}, " + $"v{AssemblyInfo.Version}, OneNote {Office.GetOneNoteVersion()}, " + $"Office {Office.GetOfficeVersion()}, " + @@ -145,28 +146,42 @@ private void CatchUnhandledException(object sender, UnhandledExceptionEventArgs - private (uint, ulong) GetMachineProps() + private (uint, double) GetMachineProps() { - static T Query(string field, string table) + // using this as a means of short-circuiting the Ensure methods for slower machines + // to speed up the display of the menus. CurrentClockSpeed will vary depending on + // battery capacity and other factors, whereas MaxClockSpeed is a constant + + uint speed = ReasonableClockSpeed; + using (var searcher = + new ManagementObjectSearcher("select CurrentClockSpeed from Win32_Processor")) { - T value = default(T); - using var searcher = new ManagementObjectSearcher($"select {field} from {table}"); foreach (var item in searcher.Get()) { - value = (T)item[field]; + speed = Convert.ToUInt32(item["CurrentClockSpeed"]); item.Dispose(); } - return value; } - // using this as a means of short-circuiting the Ensure methods for slower machines - // to speed up the display of the menus. CurrentClockSpeed will vary depending on - // battery capacity and other factors, whereas MaxClockSpeed is a constant - var speed = Query("CurrentClockSpeed", "Win32_Processor"); if (speed == 0) speed = ReasonableClockSpeed; // returns total RAM across all physical slots; as KB so convert to bytes - var memory = Query("MaxCapacityEx", "Win32_PhysicalMemoryArray") * 1024; + //var memory = Query("MaxCapacityEx", "Win32_PhysicalMemoryArray") * 1024; + //var memory = Query("Capacity", "Win32_PhysicalMemory") * 1024; + + //var memory = Math.Ceiling(Query( + // "*", "Win32_OperatingSystem", "TotalVisibleMemorySize") * 1024); + + double memory = 0; + using (var searcher = + new ManagementObjectSearcher("select * from Win32_OperatingSystem")) + { + foreach (var item in searcher.Get()) + { + memory = Convert.ToDouble(item["TotalVisibleMemorySize"]); + item.Dispose(); + } + } return (speed, memory); } diff --git a/OneMore/Helpers/Extensions/IntExtensions.cs b/OneMore/Helpers/Extensions/IntExtensions.cs index fdb89b17df..9057c51284 100644 --- a/OneMore/Helpers/Extensions/IntExtensions.cs +++ b/OneMore/Helpers/Extensions/IntExtensions.cs @@ -25,7 +25,7 @@ internal static class IntExtensions { "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX" }; // byte size names (only handles up to TB) - private static readonly string[] SizeSuffixes = { "bytes", "KB", "MB", "GB", "TB" }; + private static readonly string[] SizeSuffixes = { "bytes", "KB", "MB", "GB", "TB", "PB" }; // convert int to alphabet string