mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-29 17:02:05 +13:00
Register .sxie extension for ShareX image effects
This commit is contained in:
parent
cd052ea783
commit
6567f852e6
3 changed files with 82 additions and 9 deletions
|
@ -315,13 +315,6 @@ public void UpdateControls()
|
|||
|
||||
InitHotkeys();
|
||||
|
||||
#if !WindowsStore
|
||||
if (!Program.Portable && !IntegrationHelpers.CheckCustomUploaderExtension())
|
||||
{
|
||||
IntegrationHelpers.CreateCustomUploaderExtension(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
IsReady = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,15 @@ public static class IntegrationHelpers
|
|||
private static readonly string ShellCustomUploaderCommandPath = $@"{ShellCustomUploaderAssociatePath}\shell\open\command";
|
||||
private static readonly string ShellCustomUploaderCommandValue = $"{ApplicationPath} -CustomUploader \"%1\"";
|
||||
|
||||
private static readonly string ShellImageEffectExtensionPath = @"Software\Classes\.sxie";
|
||||
private static readonly string ShellImageEffectExtensionValue = "ShareX.sxie";
|
||||
private static readonly string ShellImageEffectAssociatePath = $@"Software\Classes\{ShellImageEffectExtensionValue}";
|
||||
private static readonly string ShellImageEffectAssociateValue = "ShareX image effect";
|
||||
private static readonly string ShellImageEffectIconPath = $@"{ShellImageEffectAssociatePath}\DefaultIcon";
|
||||
private static readonly string ShellImageEffectIconValue = $"{ApplicationPath},0";
|
||||
private static readonly string ShellImageEffectCommandPath = $@"{ShellImageEffectAssociatePath}\shell\open\command";
|
||||
private static readonly string ShellImageEffectCommandValue = $"{ApplicationPath} -ImageEffect \"%1\"";
|
||||
|
||||
private static readonly string ChromeNativeMessagingHosts = @"SOFTWARE\Google\Chrome\NativeMessagingHosts\com.getsharex.sharex";
|
||||
private static readonly string FirefoxNativeMessagingHosts = @"SOFTWARE\Mozilla\NativeMessagingHosts\ShareX";
|
||||
|
||||
|
@ -214,6 +223,57 @@ private static void UnregisterCustomUploaderExtension()
|
|||
RegistryHelpers.RemoveRegistry(ShellCustomUploaderAssociatePath, true);
|
||||
}
|
||||
|
||||
public static bool CheckImageEffectExtension()
|
||||
{
|
||||
try
|
||||
{
|
||||
return RegistryHelpers.CheckRegistry(ShellImageEffectExtensionPath, null, ShellImageEffectExtensionValue) &&
|
||||
RegistryHelpers.CheckRegistry(ShellImageEffectCommandPath, null, ShellImageEffectCommandValue);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugHelper.WriteException(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void CreateImageEffectExtension(bool create)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (create)
|
||||
{
|
||||
UnregisterImageEffectExtension();
|
||||
RegisterImageEffectExtension();
|
||||
}
|
||||
else
|
||||
{
|
||||
UnregisterImageEffectExtension();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugHelper.WriteException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void RegisterImageEffectExtension()
|
||||
{
|
||||
RegistryHelpers.CreateRegistry(ShellImageEffectExtensionPath, ShellImageEffectExtensionValue);
|
||||
RegistryHelpers.CreateRegistry(ShellImageEffectAssociatePath, ShellImageEffectAssociateValue);
|
||||
RegistryHelpers.CreateRegistry(ShellImageEffectIconPath, ShellImageEffectIconValue);
|
||||
RegistryHelpers.CreateRegistry(ShellImageEffectCommandPath, ShellImageEffectCommandValue);
|
||||
|
||||
NativeMethods.SHChangeNotify(HChangeNotifyEventID.SHCNE_ASSOCCHANGED, HChangeNotifyFlags.SHCNF_FLUSH, IntPtr.Zero, IntPtr.Zero);
|
||||
}
|
||||
|
||||
private static void UnregisterImageEffectExtension()
|
||||
{
|
||||
RegistryHelpers.RemoveRegistry(ShellImageEffectExtensionPath);
|
||||
RegistryHelpers.RemoveRegistry(ShellImageEffectAssociatePath, true);
|
||||
}
|
||||
|
||||
public static bool CheckChromeExtensionSupport()
|
||||
{
|
||||
try
|
||||
|
@ -401,6 +461,7 @@ public static void Uninstall()
|
|||
CreateShellContextMenuButton(false);
|
||||
CreateEditShellContextMenuButton(false);
|
||||
CreateCustomUploaderExtension(false);
|
||||
CreateImageEffectExtension(false);
|
||||
CreateSendToMenuButton(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -271,7 +271,6 @@ private static void Main(string[] args)
|
|||
if (CheckAdminTasks()) return; // If ShareX opened just for be able to execute task as Admin
|
||||
|
||||
UpdatePersonalPath();
|
||||
CreateParentFolders();
|
||||
|
||||
DebugHelper.Init(LogsFilePath);
|
||||
|
||||
|
@ -317,6 +316,8 @@ private static void Run()
|
|||
|
||||
IgnoreHotkeyWarning = CLI.IsCommandExist("NoHotkeys");
|
||||
|
||||
CreateParentFolders();
|
||||
RegisterExtensions();
|
||||
CheckPuushMode();
|
||||
DebugWriteFlags();
|
||||
CleanTempFiles();
|
||||
|
@ -474,7 +475,7 @@ private static void UpdatePersonalPath()
|
|||
|
||||
private static void CreateParentFolders()
|
||||
{
|
||||
if (Directory.Exists(PersonalFolder))
|
||||
if (!Sandbox && Directory.Exists(PersonalFolder))
|
||||
{
|
||||
Helpers.CreateDirectory(SettingManager.BackupFolder);
|
||||
Helpers.CreateDirectory(ImageEffectsFolder);
|
||||
|
@ -484,6 +485,24 @@ private static void CreateParentFolders()
|
|||
}
|
||||
}
|
||||
|
||||
private static void RegisterExtensions()
|
||||
{
|
||||
#if !WindowsStore
|
||||
if (!Portable)
|
||||
{
|
||||
if (!IntegrationHelpers.CheckCustomUploaderExtension())
|
||||
{
|
||||
IntegrationHelpers.CreateCustomUploaderExtension(true);
|
||||
}
|
||||
|
||||
if (!IntegrationHelpers.CheckImageEffectExtension())
|
||||
{
|
||||
IntegrationHelpers.CreateImageEffectExtension(true);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void MigratePersonalPathConfig()
|
||||
{
|
||||
if (File.Exists(PreviousPersonalPathConfigFilePath))
|
||||
|
|
Loading…
Reference in a new issue