Skip to content

Commit

Permalink
Include host manifest files in app folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaex committed Apr 17, 2024
1 parent 2328863 commit bd3a00e
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 135 deletions.
2 changes: 2 additions & 0 deletions ShareX.Setup/InnoSetup/ShareX-setup.iss
Expand Up @@ -50,6 +50,8 @@ Source: "{#MyAppRootDirectory}\Licenses\*.txt"; DestDir: {app}\Licenses; Flags:
Source: "{#MyAppOutputDirectory}\Recorder-devices-setup.exe"; DestDir: {app}; Flags: ignoreversion
Source: "{#MyAppOutputDirectory}\ffmpeg.exe"; DestDir: {app}; Flags: ignoreversion
Source: "{#MyAppReleaseDirectory}\ShareX_NativeMessagingHost.exe"; DestDir: {app}; Flags: ignoreversion
Source: "{#MyAppReleaseDirectory}\host-manifest-chrome.json"; DestDir: {app}; Flags: ignoreversion
Source: "{#MyAppReleaseDirectory}\host-manifest-firefox.json"; DestDir: {app}; Flags: ignoreversion
Source: "{#MyAppReleaseDirectory}\de\*.resources.dll"; DestDir: {app}\Languages\de; Flags: ignoreversion
Source: "{#MyAppReleaseDirectory}\es\*.resources.dll"; DestDir: {app}\Languages\es; Flags: ignoreversion
Source: "{#MyAppReleaseDirectory}\es-MX\*.resources.dll"; DestDir: {app}\Languages\es-MX; Flags: ignoreversion
Expand Down
2 changes: 2 additions & 0 deletions ShareX.Setup/Program.cs
Expand Up @@ -378,6 +378,8 @@ private static void CreateFolder(string source, string destination, SetupJobs jo
FileHelpers.CopyFiles(RecorderDevicesSetupPath, destination);

FileHelpers.CopyFiles(Path.Combine(source, "ShareX_NativeMessagingHost.exe"), destination);
FileHelpers.CopyFiles(Path.Combine(source, "host-manifest-chrome.json"), destination);
FileHelpers.CopyFiles(Path.Combine(source, "host-manifest-firefox.json"), destination);
}

foreach (string directory in Directory.GetDirectories(source))
Expand Down
36 changes: 0 additions & 36 deletions ShareX/ChromeManifest.cs

This file was deleted.

36 changes: 0 additions & 36 deletions ShareX/FirefoxManifest.cs

This file was deleted.

66 changes: 8 additions & 58 deletions ShareX/IntegrationHelpers.cs
Expand Up @@ -23,12 +23,10 @@

#endregion License Information (GPL v3)

using Newtonsoft.Json;
using ShareX.HelpersLib;
using ShareX.Properties;
using System;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace ShareX
Expand Down Expand Up @@ -73,6 +71,8 @@ public static class IntegrationHelpers

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 ChromeHostManifestFilePath = FileHelpers.GetAbsolutePath("host-manifest-chrome.json");
private static readonly string FirefoxHostManifestFilePath = FileHelpers.GetAbsolutePath("host-manifest-firefox.json");

public static bool CheckShellContextMenuButton()
{
Expand Down Expand Up @@ -278,8 +278,7 @@ public static bool CheckChromeExtensionSupport()
{
try
{
return RegistryHelpers.CheckStringValue(ChromeNativeMessagingHosts, null, Program.ChromeHostManifestFilePath) &&
File.Exists(Program.ChromeHostManifestFilePath);
return RegistryHelpers.CheckStringValue(ChromeNativeMessagingHosts, null, ChromeHostManifestFilePath) && File.Exists(ChromeHostManifestFilePath);
}
catch (Exception e)
{
Expand Down Expand Up @@ -309,47 +308,21 @@ public static void CreateChromeExtensionSupport(bool create)
}
}

private static void CreateChromeHostManifest(string filePath)
{
FileHelpers.CreateDirectoryFromFilePath(filePath);

ChromeManifest manifest = new ChromeManifest()
{
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);

File.WriteAllText(filePath, json, Encoding.UTF8);
}

private static void RegisterChromeExtensionSupport()
{
CreateChromeHostManifest(Program.ChromeHostManifestFilePath);

RegistryHelpers.CreateRegistry(ChromeNativeMessagingHosts, Program.ChromeHostManifestFilePath);
RegistryHelpers.CreateRegistry(ChromeNativeMessagingHosts, ChromeHostManifestFilePath);
}

private static void UnregisterChromeExtensionSupport()
{
if (File.Exists(Program.ChromeHostManifestFilePath))
{
File.Delete(Program.ChromeHostManifestFilePath);
}

RegistryHelpers.RemoveRegistry(ChromeNativeMessagingHosts);
}

public static bool CheckFirefoxAddonSupport()
{
try
{
return RegistryHelpers.CheckStringValue(FirefoxNativeMessagingHosts, null, Program.FirefoxHostManifestFilePath) &&
File.Exists(Program.FirefoxHostManifestFilePath);
return RegistryHelpers.CheckStringValue(FirefoxNativeMessagingHosts, null, FirefoxHostManifestFilePath) && File.Exists(FirefoxHostManifestFilePath);
}
catch (Exception e)
{
Expand Down Expand Up @@ -379,38 +352,13 @@ public static void CreateFirefoxAddonSupport(bool create)
}
}

private static void CreateFirefoxHostManifest(string filePath)
{
FileHelpers.CreateDirectoryFromFilePath(filePath);

FirefoxManifest manifest = new FirefoxManifest()
{
name = "ShareX",
description = "ShareX",
path = Program.NativeMessagingHostFilePath,
type = "stdio",
allowed_extensions = new string[] { "firefox@getsharex.com" }
};

string json = JsonConvert.SerializeObject(manifest, Formatting.Indented);

File.WriteAllText(filePath, json, Encoding.UTF8);
}

private static void RegisterFirefoxAddonSupport()
{
CreateFirefoxHostManifest(Program.FirefoxHostManifestFilePath);

RegistryHelpers.CreateRegistry(FirefoxNativeMessagingHosts, Program.FirefoxHostManifestFilePath);
RegistryHelpers.CreateRegistry(FirefoxNativeMessagingHosts, FirefoxHostManifestFilePath);
}

private static void UnregisterFirefoxAddonSupport()
{
if (File.Exists(Program.FirefoxHostManifestFilePath))
{
File.Delete(Program.FirefoxHostManifestFilePath);
}

RegistryHelpers.RemoveRegistry(FirefoxNativeMessagingHosts);
}

Expand Down Expand Up @@ -463,6 +411,8 @@ public static void Uninstall()
CreateCustomUploaderExtension(false);
CreateImageEffectExtension(false);
CreateSendToMenuButton(false);
UnregisterChromeExtensionSupport();
UnregisterFirefoxAddonSupport();
}
}
}
5 changes: 0 additions & 5 deletions ShareX/Program.cs
Expand Up @@ -161,7 +161,6 @@ private static string PersonalPathConfigFilePath
AppName, PersonalPathConfigFileName);

private static readonly string PortableCheckFilePath = FileHelpers.GetAbsolutePath("Portable");
public static readonly string NativeMessagingHostFilePath = FileHelpers.GetAbsolutePath("ShareX_NativeMessagingHost.exe");
public static readonly string SteamInAppFilePath = FileHelpers.GetAbsolutePath("Steam");

private static string CustomPersonalPath { get; set; }
Expand Down Expand Up @@ -255,10 +254,7 @@ public static string ScreenshotsParentFolder
}
}

public static string ToolsFolder => Path.Combine(PersonalFolder, "Tools");
public static string ImageEffectsFolder => Path.Combine(PersonalFolder, "ImageEffects");
public static string ChromeHostManifestFilePath => Path.Combine(ToolsFolder, "Chrome-host-manifest.json");
public static string FirefoxHostManifestFilePath => Path.Combine(ToolsFolder, "Firefox-host-manifest.json");

private static string PersonalPathDetectionMethod;

Expand Down Expand Up @@ -527,7 +523,6 @@ private static void CreateParentFolders()
FileHelpers.CreateDirectory(SettingManager.BackupFolder);
FileHelpers.CreateDirectory(ImageEffectsFolder);
FileHelpers.CreateDirectory(ScreenshotsParentFolder);
FileHelpers.CreateDirectory(ToolsFolder);
}
}

Expand Down
8 changes: 8 additions & 0 deletions ShareX/ShareX.csproj
Expand Up @@ -26,4 +26,12 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="ZXing.Net" Version="0.16.9" />
</ItemGroup>
<ItemGroup>
<None Update="host-manifest-chrome.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="host-manifest-firefox.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
9 changes: 9 additions & 0 deletions ShareX/host-manifest-chrome.json
@@ -0,0 +1,9 @@
{
"name": "com.getsharex.sharex",
"description": "ShareX",
"path": "ShareX_NativeMessagingHost.exe",
"type": "stdio",
"allowed_origins": [
"chrome-extension://nlkoigbdolhchiicbonbihbphgamnaoc/"
]
}
9 changes: 9 additions & 0 deletions ShareX/host-manifest-firefox.json
@@ -0,0 +1,9 @@
{
"name": "ShareX",
"description": "ShareX",
"path": "ShareX_NativeMessagingHost.exe",
"type": "stdio",
"allowed_extensions": [
"firefox@getsharex.com"
]
}

0 comments on commit bd3a00e

Please sign in to comment.