1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Api/Client/ClientSettings.cs

38 lines
1.3 KiB
C#
Raw Normal View History

2013-07-19 06:47:55 +03:00
using System.IO;
2013-06-16 00:42:30 +03:00
using System.Text.RegularExpressions;
using NzbDrone.Common.EnvironmentInfo;
2013-06-16 00:42:30 +03:00
using NzbDrone.Common.Messaging;
2013-06-16 01:18:41 +03:00
using NzbDrone.Common.Serializer;
2013-06-16 00:42:30 +03:00
using NzbDrone.Core.Lifecycle;
namespace NzbDrone.Api.Client
{
public class ClientSettings : IHandle<ApplicationStartedEvent>
{
private readonly IAppFolderInfo _appFolderInfo;
2013-06-16 00:42:30 +03:00
private static readonly Regex VersionRegex = new Regex(@"(?<=Version:\s')(.*)(?=')", RegexOptions.IgnoreCase | RegexOptions.Compiled);
2013-06-16 01:18:41 +03:00
private static readonly Regex BuildDateRegex = new Regex(@"(?<=BuildDate:\s)('.*')", RegexOptions.IgnoreCase | RegexOptions.Compiled);
2013-06-16 00:42:30 +03:00
public ClientSettings(IAppFolderInfo appFolderInfo)
2013-06-16 00:42:30 +03:00
{
_appFolderInfo = appFolderInfo;
2013-06-16 00:42:30 +03:00
}
public void Handle(ApplicationStartedEvent message)
{
//TODO: Update the APIKey (when we have it)
var appFile = Path.Combine(_appFolderInfo.StartUpFolder, "UI", "app.js");
2013-06-16 00:42:30 +03:00
var contents = File.ReadAllText(appFile);
var version = BuildInfo.Version;
var date = BuildInfo.BuildDateTime;
2013-06-16 00:42:30 +03:00
contents = VersionRegex.Replace(contents, version.ToString());
2013-06-16 01:18:41 +03:00
contents = BuildDateRegex.Replace(contents, date.ToUniversalTime().ToJson());
2013-06-16 00:42:30 +03:00
File.WriteAllText(appFile, contents);
}
}
}