diff --git a/BililiveRecorder.Core/Recording/RawDataRecordTask.cs b/BililiveRecorder.Core/Recording/RawDataRecordTask.cs index 941f9d3..1213810 100644 --- a/BililiveRecorder.Core/Recording/RawDataRecordTask.cs +++ b/BililiveRecorder.Core/Recording/RawDataRecordTask.cs @@ -27,23 +27,22 @@ namespace BililiveRecorder.Core.Recording protected override void StartRecordingLoop(Stream stream) { - var paths = this.CreateFileName(); + var (fullPath, relativePath) = this.CreateFileName(); try - { Directory.CreateDirectory(Path.GetDirectoryName(paths.fullPath)); } + { Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); } catch (Exception) { } this.fileOpeningEventArgs = new RecordFileOpeningEventArgs(this.room) { SessionId = this.SessionId, - FullPath = paths.fullPath, - RelativePath = paths.relativePath, + FullPath = fullPath, + RelativePath = relativePath, FileOpenTime = DateTimeOffset.Now, }; this.OnRecordFileOpening(this.fileOpeningEventArgs); - - var file = new FileStream(paths.fullPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read | FileShare.Delete); + var file = new FileStream(fullPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read | FileShare.Delete); _ = Task.Run(async () => await this.WriteStreamToFileAsync(stream, file).ConfigureAwait(false)); } diff --git a/BililiveRecorder.Core/Recording/RecordTaskBase.cs b/BililiveRecorder.Core/Recording/RecordTaskBase.cs index 37f9402..d032b0e 100644 --- a/BililiveRecorder.Core/Recording/RecordTaskBase.cs +++ b/BililiveRecorder.Core/Recording/RecordTaskBase.cs @@ -44,7 +44,7 @@ namespace BililiveRecorder.Core.Recording this.ct = this.cts.Token; - this.timer.Elapsed += this.Timer_Elapsed_TriggerStats; + this.timer.Elapsed += this.Timer_Elapsed_TriggerNetworkStats; } public Guid SessionId { get; } = Guid.NewGuid(); @@ -90,7 +90,7 @@ namespace BililiveRecorder.Core.Recording protected abstract void StartRecordingLoop(Stream stream); - private void Timer_Elapsed_TriggerStats(object sender, ElapsedEventArgs e) + private void Timer_Elapsed_TriggerNetworkStats(object sender, ElapsedEventArgs e) { int bytes; TimeSpan diff; @@ -129,12 +129,12 @@ namespace BililiveRecorder.Core.Recording protected (string fullPath, string relativePath) CreateFileName() { - var formatString = room.RoomConfig.RecordFilenameFormat!; + var formatString = this.room.RoomConfig.RecordFilenameFormat!; var now = DateTime.Now; var date = now.ToString("yyyyMMdd"); var time = now.ToString("HHmmss"); - var randomStr = random.Next(100, 999).ToString(); + var randomStr = this.random.Next(100, 999).ToString(); var relativePath = formatString .Replace(@"{date}", date) diff --git a/BililiveRecorder.Core/RecordingStats.cs b/BililiveRecorder.Core/RecordingStats.cs index 3039281..f6abbce 100644 --- a/BililiveRecorder.Core/RecordingStats.cs +++ b/BililiveRecorder.Core/RecordingStats.cs @@ -16,6 +16,11 @@ namespace BililiveRecorder.Core private long totalOutputBytes; private double duraionRatio; + public RecordingStats() + { + this.Reset(); + } + public TimeSpan SessionDuration { get => this.sessionDuration; set => this.SetField(ref this.sessionDuration, value); } public TimeSpan SessionMaxTimestamp { get => this.sessionMaxTimestamp; set => this.SetField(ref this.sessionMaxTimestamp, value); } public TimeSpan FileMaxTimestamp { get => this.fileMaxTimestamp; set => this.SetField(ref this.fileMaxTimestamp, value); } @@ -32,7 +37,7 @@ namespace BililiveRecorder.Core this.SessionDuration = TimeSpan.Zero; this.SessionMaxTimestamp = TimeSpan.Zero; this.FileMaxTimestamp = TimeSpan.Zero; - this.DuraionRatio = 0; + this.DuraionRatio = double.NaN; this.TotalInputBytes = 0; this.TotalOutputBytes = 0; this.NetworkMbps = 0; diff --git a/BililiveRecorder.Core/Room.cs b/BililiveRecorder.Core/Room.cs index 2ef83d7..0e3ba50 100644 --- a/BililiveRecorder.Core/Room.cs +++ b/BililiveRecorder.Core/Room.cs @@ -223,6 +223,7 @@ namespace BililiveRecorder.Core task.RecordSessionEnded += this.RecordTask_RecordSessionEnded; this.recordTask = task; this.recordTaskStartTime = DateTimeOffset.UtcNow; + this.Stats.Reset(); this.OnPropertyChanged(nameof(this.Recording)); _ = Task.Run(async () => @@ -368,6 +369,8 @@ namespace BililiveRecorder.Core this.basicDanmakuWriter.Disable(); this.OnPropertyChanged(nameof(this.Recording)); + this.Stats.Reset(); + RecordSessionEnded?.Invoke(this, new RecordSessionEndedEventArgs(this) { SessionId = id diff --git a/BililiveRecorder.WPF/Converters/RatioToColorBrushConverter.cs b/BililiveRecorder.WPF/Converters/RatioToColorBrushConverter.cs index 874e0ca..8e499ce 100644 --- a/BililiveRecorder.WPF/Converters/RatioToColorBrushConverter.cs +++ b/BililiveRecorder.WPF/Converters/RatioToColorBrushConverter.cs @@ -8,6 +8,7 @@ namespace BililiveRecorder.WPF.Converters { internal class RatioToColorBrushConverter : IValueConverter { + private static readonly SolidColorBrush Disabled = new SolidColorBrush(Colors.AliceBlue); private static readonly SolidColorBrush[] ColorMap; static RatioToColorBrushConverter() @@ -29,7 +30,12 @@ namespace BililiveRecorder.WPF.Converters public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - var i = (int)Math.Ceiling((1.1d - Math.Abs((1d - (double)value) * 4d)) * 20d); + var input = (double)value; + + if (double.IsNaN(input)) + return Disabled; + + var i = (int)Math.Ceiling((1.1d - Math.Abs((1d - input) * 4d)) * 20d); return i switch { < 0 => ColorMap[0],