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 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 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 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)
|
||||
{
|
||||
string filepath = Helpers.GetAbsolutePath("ShareX_DesktopBridgeHelper.exe");
|
||||
|
|
|
@ -8,23 +8,11 @@ namespace ShareX.StartupManagers
|
|||
{
|
||||
class CentennialStartupManager : IStartupManager
|
||||
{
|
||||
public int StartupTargetIndex;
|
||||
public StartupTaskState State
|
||||
{
|
||||
get => IntegrationHelpers.CheckStartupWindowsStore();
|
||||
set
|
||||
{
|
||||
bool enable;
|
||||
if (value == StartupTaskState.Enabled)
|
||||
{
|
||||
enable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
enable = false;
|
||||
}
|
||||
|
||||
IntegrationHelpers.ConfigureStartupWindowsStore(enable);
|
||||
}
|
||||
set => IntegrationHelpers.ConfigureStartupWindowsStore(value == StartupTaskState.Enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ShareX.HelpersLib;
|
||||
using System;
|
||||
|
||||
namespace ShareX.StartupManagers
|
||||
{
|
||||
class DesktopStartupManager : IStartupManager
|
||||
{
|
||||
public string StartupTargetPath;
|
||||
public StartupTaskState State
|
||||
{
|
||||
get => IntegrationHelpers.CheckStartupShortcut() ? StartupTaskState.Enabled : StartupTaskState.Disabled;
|
||||
set
|
||||
{
|
||||
if (value == StartupTaskState.Disabled)
|
||||
IntegrationHelpers.CreateStartupShortcut(false);
|
||||
else if (value == StartupTaskState.Enabled)
|
||||
IntegrationHelpers.CreateStartupShortcut(true);
|
||||
}
|
||||
get => ShortcutHelpers.CheckShortcut(Environment.SpecialFolder.Startup, StartupTargetPath) ? StartupTaskState.Enabled : StartupTaskState.Disabled;
|
||||
set => ShortcutHelpers.SetShortcut(value == StartupTaskState.Enabled, Environment.SpecialFolder.Startup, StartupTargetPath, "-silent");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ShareX.StartupManagers
|
||||
{
|
||||
|
@ -10,9 +11,20 @@ class StartupManagerFactory
|
|||
static public IStartupManager GetStartupManager()
|
||||
{
|
||||
#if WindowsStore
|
||||
return new CentennialStartupManager();
|
||||
return new CentennialStartupManager()
|
||||
{
|
||||
StartupTargetIndex = 0
|
||||
};
|
||||
#elif STEAM
|
||||
return new DesktopStartupManager()
|
||||
{
|
||||
StartupTargetPath = Helpers.GetAbsolutePath("../ShareX_Launcher.exe")
|
||||
};
|
||||
#else
|
||||
return new DesktopStartupManager();
|
||||
return new DesktopStartupManager()
|
||||
{
|
||||
StartupTargetPath = Application.ExecutablePath
|
||||
};
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue