mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
Remove dead code, move logic into Desktop implementation, and implement Steam
This commit is contained in:
parent
07f48747eb
commit
52cbee2317
4 changed files with 21 additions and 87 deletions
|
@ -40,16 +40,6 @@ public static class IntegrationHelpers
|
||||||
private static readonly string ApplicationName = "ShareX";
|
private static readonly string ApplicationName = "ShareX";
|
||||||
private static readonly string ApplicationPath = string.Format("\"{0}\"", Application.ExecutablePath);
|
private static readonly string ApplicationPath = string.Format("\"{0}\"", Application.ExecutablePath);
|
||||||
|
|
||||||
private static readonly string StartupTargetPath =
|
|
||||||
#if STEAM
|
|
||||||
Helpers.GetAbsolutePath("../ShareX_Launcher.exe");
|
|
||||||
#else
|
|
||||||
Application.ExecutablePath;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private static readonly string StartupRegistryPath = @"Software\Microsoft\Windows\CurrentVersion\Run";
|
|
||||||
private static readonly string StartupRegistryValue = $"\"{StartupTargetPath}\" -silent";
|
|
||||||
|
|
||||||
private static readonly string ShellExtMenuFiles = @"Software\Classes\*\shell\" + ApplicationName;
|
private static readonly string ShellExtMenuFiles = @"Software\Classes\*\shell\" + ApplicationName;
|
||||||
private static readonly string ShellExtMenuFilesCmd = ShellExtMenuFiles + @"\command";
|
private static readonly string ShellExtMenuFilesCmd = ShellExtMenuFiles + @"\command";
|
||||||
|
|
||||||
|
@ -75,55 +65,6 @@ public static class IntegrationHelpers
|
||||||
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";
|
||||||
|
|
||||||
public static bool CheckStartupShortcut()
|
|
||||||
{
|
|
||||||
return ShortcutHelpers.CheckShortcut(Environment.SpecialFolder.Startup, StartupTargetPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool CreateStartupShortcut(bool create)
|
|
||||||
{
|
|
||||||
return ShortcutHelpers.SetShortcut(create, Environment.SpecialFolder.Startup, StartupTargetPath, "-silent");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool CheckStartWithWindows()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return RegistryHelpers.CheckRegistry(StartupRegistryPath, ApplicationName, StartupRegistryValue);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
DebugHelper.WriteException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void CreateStartWithWindows(bool create)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (RegistryKey rk = Registry.CurrentUser.OpenSubKey(StartupRegistryPath, true))
|
|
||||||
{
|
|
||||||
if (rk != null)
|
|
||||||
{
|
|
||||||
if (create)
|
|
||||||
{
|
|
||||||
rk.SetValue(ApplicationName, StartupRegistryValue, RegistryValueKind.String);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rk.DeleteValue(ApplicationName, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
DebugHelper.WriteException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static StartupTaskState RunStartupWindowsStore(string argument, string info)
|
private static StartupTaskState RunStartupWindowsStore(string argument, string info)
|
||||||
{
|
{
|
||||||
string filepath = Helpers.GetAbsolutePath("ShareX_DesktopBridgeHelper.exe");
|
string filepath = Helpers.GetAbsolutePath("ShareX_DesktopBridgeHelper.exe");
|
||||||
|
|
|
@ -8,23 +8,11 @@ namespace ShareX.StartupManagers
|
||||||
{
|
{
|
||||||
class CentennialStartupManager : IStartupManager
|
class CentennialStartupManager : IStartupManager
|
||||||
{
|
{
|
||||||
|
public int StartupTargetIndex;
|
||||||
public StartupTaskState State
|
public StartupTaskState State
|
||||||
{
|
{
|
||||||
get => IntegrationHelpers.CheckStartupWindowsStore();
|
get => IntegrationHelpers.CheckStartupWindowsStore();
|
||||||
set
|
set => IntegrationHelpers.ConfigureStartupWindowsStore(value == StartupTaskState.Enabled);
|
||||||
{
|
|
||||||
bool enable;
|
|
||||||
if (value == StartupTaskState.Enabled)
|
|
||||||
{
|
|
||||||
enable = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
enable = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
IntegrationHelpers.ConfigureStartupWindowsStore(enable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,15 @@
|
||||||
using System;
|
using ShareX.HelpersLib;
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace ShareX.StartupManagers
|
namespace ShareX.StartupManagers
|
||||||
{
|
{
|
||||||
class DesktopStartupManager : IStartupManager
|
class DesktopStartupManager : IStartupManager
|
||||||
{
|
{
|
||||||
|
public string StartupTargetPath;
|
||||||
public StartupTaskState State
|
public StartupTaskState State
|
||||||
{
|
{
|
||||||
get => IntegrationHelpers.CheckStartupShortcut() ? StartupTaskState.Enabled : StartupTaskState.Disabled;
|
get => ShortcutHelpers.CheckShortcut(Environment.SpecialFolder.Startup, StartupTargetPath) ? StartupTaskState.Enabled : StartupTaskState.Disabled;
|
||||||
set
|
set => ShortcutHelpers.SetShortcut(value == StartupTaskState.Enabled, Environment.SpecialFolder.Startup, StartupTargetPath, "-silent");
|
||||||
{
|
|
||||||
if (value == StartupTaskState.Disabled)
|
|
||||||
IntegrationHelpers.CreateStartupShortcut(false);
|
|
||||||
else if (value == StartupTaskState.Enabled)
|
|
||||||
IntegrationHelpers.CreateStartupShortcut(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ShareX.StartupManagers
|
namespace ShareX.StartupManagers
|
||||||
{
|
{
|
||||||
|
@ -10,9 +11,20 @@ class StartupManagerFactory
|
||||||
static public IStartupManager GetStartupManager()
|
static public IStartupManager GetStartupManager()
|
||||||
{
|
{
|
||||||
#if WindowsStore
|
#if WindowsStore
|
||||||
return new CentennialStartupManager();
|
return new CentennialStartupManager()
|
||||||
|
{
|
||||||
|
StartupTargetIndex = 0
|
||||||
|
};
|
||||||
|
#elif STEAM
|
||||||
|
return new DesktopStartupManager()
|
||||||
|
{
|
||||||
|
StartupTargetPath = Helpers.GetAbsolutePath("../ShareX_Launcher.exe")
|
||||||
|
};
|
||||||
#else
|
#else
|
||||||
return new DesktopStartupManager();
|
return new DesktopStartupManager()
|
||||||
|
{
|
||||||
|
StartupTargetPath = Application.ExecutablePath
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue