2017-02-26 19:23:31 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Windows.Forms;
|
2020-04-23 08:16:16 +00:00
|
|
|
|
using HeliosPlus.Shared;
|
|
|
|
|
using HeliosPlus.ShellExtension.Resources;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
using SharpShell.Attributes;
|
|
|
|
|
using SharpShell.SharpContextMenu;
|
|
|
|
|
|
2020-04-23 08:16:16 +00:00
|
|
|
|
namespace HeliosPlus.ShellExtension
|
2017-02-26 19:23:31 +00:00
|
|
|
|
{
|
|
|
|
|
[ComVisible(true)]
|
|
|
|
|
[COMServerAssociation(AssociationType.ClassOfExtension, @".url")]
|
2019-01-17 17:15:43 +00:00
|
|
|
|
[Guid("E41ECFB2-3E7D-4A47-8A51-8627F1B21AE5")]
|
2017-02-26 19:23:31 +00:00
|
|
|
|
internal class HeliosSteamUrlMenuExtension : SharpContextMenu
|
|
|
|
|
{
|
|
|
|
|
protected override bool CanShowMenu()
|
|
|
|
|
{
|
2017-08-10 14:21:45 +00:00
|
|
|
|
return Helios.IsInstalled &&
|
2018-10-20 00:27:25 +00:00
|
|
|
|
SelectedItemPaths.Count() == 1 &&
|
2020-06-07 08:48:45 +00:00
|
|
|
|
ProfileItem.LoadAllProfiles().Any() &&
|
2018-10-20 00:27:25 +00:00
|
|
|
|
ParseSteamAppId() > 0;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override ContextMenuStrip CreateMenu()
|
|
|
|
|
{
|
|
|
|
|
var explorerMenu = new ContextMenuStrip();
|
|
|
|
|
var extensionMenu = new ToolStripMenuItem(Language.Open_under_Display_Profile,
|
2017-08-07 16:25:34 +00:00
|
|
|
|
Properties.Resources.Icon_x16);
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2020-06-07 08:48:45 +00:00
|
|
|
|
if (ProfileItem.LoadAllProfiles().Any())
|
2018-10-20 00:22:48 +00:00
|
|
|
|
{
|
2020-06-07 08:48:45 +00:00
|
|
|
|
ProfileItem.UpdateCurrentProfile();
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2020-06-07 08:48:45 +00:00
|
|
|
|
foreach (var profile in ProfileItem.LoadAllProfiles())
|
2018-10-20 00:27:25 +00:00
|
|
|
|
{
|
2018-10-20 00:22:48 +00:00
|
|
|
|
extensionMenu.DropDownItems.Add(CreateProfileMenu(profile));
|
2018-10-20 00:27:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-20 00:22:48 +00:00
|
|
|
|
extensionMenu.DropDownItems.Add(new ToolStripSeparator());
|
|
|
|
|
}
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
extensionMenu.DropDownItems.Add(new ToolStripMenuItem(Language.Manage_Profiles,
|
2017-08-07 16:25:34 +00:00
|
|
|
|
Properties.Resources.Icon_x16,
|
2018-10-20 00:27:25 +00:00
|
|
|
|
(sender, args) =>
|
|
|
|
|
{
|
2020-04-29 10:29:43 +00:00
|
|
|
|
HeliosPlus.Open();
|
2018-10-20 00:27:25 +00:00
|
|
|
|
}));
|
2017-02-26 19:23:31 +00:00
|
|
|
|
explorerMenu.Items.Add(extensionMenu);
|
|
|
|
|
explorerMenu.Items.Add(new ToolStripSeparator());
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
return explorerMenu;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 08:48:45 +00:00
|
|
|
|
private ToolStripMenuItem CreateProfileMenu(ProfileItem profile)
|
2017-02-26 19:23:31 +00:00
|
|
|
|
{
|
|
|
|
|
var appId = ParseSteamAppId();
|
|
|
|
|
var profileMenu = new ToolStripMenuItem(profile.Name, new ProfileIcon(profile).ToBitmap(16, 16));
|
2018-10-23 23:38:35 +00:00
|
|
|
|
profileMenu.DropDownItems.Add(new ToolStripMenuItem(Language.Run, null,
|
2017-02-26 19:23:31 +00:00
|
|
|
|
(sender, args) =>
|
2020-04-29 10:29:43 +00:00
|
|
|
|
HeliosPlus.OpenSteamGame(HeliosStartupAction.SwitchProfile, profile,
|
2017-02-26 19:23:31 +00:00
|
|
|
|
appId)));
|
|
|
|
|
profileMenu.DropDownItems.Add(new ToolStripSeparator());
|
2018-10-23 23:38:35 +00:00
|
|
|
|
profileMenu.DropDownItems.Add(new ToolStripMenuItem(Language.Create_Shortcut, null,
|
2017-02-26 19:23:31 +00:00
|
|
|
|
(sender, args) =>
|
2020-04-29 10:29:43 +00:00
|
|
|
|
HeliosPlus.OpenSteamGame(HeliosStartupAction.CreateShortcut, profile,
|
2017-02-26 19:23:31 +00:00
|
|
|
|
appId)));
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
return profileMenu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private uint ParseSteamAppId()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var fileAddress = SelectedItemPaths.FirstOrDefault();
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(fileAddress) &&
|
|
|
|
|
File.Exists(fileAddress) &&
|
|
|
|
|
new FileInfo(fileAddress).Length < 1024)
|
2017-02-26 19:23:31 +00:00
|
|
|
|
{
|
|
|
|
|
var fileContent = File.ReadAllText(fileAddress);
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
if (!fileContent.Contains(@"[InternetShortcut]"))
|
2018-10-20 00:27:25 +00:00
|
|
|
|
{
|
2017-02-26 19:23:31 +00:00
|
|
|
|
return 0;
|
2018-10-20 00:27:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
var steamUrlPattern = @"steam://rungameid/";
|
|
|
|
|
var urlIndex = fileContent.IndexOf(steamUrlPattern, StringComparison.InvariantCultureIgnoreCase);
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
if (urlIndex < 0)
|
2018-10-20 00:27:25 +00:00
|
|
|
|
{
|
2017-02-26 19:23:31 +00:00
|
|
|
|
return 0;
|
2018-10-20 00:27:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
var nextLine = fileContent.IndexOf(@"\r", urlIndex + steamUrlPattern.Length,
|
|
|
|
|
StringComparison.InvariantCultureIgnoreCase);
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
if (nextLine < 0)
|
2018-10-20 00:27:25 +00:00
|
|
|
|
{
|
2017-02-26 19:23:31 +00:00
|
|
|
|
nextLine = fileContent.Length - 1;
|
2018-10-20 00:27:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
var appIdString = fileContent.Substring(urlIndex + steamUrlPattern.Length,
|
|
|
|
|
nextLine - urlIndex - steamUrlPattern.Length);
|
|
|
|
|
uint appId;
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
if (uint.TryParse(appIdString, out appId))
|
2018-10-20 00:27:25 +00:00
|
|
|
|
{
|
2017-02-26 19:23:31 +00:00
|
|
|
|
return appId;
|
2018-10-20 00:27:25 +00:00
|
|
|
|
}
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|