bb8df8dfa0
Added ProductName and ServerVersion to API. Added build version and build step. Addressed issues wtih indentation. Made the BuildVersion an actual object. This lets up link to the github page of that commit. Fixed class method type and styled link. Fixed languages and split out the information in the UI. Moved update-version script and gave it executable permissions. Windows correctly finds the .bat file. And linux takes the one without extension. Removed tempfiles from replace sessions from csproj. Updated version generation scripts. Will also work with pre existing version files. (Source tarballs etc.) Added simple replace for ssh github links. Add execute rights to update-version. Wrapped long line in ApplicationHost.cs Fixed some small issues. Fixed some small issues, and flipped some if's around. Converted parameter names to camelBack casing. Sealed the attribute class. Removed MPLv2 license. Fixed file headers. Added newline. Moved links in *.csproj files as well. Fix issues caused by rebase auto merging. Removed default constructor and added init values to properties, also hid the Remote value form API.
134 lines
5.8 KiB
C#
134 lines
5.8 KiB
C#
// Jellyfin.Versioning/ExtendedVersion.cs
|
|
// Part of the Jellyfin project (https://jellyfin.media)
|
|
//
|
|
// All copyright belongs to the Jellyfin contributors; a full list can
|
|
// be found in the file CONTRIBUTORS.md
|
|
//
|
|
// 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, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Runtime.Serialization;
|
|
using System.Text;
|
|
|
|
namespace Jellyfin.Versioning
|
|
{
|
|
public class ExtendedVersion
|
|
{
|
|
[IgnoreDataMember]
|
|
public Version ApiVersion { get; }
|
|
|
|
public string CommitHash { get; } = String.Empty;
|
|
|
|
public long Revision { get; } = 0;
|
|
|
|
public string Branch { get; } = String.Empty;
|
|
|
|
public string TagDescription { get; } = String.Empty;
|
|
|
|
[IgnoreDataMember]
|
|
public Uri Remote { get; } = null;
|
|
|
|
public ExtendedVersion(Version apiVersion, Stream extendedVersionFileStream)
|
|
{
|
|
ApiVersion = apiVersion;
|
|
int line = 1;
|
|
using (var reader = new StreamReader(extendedVersionFileStream))
|
|
{
|
|
while (!reader.EndOfStream)
|
|
{
|
|
string item = reader.ReadLine();
|
|
|
|
if (string.IsNullOrWhiteSpace(item.Trim()))
|
|
{
|
|
//empty line, skip
|
|
continue;
|
|
}
|
|
var kvpair = item.Split('=');
|
|
if (kvpair.Length != 2)
|
|
{
|
|
throw new ArgumentException(nameof(extendedVersionFileStream),
|
|
$"ExtendedVersionFile contains bad key-value pair '{item}' at line {line}.");
|
|
}
|
|
var key = kvpair[0].Trim().ToLower();
|
|
var value = kvpair[1].Trim();
|
|
switch (key)
|
|
{
|
|
case "commit":
|
|
if (value.Length < 7 || value.Length > 40)
|
|
{
|
|
throw new ArgumentException(nameof(extendedVersionFileStream),
|
|
$"ExtendedVersionFile has a bad commit hash '{value}' on line {line}, it should be a string between 7 and 40 characters.");
|
|
}
|
|
CommitHash = value;
|
|
break;
|
|
case "branch":
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
{
|
|
throw new ArgumentException(nameof(extendedVersionFileStream),
|
|
$"ExtendedVersionFile has a bad branch '{value}' on line {line}, it can not be empty.");
|
|
}
|
|
Branch = value;
|
|
break;
|
|
case "revision":
|
|
if (!long.TryParse(value, out long rev))
|
|
{
|
|
throw new ArgumentException(nameof(extendedVersionFileStream),
|
|
$"ExtendedVersionFile has a bad revision '{value}' on line {line}, it should be an integer.");
|
|
}
|
|
Revision = rev;
|
|
break;
|
|
case "tagdesc":
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
{
|
|
throw new ArgumentException(nameof(extendedVersionFileStream),
|
|
$"ExtendedVersionFile has a bad tag description '{value}' on line {line}, it can not be empty.");
|
|
}
|
|
TagDescription = value;
|
|
break;
|
|
case "remote":
|
|
var remoteRepo = value.Replace(".git", string.Empty).Replace("git@github.com:", "https://github.com/");
|
|
if (Uri.IsWellFormedUriString(remoteRepo, UriKind.Absolute))
|
|
{
|
|
Remote = new Uri(remoteRepo);
|
|
}
|
|
else if (Uri.IsWellFormedUriString(value, UriKind.Absolute))
|
|
{
|
|
//fallback if the replace about broke the Uri
|
|
Remote = new Uri(value);
|
|
}
|
|
else
|
|
{
|
|
throw new ArgumentException(nameof(extendedVersionFileStream),
|
|
$"ExtendedVersionFile has a bad remote URI '{value}' on line {line}, it should be a valid remote URI (ssh or https).");
|
|
}
|
|
break;
|
|
default:
|
|
throw new ArgumentException(nameof(extendedVersionFileStream),
|
|
$"ExtendedVersionFile contains an unrecognized key-value pair '{item}' at line {line}.");
|
|
}
|
|
line++;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{ApiVersion};{CommitHash};{Revision};{Branch};{TagDescription};{Remote}";
|
|
}
|
|
}
|
|
}
|