cleanup JumpLists.cs

This commit is contained in:
adelikat 2019-12-21 09:05:11 -06:00
parent e06799ce38
commit c42889ceef
2 changed files with 32 additions and 28 deletions

View File

@ -1,7 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
@ -9,54 +6,60 @@ namespace BizHawk.Client.EmuHawk
{ {
public class JumpLists public class JumpLists
{ {
static readonly Assembly PresentationFramework; private static readonly Type JumpList;
static Type Application; private static readonly Type JumpTask;
static Type JumpList;
static Type JumpTask;
static object _app;
static JumpLists() static JumpLists()
{ {
try try
{ {
PresentationFramework = Assembly.Load("PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); var presentationFramework =
Application = PresentationFramework.GetType("System.Windows.Application"); Assembly.Load(
JumpList = PresentationFramework.GetType("System.Windows.Shell.JumpList"); "PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
JumpTask = PresentationFramework.GetType("System.Windows.Shell.JumpTask"); var application = presentationFramework.GetType("System.Windows.Application");
_app = Activator.CreateInstance(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); dynamic jmp = Activator.CreateInstance(JumpList);
jmp.ShowRecentCategory = true; jmp.ShowRecentCategory = true;
JumpList.GetMethod("SetJumpList").Invoke(null, new[] { _app, jmp }); JumpList
.GetMethod("SetJumpList")
?.Invoke(null, new[] {app, jmp});
}
catch
{
// Do nothing
} }
catch { }
} }
/// <summary> /// <summary>
/// add an item to the W7+ jumplist /// add an item to the W7+ jumplist
/// </summary> /// </summary>
/// <param name="fullpath">fully qualified path, can include '|' character for archives</param> /// <param name="fullPath">fully qualified path, can include '|' character for archives</param>
public static void AddRecentItem(string fullpath, string title) /// <param name="title">The text displayed in the jumplist entry</param>
public static void AddRecentItem(string fullPath, string title)
{ {
//string title;
//if (fullpath.Contains('|'))
// title = fullpath.Split('|')[1];
//else
// title = Path.GetFileName(fullpath);
try try
{ {
string exepath = Assembly.GetEntryAssembly().Location; string execPath = Assembly.GetEntryAssembly()
?.Location;
dynamic ji = Activator.CreateInstance(JumpTask); dynamic ji = Activator.CreateInstance(JumpTask);
ji.ApplicationPath = exepath; ji.ApplicationPath = execPath;
ji.Arguments = $"\"{fullpath}\""; ji.Arguments = $"\"{fullPath}\"";
ji.Title = title; ji.Title = title;
// for some reason, this doesn't work // 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 { }
} }
} }
} }

View File

@ -261,6 +261,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=ints/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=ints/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=INTV/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=INTV/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Joypad/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Joypad/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=jumplist/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Justifier/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Justifier/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=keepalives/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=keepalives/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=KEYMENU/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=KEYMENU/@EntryIndexedValue">True</s:Boolean>