Files

108 lines
5.1 KiB
C#
Raw Permalink Normal View History

2025-12-19 17:31:03 -07:00
using Microsoft.Win32;
2025-04-13 15:18:03 -06:00
using Repackinator.Core.Helpers;
2022-11-27 21:50:42 -08:00
2025-12-19 17:31:03 -07:00
namespace Repackinator.Shell.Shell
2022-11-27 21:50:42 -08:00
{
2022-12-03 17:37:25 -08:00
public class ContextMenu
2022-11-27 21:50:42 -08:00
{
2025-12-19 17:54:45 -07:00
private static void RegisterSubMenu(RegistryKey key, string name, string description, string command, string iconPath)
2022-11-27 21:50:42 -08:00
{
2025-11-22 17:30:18 -08:00
if (OperatingSystem.IsWindows() && Utility.IsAdmin())
2022-11-27 21:50:42 -08:00
{
2025-11-22 17:30:18 -08:00
var menu1Key = key.CreateSubKey($"shell\\{name}");
menu1Key.SetValue("MUIVerb", description);
2025-12-19 17:54:45 -07:00
menu1Key.SetValue("Icon", $"{iconPath},0");
2025-11-22 17:30:18 -08:00
var commandMenu1Key = menu1Key.CreateSubKey("command");
commandMenu1Key.SetValue(null, command);
2022-11-27 21:50:42 -08:00
}
}
2023-01-04 21:08:49 -08:00
public static bool RegisterContext()
2022-11-27 21:50:42 -08:00
{
2025-11-22 17:30:18 -08:00
if (OperatingSystem.IsWindows() && Utility.IsAdmin())
2022-11-27 21:50:42 -08:00
{
2025-12-19 17:54:45 -07:00
// Always unregister first to clear old menus
UnregisterContext();
2025-12-19 16:33:29 -07:00
// Use shell executable for command-line actions
var baseDir = AppDomain.CurrentDomain.BaseDirectory;
var shellExePath = Path.Combine(baseDir, "repackinator.shell.exe");
// Fallback to main exe if shell doesn't exist (for backwards compatibility)
var exePath = File.Exists(shellExePath) ? shellExePath : Path.Combine(baseDir, $"{AppDomain.CurrentDomain.FriendlyName}.exe");
2025-12-19 15:58:45 -07:00
2025-11-22 17:30:18 -08:00
using var key = Registry.ClassesRoot.CreateSubKey($"*\\shell\\Repackinator");
key.SetValue("AppliesTo", ".iso OR .cci");
key.SetValue("MUIVerb", "Repackinator");
key.SetValue("SubCommands", string.Empty);
2025-12-19 17:54:45 -07:00
key.SetValue("Icon", $"{exePath},0");
2025-12-19 17:31:03 -07:00
key.SetValue("Version", Core.Version.Value);
2025-11-22 17:30:18 -08:00
2025-12-19 16:33:29 -07:00
// Convert to ISO options
2025-12-19 17:54:45 -07:00
RegisterSubMenu(key, "01ConvertToISO", "Convert to ISO", $"\"{exePath}\" -a=convert -i \"%L\" -w", exePath);
RegisterSubMenu(key, "02ConvertToISOScrub", "Convert to ISO (Scrub)", $"\"{exePath}\" -a=convert -i \"%L\" -s -w", exePath);
RegisterSubMenu(key, "03ConvertToISOTrimScrub", "Convert to ISO (TrimScrub)", $"\"{exePath}\" -a=convert -i \"%L\" -t -w", exePath);
2025-11-22 17:30:18 -08:00
2025-12-19 16:33:29 -07:00
// Convert to CCI options
2025-12-19 17:54:45 -07:00
RegisterSubMenu(key, "04ConvertToCCI", "Convert to CCI", $"\"{exePath}\" -a=convert -i \"%L\" -c -w", exePath);
RegisterSubMenu(key, "05ConvertToCCIScrub", "Convert to CCI (Scrub)", $"\"{exePath}\" -a=convert -i \"%L\" -s -c -w", exePath);
RegisterSubMenu(key, "06ConvertToCCITrimScrub", "Convert to CCI (TrimScrub)", $"\"{exePath}\" -a=convert -i \"%L\" -t -c -w", exePath);
2025-12-19 17:31:03 -07:00
2025-12-19 16:33:29 -07:00
// Information and extraction options
2025-12-19 17:54:45 -07:00
RegisterSubMenu(key, "07XbeInfo", "XBE Info", $"\"{exePath}\" -a=xbeinfo -i \"%L\" -w", exePath);
RegisterSubMenu(key, "08Info", "Sector Info", $"\"{exePath}\" -a=info -i \"%L\" -w", exePath);
RegisterSubMenu(key, "09Checksum", "Checksum (SHA256)", $"\"{exePath}\" -a=checksum -i \"%L\" -w", exePath);
RegisterSubMenu(key, "10Extract", "Extract Files", $"\"{exePath}\" -a=extract -i \"%L\" -w", exePath);
2025-12-19 16:33:29 -07:00
// Compare options
2025-12-19 17:54:45 -07:00
RegisterSubMenu(key, "11CompareSetFirst", "Compare - Set First", $"\"{exePath}\" -a=compare -f \"%L\"", exePath);
RegisterSubMenu(key, "12CompareFirstWith", "Compare - First With This", $"\"{exePath}\" -a=compare -s \"%L\" -c -w", exePath);
2025-11-22 17:30:18 -08:00
2025-12-19 15:58:45 -07:00
// Register context menu for folders (Directory)
2025-12-19 17:54:45 -07:00
// (UnregisterFolderContext was already called by UnregisterContext above)
2025-12-19 15:58:45 -07:00
using var dirKey = Registry.ClassesRoot.CreateSubKey($"Directory\\shell\\Repackinator");
dirKey.SetValue("MUIVerb", "Repackinator");
dirKey.SetValue("SubCommands", string.Empty);
2025-12-19 17:54:45 -07:00
dirKey.SetValue("Icon", $"{exePath},0");
2025-12-19 17:31:03 -07:00
dirKey.SetValue("Version", Core.Version.Value);
2025-12-19 15:58:45 -07:00
// Pack To ISO - output will be in parent directory with folder name
2025-12-19 17:54:45 -07:00
RegisterSubMenu(dirKey, "01PackToISO", "Pack To ISO", $"\"{exePath}\" -a=pack -i \"%1\" -o \"%1.iso\" -w", exePath);
2025-12-19 15:58:45 -07:00
// Pack To CCI - output will be in parent directory with folder name
2025-12-19 17:54:45 -07:00
RegisterSubMenu(dirKey, "02PackToCCI", "Pack To CCI", $"\"{exePath}\" -a=pack -i \"%1\" -o \"%1.cci\" -c -w", exePath);
2025-12-19 15:58:45 -07:00
2025-11-22 17:30:18 -08:00
return true;
2022-11-27 21:50:42 -08:00
}
2025-11-22 17:30:18 -08:00
return false;
2022-11-27 21:50:42 -08:00
}
2022-11-28 14:49:05 -08:00
public static bool UnregisterContext()
2022-11-27 21:50:42 -08:00
{
2025-11-22 17:30:18 -08:00
if (OperatingSystem.IsWindows() && Utility.IsAdmin())
2022-11-27 21:50:42 -08:00
{
2025-11-22 17:30:18 -08:00
Registry.ClassesRoot.DeleteSubKeyTree("*\\shell\\Repackinator", false);
2025-12-19 15:58:45 -07:00
UnregisterFolderContext();
return true;
}
return false;
}
private static bool UnregisterFolderContext()
{
if (OperatingSystem.IsWindows() && Utility.IsAdmin())
{
Registry.ClassesRoot.DeleteSubKeyTree("Directory\\shell\\Repackinator", false);
2025-11-22 17:30:18 -08:00
return true;
2022-11-27 21:50:42 -08:00
}
2025-11-22 17:30:18 -08:00
return false;
2022-11-27 21:50:42 -08:00
}
}
}
2025-12-19 17:31:03 -07:00