Register .sxie extension for ShareX image effects

This commit is contained in:
Jaex 2020-06-15 07:53:20 +03:00
parent cd052ea783
commit 6567f852e6
3 changed files with 82 additions and 9 deletions

View file

@ -315,13 +315,6 @@ public void UpdateControls()
InitHotkeys(); InitHotkeys();
#if !WindowsStore
if (!Program.Portable && !IntegrationHelpers.CheckCustomUploaderExtension())
{
IntegrationHelpers.CreateCustomUploaderExtension(true);
}
#endif
IsReady = true; IsReady = true;
} }

View file

@ -62,6 +62,15 @@ public static class IntegrationHelpers
private static readonly string ShellCustomUploaderCommandPath = $@"{ShellCustomUploaderAssociatePath}\shell\open\command"; private static readonly string ShellCustomUploaderCommandPath = $@"{ShellCustomUploaderAssociatePath}\shell\open\command";
private static readonly string ShellCustomUploaderCommandValue = $"{ApplicationPath} -CustomUploader \"%1\""; 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 ChromeNativeMessagingHosts = @"SOFTWARE\Google\Chrome\NativeMessagingHosts\com.getsharex.sharex";
private static readonly string FirefoxNativeMessagingHosts = @"SOFTWARE\Mozilla\NativeMessagingHosts\ShareX"; private static readonly string FirefoxNativeMessagingHosts = @"SOFTWARE\Mozilla\NativeMessagingHosts\ShareX";
@ -214,6 +223,57 @@ private static void UnregisterCustomUploaderExtension()
RegistryHelpers.RemoveRegistry(ShellCustomUploaderAssociatePath, true); 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() public static bool CheckChromeExtensionSupport()
{ {
try try
@ -401,6 +461,7 @@ public static void Uninstall()
CreateShellContextMenuButton(false); CreateShellContextMenuButton(false);
CreateEditShellContextMenuButton(false); CreateEditShellContextMenuButton(false);
CreateCustomUploaderExtension(false); CreateCustomUploaderExtension(false);
CreateImageEffectExtension(false);
CreateSendToMenuButton(false); CreateSendToMenuButton(false);
} }
} }

View file

@ -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 if (CheckAdminTasks()) return; // If ShareX opened just for be able to execute task as Admin
UpdatePersonalPath(); UpdatePersonalPath();
CreateParentFolders();
DebugHelper.Init(LogsFilePath); DebugHelper.Init(LogsFilePath);
@ -317,6 +316,8 @@ private static void Run()
IgnoreHotkeyWarning = CLI.IsCommandExist("NoHotkeys"); IgnoreHotkeyWarning = CLI.IsCommandExist("NoHotkeys");
CreateParentFolders();
RegisterExtensions();
CheckPuushMode(); CheckPuushMode();
DebugWriteFlags(); DebugWriteFlags();
CleanTempFiles(); CleanTempFiles();
@ -474,7 +475,7 @@ private static void UpdatePersonalPath()
private static void CreateParentFolders() private static void CreateParentFolders()
{ {
if (Directory.Exists(PersonalFolder)) if (!Sandbox && Directory.Exists(PersonalFolder))
{ {
Helpers.CreateDirectory(SettingManager.BackupFolder); Helpers.CreateDirectory(SettingManager.BackupFolder);
Helpers.CreateDirectory(ImageEffectsFolder); 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() private static void MigratePersonalPathConfig()
{ {
if (File.Exists(PreviousPersonalPathConfigFilePath)) if (File.Exists(PreviousPersonalPathConfigFilePath))