1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Merge pull request #248 from mitchellcash/sabnzbd_develop

Fixed: Parsing of SABnzbd develop version
This commit is contained in:
Devin Buhl 2017-01-14 00:57:04 -05:00 committed by GitHub
commit ad38437b70

View File

@ -30,7 +30,7 @@ public Sabnzbd(ISabnzbdProxy proxy,
}
// patch can be a number (releases) or 'x' (git)
private static readonly Regex VersionRegex = new Regex(@"(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+|x)(?<candidate>.*)", RegexOptions.Compiled);
private static readonly Regex VersionRegex = new Regex(@"(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+|x)", RegexOptions.Compiled);
protected override string AddFromNzbFile(RemoteEpisode remoteEpisode, string filename, byte[] fileContents)
{
@ -284,110 +284,103 @@ protected override void Test(List<ValidationFailure> failures)
failures.AddIfNotNull(TestCategory());
}
private bool HasVersion(int major, int minor, int patch = 0, string candidate = null)
private bool HasVersion(int major, int minor, int patch = 0)
{
candidate = candidate ?? string.Empty;
var rawVersion = _proxy.GetVersion(Settings);
var version = ParseVersion(rawVersion);
var version = _proxy.GetVersion(Settings);
if (version == null)
{
return false;
}
if (version.Major > major)
{
return true;
}
else if (version.Major < major)
{
return false;
}
if (version.Minor > minor)
{
return true;
}
else if (version.Minor < minor)
{
return false;
}
if (version.Build > patch)
{
return true;
}
else if (version.Build < patch)
{
return false;
}
return true;
}
private Version ParseVersion(string version)
{
var parsed = VersionRegex.Match(version);
int actualMajor;
int actualMinor;
int actualPatch;
string actualCandidate;
int major;
int minor;
int patch;
if (!parsed.Success)
if (parsed.Success)
{
major = Convert.ToInt32(parsed.Groups["major"].Value);
minor = Convert.ToInt32(parsed.Groups["minor"].Value);
patch = Convert.ToInt32(parsed.Groups["patch"].Value.Replace("x", "0"));
}
else
{
if (!version.Equals("develop", StringComparison.InvariantCultureIgnoreCase))
{
return false;
return null;
}
actualMajor = 1;
actualMinor = 1;
actualPatch = 0;
actualCandidate = null;
major = 1;
minor = 1;
patch = 0;
}
else
{
actualMajor = Convert.ToInt32(parsed.Groups["major"].Value);
actualMinor = Convert.ToInt32(parsed.Groups["minor"].Value);
actualPatch = Convert.ToInt32(parsed.Groups["patch"].Value.Replace("x", ""));
actualCandidate = parsed.Groups["candidate"].Value.ToUpper();
}
if (actualMajor > major)
{
return true;
}
else if (actualMajor < major)
{
return false;
}
if (actualMinor > minor)
{
return true;
}
else if (actualMinor < minor)
{
return false;
}
if (actualPatch > patch)
{
return true;
}
else if (actualPatch < patch)
{
return false;
}
if (actualCandidate.IsNullOrWhiteSpace())
{
return true;
}
else if (candidate.IsNullOrWhiteSpace())
{
return false;
}
else
{
return actualCandidate.CompareTo(candidate) > 0;
}
return new Version(major, minor, patch);
}
private ValidationFailure TestConnectionAndVersion()
{
try
{
var version = _proxy.GetVersion(Settings);
var parsed = VersionRegex.Match(version);
var rawVersion = _proxy.GetVersion(Settings);
var version = ParseVersion(rawVersion);
if (!parsed.Success)
if (version == null)
{
if (version.Equals("develop", StringComparison.InvariantCultureIgnoreCase))
{
return new NzbDroneValidationFailure("Version", "Sabnzbd develop version, assuming version 1.1.0 or higher.")
{
IsWarning = true,
DetailedDescription = "Radarr may not be able to support new features added to SABnzbd when running develop versions."
};
}
return new ValidationFailure("Version", "Unknown Version: " + version);
}
var major = Convert.ToInt32(parsed.Groups["major"].Value);
var minor = Convert.ToInt32(parsed.Groups["minor"].Value);
if (rawVersion.Equals("develop", StringComparison.InvariantCultureIgnoreCase))
{
return new NzbDroneValidationFailure("Version", "Sabnzbd develop version, assuming version 1.1.0 or higher.")
{
IsWarning = true,
DetailedDescription = "Radarr may not be able to support new features added to SABnzbd when running develop versions."
};
}
if (major >= 1)
if (version.Major >= 1)
{
return null;
}
if (minor >= 7)
if (version.Minor >= 7)
{
return null;
}