Remove dead code, move logic into Desktop implementation, and implement Steam

This commit is contained in:
Charles Milette 2017-10-04 10:59:29 -04:00
parent 07f48747eb
commit 52cbee2317
No known key found for this signature in database
GPG key ID: 9BC74CC51CB137CE
4 changed files with 21 additions and 87 deletions

View file

@ -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");

View file

@ -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);
}
}
}

View file

@ -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");
}
}
}

View file

@ -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
}
}