Merge pull request #271 from erri120/steam-fixes

SteamHandler and ExceptionManager fixes
This commit is contained in:
Timothy Baldridge 2019-12-14 16:01:48 -07:00 committed by GitHub
commit 38c2ad0aa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 14 deletions

View File

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

View File

@ -92,11 +92,13 @@ namespace Wabbajack.Common
if (!l.Contains("BaseInstallFolder_")) return; if (!l.Contains("BaseInstallFolder_")) return;
var s = GetVdfValue(l); var s = GetVdfValue(l);
s = Path.Combine(s, "steamapps"); s = Path.Combine(s, "steamapps");
paths.Add(s); if(Directory.Exists(s))
paths.Add(s);
}); });
// Default path in the Steam folder isn't in the configs // Default path in the Steam folder isn't in the configs
paths.Add(Path.Combine(SteamPath, "steamapps")); if(Directory.Exists(Path.Combine(SteamPath, "steamapps")))
paths.Add(Path.Combine(SteamPath, "steamapps"));
InstallFolders = paths; InstallFolders = paths;
} }
@ -111,7 +113,7 @@ namespace Wabbajack.Common
InstallFolders.Do(p => InstallFolders.Do(p =>
{ {
Directory.EnumerateFiles(p, "*.acf", SearchOption.TopDirectoryOnly).Do(f => Directory.EnumerateFiles(p, "*.acf", SearchOption.TopDirectoryOnly).Where(File.Exists).Do(f =>
{ {
var steamGame = new SteamGame(); var steamGame = new SteamGame();
var valid = false; var valid = false;
@ -122,8 +124,11 @@ namespace Wabbajack.Common
return; return;
if(l.Contains("\"name\"")) if(l.Contains("\"name\""))
steamGame.Name = GetVdfValue(l); steamGame.Name = GetVdfValue(l);
if(l.Contains("\"installdir\"")) if (l.Contains("\"installdir\""))
steamGame.InstallDir = Path.Combine(p, "common", GetVdfValue(l)); {
var path = Path.Combine(p, "common", GetVdfValue(l));
steamGame.InstallDir = Directory.Exists(path) ? path : null;
}
if (steamGame.AppId != 0 && !string.IsNullOrWhiteSpace(steamGame.Name) && if (steamGame.AppId != 0 && !string.IsNullOrWhiteSpace(steamGame.Name) &&
!string.IsNullOrWhiteSpace(steamGame.InstallDir)) !string.IsNullOrWhiteSpace(steamGame.InstallDir))
@ -157,7 +162,7 @@ namespace Wabbajack.Common
if(!Directory.Exists(workshop)) if(!Directory.Exists(workshop))
return; return;
Directory.EnumerateFiles(workshop, "*.acf", SearchOption.TopDirectoryOnly).Do(f => Directory.EnumerateFiles(workshop, "*.acf", SearchOption.TopDirectoryOnly).Where(File.Exists).Do(f =>
{ {
if (Path.GetFileName(f) != $"appworkshop_{game.AppId}.acf") if (Path.GetFileName(f) != $"appworkshop_{game.AppId}.acf")
return; return;

View File

@ -4,6 +4,7 @@ using System.Windows;
using MahApps.Metro.Controls; using MahApps.Metro.Controls;
using Wabbajack.Common; using Wabbajack.Common;
using Application = System.Windows.Application; using Application = System.Windows.Application;
using Utils = Wabbajack.Common.Utils;
namespace Wabbajack namespace Wabbajack
{ {
@ -25,10 +26,18 @@ namespace Wabbajack
}; };
var appPath = System.Reflection.Assembly.GetExecutingAssembly().Location; 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}"); Wabbajack.Common.Utils.Log($"Wabbajack Build - {ThisAssembly.Git.Sha}");