mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-10-30 23:42:33 +01:00
Pass data cmd argument between application and update.
This commit is contained in:
parent
9b715ee078
commit
cb3d5fbfe7
@ -38,5 +38,29 @@ namespace NzbDrone.Common.Test.EnvironmentTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[TestCase("/data=test", "/data=test")]
|
||||||
|
[TestCase("/Data=/a/b/c", "/data=/a/b/c")]
|
||||||
|
public void should_preserver_data(string arg, string preserved)
|
||||||
|
{
|
||||||
|
var args = new StartupContext(new[] { arg });
|
||||||
|
args.PreservedArguments.Should().Be(preserved);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase("/nobrowser", "/nobrowser")]
|
||||||
|
[TestCase("/Nobrowser", "/nobrowser")]
|
||||||
|
[TestCase("-Nobrowser", "/nobrowser")]
|
||||||
|
public void should_preserver_no_browser(string arg, string preserved)
|
||||||
|
{
|
||||||
|
var args = new StartupContext(new[] { arg });
|
||||||
|
args.PreservedArguments.Should().Be(preserved);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_preserver_both()
|
||||||
|
{
|
||||||
|
var args = new StartupContext(new[] { "/data=test", "/Nobrowser" });
|
||||||
|
args.PreservedArguments.Should().Be("/data=test /nobrowser");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Common.Instrumentation;
|
||||||
|
|
||||||
namespace NzbDrone.Common.EnvironmentInfo
|
namespace NzbDrone.Common.EnvironmentInfo
|
||||||
{
|
{
|
||||||
@ -15,6 +17,9 @@ namespace NzbDrone.Common.EnvironmentInfo
|
|||||||
{
|
{
|
||||||
private readonly Environment.SpecialFolder DATA_SPECIAL_FOLDER = Environment.SpecialFolder.CommonApplicationData;
|
private readonly Environment.SpecialFolder DATA_SPECIAL_FOLDER = Environment.SpecialFolder.CommonApplicationData;
|
||||||
|
|
||||||
|
|
||||||
|
private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(AppFolderInfo));
|
||||||
|
|
||||||
public AppFolderInfo(IStartupContext startupContext)
|
public AppFolderInfo(IStartupContext startupContext)
|
||||||
{
|
{
|
||||||
if (OsInfo.IsNotWindows)
|
if (OsInfo.IsNotWindows)
|
||||||
@ -25,6 +30,7 @@ namespace NzbDrone.Common.EnvironmentInfo
|
|||||||
if (startupContext.Args.ContainsKey(StartupContext.APPDATA))
|
if (startupContext.Args.ContainsKey(StartupContext.APPDATA))
|
||||||
{
|
{
|
||||||
AppDataFolder = startupContext.Args[StartupContext.APPDATA];
|
AppDataFolder = startupContext.Args[StartupContext.APPDATA];
|
||||||
|
Logger.Info("Data directory is being overridden to [{0}]", AppDataFolder);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.InteropServices.ComTypes;
|
||||||
|
|
||||||
namespace NzbDrone.Common.EnvironmentInfo
|
namespace NzbDrone.Common.EnvironmentInfo
|
||||||
{
|
{
|
||||||
@ -8,6 +9,8 @@ namespace NzbDrone.Common.EnvironmentInfo
|
|||||||
Dictionary<string, string> Args { get; }
|
Dictionary<string, string> Args { get; }
|
||||||
bool InstallService { get; }
|
bool InstallService { get; }
|
||||||
bool UninstallService { get; }
|
bool UninstallService { get; }
|
||||||
|
|
||||||
|
string PreservedArguments { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class StartupContext : IStartupContext
|
public class StartupContext : IStartupContext
|
||||||
@ -60,5 +63,25 @@ namespace NzbDrone.Common.EnvironmentInfo
|
|||||||
return Flags.Contains(UNINSTALL_SERVICE);
|
return Flags.Contains(UNINSTALL_SERVICE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string PreservedArguments
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var args = "";
|
||||||
|
|
||||||
|
if (Args.ContainsKey(APPDATA))
|
||||||
|
{
|
||||||
|
args = "/data=" + Args[APPDATA];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Flags.Contains(NO_BROWSER))
|
||||||
|
{
|
||||||
|
args += " /" + NO_BROWSER;
|
||||||
|
}
|
||||||
|
|
||||||
|
return args.Trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,6 +27,7 @@ namespace NzbDrone.Core.Update
|
|||||||
private readonly IArchiveService _archiveService;
|
private readonly IArchiveService _archiveService;
|
||||||
private readonly IProcessProvider _processProvider;
|
private readonly IProcessProvider _processProvider;
|
||||||
private readonly IVerifyUpdates _updateVerifier;
|
private readonly IVerifyUpdates _updateVerifier;
|
||||||
|
private readonly IStartupContext _startupContext;
|
||||||
private readonly IConfigFileProvider _configFileProvider;
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
private readonly IRuntimeInfo _runtimeInfo;
|
private readonly IRuntimeInfo _runtimeInfo;
|
||||||
private readonly IBackupService _backupService;
|
private readonly IBackupService _backupService;
|
||||||
@ -36,6 +37,7 @@ namespace NzbDrone.Core.Update
|
|||||||
IDiskProvider diskProvider, IHttpClient httpClient,
|
IDiskProvider diskProvider, IHttpClient httpClient,
|
||||||
IArchiveService archiveService, IProcessProvider processProvider,
|
IArchiveService archiveService, IProcessProvider processProvider,
|
||||||
IVerifyUpdates updateVerifier,
|
IVerifyUpdates updateVerifier,
|
||||||
|
IStartupContext startupContext,
|
||||||
IConfigFileProvider configFileProvider,
|
IConfigFileProvider configFileProvider,
|
||||||
IRuntimeInfo runtimeInfo,
|
IRuntimeInfo runtimeInfo,
|
||||||
IBackupService backupService,
|
IBackupService backupService,
|
||||||
@ -52,6 +54,7 @@ namespace NzbDrone.Core.Update
|
|||||||
_archiveService = archiveService;
|
_archiveService = archiveService;
|
||||||
_processProvider = processProvider;
|
_processProvider = processProvider;
|
||||||
_updateVerifier = updateVerifier;
|
_updateVerifier = updateVerifier;
|
||||||
|
_startupContext = startupContext;
|
||||||
_configFileProvider = configFileProvider;
|
_configFileProvider = configFileProvider;
|
||||||
_runtimeInfo = runtimeInfo;
|
_runtimeInfo = runtimeInfo;
|
||||||
_backupService = backupService;
|
_backupService = backupService;
|
||||||
@ -142,7 +145,7 @@ namespace NzbDrone.Core.Update
|
|||||||
var processId = _processProvider.GetCurrentProcess().Id.ToString();
|
var processId = _processProvider.GetCurrentProcess().Id.ToString();
|
||||||
var executingApplication = _runtimeInfo.ExecutingApplication;
|
var executingApplication = _runtimeInfo.ExecutingApplication;
|
||||||
|
|
||||||
return String.Join(" ", processId, updateSandboxFolder.TrimEnd(Path.DirectorySeparatorChar).WrapInQuotes(), executingApplication.WrapInQuotes());
|
return String.Join(" ", processId, updateSandboxFolder.TrimEnd(Path.DirectorySeparatorChar).WrapInQuotes(), executingApplication.WrapInQuotes(), _startupContext.PreservedArguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EnsureAppDataSafety()
|
private void EnsureAppDataSafety()
|
||||||
|
@ -17,12 +17,14 @@ namespace NzbDrone.Update.UpdateEngine
|
|||||||
{
|
{
|
||||||
private readonly IServiceProvider _serviceProvider;
|
private readonly IServiceProvider _serviceProvider;
|
||||||
private readonly IProcessProvider _processProvider;
|
private readonly IProcessProvider _processProvider;
|
||||||
|
private readonly IStartupContext _startupContext;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public StartNzbDrone(IServiceProvider serviceProvider, IProcessProvider processProvider, Logger logger)
|
public StartNzbDrone(IServiceProvider serviceProvider, IProcessProvider processProvider, IStartupContext startupContext, Logger logger)
|
||||||
{
|
{
|
||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
_processProvider = processProvider;
|
_processProvider = processProvider;
|
||||||
|
_startupContext = startupContext;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +75,12 @@ namespace NzbDrone.Update.UpdateEngine
|
|||||||
_logger.Info("Starting {0}", fileName);
|
_logger.Info("Starting {0}", fileName);
|
||||||
var path = Path.Combine(installationFolder, fileName);
|
var path = Path.Combine(installationFolder, fileName);
|
||||||
|
|
||||||
_processProvider.SpawnNewProcess(path, "--" + StartupContext.NO_BROWSER);
|
if (!_startupContext.Flags.Contains(StartupContext.NO_BROWSER))
|
||||||
|
{
|
||||||
|
_startupContext.Flags.Add(StartupContext.NO_BROWSER);
|
||||||
|
}
|
||||||
|
|
||||||
|
_processProvider.SpawnNewProcess(path, _startupContext.PreservedArguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user