Skip to content

Commit

Permalink
Installer cleanup (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn authored Jan 11, 2022
1 parent c87cad0 commit c46a453
Show file tree
Hide file tree
Showing 19 changed files with 831 additions and 143 deletions.
Binary file modified OneMore/Properties/AssemblyInfo.cs
Binary file not shown.
2 changes: 2 additions & 0 deletions OneMoreCalendar/MonthView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public void SetRange(DateTime startDate, DateTime endDate, CalendarPages pages)
{
if (Controls[i] is MoreButton)
{
var c = Controls[i];
Controls.RemoveAt(i);
c.Dispose();
}
}

Expand Down
Binary file modified OneMoreCalendar/Properties/AssemblyInfo.cs
Binary file not shown.
Binary file modified OneMoreProtocolHandler/Properties/AssemblyInfo.cs
Binary file not shown.
Binary file modified OneMoreSetup/OneMoreSetup.vdproj
Binary file not shown.
Binary file added OneMoreSetup/Resources/Banner.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added OneMoreSetup/Resources/Banner.psd
Binary file not shown.
455 changes: 405 additions & 50 deletions OneMoreSetup/Resources/license.rtf

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions OneMoreSetupActions/Deployments/Deployment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace OneMoreSetupActions

internal abstract class Deployment
{
public const int SUCCESS = 0;
public const int FAILURE = 1;

protected readonly Logger logger;
protected readonly Stepper stepper;

Expand All @@ -18,9 +21,9 @@ protected Deployment(Logger logger, Stepper stepper)
}


public abstract bool Install();
public abstract int Install();


public abstract bool Uninstall();
public abstract int Uninstall();
}
}
14 changes: 7 additions & 7 deletions OneMoreSetupActions/Deployments/EdgeWebViewDeployment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public EdgeWebViewDeployment(Logger logger, Stepper stepper)
}


public override bool Install()
public override int Install()
{
logger.WriteLine();
logger.WriteLine("EdgeWebViewDeployment.Install ---");
Expand All @@ -38,7 +38,7 @@ public override bool Install()
{
logger.WriteLine("WebView2 Runtime is already installed");
CleanupChromium();
return true;
return SUCCESS;
}

var bootstrap = Path.Combine(
Expand All @@ -47,7 +47,7 @@ public override bool Install()

if (!DownloadBootstrap(bootstrap))
{
return false;
return FAILURE;
}

logger.WriteLine("running bootstrap");
Expand Down Expand Up @@ -80,7 +80,7 @@ public override bool Install()
// deprecate
CleanupChromium();

return true;
return SUCCESS;
}


Expand Down Expand Up @@ -110,7 +110,7 @@ private bool DownloadBootstrap(string bootstrap)
}


public override bool Uninstall()
public override int Uninstall()
{
logger.WriteLine();
logger.WriteLine("EdgeWebViewDeployment.Uninstall ---");
Expand All @@ -130,7 +130,7 @@ public override bool Uninstall()
logger.WriteLine($"command: {command}");

Process.Start(match.Groups[1].Value, match.Groups[2].Value).WaitForExit();
return true;
return SUCCESS;
}
}
else
Expand All @@ -146,7 +146,7 @@ public override bool Uninstall()
// deprecate
CleanupChromium();

return false;
return FAILURE;
}


Expand Down
24 changes: 12 additions & 12 deletions OneMoreSetupActions/Deployments/ProtocolHandlerDeployment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ProtocolHandlerDeployment(Logger logger, Stepper stepper)
}


public override bool Install()
public override int Install()
{
logger.WriteLine();
logger.WriteLine("ProtocolHandlerDeployment.Install ---");
Expand Down Expand Up @@ -59,13 +59,13 @@ public override bool Install()
{
logger.WriteLine("error creating onemore parent key");
logger.WriteLine(exc);
return false;
return FAILURE;
}

if (parent == null)
{
logger.WriteLine("could not create onemore parent key, unknown reason");
return false;
return FAILURE;
}
}

Expand All @@ -90,13 +90,13 @@ public override bool Install()
{
logger.WriteLine("error creating onemore command");
logger.WriteLine(exc);
return false;
return FAILURE;
}

if (key == null)
{
logger.WriteLine("could not create onemore command, unknown reason");
return false;
return FAILURE;
}
}

Expand All @@ -114,7 +114,7 @@ public override bool Install()
parent.Dispose();

// confirm
var verified = true;
var verified = SUCCESS;
using (key = hive.OpenSubKey($@"{path}\{cmdpath}", false))
{
if (key != null)
Expand All @@ -127,21 +127,21 @@ public override bool Install()
else
{
logger.WriteLine("coult not get command value");
verified = false;
verified = FAILURE;
}
}
else
{
logger.WriteLine("key not created");
verified = false;
verified = FAILURE;
}
}

return verified;
}


public override bool Uninstall()
public override int Uninstall()
{
logger.WriteLine();
logger.WriteLine("ProtocolHandlerDeployment.Uninstall ---");
Expand All @@ -161,11 +161,11 @@ public override bool Uninstall()
{
logger.WriteLine("warning deleting protocol class");
logger.WriteLine(exc);
return false;
return FAILURE;
}

// confirm
var verified = true;
var verified = SUCCESS;
using (var key = hive.OpenSubKey(path, false))
{
if (key == null)
Expand All @@ -175,7 +175,7 @@ public override bool Uninstall()
else
{
logger.WriteLine("key not deleted");
verified = false;
verified = FAILURE;
}
}

Expand Down
162 changes: 162 additions & 0 deletions OneMoreSetupActions/Deployments/RegistryDeployment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
//************************************************************************************************
// Copyright © 2022 Steven M Cohn. All rights reserved.
//************************************************************************************************

namespace OneMoreSetupActions
{
using Microsoft.Win32;
using System;


internal class RegistryDeployment : Deployment
{
private const string OneNoteID = "{88AB88AB-CDFB-4C68-9C3A-F10B75A5BC61}";


public RegistryDeployment(Logger logger, Stepper stepper)
: base(logger, stepper)
{
}


//========================================================================================

public override int Install()
{
logger.WriteLine();
logger.WriteLine($"RegistryDeployment.Install --- x64:{Environment.Is64BitProcess}");

if (CloningRequired())
{
// delete subtrees to start from scratch
// then create new subtrees

if (UnregisterWow() == SUCCESS &&
RegisterWow() == SUCCESS)
{
return SUCCESS;
}
}

return SUCCESS;
}


/*
* Initial attempt was to use RegistryKey.OpenBase specifying the RegistryHive and
* RegistryView.Registry32. This required configuring the project as AnyCPU and
* disabling the Prefer 32-bit option. However, this did not work consistently as
* it should. After trial and error, realized that only the ClassesRoot\CLSID\{guid}
* key needed to be cloned to WOW6432Node\CLSID and that could be done directly.
*/
private int RegisterWow()
{
logger.WriteLine("cloning CLSID");
using (var source = Registry.ClassesRoot.OpenSubKey($@"CLSID\{OneNoteID}", true))
{
if (source != null)
{
using (var target = Registry.ClassesRoot.OpenSubKey(@"WOW6432Node\CLSID", true))
{
logger.WriteLine($"copying from {source.Name} to {target.Name}");
source.CopyTo(target, logger);
}
}
}

return SUCCESS;
}


//========================================================================================

public override int Uninstall()
{
logger.WriteLine();
logger.WriteLine($"RegistryDeployment.Uninstall --- x64:{Environment.Is64BitProcess}");

if (CloningRequired())
{
return UnregisterWow();
}

return SUCCESS;
}


private int UnregisterWow()
{
logger.WriteLine("deleting CLSID clone");
using (var key = Registry.ClassesRoot.OpenSubKey(@"WOW6432Node\CLSID", true))
{
if (key != null)
{
key.DeleteSubKeyTree(OneNoteID, false);
key.DeleteSubKey(OneNoteID, false);
}
else
{
logger.WriteLine("CLSID clone note found");
}
}

return SUCCESS;
}



// Determines if 32-bit OneNote is installed.
// When this is true, the guid will exist under ClassesRoot\CLSID however the path
// will be blank and instead the the path is under ClassesRoot\Wow6432Node\CLSID\{guid}
private bool CloningRequired()
{
string clsid = null;
using (var key = Registry.ClassesRoot.OpenSubKey(@"\OneNote.Application\CLSID"))
{
if (key != null)
{
clsid = (string)key.GetValue(string.Empty); // default value
}
}

string path = null;
if (!string.IsNullOrEmpty(clsid))
{
using (var key = Registry.ClassesRoot
.OpenSubKey($@"CLSID\{clsid}\Localserver32"))
{
if (key != null)
{
path = (string)key.GetValue(string.Empty); // default value
}
}

if (path == null)
{
using (var key = Registry.ClassesRoot
.OpenSubKey($@"WOW6432Node\CLSID\{clsid}\Localserver32"))
{
if (key != null)
{
path = (string)key.GetValue(string.Empty); // default value
}
}
}
}

if (path == null)
{
logger.WriteLine("OneNote application path note found; continuing optimistically");
return true;
}
else if (path.Contains(@"\Program Files (x86)\"))
{
logger.WriteLine("detected 32-bit install");
return true;
}

logger.WriteLine("detected 64-bit install");
return false;
}
}
}
Loading

0 comments on commit c46a453

Please sign in to comment.