core: fix manual update when automatic updates are disabled (#8767)

This commit is contained in:
Diego Heras 2020-05-25 22:41:26 +02:00 committed by GitHub
parent 9f4cb17284
commit fa9fb4799f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 28 deletions

View File

@ -22,31 +22,28 @@ using NLog;
namespace Jackett.Common.Services
{
public class UpdateService : IUpdateService
{
private readonly Logger logger;
private readonly WebClient client;
private readonly IConfigurationService configService;
private readonly ManualResetEvent locker = new ManualResetEvent(false);
private readonly ITrayLockService lockService;
private readonly IProcessService processService;
private readonly IServiceConfigService windowsService;
private readonly IFilePermissionService filePermissionService;
private readonly ServerConfig serverConfig;
private bool forceupdatecheck = false;
private Variants.JackettVariant variant = Variants.JackettVariant.NotFound;
private bool forceUpdateCheck; // false by default
private Variants.JackettVariant variant;
public UpdateService(Logger l, WebClient c, IConfigurationService cfg, ITrayLockService ls, IProcessService ps, IServiceConfigService ws, IFilePermissionService fps, ServerConfig sc)
public UpdateService(Logger l, WebClient c, ITrayLockService ls, IServiceConfigService ws, IFilePermissionService fps, ServerConfig sc)
{
logger = l;
client = c;
configService = cfg;
lockService = ls;
processService = ps;
windowsService = ws;
serverConfig = sc;
filePermissionService = fps;
variant = new Variants().GetVariant();
}
private string ExePath()
@ -62,7 +59,7 @@ namespace Jackett.Common.Services
public void CheckForUpdatesNow()
{
forceupdatecheck = true;
forceUpdateCheck = true;
locker.Set();
}
@ -82,16 +79,19 @@ namespace Jackett.Common.Services
private async Task CheckForUpdates()
{
logger.Info("Checking for updates... Jackett variant: " + variant);
if (serverConfig.RuntimeSettings.NoUpdates)
{
logger.Info("Updates are disabled via --NoUpdates.");
return;
}
if (serverConfig.UpdateDisabled && !forceupdatecheck)
if (serverConfig.UpdateDisabled && !forceUpdateCheck)
{
logger.Info("Skipping update check as it is disabled.");
return;
}
forceUpdateCheck = false; // Used when updates are disabled and the user click update button
if (Debugger.IsAttached)
{
logger.Info("Skipping checking for new releases as the debugger is attached.");
@ -100,17 +100,11 @@ namespace Jackett.Common.Services
var currentVersion = $"v{GetCurrentVersion()}";
if (currentVersion == "v0.0.0")
{
logger.Info("Skipping checking for new releases because we are runing in IDE.");
logger.Info("Skipping checking for new releases because Jackett is runing in IDE.");
return;
}
var variants = new Variants();
variant = variants.GetVariant();
logger.Info("Jackett variant: " + variant.ToString());
forceupdatecheck = true;
var isWindows = System.Environment.OSVersion.Platform != PlatformID.Unix;
var isWindows = Environment.OSVersion.Platform != PlatformID.Unix;
var trayIsRunning = false;
if (isWindows)
@ -144,7 +138,7 @@ namespace Jackett.Common.Services
var latestRelease = releases.OrderByDescending(o => o.Created_at).First();
if (latestRelease.Name != currentVersion)
{
logger.Info($"New release found. Current: {currentVersion} New: {latestRelease.Name}");
logger.Info($"New release found. Current version: {currentVersion} New version: {latestRelease.Name}");
logger.Info($"Downloading release {latestRelease.Name} It could take a while...");
try
{
@ -164,7 +158,7 @@ namespace Jackett.Common.Services
}
else
{
logger.Info($"Checked for a updated release but none was found. Current: {currentVersion} Latest: {latestRelease.Name}");
logger.Info($"Jackett is already updated. Current version: {currentVersion}");
}
}
}
@ -196,11 +190,10 @@ namespace Jackett.Common.Services
private WebRequest SetDownloadHeaders(WebRequest req)
{
req.Headers = new Dictionary<string, string>()
req.Headers = new Dictionary<string, string>
{
{ "Accept", "application/octet-stream" }
};
return req;
}
@ -210,7 +203,7 @@ namespace Jackett.Common.Services
if (!Directory.Exists(tempDir))
{
logger.Error("Temp dir doesn't exist: " + tempDir.ToString());
logger.Error("Temp dir doesn't exist: " + tempDir);
return;
}
@ -233,7 +226,7 @@ namespace Jackett.Common.Services
}
catch (Exception e)
{
logger.Error("Unexpected error while deleting temp files from " + tempDir.ToString());
logger.Error("Unexpected error while deleting temp files from " + tempDir);
logger.Error(e);
}
}
@ -340,7 +333,7 @@ namespace Jackett.Common.Services
return tempDir;
}
private void StartUpdate(string updaterExePath, string installLocation, bool isWindows, bool NoRestart, bool trayIsRunning)
private void StartUpdate(string updaterExePath, string installLocation, bool isWindows, bool noRestart, bool trayIsRunning)
{
var appType = "Console";
@ -363,7 +356,6 @@ namespace Jackett.Common.Services
{
// Wrap mono
args = exe + " " + args;
exe = "mono";
startInfo.Arguments = $"{Path.Combine(updaterExePath)} --Path \"{installLocation}\" --Type \"{appType}\" --Args \" {args}\"";
startInfo.FileName = "mono";
@ -385,7 +377,7 @@ namespace Jackett.Common.Services
logger.Error(e);
}
if (NoRestart)
if (noRestart)
{
startInfo.Arguments += " --NoRestart";
}
@ -404,7 +396,7 @@ namespace Jackett.Common.Services
var procInfo = Process.Start(startInfo);
logger.Info($"Updater started process id: {procInfo.Id}");
if (!NoRestart)
if (!noRestart)
{
if (isWindows)
{