mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-28 23:42:13 +12:00
Code refactoring
This commit is contained in:
parent
8eb08c4a9a
commit
cbad9a45e4
9 changed files with 48 additions and 224 deletions
|
@ -291,7 +291,7 @@ private void UpdateStartWithWindows()
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StartupState state = StartupManagerSingletonProvider.CurrentStartupManager.State;
|
StartupState state = StartupManager.State;
|
||||||
cbStartWithWindows.Checked = state == StartupState.Enabled || state == StartupState.EnabledByPolicy;
|
cbStartWithWindows.Checked = state == StartupState.Enabled || state == StartupState.EnabledByPolicy;
|
||||||
|
|
||||||
if (state == StartupState.DisabledByUser)
|
if (state == StartupState.DisabledByUser)
|
||||||
|
@ -592,7 +592,7 @@ private void cbStartWithWindows_CheckedChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StartupManagerSingletonProvider.CurrentStartupManager.State = cbStartWithWindows.Checked ? StartupState.Enabled : StartupState.Disabled;
|
StartupManager.State = cbStartWithWindows.Checked ? StartupState.Enabled : StartupState.Disabled;
|
||||||
UpdateStartWithWindows();
|
UpdateStartWithWindows();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
@ -38,7 +38,7 @@ public FirstTimeConfigForm()
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
ShareXResources.ApplyTheme(this);
|
ShareXResources.ApplyTheme(this);
|
||||||
|
|
||||||
StartupState state = StartupManagerSingletonProvider.CurrentStartupManager.State;
|
StartupState state = StartupManager.State;
|
||||||
cbRunStartup.Checked = state == StartupState.Enabled || state == StartupState.EnabledByPolicy;
|
cbRunStartup.Checked = state == StartupState.Enabled || state == StartupState.EnabledByPolicy;
|
||||||
cbRunStartup.Enabled = state != StartupState.DisabledByUser && state != StartupState.DisabledByPolicy && state != StartupState.EnabledByPolicy;
|
cbRunStartup.Enabled = state != StartupState.DisabledByUser && state != StartupState.DisabledByPolicy && state != StartupState.EnabledByPolicy;
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ private void cbRunStartup_CheckedChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (loaded)
|
if (loaded)
|
||||||
{
|
{
|
||||||
StartupManagerSingletonProvider.CurrentStartupManager.State = cbRunStartup.Checked ? StartupState.Enabled : StartupState.Disabled;
|
StartupManager.State = cbRunStartup.Checked ? StartupState.Enabled : StartupState.Disabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -457,7 +457,7 @@ public static void SteamShowInApp(bool showInApp)
|
||||||
|
|
||||||
public static void Uninstall()
|
public static void Uninstall()
|
||||||
{
|
{
|
||||||
StartupManagerSingletonProvider.CurrentStartupManager.State = StartupState.Disabled;
|
StartupManager.State = StartupState.Disabled;
|
||||||
CreateShellContextMenuButton(false);
|
CreateShellContextMenuButton(false);
|
||||||
CreateEditShellContextMenuButton(false);
|
CreateEditShellContextMenuButton(false);
|
||||||
CreateCustomUploaderExtension(false);
|
CreateCustomUploaderExtension(false);
|
||||||
|
|
|
@ -23,22 +23,43 @@ You should have received a copy of the GNU General Public License
|
||||||
|
|
||||||
#endregion License Information (GPL v3)
|
#endregion License Information (GPL v3)
|
||||||
|
|
||||||
#if !MicrosoftStore
|
|
||||||
|
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using ShareX.HelpersLib;
|
using ShareX.HelpersLib;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
#if MicrosoftStore
|
||||||
|
using Windows.ApplicationModel;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace ShareX
|
namespace ShareX
|
||||||
{
|
{
|
||||||
public abstract class GenericStartupManager : IStartupManager
|
public static class StartupManager
|
||||||
{
|
{
|
||||||
public abstract string StartupTargetPath { get; }
|
#if MicrosoftStore
|
||||||
|
private const int StartupTargetIndex = 0;
|
||||||
|
private static readonly StartupTask packageTask = StartupTask.GetForCurrentPackageAsync().GetAwaiter().GetResult()[StartupTargetIndex];
|
||||||
|
#endif
|
||||||
|
|
||||||
public StartupState State
|
public static string StartupTargetPath
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
#if STEAM
|
||||||
|
return FileHelpers.GetAbsolutePath("../ShareX_Launcher.exe");
|
||||||
|
#else
|
||||||
|
return Application.ExecutablePath;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StartupState State
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
#if MicrosoftStore
|
||||||
|
return (StartupState)packageTask.State;
|
||||||
|
#else
|
||||||
if (ShortcutHelpers.CheckShortcut(Environment.SpecialFolder.Startup, "ShareX", StartupTargetPath))
|
if (ShortcutHelpers.CheckShortcut(Environment.SpecialFolder.Startup, "ShareX", StartupTargetPath))
|
||||||
{
|
{
|
||||||
if (Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\StartupFolder",
|
if (Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\StartupFolder",
|
||||||
|
@ -55,9 +76,24 @@ public StartupState State
|
||||||
{
|
{
|
||||||
return StartupState.Disabled;
|
return StartupState.Disabled;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
#if MicrosoftStore
|
||||||
|
if (value == StartupState.Enabled)
|
||||||
|
{
|
||||||
|
packageTask.RequestEnableAsync().GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
else if (value == StartupState.Disabled)
|
||||||
|
{
|
||||||
|
packageTask.Disable();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (value == StartupState.Enabled || value == StartupState.Disabled)
|
if (value == StartupState.Enabled || value == StartupState.Disabled)
|
||||||
{
|
{
|
||||||
ShortcutHelpers.SetShortcut(value == StartupState.Enabled, Environment.SpecialFolder.Startup, "ShareX", StartupTargetPath, "-silent");
|
ShortcutHelpers.SetShortcut(value == StartupState.Enabled, Environment.SpecialFolder.Startup, "ShareX", StartupTargetPath, "-silent");
|
||||||
|
@ -66,9 +102,8 @@ public StartupState State
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,60 +0,0 @@
|
||||||
#region License Information (GPL v3)
|
|
||||||
|
|
||||||
/*
|
|
||||||
ShareX - A program that allows you to take screenshots and share any file type
|
|
||||||
Copyright (c) 2007-2024 ShareX Team
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
#if MicrosoftStore
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using Windows.ApplicationModel;
|
|
||||||
|
|
||||||
namespace ShareX
|
|
||||||
{
|
|
||||||
public class CentennialStartupManager : IStartupManager
|
|
||||||
{
|
|
||||||
private const int StartupTargetIndex = 0;
|
|
||||||
private readonly StartupTask packageTask = StartupTask.GetForCurrentPackageAsync().GetAwaiter().GetResult()[StartupTargetIndex];
|
|
||||||
|
|
||||||
public StartupState State
|
|
||||||
{
|
|
||||||
get => (StartupState)packageTask.State;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (value == StartupState.Enabled)
|
|
||||||
{
|
|
||||||
packageTask.RequestEnableAsync().GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
else if (value == StartupState.Disabled)
|
|
||||||
{
|
|
||||||
packageTask.Disable();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,38 +0,0 @@
|
||||||
#region License Information (GPL v3)
|
|
||||||
|
|
||||||
/*
|
|
||||||
ShareX - A program that allows you to take screenshots and share any file type
|
|
||||||
Copyright (c) 2007-2024 ShareX Team
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
#if !MicrosoftStore
|
|
||||||
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace ShareX
|
|
||||||
{
|
|
||||||
public class DesktopStartupManager : GenericStartupManager
|
|
||||||
{
|
|
||||||
public override string StartupTargetPath => Application.ExecutablePath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,32 +0,0 @@
|
||||||
#region License Information (GPL v3)
|
|
||||||
|
|
||||||
/*
|
|
||||||
ShareX - A program that allows you to take screenshots and share any file type
|
|
||||||
Copyright (c) 2007-2024 ShareX Team
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
namespace ShareX
|
|
||||||
{
|
|
||||||
public interface IStartupManager
|
|
||||||
{
|
|
||||||
StartupState State { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
#region License Information (GPL v3)
|
|
||||||
|
|
||||||
/*
|
|
||||||
ShareX - A program that allows you to take screenshots and share any file type
|
|
||||||
Copyright (c) 2007-2024 ShareX Team
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
namespace ShareX
|
|
||||||
{
|
|
||||||
public static class StartupManagerSingletonProvider
|
|
||||||
{
|
|
||||||
public static IStartupManager CurrentStartupManager { get; private set; }
|
|
||||||
|
|
||||||
static StartupManagerSingletonProvider()
|
|
||||||
{
|
|
||||||
#if MicrosoftStore
|
|
||||||
CurrentStartupManager = new CentennialStartupManager();
|
|
||||||
#elif STEAM
|
|
||||||
CurrentStartupManager = new SteamStartupManager();
|
|
||||||
#else
|
|
||||||
CurrentStartupManager = new DesktopStartupManager();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
#region License Information (GPL v3)
|
|
||||||
|
|
||||||
/*
|
|
||||||
ShareX - A program that allows you to take screenshots and share any file type
|
|
||||||
Copyright (c) 2007-2024 ShareX Team
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
#if STEAM
|
|
||||||
|
|
||||||
using ShareX.HelpersLib;
|
|
||||||
|
|
||||||
namespace ShareX
|
|
||||||
{
|
|
||||||
public class SteamStartupManager : GenericStartupManager
|
|
||||||
{
|
|
||||||
public override string StartupTargetPath => FileHelpers.GetAbsolutePath("../ShareX_Launcher.exe");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in a new issue