Skip to content
This repository has been archived by the owner on Jan 7, 2024. It is now read-only.

Commit

Permalink
Migration to C#10
Browse files Browse the repository at this point in the history
  • Loading branch information
iXab3r committed Jun 20, 2022
1 parent ff98f39 commit 91b933c
Show file tree
Hide file tree
Showing 25 changed files with 74 additions and 166 deletions.
30 changes: 5 additions & 25 deletions Sources/MicSwitch/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reflection;
using System.Reflection;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using MicSwitch.MainWindow.Models;
using MicSwitch.MainWindow.ViewModels;
using MicSwitch.Modularity;
using MicSwitch.Prism;
using MicSwitch.Services;
using PoeShared;
using PoeShared.Modularity;
using PoeShared.Native;
using PoeShared.Native.Scaffolding;
using PoeShared.Prism;
using PoeShared.Scaffolding;
using PoeShared.Services;
using PoeShared.Squirrel.Core;
using PoeShared.Squirrel.Prism;
using PoeShared.Squirrel.Updater;
using PoeShared.UI;
using PoeShared.Wpf.Scaffolding;
using ReactiveUI;
using Unity;
using Unity.Resolution;

namespace MicSwitch
Expand Down Expand Up @@ -89,7 +69,7 @@ private void SingleInstanceValidationRoutine(bool retryIfAbandoned)
}
catch (AbandonedMutexException ex)
{
Log.Debug($"Mutex is abandoned {mutexId} (retryIfAbandoned: {retryIfAbandoned})");
Log.Debug($"Mutex is abandoned {mutexId} (retryIfAbandoned: {retryIfAbandoned})", ex);
if (retryIfAbandoned)
{
SingleInstanceValidationRoutine(false);
Expand Down Expand Up @@ -169,7 +149,7 @@ protected override void OnStartup(StartupEventArgs e)
sw.Step($"Main window shown");
}

private static void ActualizeConfig(IConfigProvider<MicSwitchConfig> mainConfigProvider)
private void ActualizeConfig(IConfigProvider<MicSwitchConfig> mainConfigProvider)
{
Log.Debug($"Actualizing configuration format of {mainConfigProvider}");
var config = mainConfigProvider.ActualConfig.CloneJson();
Expand All @@ -187,7 +167,7 @@ private static void ActualizeConfig(IConfigProvider<MicSwitchConfig> mainConfigP
Log.Debug("Config format updated successfully");
}

private static void ActualizeConfig(IConfigProvider<MicSwitchConfig> mainConfigProvider, IConfigProvider<MicSwitchHotkeyConfig> hotkeyConfigProvider)
private void ActualizeConfig(IConfigProvider<MicSwitchConfig> mainConfigProvider, IConfigProvider<MicSwitchHotkeyConfig> hotkeyConfigProvider)
{
Log.Debug($"Actualizing configuration format of {hotkeyConfigProvider}");

Expand Down Expand Up @@ -220,7 +200,7 @@ private static void ActualizeConfig(IConfigProvider<MicSwitchConfig> mainConfigP
Log.Debug("Config format updated successfully");
}

private static void ActualizeConfig(IConfigProvider<MicSwitchConfig> mainConfigProvider, IConfigProvider<MicSwitchOverlayConfig> overlayConfigProvider)
private void ActualizeConfig(IConfigProvider<MicSwitchConfig> mainConfigProvider, IConfigProvider<MicSwitchOverlayConfig> overlayConfigProvider)
{
Log.Debug($"Actualizing configuration format of {overlayConfigProvider}");

Expand Down
1 change: 0 additions & 1 deletion Sources/MicSwitch/MainWindow/Models/GraphicsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
Expand Down
10 changes: 0 additions & 10 deletions Sources/MicSwitch/MainWindow/Models/ImageProvider.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
using System;
using System.Drawing;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using JetBrains.Annotations;
using log4net;
using MicSwitch.Modularity;
using MicSwitch.Services;
using PoeShared;
using PoeShared.Modularity;
using PoeShared.Prism;
using PoeShared.Scaffolding;
using ReactiveUI;
using Unity;

namespace MicSwitch.MainWindow.Models
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
using System;
using System.Reactive.Linq;
using System.Windows.Input;
using log4net;
using MicSwitch.MainWindow.Models;
using PoeShared;
using PoeShared.Scaffolding;
using PoeShared.UI;
using PropertyBinder;
using ReactiveUI;

namespace MicSwitch.MainWindow.ViewModels
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using MicSwitch.MainWindow.Models;
using PoeShared.Scaffolding;
using PoeShared.UI;

namespace MicSwitch.MainWindow.ViewModels
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using PoeShared.Scaffolding;

namespace MicSwitch.MainWindow.ViewModels
{
public interface IMainWindowViewModel : IDisposableReactiveObject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using MicSwitch.MainWindow.Models;
using PoeShared.Native;

namespace MicSwitch.MainWindow.ViewModels
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System.Collections.ObjectModel;
using MicSwitch.MainWindow.Models;
using MicSwitch.Services;
using PoeShared.Audio.Models;
using PoeShared.Scaffolding;
using PoeShared.Scaffolding.WPF;

namespace MicSwitch.MainWindow.ViewModels
{
Expand Down
44 changes: 17 additions & 27 deletions Sources/MicSwitch/MainWindow/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using log4net;
Expand All @@ -15,19 +8,8 @@
using Microsoft.Win32;
using MicSwitch.MainWindow.Models;
using MicSwitch.Modularity;
using PoeShared;
using PoeShared.Audio.Services;
using PoeShared.Audio.ViewModels;
using PoeShared.Modularity;
using PoeShared.Native;
using PoeShared.Prism;
using PoeShared.Scaffolding;
using PoeShared.Scaffolding.WPF;
using PoeShared.Services;
using PoeShared.Squirrel.Updater;
using PoeShared.UI;
using ReactiveUI;
using Unity;
using Application = System.Windows.Application;
using Size = System.Windows.Size;

Expand Down Expand Up @@ -105,14 +87,22 @@ public MainWindowViewModel(
WindowState = WindowState.Minimized;
Overlay = overlay.AddTo(Anchors);

var startupManagerArgs = new StartupManagerArgs
try
{
UniqueAppName = $"{appArguments.AppName}{(appArguments.IsDebugMode ? "-debug" : string.Empty)}",
ExecutablePath = appUpdater.GetLatestExecutable().FullName,
CommandLineArgs = appArguments.StartupArgs,
AutostartFlag = appArguments.AutostartFlag
};
this.startupManager = startupManagerFactory.Create(startupManagerArgs);
var startupManagerArgs = new StartupManagerArgs
{
UniqueAppName = $"{appArguments.AppName}{(appArguments.IsDebugMode ? "-debug" : string.Empty)}",
ExecutablePath = appUpdater.LauncherExecutable.FullName,
CommandLineArgs = appArguments.StartupArgs,
AutostartFlag = appArguments.AutostartFlag
};
this.startupManager = startupManagerFactory.Create(startupManagerArgs);
RunAtLoginToggleCommand = CommandWrapper.Create<bool>(RunAtLoginCommandExecuted, Observable.Return(startupManager?.IsReady ?? false));
}
catch (Exception e)
{
Log.Warn("Failed to initialize startup manager", e);
}

this.RaiseWhenSourceValue(x => x.IsActive, mainWindowTracker, x => x.IsActive, uiScheduler).AddTo(Anchors);
this.RaiseWhenSourceValue(x => x.RunAtLogin, startupManager, x => x.IsRegistered, uiScheduler).AddTo(Anchors);
Expand Down Expand Up @@ -328,7 +318,7 @@ public MainWindowViewModel(

public bool IsActive => mainWindowTracker.IsActive;

public bool RunAtLogin => startupManager.IsRegistered;
public bool RunAtLogin => startupManager?.IsRegistered ?? false;

public Size MinSize { get; } = new Size(600, 430);
public Size MaxSize { get; } = new Size(900, 980);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
using System;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using log4net;
using MicSwitch.MainWindow.Models;
using MicSwitch.Modularity;
using MicSwitch.Services;
using PoeShared;
using PoeShared.Modularity;
using PoeShared.Native;
using PoeShared.Prism;
using PoeShared.Scaffolding;
using PoeShared.Scaffolding.WPF;
using ReactiveUI;
using Unity;
using Size = System.Drawing.Size;

namespace MicSwitch.MainWindow.ViewModels
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Linq.Expressions;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using DynamicData;
using DynamicData.Binding;
using log4net;
using MicSwitch.MainWindow.Models;
using MicSwitch.Modularity;
using MicSwitch.Services;
using PoeShared;
using PoeShared.Audio.Models;
using PoeShared.Modularity;
using PoeShared.Prism;
using PoeShared.Scaffolding;
using PoeShared.Scaffolding.WPF;
using PoeShared.UI;
using ReactiveUI;
using Unity;

namespace MicSwitch.MainWindow.ViewModels
{
Expand Down
9 changes: 2 additions & 7 deletions Sources/MicSwitch/MainWindow/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.ComponentModel;
using System.Reactive.Disposables;
using System.ComponentModel;
using System.Windows;
using log4net;
using PoeShared.Modularity;
using PoeShared.Scaffolding;
using PoeShared.Scaffolding.WPF;

namespace MicSwitch.MainWindow.Views
{
Expand All @@ -15,7 +10,7 @@ namespace MicSwitch.MainWindow.Views
public partial class MainWindow
{
private static readonly ILog Log = LogManager.GetLogger(typeof(MainWindow));
private readonly CompositeDisposable anchors = new CompositeDisposable();
private readonly CompositeDisposable anchors = new();

public MainWindow(IAppArguments appArguments)
{
Expand Down
6 changes: 1 addition & 5 deletions Sources/MicSwitch/MicSwitch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6-windows10.0.19041.0</TargetFramework>
<LangVersion>9</LangVersion>
<LangVersion>10</LangVersion>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AssemblyName>MicSwitch</AssemblyName>
<OutputPath>..\bin</OutputPath>
Expand All @@ -24,15 +24,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CsQuery" Version="1.3.4" />
<PackageReference Include="DynamicData" Version="7.4.9" />
<PackageReference Include="H.NotifyIcon.Wpf" Version="2.0.48" />
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3" />
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="NAudio" Version="2.0.1" />
<PackageReference Include="Prism.Core" Version="7.2.0.1367" />
<PackageReference Include="Prism.Unity" Version="7.2.0.1367" />
<PackageReference Include="Prism.Wpf" Version="7.2.0.1367" />
<PackageReference Include="ReactiveUI" Version="17.1.17" />
<PackageReference Include="SevenZipSharp.Interop" Version="19.0.1" />
<PackageReference Include="System.Drawing.Primitives" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit" Version="4.7.0" />
Expand Down
6 changes: 1 addition & 5 deletions Sources/MicSwitch/Modularity/MicSwitchConfig.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using System;
using System.Drawing;
using System.Drawing;
using System.Windows;
using MicSwitch.MainWindow.Models;
using MicSwitch.Services;
using Newtonsoft.Json;
using PoeShared.Audio.Models;
using PoeShared.Modularity;
using Point = System.Windows.Point;
using Size = System.Windows.Size;

Expand Down
1 change: 0 additions & 1 deletion Sources/MicSwitch/Modularity/MicSwitchHotkeyConfig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using MicSwitch.MainWindow.Models;
using PoeShared.Modularity;

namespace MicSwitch.Modularity
{
Expand Down
2 changes: 0 additions & 2 deletions Sources/MicSwitch/Modularity/MicSwitchOverlayConfig.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Drawing;
using MicSwitch.MainWindow.Models;
using PoeShared.Modularity;
using PoeShared.Native;
using Point = System.Windows.Point;
using Size = System.Windows.Size;

Expand Down
47 changes: 47 additions & 0 deletions Sources/MicSwitch/Properties/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// ReSharper disable RedundantUsingDirective.Global
global using PoeShared.Audio.ViewModels;
global using PoeShared.Scaffolding.WPF;
global using PoeShared.UI.Bindings;
global using PoeShared.Wpf.Scaffolding;
global using System.Collections.Generic;
global using System.Diagnostics;
global using System.Linq;
global using PoeShared;
global using PoeShared.Modularity;
global using PoeShared.Native;
global using PoeShared.Scaffolding;
global using PoeShared.Logging;
global using System;
global using System.Reactive;
global using System.Reactive.Concurrency;
global using System.Reactive.Linq;
global using System.Reactive.Subjects;
global using System.Threading;
global using System.Reactive.Disposables;
global using System.Linq.Expressions;
global using System.Collections.ObjectModel;
global using System.Collections.Concurrent;
global using System.Reactive.Threading.Tasks;
global using System.Threading.Tasks;
global using JetBrains.Annotations;
global using PoeShared.Prism;
global using PoeShared.UI;
global using PoeShared.WindowSeekers;
global using PoeShared.Services;
global using ReactiveUI;
global using Unity;
global using System.IO;
global using PropertyBinder;
global using DynamicData;
global using DynamicData.Binding;
global using DynamicData.Kernel;
global using WinSize = System.Drawing.Size;
global using WinPoint = System.Drawing.Point;
global using WinRectangle = System.Drawing.Rectangle;
global using IDisposable = System.IDisposable;
global using Guard = PoeShared.Guard;
global using AwesomeIcons = PoeShared.Themes.AwesomeIcons;
global using Path = System.IO.Path;
global using Directory = System.IO.Directory;
global using SearchOption = System.IO.SearchOption;
global using File = System.IO.File;
6 changes: 0 additions & 6 deletions Sources/MicSwitch/Services/AllMicrophonesController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
using System.Collections.ObjectModel;
using System.Linq;
using DynamicData.Binding;
using DynamicData;
using log4net;
using PoeShared;
using PoeShared.Audio.Models;
using PoeShared.Scaffolding;

namespace MicSwitch.Services
{
Expand Down
Loading

0 comments on commit 91b933c

Please sign in to comment.