BizHawk/BizHawk.Client.EmuHawk/JumpLists.cs

66 lines
1.7 KiB
C#
Raw Normal View History

2013-12-13 04:57:14 +00:00
using System;
using System.IO;
using System.Reflection;
namespace BizHawk.Client.EmuHawk
{
public class JumpLists
{
2019-12-21 15:05:11 +00:00
private static readonly Type JumpList;
private static readonly Type JumpTask;
2013-12-13 04:57:14 +00:00
static JumpLists()
{
try
{
2019-12-21 15:05:11 +00:00
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;
2019-12-21 15:05:11 +00:00
JumpList
.GetMethod("SetJumpList")
?.Invoke(null, new[] {app, jmp});
}
catch
{
// Do nothing
}
2013-12-13 04:57:14 +00:00
}
/// <summary>
/// add an item to the W7+ jumplist
/// </summary>
2019-12-21 15:05:11 +00:00
/// <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)
2013-12-13 04:57:14 +00:00
{
try
{
2019-12-21 15:05:11 +00:00
string execPath = Assembly.GetEntryAssembly()
?.Location;
2013-12-13 04:57:14 +00:00
dynamic ji = Activator.CreateInstance(JumpTask);
2013-12-13 04:57:14 +00:00
2019-12-21 15:05:11 +00:00
ji.ApplicationPath = execPath;
ji.Arguments = $"\"{fullPath}\"";
ji.Title = title;
2013-12-13 04:57:14 +00:00
// for some reason, this doesn't work
2019-12-21 15:05:11 +00:00
ji.WorkingDirectory = Path.GetDirectoryName(execPath);
2019-12-21 15:05:11 +00:00
JumpList
.GetMethod("AddToRecentCategory", new[] {JumpTask})
?.Invoke(null, new[] {ji});
}
catch
{
// Do nothing
}
2013-12-13 04:57:14 +00:00
}
}
}