Added GitHubUpdateManager to HelpersLib

This commit is contained in:
Jaex 2016-11-24 03:18:42 +03:00
parent 73072e2c7c
commit 54b15d421a
6 changed files with 32 additions and 22 deletions

View file

@ -399,6 +399,7 @@
<Compile Include="Controls\MyPictureBox.Designer.cs">
<DependentUpon>MyPictureBox.cs</DependentUpon>
</Compile>
<Compile Include="UpdateChecker\GitHubUpdateManager.cs" />
<Compile Include="UpdateChecker\UpdateMessageBox.cs">
<SubType>Form</SubType>
</Compile>

View file

@ -23,39 +23,48 @@
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
using System;
using System.Windows.Forms;
using Timer = System.Threading.Timer;
namespace ShareX
namespace ShareX.HelpersLib
{
public class UpdateManager : IDisposable
public class GitHubUpdateManager : IDisposable
{
public double UpdateCheckInterval { get; private set; } = 1; // Hour
public bool AutoUpdateEnabled { get; set; } // ConfigureAutoUpdate function must be called after change this
public TimeSpan UpdateCheckInterval { get; private set; } = TimeSpan.FromHours(1);
public TimeSpan UpdateReCheckInterval { get; private set; } = TimeSpan.FromHours(24); // If "No" button pressed in update message box then this interval will be used
public string GitHubOwner { get; set; }
public string GitHubRepo { get; set; }
public bool IsBeta { get; set; } // If current build is beta and latest stable release is same version as current build then it will be downloaded
public bool IsPortable { get; set; } // If current build is portable then download URL will be opened in browser instead of downloading it
public bool CheckPreReleaseUpdates { get; set; }
private bool firstUpdateCheck = true;
private Timer updateTimer = null;
private readonly object updateTimerLock = new object();
public UpdateManager()
public GitHubUpdateManager(string owner, string repo)
{
GitHubOwner = owner;
GitHubRepo = repo;
}
public UpdateManager(double updateCheckInterval)
public GitHubUpdateManager(string owner, string repo, bool beta, bool portable) : this(owner, repo)
{
UpdateCheckInterval = updateCheckInterval;
IsBeta = beta;
IsPortable = portable;
}
public void ConfigureAutoUpdate()
{
lock (updateTimerLock)
{
if (Program.Settings.AutoCheckUpdate && !Program.PortableApps)
if (AutoUpdateEnabled)
{
if (updateTimer == null)
{
updateTimer = new Timer(state => CheckUpdate(), null, TimeSpan.Zero, TimeSpan.FromHours(UpdateCheckInterval));
updateTimer = new Timer(state => CheckUpdate(), null, TimeSpan.Zero, UpdateCheckInterval);
}
}
else
@ -74,21 +83,20 @@ private void CheckUpdate()
if (UpdateMessageBox.Start(updateChecker, firstUpdateCheck) != DialogResult.Yes)
{
TimeSpan interval = TimeSpan.FromHours(24);
updateTimer.Change(interval, interval);
updateTimer.Change(UpdateReCheckInterval, UpdateReCheckInterval);
}
firstUpdateCheck = false;
}
}
public static UpdateChecker CreateUpdateChecker()
public GitHubUpdateChecker CreateUpdateChecker()
{
return new GitHubUpdateChecker("ShareX", "ShareX")
return new GitHubUpdateChecker(GitHubOwner, GitHubRepo)
{
IsBeta = Program.Beta,
IsPortable = Program.Portable,
IncludePreRelease = Program.Settings.CheckPreReleaseUpdates,
IsBeta = IsBeta,
IsPortable = IsPortable,
IncludePreRelease = CheckPreReleaseUpdates,
Proxy = HelpersOptions.CurrentProxy.GetWebProxy()
};
}

View file

@ -52,7 +52,7 @@ public AboutForm()
if (!Program.PortableApps)
{
UpdateChecker updateChecker = UpdateManager.CreateUpdateChecker();
UpdateChecker updateChecker = Program.UpdateManager.CreateUpdateChecker();
uclUpdate.CheckUpdate(updateChecker);
}
else

View file

@ -45,7 +45,6 @@ public partial class MainForm : HotkeyForm
private bool forceClose, trayMenuSaveSettings = true;
private UploadInfoManager uim;
private ToolStripDropDownItem tsmiImageFileUploaders, tsmiTrayImageFileUploaders, tsmiTextFileUploaders, tsmiTrayTextFileUploaders;
private UpdateManager updateManager;
public MainForm()
{
@ -180,8 +179,6 @@ private void InitializeControls()
ExportImportControl.UploadRequested += json => UploadManager.UploadText(json);
updateManager = new UpdateManager();
HandleCreated += MainForm_HandleCreated;
}
@ -670,7 +667,9 @@ private void AfterSettingsJobs()
TaskManager.RecentManager.MaxCount = Program.Settings.RecentTasksMaxCount;
#if RELEASE
updateManager.ConfigureAutoUpdate();
Program.UpdateManager.AutoUpdateEnabled = Program.Settings.AutoCheckUpdate && !Program.PortableApps;
Program.UpdateManager.CheckPreReleaseUpdates = Program.Settings.CheckPreReleaseUpdates;
Program.UpdateManager.ConfigureAutoUpdate();
#endif
}

View file

@ -92,6 +92,7 @@ public static string Title
public static Stopwatch StartTimer { get; private set; }
public static HotkeyManager HotkeyManager { get; set; }
public static WatchFolderManager WatchFolderManager { get; set; }
public static GitHubUpdateManager UpdateManager { get; set; }
public static CLIManager CLI { get; private set; }
private static bool restarting;
@ -341,6 +342,8 @@ private static void Run()
HotkeySettingsResetEvent = new ManualResetEvent(false);
TaskEx.Run(LoadSettings);
UpdateManager = new GitHubUpdateManager("ShareX", "ShareX", Beta, Portable);
LanguageHelper.ChangeLanguage(Settings.Language);
DebugHelper.WriteLine("MainForm init started");

View file

@ -276,7 +276,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TaskManager.cs" />
<Compile Include="TaskSettings.cs" />
<Compile Include="UpdateManager.cs" />
<Compile Include="UploadInfoParser.cs" />
<Compile Include="UploadInfoStatus.cs" />
<Compile Include="Forms\HotkeySettingsForm.cs">