From c42889ceef942956cf064cafa958f90bbf15dfdb Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 21 Dec 2019 09:05:11 -0600 Subject: [PATCH] cleanup JumpLists.cs --- BizHawk.Client.EmuHawk/JumpLists.cs | 59 +++++++++++++++-------------- BizHawk.sln.DotSettings | 1 + 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/BizHawk.Client.EmuHawk/JumpLists.cs b/BizHawk.Client.EmuHawk/JumpLists.cs index d36aabdb3f..d13c3caae7 100644 --- a/BizHawk.Client.EmuHawk/JumpLists.cs +++ b/BizHawk.Client.EmuHawk/JumpLists.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.IO; using System.Reflection; @@ -9,54 +6,60 @@ namespace BizHawk.Client.EmuHawk { public class JumpLists { - static readonly Assembly PresentationFramework; - static Type Application; - static Type JumpList; - static Type JumpTask; + private static readonly Type JumpList; + private static readonly Type JumpTask; - static object _app; static JumpLists() { try { - PresentationFramework = Assembly.Load("PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - Application = PresentationFramework.GetType("System.Windows.Application"); - JumpList = PresentationFramework.GetType("System.Windows.Shell.JumpList"); - JumpTask = PresentationFramework.GetType("System.Windows.Shell.JumpTask"); - _app = Activator.CreateInstance(Application); + var presentationFramework = + Assembly.Load( + "PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + var application = presentationFramework.GetType("System.Windows.Application"); + JumpList = presentationFramework.GetType("System.Windows.Shell.JumpList"); + JumpTask = presentationFramework.GetType("System.Windows.Shell.JumpTask"); + var app = Activator.CreateInstance(application); dynamic jmp = Activator.CreateInstance(JumpList); jmp.ShowRecentCategory = true; - JumpList.GetMethod("SetJumpList").Invoke(null, new[] { _app, jmp }); + JumpList + .GetMethod("SetJumpList") + ?.Invoke(null, new[] {app, jmp}); + } + catch + { + // Do nothing } - catch { } } /// /// add an item to the W7+ jumplist /// - /// fully qualified path, can include '|' character for archives - public static void AddRecentItem(string fullpath, string title) + /// fully qualified path, can include '|' character for archives + /// The text displayed in the jumplist entry + public static void AddRecentItem(string fullPath, string title) { - //string title; - //if (fullpath.Contains('|')) - // title = fullpath.Split('|')[1]; - //else - // title = Path.GetFileName(fullpath); try { - string exepath = Assembly.GetEntryAssembly().Location; + string execPath = Assembly.GetEntryAssembly() + ?.Location; dynamic ji = Activator.CreateInstance(JumpTask); - ji.ApplicationPath = exepath; - ji.Arguments = $"\"{fullpath}\""; + ji.ApplicationPath = execPath; + ji.Arguments = $"\"{fullPath}\""; ji.Title = title; // for some reason, this doesn't work - ji.WorkingDirectory = Path.GetDirectoryName(exepath); + ji.WorkingDirectory = Path.GetDirectoryName(execPath); - JumpList.GetMethod("AddToRecentCategory", new[] { JumpTask }).Invoke(null, new[] { ji }); + JumpList + .GetMethod("AddToRecentCategory", new[] {JumpTask}) + ?.Invoke(null, new[] {ji}); + } + catch + { + // Do nothing } - catch { } } } } diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index 4db542a120..74cfaee202 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -261,6 +261,7 @@ True True True + True True True True