mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-12-27 12:35:35 +08:00
64 lines
2.0 KiB
C#
64 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
using BililiveRecorder.Core;
|
|
|
|
namespace BililiveRecorder.WPF.Models
|
|
{
|
|
internal class RootModel : INotifyPropertyChanged, IDisposable
|
|
{
|
|
private bool disposedValue;
|
|
private IRecorder recorder;
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
public LogModel Logs { get; } = new LogModel();
|
|
|
|
public IRecorder Recorder { get => recorder; internal set => SetField(ref recorder, value); }
|
|
|
|
public RootModel()
|
|
{
|
|
}
|
|
|
|
protected virtual void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = "")
|
|
{
|
|
if (EqualityComparer<T>.Default.Equals(field, value)) { return false; }
|
|
field = value; OnPropertyChanged(propertyName); return true;
|
|
}
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
{
|
|
if (!disposedValue)
|
|
{
|
|
if (disposing)
|
|
{
|
|
// dispose managed state (managed objects)
|
|
Recorder?.Dispose();
|
|
Logs.Dispose();
|
|
}
|
|
|
|
// free unmanaged resources (unmanaged objects) and override finalizer
|
|
// set large fields to null
|
|
disposedValue = true;
|
|
}
|
|
}
|
|
|
|
// override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
|
|
// ~RootModel()
|
|
// {
|
|
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
|
// Dispose(disposing: false);
|
|
// }
|
|
|
|
public void Dispose()
|
|
{
|
|
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
|
Dispose(disposing: true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|
|
}
|