Skip to content

Commit

Permalink
1506 hashtag startup logic (#1526)
Browse files Browse the repository at this point in the history
* step 1

* step 2

* step 3

* legacy encapsulation

* step 3
  • Loading branch information
stevencohn authored Aug 10, 2024
1 parent e42dcd3 commit da744fe
Show file tree
Hide file tree
Showing 29 changed files with 546 additions and 332 deletions.
65 changes: 1 addition & 64 deletions OneMore/AddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ namespace River.OneMoreAddIn
{
using Extensibility;
using Microsoft.Office.Core;
using River.OneMoreAddIn.Helpers.Office;
using River.OneMoreAddIn.Settings;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Management;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

Expand All @@ -32,7 +30,6 @@ namespace River.OneMoreAddIn
[ProgId("River.OneMoreAddin")]
public partial class AddIn : IDTExtensibility2, IRibbonExtensibility
{
private const uint ReasonableClockSpeed = 1800;

private IRibbonUI ribbon; // the ribbon control
private ILogger logger; // our diagnostic logger
Expand Down Expand Up @@ -64,25 +61,7 @@ public AddIn()
thread.CurrentCulture = Culture;
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, {uram}, " +
$"{thread.CurrentCulture.Name}/{thread.CurrentUICulture.Name}, " +
$"v{AssemblyInfo.Version}, OneNote {Office.GetOneNoteVersion()}, " +
$"Office {Office.GetOfficeVersion()}, " +
DateTime.Now.ToString("yyyy-MM-dd HH:mm"));

logger.WriteLine(Commands.DiagnosticsCommand.GetWindowsProductName());

var hostproc = Process.GetProcessesByName("ONENOTE");
if (hostproc.Length > 0)
{
var module = hostproc[0].MainModule;
logger.WriteLine($"{module.FileName} ({module.FileVersionInfo.ProductVersion})");
}
River.OneMoreAddIn.Helpers.SessionLogger.WriteSessionHeader();

Self = this;

Expand Down Expand Up @@ -172,48 +151,6 @@ private void CatchUnhandledException(object sender, UnhandledExceptionEventArgs
public static AddIn Self { get; private set; }



private (uint, double) GetMachineProps()
{
// 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"))
{
foreach (var item in searcher.Get())
{
speed = Convert.ToUInt32(item["CurrentClockSpeed"]);
item.Dispose();
}
}

if (speed == 0) speed = ReasonableClockSpeed;

// returns total RAM across all physical slots; as KB so convert to bytes
//var memory = Query<ulong>("MaxCapacityEx", "Win32_PhysicalMemoryArray") * 1024;
//var memory = Query<ulong>("Capacity", "Win32_PhysicalMemory") * 1024;

//var memory = Math.Ceiling(Query<double>(
// "*", "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);
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// IDTExtensibility2
Expand Down
3 changes: 1 addition & 2 deletions OneMore/Commands/CommandProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public List<CommandInfo> LoadPaletteCommands()
var setprovider = new SettingsProvider();

// TODO: temporary Page tagging
var tagging = setprovider.GetCollection("tagging");
if (tagging.Get("converted", false))
if (new Commands.LegacyTaggingConverter().IsConverted())
{
if (commands.Find(c => c.Method.Name == "TaggedCmd") is CommandInfo cmd1)
{
Expand Down
6 changes: 3 additions & 3 deletions OneMore/Commands/Settings/HashtagSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ private async void UpgradeTags(object sender, LinkLabelLinkClickedEventArgs e)

private void ResetUpgradeCheck(object sender, LinkLabelLinkClickedEventArgs e)
{
// this will save settings.xml
// this will save settings.xml...
LegacyTaggingConverter.ResetUpgradeCheck();

// now update local in-memory copy of settings
provider.RemoveCollection("tagging");
// .. and now update local in-memory copy of settings
provider.RemoveCollection(LegacyTaggingConverter.SettingsName);

upgradeLink.Enabled = true;
resetLink.Visible = false;
Expand Down
2 changes: 1 addition & 1 deletion OneMore/Commands/Tagging/HashtagCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private async Task<bool> ConfirmReady()
{
var scheduler = new HashtagScheduler();

if (!HashtagProvider.DatabaseExists())
if (!HashtagProvider.CatalogExists())
{
using var sdialog = scheduler.State == ScanningState.None
? new ScheduleScanDialog(false)
Expand Down
Loading

0 comments on commit da744fe

Please sign in to comment.