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.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 { }
}
/// <summary>
/// add an item to the W7+ jumplist
/// </summary>
/// <param name="fullpath">fully qualified path, can include '|' character for archives</param>
public static void AddRecentItem(string fullpath, string title)
/// <param name="fullPath">fully qualified path, can include '|' character for archives</param>
/// <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
{
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 { }
}
}
}

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/=INTV/@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/=keepalives/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=KEYMENU/@EntryIndexedValue">True</s:Boolean>