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