-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c87cad0
commit c46a453
Showing
19 changed files
with
831 additions
and
143 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.