2015-09-11 12:45:40 +12:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2024-01-03 12:57:14 +13:00
|
|
|
|
Copyright (c) 2007-2024 ShareX Team
|
2015-09-11 12:45:40 +12:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
2017-02-11 04:06:12 +13:00
|
|
|
|
using Newtonsoft.Json;
|
2015-09-11 12:45:40 +12:00
|
|
|
|
using ShareX.HelpersLib;
|
|
|
|
|
using ShareX.Properties;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2017-02-11 04:06:12 +13:00
|
|
|
|
using System.Text;
|
2015-09-11 12:45:40 +12:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace ShareX
|
|
|
|
|
{
|
|
|
|
|
public static class IntegrationHelpers
|
|
|
|
|
{
|
2018-04-03 08:58:17 +12:00
|
|
|
|
private static readonly string ApplicationPath = $"\"{Application.ExecutablePath}\"";
|
2017-01-15 02:00:22 +13:00
|
|
|
|
|
2018-04-03 07:44:16 +12:00
|
|
|
|
private static readonly string ShellExtMenuName = "ShareX";
|
2018-04-03 08:58:17 +12:00
|
|
|
|
private static readonly string ShellExtMenuFiles = $@"Software\Classes\*\shell\{ShellExtMenuName}";
|
|
|
|
|
private static readonly string ShellExtMenuFilesCmd = $@"{ShellExtMenuFiles}\command";
|
|
|
|
|
private static readonly string ShellExtMenuDirectory = $@"Software\Classes\Directory\shell\{ShellExtMenuName}";
|
|
|
|
|
private static readonly string ShellExtMenuDirectoryCmd = $@"{ShellExtMenuDirectory}\command";
|
2017-06-16 10:57:39 +12:00
|
|
|
|
private static readonly string ShellExtDesc = Resources.IntegrationHelpers_UploadWithShareX;
|
2018-04-03 08:58:17 +12:00
|
|
|
|
private static readonly string ShellExtIcon = $"{ApplicationPath},0";
|
|
|
|
|
private static readonly string ShellExtPath = $"{ApplicationPath} \"%1\"";
|
2017-01-15 01:02:43 +13:00
|
|
|
|
|
2018-04-03 07:44:16 +12:00
|
|
|
|
private static readonly string ShellExtEditName = "ShareXImageEditor";
|
2018-04-03 08:58:17 +12:00
|
|
|
|
private static readonly string ShellExtEditImage = $@"Software\Classes\SystemFileAssociations\image\shell\{ShellExtEditName}";
|
|
|
|
|
private static readonly string ShellExtEditImageCmd = $@"{ShellExtEditImage}\command";
|
2018-05-13 15:19:16 +12:00
|
|
|
|
private static readonly string ShellExtEditDesc = Resources.IntegrationHelpers_EditWithShareX;
|
2018-04-03 08:58:17 +12:00
|
|
|
|
private static readonly string ShellExtEditIcon = $"{ApplicationPath},0";
|
|
|
|
|
private static readonly string ShellExtEditPath = $"{ApplicationPath} -ImageEditor \"%1\"";
|
2018-04-01 00:16:09 +13:00
|
|
|
|
|
2017-01-15 01:02:43 +13:00
|
|
|
|
private static readonly string ShellCustomUploaderExtensionPath = @"Software\Classes\.sxcu";
|
|
|
|
|
private static readonly string ShellCustomUploaderExtensionValue = "ShareX.sxcu";
|
2018-04-03 08:58:17 +12:00
|
|
|
|
private static readonly string ShellCustomUploaderAssociatePath = $@"Software\Classes\{ShellCustomUploaderExtensionValue}";
|
2017-01-15 01:02:43 +13:00
|
|
|
|
private static readonly string ShellCustomUploaderAssociateValue = "ShareX custom uploader";
|
2018-04-03 08:58:17 +12:00
|
|
|
|
private static readonly string ShellCustomUploaderIconPath = $@"{ShellCustomUploaderAssociatePath}\DefaultIcon";
|
|
|
|
|
private static readonly string ShellCustomUploaderIconValue = $"{ApplicationPath},0";
|
|
|
|
|
private static readonly string ShellCustomUploaderCommandPath = $@"{ShellCustomUploaderAssociatePath}\shell\open\command";
|
|
|
|
|
private static readonly string ShellCustomUploaderCommandValue = $"{ApplicationPath} -CustomUploader \"%1\"";
|
2017-01-15 01:02:43 +13:00
|
|
|
|
|
2020-07-06 11:23:59 +12:00
|
|
|
|
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\"";
|
|
|
|
|
|
2017-01-15 01:02:43 +13:00
|
|
|
|
private static readonly string ChromeNativeMessagingHosts = @"SOFTWARE\Google\Chrome\NativeMessagingHosts\com.getsharex.sharex";
|
2017-02-11 04:24:20 +13:00
|
|
|
|
private static readonly string FirefoxNativeMessagingHosts = @"SOFTWARE\Mozilla\NativeMessagingHosts\ShareX";
|
2017-01-15 01:02:43 +13:00
|
|
|
|
|
2015-09-11 13:18:12 +12:00
|
|
|
|
public static bool CheckShellContextMenuButton()
|
|
|
|
|
{
|
2017-01-15 01:02:43 +13:00
|
|
|
|
try
|
|
|
|
|
{
|
2021-10-13 00:04:20 +13:00
|
|
|
|
return RegistryHelpers.CheckStringValue(ShellExtMenuFilesCmd, null, ShellExtPath) &&
|
|
|
|
|
RegistryHelpers.CheckStringValue(ShellExtMenuDirectoryCmd, null, ShellExtPath);
|
2017-01-15 01:02:43 +13:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.WriteException(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2015-09-11 13:18:12 +12:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-11 12:45:40 +12:00
|
|
|
|
public static void CreateShellContextMenuButton(bool create)
|
|
|
|
|
{
|
2017-01-15 01:02:43 +13:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (create)
|
|
|
|
|
{
|
|
|
|
|
UnregisterShellContextMenuButton();
|
|
|
|
|
RegisterShellContextMenuButton();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UnregisterShellContextMenuButton();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.WriteException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void RegisterShellContextMenuButton()
|
|
|
|
|
{
|
|
|
|
|
RegistryHelpers.CreateRegistry(ShellExtMenuFiles, ShellExtDesc);
|
|
|
|
|
RegistryHelpers.CreateRegistry(ShellExtMenuFiles, "Icon", ShellExtIcon);
|
|
|
|
|
RegistryHelpers.CreateRegistry(ShellExtMenuFilesCmd, ShellExtPath);
|
|
|
|
|
|
|
|
|
|
RegistryHelpers.CreateRegistry(ShellExtMenuDirectory, ShellExtDesc);
|
|
|
|
|
RegistryHelpers.CreateRegistry(ShellExtMenuDirectory, "Icon", ShellExtIcon);
|
|
|
|
|
RegistryHelpers.CreateRegistry(ShellExtMenuDirectoryCmd, ShellExtPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void UnregisterShellContextMenuButton()
|
|
|
|
|
{
|
|
|
|
|
RegistryHelpers.RemoveRegistry(ShellExtMenuFiles, true);
|
|
|
|
|
RegistryHelpers.RemoveRegistry(ShellExtMenuDirectory, true);
|
2015-09-11 12:45:40 +12:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-01 00:16:09 +13:00
|
|
|
|
public static bool CheckEditShellContextMenuButton()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-10-13 00:04:20 +13:00
|
|
|
|
return RegistryHelpers.CheckStringValue(ShellExtEditImageCmd, null, ShellExtEditPath);
|
2018-04-01 00:16:09 +13:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.WriteException(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void CreateEditShellContextMenuButton(bool create)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (create)
|
|
|
|
|
{
|
|
|
|
|
UnregisterEditShellContextMenuButton();
|
|
|
|
|
RegisterEditShellContextMenuButton();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UnregisterEditShellContextMenuButton();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.WriteException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void RegisterEditShellContextMenuButton()
|
|
|
|
|
{
|
2018-04-03 07:44:16 +12:00
|
|
|
|
RegistryHelpers.CreateRegistry(ShellExtEditImage, ShellExtEditDesc);
|
|
|
|
|
RegistryHelpers.CreateRegistry(ShellExtEditImage, "Icon", ShellExtEditIcon);
|
|
|
|
|
RegistryHelpers.CreateRegistry(ShellExtEditImageCmd, ShellExtEditPath);
|
2018-04-01 00:16:09 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void UnregisterEditShellContextMenuButton()
|
|
|
|
|
{
|
2018-04-03 07:44:16 +12:00
|
|
|
|
RegistryHelpers.RemoveRegistry(ShellExtEditImage, true);
|
2018-04-01 00:16:09 +13:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-10 04:50:09 +13:00
|
|
|
|
public static bool CheckCustomUploaderExtension()
|
|
|
|
|
{
|
2017-01-15 01:02:43 +13:00
|
|
|
|
try
|
|
|
|
|
{
|
2021-10-13 00:04:20 +13:00
|
|
|
|
return RegistryHelpers.CheckStringValue(ShellCustomUploaderExtensionPath, null, ShellCustomUploaderExtensionValue) &&
|
|
|
|
|
RegistryHelpers.CheckStringValue(ShellCustomUploaderCommandPath, null, ShellCustomUploaderCommandValue);
|
2017-01-15 01:02:43 +13:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.WriteException(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2017-01-10 04:50:09 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void CreateCustomUploaderExtension(bool create)
|
|
|
|
|
{
|
2017-01-15 01:02:43 +13:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (create)
|
|
|
|
|
{
|
|
|
|
|
UnregisterCustomUploaderExtension();
|
|
|
|
|
RegisterCustomUploaderExtension();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UnregisterCustomUploaderExtension();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.WriteException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void RegisterCustomUploaderExtension()
|
|
|
|
|
{
|
|
|
|
|
RegistryHelpers.CreateRegistry(ShellCustomUploaderExtensionPath, ShellCustomUploaderExtensionValue);
|
|
|
|
|
RegistryHelpers.CreateRegistry(ShellCustomUploaderAssociatePath, ShellCustomUploaderAssociateValue);
|
|
|
|
|
RegistryHelpers.CreateRegistry(ShellCustomUploaderIconPath, ShellCustomUploaderIconValue);
|
|
|
|
|
RegistryHelpers.CreateRegistry(ShellCustomUploaderCommandPath, ShellCustomUploaderCommandValue);
|
|
|
|
|
|
|
|
|
|
NativeMethods.SHChangeNotify(HChangeNotifyEventID.SHCNE_ASSOCCHANGED, HChangeNotifyFlags.SHCNF_FLUSH, IntPtr.Zero, IntPtr.Zero);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void UnregisterCustomUploaderExtension()
|
|
|
|
|
{
|
|
|
|
|
RegistryHelpers.RemoveRegistry(ShellCustomUploaderExtensionPath);
|
|
|
|
|
RegistryHelpers.RemoveRegistry(ShellCustomUploaderAssociatePath, true);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-06 11:23:59 +12:00
|
|
|
|
public static bool CheckImageEffectExtension()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-10-13 00:04:20 +13:00
|
|
|
|
return RegistryHelpers.CheckStringValue(ShellImageEffectExtensionPath, null, ShellImageEffectExtensionValue) &&
|
|
|
|
|
RegistryHelpers.CheckStringValue(ShellImageEffectCommandPath, null, ShellImageEffectCommandValue);
|
2020-07-06 11:23:59 +12:00
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-11 04:41:11 +13:00
|
|
|
|
public static bool CheckChromeExtensionSupport()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-10-13 00:04:20 +13:00
|
|
|
|
return RegistryHelpers.CheckStringValue(ChromeNativeMessagingHosts, null, Program.ChromeHostManifestFilePath) &&
|
2018-04-03 08:58:17 +12:00
|
|
|
|
File.Exists(Program.ChromeHostManifestFilePath);
|
2017-02-11 04:41:11 +13:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.WriteException(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void CreateChromeExtensionSupport(bool create)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (create)
|
|
|
|
|
{
|
2017-02-11 05:12:09 +13:00
|
|
|
|
UnregisterChromeExtensionSupport();
|
|
|
|
|
RegisterChromeExtensionSupport();
|
2017-02-11 04:41:11 +13:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-11 05:12:09 +13:00
|
|
|
|
UnregisterChromeExtensionSupport();
|
2017-02-11 04:41:11 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.WriteException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-05 20:44:18 +13:00
|
|
|
|
private static void CreateChromeHostManifest(string filePath)
|
2017-02-11 05:12:09 +13:00
|
|
|
|
{
|
2022-05-03 18:34:18 +12:00
|
|
|
|
FileHelpers.CreateDirectoryFromFilePath(filePath);
|
2017-02-11 05:12:09 +13:00
|
|
|
|
|
2020-01-18 00:13:06 +13:00
|
|
|
|
ChromeManifest manifest = new ChromeManifest()
|
2017-02-11 05:12:09 +13:00
|
|
|
|
{
|
|
|
|
|
name = "com.getsharex.sharex",
|
|
|
|
|
description = "ShareX",
|
|
|
|
|
path = Program.NativeMessagingHostFilePath,
|
|
|
|
|
type = "stdio",
|
|
|
|
|
allowed_origins = new string[] { "chrome-extension://nlkoigbdolhchiicbonbihbphgamnaoc/" }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
string json = JsonConvert.SerializeObject(manifest, Formatting.Indented);
|
|
|
|
|
|
2022-01-05 20:44:18 +13:00
|
|
|
|
File.WriteAllText(filePath, json, Encoding.UTF8);
|
2017-02-11 05:12:09 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void RegisterChromeExtensionSupport()
|
2017-02-11 04:06:12 +13:00
|
|
|
|
{
|
|
|
|
|
CreateChromeHostManifest(Program.ChromeHostManifestFilePath);
|
|
|
|
|
|
|
|
|
|
RegistryHelpers.CreateRegistry(ChromeNativeMessagingHosts, Program.ChromeHostManifestFilePath);
|
2017-01-15 01:02:43 +13:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-11 05:12:09 +13:00
|
|
|
|
private static void UnregisterChromeExtensionSupport()
|
2017-01-15 01:02:43 +13:00
|
|
|
|
{
|
2017-02-11 04:06:12 +13:00
|
|
|
|
if (File.Exists(Program.ChromeHostManifestFilePath))
|
|
|
|
|
{
|
|
|
|
|
File.Delete(Program.ChromeHostManifestFilePath);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-15 01:02:43 +13:00
|
|
|
|
RegistryHelpers.RemoveRegistry(ChromeNativeMessagingHosts);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-11 05:12:09 +13:00
|
|
|
|
public static bool CheckFirefoxAddonSupport()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-10-13 00:04:20 +13:00
|
|
|
|
return RegistryHelpers.CheckStringValue(FirefoxNativeMessagingHosts, null, Program.FirefoxHostManifestFilePath) &&
|
2018-04-03 08:58:17 +12:00
|
|
|
|
File.Exists(Program.FirefoxHostManifestFilePath);
|
2017-02-11 05:12:09 +13:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.WriteException(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void CreateFirefoxAddonSupport(bool create)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (create)
|
|
|
|
|
{
|
|
|
|
|
UnregisterFirefoxAddonSupport();
|
|
|
|
|
RegisterFirefoxAddonSupport();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UnregisterFirefoxAddonSupport();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.WriteException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-05 20:44:18 +13:00
|
|
|
|
private static void CreateFirefoxHostManifest(string filePath)
|
2017-02-11 04:24:20 +13:00
|
|
|
|
{
|
2022-05-03 18:34:18 +12:00
|
|
|
|
FileHelpers.CreateDirectoryFromFilePath(filePath);
|
2017-02-11 04:24:20 +13:00
|
|
|
|
|
2020-01-18 00:13:06 +13:00
|
|
|
|
FirefoxManifest manifest = new FirefoxManifest()
|
2017-02-11 04:24:20 +13:00
|
|
|
|
{
|
|
|
|
|
name = "ShareX",
|
|
|
|
|
description = "ShareX",
|
|
|
|
|
path = Program.NativeMessagingHostFilePath,
|
|
|
|
|
type = "stdio",
|
|
|
|
|
allowed_extensions = new string[] { "firefox@getsharex.com" }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
string json = JsonConvert.SerializeObject(manifest, Formatting.Indented);
|
|
|
|
|
|
2022-01-05 20:44:18 +13:00
|
|
|
|
File.WriteAllText(filePath, json, Encoding.UTF8);
|
2017-02-11 04:24:20 +13:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-11 05:12:09 +13:00
|
|
|
|
private static void RegisterFirefoxAddonSupport()
|
2017-02-11 04:24:20 +13:00
|
|
|
|
{
|
|
|
|
|
CreateFirefoxHostManifest(Program.FirefoxHostManifestFilePath);
|
|
|
|
|
|
|
|
|
|
RegistryHelpers.CreateRegistry(FirefoxNativeMessagingHosts, Program.FirefoxHostManifestFilePath);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-11 05:12:09 +13:00
|
|
|
|
private static void UnregisterFirefoxAddonSupport()
|
2017-02-11 04:24:20 +13:00
|
|
|
|
{
|
|
|
|
|
if (File.Exists(Program.FirefoxHostManifestFilePath))
|
|
|
|
|
{
|
|
|
|
|
File.Delete(Program.FirefoxHostManifestFilePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RegistryHelpers.RemoveRegistry(FirefoxNativeMessagingHosts);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-11 13:18:12 +12:00
|
|
|
|
public static bool CheckSendToMenuButton()
|
|
|
|
|
{
|
2021-12-20 12:11:04 +13:00
|
|
|
|
return ShortcutHelpers.CheckShortcut(Environment.SpecialFolder.SendTo, "ShareX", Application.ExecutablePath);
|
2015-09-11 13:18:12 +12:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-22 06:52:14 +12:00
|
|
|
|
public static bool CreateSendToMenuButton(bool create)
|
2015-09-11 12:45:40 +12:00
|
|
|
|
{
|
2021-12-20 12:11:04 +13:00
|
|
|
|
return ShortcutHelpers.SetShortcut(create, Environment.SpecialFolder.SendTo, "ShareX", Application.ExecutablePath);
|
2015-09-11 12:45:40 +12:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-11 13:18:12 +12:00
|
|
|
|
public static bool CheckSteamShowInApp()
|
|
|
|
|
{
|
2015-10-27 15:03:24 +13:00
|
|
|
|
return File.Exists(Program.SteamInAppFilePath);
|
2015-09-11 13:18:12 +12:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-01 23:28:08 +13:00
|
|
|
|
public static void SteamShowInApp(bool showInApp)
|
2015-09-11 12:45:40 +12:00
|
|
|
|
{
|
2015-10-27 15:03:24 +13:00
|
|
|
|
string path = Program.SteamInAppFilePath;
|
2015-09-11 12:45:40 +12:00
|
|
|
|
|
2015-10-01 23:28:08 +13:00
|
|
|
|
try
|
2015-09-11 12:45:40 +12:00
|
|
|
|
{
|
2015-10-01 23:28:08 +13:00
|
|
|
|
if (showInApp)
|
|
|
|
|
{
|
2022-05-03 18:34:18 +12:00
|
|
|
|
FileHelpers.CreateEmptyFile(path);
|
2015-10-01 23:28:08 +13:00
|
|
|
|
}
|
|
|
|
|
else if (File.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
File.Delete(path);
|
|
|
|
|
}
|
2015-09-11 12:45:40 +12:00
|
|
|
|
}
|
2015-10-01 23:28:08 +13:00
|
|
|
|
catch (Exception e)
|
2015-09-11 12:45:40 +12:00
|
|
|
|
{
|
2015-10-01 23:28:08 +13:00
|
|
|
|
DebugHelper.WriteException(e);
|
2017-04-22 08:42:52 +12:00
|
|
|
|
e.ShowError();
|
2015-10-01 23:28:08 +13:00
|
|
|
|
return;
|
2015-09-11 12:45:40 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MessageBox.Show(Resources.ApplicationSettingsForm_cbSteamShowInApp_CheckedChanged_For_settings_to_take_effect_ShareX_needs_to_be_reopened_from_Steam_,
|
|
|
|
|
"ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
2015-09-12 11:05:31 +12:00
|
|
|
|
|
|
|
|
|
public static void Uninstall()
|
|
|
|
|
{
|
2024-04-12 05:42:10 +12:00
|
|
|
|
StartupManager.State = StartupState.Disabled;
|
2015-09-12 11:05:31 +12:00
|
|
|
|
CreateShellContextMenuButton(false);
|
2018-04-03 08:58:17 +12:00
|
|
|
|
CreateEditShellContextMenuButton(false);
|
2017-01-14 08:09:38 +13:00
|
|
|
|
CreateCustomUploaderExtension(false);
|
2020-07-06 11:23:59 +12:00
|
|
|
|
CreateImageEffectExtension(false);
|
2015-09-12 11:05:31 +12:00
|
|
|
|
CreateSendToMenuButton(false);
|
|
|
|
|
}
|
2015-09-11 12:45:40 +12:00
|
|
|
|
}
|
|
|
|
|
}
|