Skip to content

Commit

Permalink
apply code style preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
radj307 committed Jul 7, 2022
1 parent e7ae265 commit 9f936b5
Show file tree
Hide file tree
Showing 72 changed files with 1,174 additions and 1,275 deletions.
13 changes: 7 additions & 6 deletions AppConfig/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using PropertyChanged;
using System.ComponentModel;
using System.Reflection;

Expand Down Expand Up @@ -32,11 +33,11 @@ public Configuration()
/// </summary>
[JsonIgnore]
public static Configuration Default { get; set; } = null!;

[SuppressPropertyChangedWarnings]
public object? this[string name]
{
get => GetType().GetProperty(name)?.GetValue(this);
set => GetType().GetProperty(name)?.SetValue(this, value);
get => this.GetType().GetProperty(name)?.GetValue(this);
set => this.GetType().GetProperty(name)?.SetValue(this, value);
}
#endregion Properties

Expand All @@ -56,9 +57,9 @@ public object? this[string name]
/// <param name="other">Another <see cref="Configuration"/>-derived instance.</param>
public virtual void SetTo(Configuration other)
{
Type myType = GetType();
Type myType = this.GetType();
Type otherType = other.GetType();
foreach (var member in myType.GetMembers())
foreach (MemberInfo? member in myType.GetMembers())
{
if (member.Name.Equals("Item"))
continue;
Expand Down Expand Up @@ -89,7 +90,7 @@ public virtual bool Load(string path)
{
if (path.Length == 0)
return false;
if (JsonFile.Load(path, GetType()) is Configuration cfg)
if (JsonFile.Load(path, this.GetType()) is Configuration cfg)
{
this.SetTo(cfg);
return true;
Expand Down
6 changes: 3 additions & 3 deletions AppConfig/ConfigurationFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class ConfigurationFile : Configuration
/// Creates a new <see cref="ConfigurationFile"/> instance using the given <paramref name="location"/>.
/// </summary>
/// <param name="location">The location of the JSON file in the filesystem.</param>
public ConfigurationFile(string location) : base() => Location = location;
public ConfigurationFile(string location) : base() => this.Location = location;
/// <summary>
/// Creates a new <see cref="ConfigurationFile"/> instance without a filepath.<br/>
/// Note that the filepath must be provided before calling methods that use it implicitly.
Expand All @@ -35,13 +35,13 @@ public ConfigurationFile() : this(string.Empty) { }
/// </summary>
/// <remarks>This method may be overloaded in derived classes.</remarks>
/// <returns><see langword="true"/> when the file specified by <paramref name="Location"/> exists and was successfully loaded; otherwise <see langword="false"/>.</returns>
public virtual bool Load() => base.Load(Location);
public virtual bool Load() => base.Load(this.Location);
/// <summary>
/// Saves config values to the JSON file specified by <paramref name="Location"/>
/// </summary>
/// <remarks>This method may be overloaded in derived classes.</remarks>
/// <param name="formatting">Formatting type to use when serializing this class instance.</param>
public virtual void Save(Formatting formatting = Formatting.Indented) => base.Save(Location, formatting);
public virtual void Save(Formatting formatting = Formatting.Indented) => base.Save(this.Location, formatting);
#endregion Methods
}
}
227 changes: 112 additions & 115 deletions VolumeControl.Audio/AudioAPI.cs

Large diffs are not rendered by default.

200 changes: 102 additions & 98 deletions VolumeControl.Audio/AudioDevice.cs

Large diffs are not rendered by default.

128 changes: 64 additions & 64 deletions VolumeControl.Audio/AudioSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,49 @@ public sealed class AudioSession : IProcess, ISession, INotifyPropertyChanged, I
internal AudioSession(AudioSessionControl controller)
{
_controller = controller;
PID = Convert.ToInt64(_controller.GetProcessID);
this.PID = Convert.ToInt64(_controller.GetProcessID);

if (GetProcess() is not Process proc)
if (this.GetProcess() is not Process proc)
{
FLog.Log.Error($"The constructor of '{typeof(AudioSession).FullName}' encountered an error when getting process with ID '{PID}'!");
Dispose();
ProcessName = string.Empty;
Process = null!;
FLog.Log.Error($"The constructor of '{typeof(AudioSession).FullName}' encountered an error when getting process with ID '{this.PID}'!");
this.Dispose();
this.ProcessName = string.Empty;
this.Process = null!;
}
else
{
Process = proc;
this.Process = proc;

var hashcode = Process.GetHashCode();
int hashcode = this.Process.GetHashCode();

ProcessName = Process.ProcessName;
this.ProcessName = this.Process.ProcessName;
}

_controller.RegisterEventClient(NotificationClient = new());
_controller.RegisterEventClient(this.NotificationClient = new());

NotificationClient.IconPathChanged += (s, e) =>
this.NotificationClient.IconPathChanged += (s, e) =>
{
_icons = null;
NotifyPropertyChanged(nameof(IconPath));
NotifyPropertyChanged(nameof(SmallIcon));
NotifyPropertyChanged(nameof(LargeIcon));
NotifyPropertyChanged(nameof(Icon));
this.NotifyPropertyChanged(nameof(this.IconPath));
this.NotifyPropertyChanged(nameof(this.SmallIcon));
this.NotifyPropertyChanged(nameof(this.LargeIcon));
this.NotifyPropertyChanged(nameof(this.Icon));
};
NotificationClient.VolumeChanged += (s, e) =>
this.NotificationClient.VolumeChanged += (s, e) =>
{
NotifyPropertyChanged(nameof(NativeVolume));
NotifyPropertyChanged(nameof(Volume));
NotifyPropertyChanged(nameof(Muted));
this.NotifyPropertyChanged(nameof(this.NativeVolume));
this.NotifyPropertyChanged(nameof(this.Volume));
this.NotifyPropertyChanged(nameof(this.Muted));
};
NotificationClient.DisplayNameChanged += (s, e) =>
this.NotificationClient.DisplayNameChanged += (s, e) =>
{
NotifyPropertyChanged(nameof(DisplayName));
this.NotifyPropertyChanged(nameof(this.DisplayName));
};
NotificationClient.GroupingParamChanged += (s, e) =>
this.NotificationClient.GroupingParamChanged += (s, e) =>
{
NotifyPropertyChanged(nameof(GroupingParam));
this.NotifyPropertyChanged(nameof(this.GroupingParam));
};
NotificationClient.StateChanged += NotifyStateChanged;
this.NotificationClient.StateChanged += this.NotifyStateChanged;
}

#region Fields
Expand All @@ -73,7 +73,7 @@ internal AudioSession(AudioSessionControl controller)

#region Properties
/// <inheritdoc/>
public int HashCode => _hashCode ??= Process.GetHashCode();
public int HashCode => _hashCode ??= this.Process.GetHashCode();
private int? _hashCode;
/// <summary>
/// Gets the <see cref="SimpleAudioVolume"/> object from the underlying <see cref="AudioSessionControl"/> type.
Expand Down Expand Up @@ -103,38 +103,38 @@ internal AudioSession(AudioSessionControl controller)
/// Gets the large or small icon, depending on whether they are null or not.
/// </summary>
/// <remarks>Checks and returns <see cref="LargeIcon"/> first, if that is null then it checks and returns <see cref="SmallIcon"/>.<br/>If both are null, returns null.</remarks>
public ImageSource? Icon => SmallIcon ?? LargeIcon;
public ImageSource? Icon => this.SmallIcon ?? this.LargeIcon;
/// <inheritdoc/>
public int Volume
{
get => Convert.ToInt32(NativeVolume * 100f);
get => Convert.ToInt32(this.NativeVolume * 100f);
set
{
NotifyPropertyChanging();
NativeVolume = (float)MathExt.Clamp(Convert.ToDouble(value) / 100f, 0.0, 1.0);
NotifyPropertyChanged();
this.NotifyPropertyChanging();
this.NativeVolume = (float)MathExt.Clamp(Convert.ToDouble(value) / 100f, 0.0, 1.0);
this.NotifyPropertyChanged();
}
}
/// <inheritdoc/>
public float NativeVolume
{
get => VolumeController.Volume;
get => this.VolumeController.Volume;
set
{
NotifyPropertyChanging();
VolumeController.Volume = MathExt.Clamp(value, 0f, 1f);
NotifyPropertyChanged();
this.NotifyPropertyChanging();
this.VolumeController.Volume = MathExt.Clamp(value, 0f, 1f);
this.NotifyPropertyChanged();
}
}
/// <inheritdoc/>
public bool Muted
{
get => VolumeController.Mute;
get => this.VolumeController.Mute;
set
{
NotifyPropertyChanging();
VolumeController.Mute = value;
NotifyPropertyChanged();
this.NotifyPropertyChanging();
this.VolumeController.Mute = value;
this.NotifyPropertyChanged();
}
}
/// <summary><see href="https://docs.microsoft.com/en-us/windows/win32/coreaudio/grouping-parameters"/></summary>
Expand All @@ -144,9 +144,9 @@ public Guid GroupingParam
get => _controller.GetGroupingParam();
set
{
NotifyPropertyChanging();
this.NotifyPropertyChanging();
_controller.SetGroupingParam(value, Guid.NewGuid());
NotifyPropertyChanged();
this.NotifyPropertyChanged();
}
}
/// <summary>Session display name.</summary>
Expand All @@ -155,9 +155,9 @@ public string DisplayName
get => _controller.DisplayName;
set
{
NotifyPropertyChanging();
this.NotifyPropertyChanging();
_controller.DisplayName = value;
NotifyPropertyChanged();
this.NotifyPropertyChanged();
_name = null; //< set the _name field to null, causing 'Name' to be refreshed.
}
}
Expand All @@ -166,7 +166,7 @@ public string DisplayName
/// <inheritdoc/>
public long PID { get; }
/// <inheritdoc/>
public string ProcessIdentifier => _processIdentifier ??= PID != -1L ? $"{PID}:{ProcessName}" : string.Empty;
public string ProcessIdentifier => _processIdentifier ??= this.PID != -1L ? $"{this.PID}:{this.ProcessName}" : string.Empty;
private string? _processIdentifier = null;
/// <summary>
/// Checks if the process that owns this session is still running.
Expand All @@ -176,7 +176,7 @@ public bool IsRunning
{
get
{
if (State.Equals(AudioSessionState.AudioSessionStateExpired) || GetProcess() is not Process proc)
if (this.State.Equals(AudioSessionState.AudioSessionStateExpired) || this.GetProcess() is not Process proc)
return false;
try
{
Expand All @@ -196,20 +196,20 @@ public bool IsRunning
/// <summary>
/// Checks if the session's state is set to active and the associated process is running.
/// </summary>
public bool Active => State.Equals(AudioSessionState.AudioSessionStateActive) && IsRunning;
public bool Active => this.State.Equals(AudioSessionState.AudioSessionStateActive) && this.IsRunning;
/// <summary>This session's parent <see cref="Process"/>.</summary>
public Process Process { get; }
/// <inheritdoc/>
/// <remarks>This is the <see cref="DisplayName"/> if it is set to a non-empty string; otherwise this is the <see cref="ProcessName"/>.</remarks>
public string Name
{
get => _name ??= PID.Equals(0) ? "System Sounds" : (DisplayName.Length > 0 ? DisplayName : ProcessName);
get => _name ??= this.PID.Equals(0) ? "System Sounds" : (this.DisplayName.Length > 0 ? this.DisplayName : this.ProcessName);
set
{
DisplayName = value;
NotifyPropertyChanging();
_name = DisplayName;
NotifyPropertyChanged();
this.DisplayName = value;
this.NotifyPropertyChanging();
_name = this.DisplayName;
this.NotifyPropertyChanged();
}
}
private string? _name;
Expand All @@ -223,7 +223,7 @@ public string Name
public event EventHandler<AudioSessionState>? StateChanged;
private void NotifyStateChanged(object? _, AudioSessionState e)
{
NotifyPropertyChanged(nameof(State));
this.NotifyPropertyChanged(nameof(this.State));
StateChanged?.Invoke(this, e);
}
/// <summary>Triggered after one of this instance's properties have been set.</summary>
Expand All @@ -238,16 +238,16 @@ private void NotifyStateChanged(object? _, AudioSessionState e)
/// <inheritdoc cref="IconGetter.GetIcons(string)"/>
public (ImageSource?, ImageSource?)? GetIcons()
{
if (IconPath.Length > 0)
return IconGetter.GetIcons(IconPath);
var proc = GetProcess();
if (this.IconPath.Length > 0)
return IconGetter.GetIcons(this.IconPath);
Process? proc = this.GetProcess();
try
{
string? path = proc?.MainModule?.FileName;
if (path != null)
return IconGetter.GetIcons(path);
}
catch(Exception ex)
catch (Exception ex)
{
FLog.Log.Error($"Failed to query information for process {proc?.Id}", ex);
}
Expand All @@ -261,7 +261,7 @@ private void NotifyStateChanged(object? _, AudioSessionState e)
{
try
{
return Process.GetProcessById((int)PID);
return Process.GetProcessById((int)this.PID);
}
catch (Exception ex)
{
Expand All @@ -272,7 +272,7 @@ private void NotifyStateChanged(object? _, AudioSessionState e)
/// <inheritdoc/>
public void Dispose()
{
_controller.UnRegisterEventClient(NotificationClient);
_controller.UnRegisterEventClient(this.NotificationClient);
_controller.Dispose();
GC.SuppressFinalize(this);
}
Expand Down Expand Up @@ -301,19 +301,19 @@ public static (int, string) ParseProcessIdentifier(string identifier)
}
else // both
{
if (!int.TryParse(identifier[..delim], out int result))
throw new FormatException($"Invalid process identifier string '{identifier}'");
return (result, identifier[(delim + 1)..]);
return !int.TryParse(identifier[..delim], out int result)
? throw new FormatException($"Invalid process identifier string '{identifier}'")
: ((int, string))(result, identifier[(delim + 1)..]);
}
}
/// <inheritdoc/>
public bool Equals(ISession? other) => PID.Equals(other?.PID);
public bool Equals(ISession? other) => this.PID.Equals(other?.PID);
/// <inheritdoc/>
public bool Equals(AudioSession? other) => PID.Equals(other?.PID);
public bool Equals(AudioSession? other) => this.PID.Equals(other?.PID);
/// <inheritdoc/>
public override bool Equals(object? obj) => Equals(obj as AudioSession);
public override bool Equals(object? obj) => this.Equals(obj as AudioSession);
/// <inheritdoc/>
public override int GetHashCode() => ProcessIdentifier.GetHashCode();
public override int GetHashCode() => this.ProcessIdentifier.GetHashCode();
#endregion Methods
}
}
Loading

0 comments on commit 9f936b5

Please sign in to comment.