2016-09-29 13:33:12 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2022-01-12 05:32:17 +13:00
|
|
|
|
Copyright (c) 2007-2022 ShareX Team
|
2016-09-29 13:33:12 +13:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Timer = System.Threading.Timer;
|
|
|
|
|
|
2016-11-24 13:18:42 +13:00
|
|
|
|
namespace ShareX.HelpersLib
|
2016-09-29 13:33:12 +13:00
|
|
|
|
{
|
2016-11-24 13:18:42 +13:00
|
|
|
|
public class GitHubUpdateManager : IDisposable
|
2016-09-29 13:33:12 +13:00
|
|
|
|
{
|
2022-09-22 07:41:13 +12:00
|
|
|
|
public bool AllowAutoUpdate { get; set; } // ConfigureAutoUpdate function must be called after change this
|
|
|
|
|
public bool AutoUpdateEnabled { get; set; } = true;
|
2016-11-24 13:18:42 +13:00
|
|
|
|
public TimeSpan UpdateCheckInterval { get; private set; } = TimeSpan.FromHours(1);
|
|
|
|
|
public string GitHubOwner { get; set; }
|
|
|
|
|
public string GitHubRepo { get; set; }
|
2022-09-21 11:40:03 +12:00
|
|
|
|
public bool IsDev { get; set; } // If current build is dev and latest stable release is same version as current build then it will be downloaded
|
2016-11-24 13:18:42 +13:00
|
|
|
|
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; }
|
2016-09-29 13:33:12 +13:00
|
|
|
|
|
|
|
|
|
private bool firstUpdateCheck = true;
|
|
|
|
|
private Timer updateTimer = null;
|
|
|
|
|
private readonly object updateTimerLock = new object();
|
|
|
|
|
|
2016-11-24 13:18:42 +13:00
|
|
|
|
public GitHubUpdateManager(string owner, string repo)
|
2016-09-29 13:33:12 +13:00
|
|
|
|
{
|
2016-11-24 13:18:42 +13:00
|
|
|
|
GitHubOwner = owner;
|
|
|
|
|
GitHubRepo = repo;
|
2016-09-29 13:33:12 +13:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-21 11:40:03 +12:00
|
|
|
|
public GitHubUpdateManager(string owner, string repo, bool dev, bool portable) : this(owner, repo)
|
2016-09-29 13:33:12 +13:00
|
|
|
|
{
|
2022-09-21 11:40:03 +12:00
|
|
|
|
IsDev = dev;
|
2016-11-24 13:18:42 +13:00
|
|
|
|
IsPortable = portable;
|
2016-09-29 13:33:12 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ConfigureAutoUpdate()
|
|
|
|
|
{
|
|
|
|
|
lock (updateTimerLock)
|
|
|
|
|
{
|
2022-09-22 07:41:13 +12:00
|
|
|
|
if (AllowAutoUpdate)
|
2016-09-29 13:33:12 +13:00
|
|
|
|
{
|
|
|
|
|
if (updateTimer == null)
|
|
|
|
|
{
|
2016-11-24 13:18:42 +13:00
|
|
|
|
updateTimer = new Timer(state => CheckUpdate(), null, TimeSpan.Zero, UpdateCheckInterval);
|
2016-09-29 13:33:12 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckUpdate()
|
|
|
|
|
{
|
2022-09-22 07:41:13 +12:00
|
|
|
|
if (AutoUpdateEnabled && !UpdateMessageBox.IsOpen)
|
2016-09-29 13:33:12 +13:00
|
|
|
|
{
|
|
|
|
|
UpdateChecker updateChecker = CreateUpdateChecker();
|
|
|
|
|
updateChecker.CheckUpdate();
|
|
|
|
|
|
2022-09-22 09:57:04 +12:00
|
|
|
|
if (UpdateMessageBox.Start(updateChecker, firstUpdateCheck) == DialogResult.No)
|
2016-09-29 13:33:12 +13:00
|
|
|
|
{
|
2022-09-22 07:41:13 +12:00
|
|
|
|
AutoUpdateEnabled = false;
|
2016-09-29 13:33:12 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
firstUpdateCheck = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-24 13:18:42 +13:00
|
|
|
|
public GitHubUpdateChecker CreateUpdateChecker()
|
2016-09-29 13:33:12 +13:00
|
|
|
|
{
|
2016-11-24 13:18:42 +13:00
|
|
|
|
return new GitHubUpdateChecker(GitHubOwner, GitHubRepo)
|
2016-09-29 13:33:12 +13:00
|
|
|
|
{
|
2022-09-21 11:40:03 +12:00
|
|
|
|
IsDev = IsDev,
|
2016-11-24 13:18:42 +13:00
|
|
|
|
IsPortable = IsPortable,
|
2022-08-25 17:35:33 +12:00
|
|
|
|
IncludePreRelease = CheckPreReleaseUpdates
|
2016-09-29 13:33:12 +13:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
if (updateTimer != null)
|
|
|
|
|
{
|
|
|
|
|
updateTimer.Dispose();
|
|
|
|
|
updateTimer = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|