Added ExtensionManager safety checks

This commit is contained in:
erri120 2019-12-14 22:40:10 +01:00
parent 86d91a3e4b
commit e13a57009a
No known key found for this signature in database
GPG Key ID: A8C0A18D8D4D3135
2 changed files with 18 additions and 8 deletions

View File

@ -33,25 +33,26 @@ namespace Wabbajack.Common
var progIDKey = Registry.CurrentUser.OpenSubKey(ProgIDPath);
var tempKey = progIDKey?.OpenSubKey("shell\\open\\command");
if (progIDKey == null || tempKey == null) return true;
return tempKey.GetValue("").ToString().Equals($"\"{appPath}\" -i \"%1\"");
var value = tempKey.GetValue("");
return value == null || value.ToString().Equals($"\"{appPath}\" -i \"%1\"");
}
public static bool IsAssociated()
{
var progIDKey = Registry.CurrentUser.OpenSubKey(ProgIDPath);
var extKey = Registry.CurrentUser.OpenSubKey(ExtPath);
return (progIDKey != null && extKey != null);
return progIDKey != null && extKey != null;
}
public static void Associate(string appPath)
{
var progIDKey = Registry.CurrentUser.CreateSubKey(ProgIDPath, RegistryKeyPermissionCheck.ReadWriteSubTree);
foreach (KeyValuePair<string, string> entry in ProgIDList)
foreach (var entry in ProgIDList)
{
if (entry.Key.Contains("\\"))
{
var tempKey = progIDKey.CreateSubKey(entry.Key);
tempKey.SetValue("", entry.Value.Replace("{appPath}", appPath));
var tempKey = progIDKey?.CreateSubKey(entry.Key);
tempKey?.SetValue("", entry.Value.Replace("{appPath}", appPath));
}
else
{
@ -60,7 +61,7 @@ namespace Wabbajack.Common
}
var extKey = Registry.CurrentUser.CreateSubKey(ExtPath, RegistryKeyPermissionCheck.ReadWriteSubTree);
foreach (KeyValuePair<string, string> entry in ExtList)
foreach (var entry in ExtList)
{
extKey?.SetValue(entry.Key, entry.Value);
}

View File

@ -4,6 +4,7 @@ using System.Windows;
using MahApps.Metro.Controls;
using Wabbajack.Common;
using Application = System.Windows.Application;
using Utils = Wabbajack.Common.Utils;
namespace Wabbajack
{
@ -25,10 +26,18 @@ namespace Wabbajack
};
var appPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
if (!ExtensionManager.IsAssociated() || ExtensionManager.NeedsUpdating(appPath))
try
{
ExtensionManager.Associate(appPath);
if (!ExtensionManager.IsAssociated() || ExtensionManager.NeedsUpdating(appPath))
{
ExtensionManager.Associate(appPath);
}
}
catch (Exception e)
{
Utils.Log($"ExtensionManager had an exception:\n{e}");
}
Wabbajack.Common.Utils.Log($"Wabbajack Build - {ThisAssembly.Git.Sha}");