Use CSharpier

This commit is contained in:
Tyrrrz
2023-08-22 21:17:19 +03:00
parent c410e745b1
commit 20f58963a6
174 changed files with 11084 additions and 10670 deletions

View File

@@ -24,17 +24,19 @@ public partial class App
public partial class App
{
private static Theme LightTheme { get; } = Theme.Create(
new MaterialDesignLightTheme(),
MediaColor.FromHex("#343838"),
MediaColor.FromHex("#F9A825")
);
private static Theme LightTheme { get; } =
Theme.Create(
new MaterialDesignLightTheme(),
MediaColor.FromHex("#343838"),
MediaColor.FromHex("#F9A825")
);
private static Theme DarkTheme { get; } = Theme.Create(
new MaterialDesignDarkTheme(),
MediaColor.FromHex("#E8E8E8"),
MediaColor.FromHex("#F9A825")
);
private static Theme DarkTheme { get; } =
Theme.Create(
new MaterialDesignDarkTheme(),
MediaColor.FromHex("#E8E8E8"),
MediaColor.FromHex("#F9A825")
);
public static void SetLightTheme()
{
@@ -47,4 +49,4 @@ public partial class App
var paletteHelper = new PaletteHelper();
paletteHelper.SetTheme(DarkTheme);
}
}
}

View File

@@ -2,6 +2,4 @@
namespace DiscordChatExporter.Gui.Behaviors;
public class ChannelMultiSelectionListBoxBehavior : MultiSelectionListBoxBehavior<Channel>
{
}
public class ChannelMultiSelectionListBoxBehavior : MultiSelectionListBoxBehavior<Channel> { }

View File

@@ -20,10 +20,14 @@ public class MultiSelectionListBoxBehavior<T> : Behavior<ListBox>
)
);
private static void OnSelectedItemsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
private static void OnSelectedItemsChanged(
DependencyObject sender,
DependencyPropertyChangedEventArgs args
)
{
var behavior = (MultiSelectionListBoxBehavior<T>) sender;
if (behavior._modelHandled) return;
var behavior = (MultiSelectionListBoxBehavior<T>)sender;
if (behavior._modelHandled)
return;
if (behavior.AssociatedObject is null)
return;
@@ -38,7 +42,7 @@ public class MultiSelectionListBoxBehavior<T> : Behavior<ListBox>
public IList? SelectedItems
{
get => (IList?) GetValue(SelectedItemsProperty);
get => (IList?)GetValue(SelectedItemsProperty);
set => SetValue(SelectedItemsProperty, value);
}
@@ -60,16 +64,20 @@ public class MultiSelectionListBoxBehavior<T> : Behavior<ListBox>
// Propagate selected items from the view to the model
private void OnListBoxSelectionChanged(object? sender, SelectionChangedEventArgs args)
{
if (_viewHandled) return;
if (AssociatedObject.Items.SourceCollection is null) return;
if (_viewHandled)
return;
if (AssociatedObject.Items.SourceCollection is null)
return;
SelectedItems = AssociatedObject.SelectedItems.Cast<T>().ToArray();
}
private void OnListBoxItemsChanged(object? sender, NotifyCollectionChangedEventArgs args)
{
if (_viewHandled) return;
if (AssociatedObject.Items.SourceCollection is null) return;
if (_viewHandled)
return;
if (AssociatedObject.Items.SourceCollection is null)
return;
SelectItems();
}
@@ -78,7 +86,8 @@ public class MultiSelectionListBoxBehavior<T> : Behavior<ListBox>
base.OnAttached();
AssociatedObject.SelectionChanged += OnListBoxSelectionChanged;
((INotifyCollectionChanged) AssociatedObject.Items).CollectionChanged += OnListBoxItemsChanged;
((INotifyCollectionChanged)AssociatedObject.Items).CollectionChanged +=
OnListBoxItemsChanged;
}
protected override void OnDetaching()
@@ -88,7 +97,8 @@ public class MultiSelectionListBoxBehavior<T> : Behavior<ListBox>
if (AssociatedObject is not null)
{
AssociatedObject.SelectionChanged -= OnListBoxSelectionChanged;
((INotifyCollectionChanged) AssociatedObject.Items).CollectionChanged -= OnListBoxItemsChanged;
((INotifyCollectionChanged)AssociatedObject.Items).CollectionChanged -=
OnListBoxItemsChanged;
}
}
}
}

View File

@@ -43,4 +43,4 @@ public class Bootstrapper : Bootstrapper<RootViewModel>
);
}
#endif
}
}

View File

@@ -9,13 +9,18 @@ public class DateTimeOffsetToDateTimeConverter : IValueConverter
{
public static DateTimeOffsetToDateTimeConverter Instance { get; } = new();
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
value is DateTimeOffset dateTimeOffsetValue
? dateTimeOffsetValue.DateTime
? dateTimeOffsetValue.DateTime
: default(DateTime?);
public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
value is DateTime dateTimeValue
public object? ConvertBack(
object value,
Type targetType,
object parameter,
CultureInfo culture
) =>
value is DateTime dateTimeValue
? new DateTimeOffset(dateTimeValue)
: default(DateTimeOffset?);
}
}

View File

@@ -10,11 +10,13 @@ public class ExportFormatToStringConverter : IValueConverter
{
public static ExportFormatToStringConverter Instance { get; } = new();
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
value is ExportFormat exportFormatValue
? exportFormatValue.GetDisplayName()
: default;
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
value is ExportFormat exportFormatValue ? exportFormatValue.GetDisplayName() : default;
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
throw new NotSupportedException();
}
public object ConvertBack(
object value,
Type targetType,
object parameter,
CultureInfo culture
) => throw new NotSupportedException();
}

View File

@@ -12,6 +12,10 @@ public class InverseBoolConverter : IValueConverter
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
value is false;
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
value is false;
}
public object ConvertBack(
object value,
Type targetType,
object parameter,
CultureInfo culture
) => value is false;
}

View File

@@ -11,10 +11,12 @@ public class SnowflakeToDateTimeOffsetConverter : IValueConverter
public static SnowflakeToDateTimeOffsetConverter Instance { get; } = new();
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
value is Snowflake snowflake
? snowflake.ToDate()
: null;
value is Snowflake snowflake ? snowflake.ToDate() : null;
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
throw new NotSupportedException();
}
public object ConvertBack(
object value,
Type targetType,
object parameter,
CultureInfo culture
) => throw new NotSupportedException();
}

View File

@@ -9,13 +9,13 @@ public class TimeSpanToDateTimeConverter : IValueConverter
{
public static TimeSpanToDateTimeConverter Instance { get; } = new();
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
value is TimeSpan timeSpanValue
? DateTime.Today.Add(timeSpanValue)
: default(DateTime?);
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
value is TimeSpan timeSpanValue ? DateTime.Today.Add(timeSpanValue) : default(DateTime?);
public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
value is DateTime dateTimeValue
? dateTimeValue.TimeOfDay
: default(TimeSpan?);
}
public object? ConvertBack(
object value,
Type targetType,
object parameter,
CultureInfo culture
) => value is DateTime dateTimeValue ? dateTimeValue.TimeOfDay : default(TimeSpan?);
}

View File

@@ -14,6 +14,7 @@
<ItemGroup>
<PackageReference Include="Cogwheel" Version="2.0.3" />
<PackageReference Include="CSharpier.MsBuild" Version="0.25.0" PrivateAssets="all" />
<PackageReference Include="Deorcify" Version="1.0.2" PrivateAssets="all" />
<PackageReference Include="DotnetRuntimeBootstrapper" Version="2.5.1" PrivateAssets="all" />
<PackageReference Include="Gress" Version="2.1.1" />

View File

@@ -43,9 +43,7 @@ public partial class SettingsService : SettingsBase
public string? LastAssetsDirPath { get; set; }
public SettingsService()
: base(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Settings.dat"))
{
}
: base(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Settings.dat")) { }
public override void Save()
{
@@ -66,14 +64,17 @@ public partial class SettingsService
{
try
{
return Registry.CurrentUser.OpenSubKey(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
false
)?.GetValue("AppsUseLightTheme") is 0;
return Registry.CurrentUser
.OpenSubKey(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
false
)
?.GetValue("AppsUseLightTheme")
is 0;
}
catch
{
return false;
}
}
}
}

View File

@@ -77,4 +77,4 @@ public class UpdateService : IDisposable
}
public void Dispose() => _updateManager.Dispose();
}
}

View File

@@ -5,6 +5,6 @@ namespace DiscordChatExporter.Gui.Utils;
internal static class Internationalization
{
public static bool Is24Hours =>
string.IsNullOrWhiteSpace(CultureInfo.CurrentCulture.DateTimeFormat.AMDesignator) &&
string.IsNullOrWhiteSpace(CultureInfo.CurrentCulture.DateTimeFormat.PMDesignator);
}
string.IsNullOrWhiteSpace(CultureInfo.CurrentCulture.DateTimeFormat.AMDesignator)
&& string.IsNullOrWhiteSpace(CultureInfo.CurrentCulture.DateTimeFormat.PMDesignator);
}

View File

@@ -4,5 +4,5 @@ namespace DiscordChatExporter.Gui.Utils;
internal static class MediaColor
{
public static Color FromHex(string hex) => (Color) ColorConverter.ConvertFromString(hex);
}
public static Color FromHex(string hex) => (Color)ColorConverter.ConvertFromString(hex);
}

View File

@@ -8,13 +8,9 @@ internal static class ProcessEx
{
using var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = path,
UseShellExecute = true
}
StartInfo = new ProcessStartInfo { FileName = path, UseShellExecute = true }
};
process.Start();
}
}
}

View File

@@ -52,7 +52,8 @@ public class DashboardViewModel : PropertyChangedBase
IViewModelFactory viewModelFactory,
IEventAggregator eventAggregator,
DialogManager dialogManager,
SettingsService settingsService)
SettingsService settingsService
)
{
_viewModelFactory = viewModelFactory;
_eventAggregator = eventAggregator;
@@ -61,10 +62,7 @@ public class DashboardViewModel : PropertyChangedBase
_progressMuxer = Progress.CreateMuxer().WithAutoReset();
this.Bind(
o => o.IsBusy,
(_, _) => NotifyOfPropertyChange(() => IsProgressIndeterminate)
);
this.Bind(o => o.IsBusy, (_, _) => NotifyOfPropertyChange(() => IsProgressIndeterminate));
Progress.Bind(
o => o.Current,
@@ -125,9 +123,7 @@ public class DashboardViewModel : PropertyChangedBase
}
catch (DiscordChatExporterException ex) when (!ex.IsFatal)
{
_eventAggregator.Publish(
new NotificationMessage(ex.Message.TrimEnd('.'))
);
_eventAggregator.Publish(new NotificationMessage(ex.Message.TrimEnd('.')));
}
catch (Exception ex)
{
@@ -145,7 +141,8 @@ public class DashboardViewModel : PropertyChangedBase
}
}
public bool CanPullChannelsAsync => !IsBusy && _discord is not null && SelectedGuild is not null;
public bool CanPullChannelsAsync =>
!IsBusy && _discord is not null && SelectedGuild is not null;
public async ValueTask PullChannelsAsync()
{
@@ -174,9 +171,12 @@ public class DashboardViewModel : PropertyChangedBase
// Threads
if (_settingsService.ShouldShowThreads)
{
await foreach (var thread in _discord.GetGuildThreadsAsync(
SelectedGuild.Id,
_settingsService.ShouldShowArchivedThreads))
await foreach (
var thread in _discord.GetGuildThreadsAsync(
SelectedGuild.Id,
_settingsService.ShouldShowArchivedThreads
)
)
{
channels.Add(thread);
}
@@ -187,9 +187,7 @@ public class DashboardViewModel : PropertyChangedBase
}
catch (DiscordChatExporterException ex) when (!ex.IsFatal)
{
_eventAggregator.Publish(
new NotificationMessage(ex.Message.TrimEnd('.'))
);
_eventAggregator.Publish(new NotificationMessage(ex.Message.TrimEnd('.')));
}
catch (Exception ex)
{
@@ -208,10 +206,10 @@ public class DashboardViewModel : PropertyChangedBase
}
public bool CanExportAsync =>
!IsBusy &&
_discord is not null &&
SelectedGuild is not null &&
SelectedChannels?.Any() is true;
!IsBusy
&& _discord is not null
&& SelectedGuild is not null
&& SelectedChannels?.Any() is true;
public async ValueTask ExportAsync()
{
@@ -219,20 +217,26 @@ public class DashboardViewModel : PropertyChangedBase
try
{
if (_discord is null || SelectedGuild is null || SelectedChannels is null || !SelectedChannels.Any())
if (
_discord is null
|| SelectedGuild is null
|| SelectedChannels is null
|| !SelectedChannels.Any()
)
return;
var dialog = _viewModelFactory.CreateExportSetupViewModel(SelectedGuild, SelectedChannels);
var dialog = _viewModelFactory.CreateExportSetupViewModel(
SelectedGuild,
SelectedChannels
);
if (await _dialogManager.ShowDialogAsync(dialog) != true)
return;
var exporter = new ChannelExporter(_discord);
var channelProgressPairs = dialog.Channels!.Select(c => new
{
Channel = c,
Progress = _progressMuxer.CreateInput()
}).ToArray();
var channelProgressPairs = dialog.Channels!
.Select(c => new { Channel = c, Progress = _progressMuxer.CreateInput() })
.ToArray();
var successfulExportCount = 0;
@@ -286,7 +290,9 @@ public class DashboardViewModel : PropertyChangedBase
if (successfulExportCount > 0)
{
_eventAggregator.Publish(
new NotificationMessage($"Successfully exported {successfulExportCount} channel(s)")
new NotificationMessage(
$"Successfully exported {successfulExportCount} channel(s)"
)
);
}
}
@@ -305,9 +311,8 @@ public class DashboardViewModel : PropertyChangedBase
}
}
public void OpenDiscord() =>
ProcessEx.StartShellExecute("https://discord.com/app");
public void OpenDiscord() => ProcessEx.StartShellExecute("https://discord.com/app");
public void OpenDiscordDeveloperPortal() =>
ProcessEx.StartShellExecute("https://discord.com/developers/applications");
}
}

View File

@@ -49,15 +49,17 @@ public class ExportSetupViewModel : DialogScreen
public string? PartitionLimitValue { get; set; }
public PartitionLimit PartitionLimit => !string.IsNullOrWhiteSpace(PartitionLimitValue)
? PartitionLimit.Parse(PartitionLimitValue)
: PartitionLimit.Null;
public PartitionLimit PartitionLimit =>
!string.IsNullOrWhiteSpace(PartitionLimitValue)
? PartitionLimit.Parse(PartitionLimitValue)
: PartitionLimit.Null;
public string? MessageFilterValue { get; set; }
public MessageFilter MessageFilter => !string.IsNullOrWhiteSpace(MessageFilterValue)
? MessageFilter.Parse(MessageFilterValue)
: MessageFilter.Null;
public MessageFilter MessageFilter =>
!string.IsNullOrWhiteSpace(MessageFilterValue)
? MessageFilter.Parse(MessageFilterValue)
: MessageFilter.Null;
public bool ShouldFormatMarkdown { get; set; }
@@ -86,13 +88,13 @@ public class ExportSetupViewModel : DialogScreen
// Show the "advanced options" section by default if any
// of the advanced options are set to non-default values.
IsAdvancedSectionDisplayed =
After is not null ||
Before is not null ||
!string.IsNullOrWhiteSpace(PartitionLimitValue) ||
!string.IsNullOrWhiteSpace(MessageFilterValue) ||
ShouldDownloadAssets ||
ShouldReuseAssets ||
!string.IsNullOrWhiteSpace(AssetsDirPath);
After is not null
|| Before is not null
|| !string.IsNullOrWhiteSpace(PartitionLimitValue)
|| !string.IsNullOrWhiteSpace(MessageFilterValue)
|| ShouldDownloadAssets
|| ShouldReuseAssets
|| !string.IsNullOrWhiteSpace(AssetsDirPath);
}
public void ToggleAdvancedSection() => IsAdvancedSectionDisplayed = !IsAdvancedSectionDisplayed;
@@ -161,7 +163,8 @@ public static class ExportSetupViewModelExtensions
public static ExportSetupViewModel CreateExportSetupViewModel(
this IViewModelFactory factory,
Guild guild,
IReadOnlyList<Channel> channels)
IReadOnlyList<Channel> channels
)
{
var viewModel = factory.CreateExportSetupViewModel();
@@ -170,4 +173,4 @@ public static class ExportSetupViewModelExtensions
return viewModel;
}
}
}

View File

@@ -16,9 +16,7 @@ public class MessageBoxViewModel : DialogScreen
public string? CancelButtonText { get; set; }
public int ButtonsCount =>
(IsOkButtonVisible ? 1 : 0) +
(IsCancelButtonVisible ? 1 : 0);
public int ButtonsCount => (IsOkButtonVisible ? 1 : 0) + (IsCancelButtonVisible ? 1 : 0);
}
public static class MessageBoxViewModelExtensions
@@ -28,7 +26,8 @@ public static class MessageBoxViewModelExtensions
string title,
string message,
string? okButtonText,
string? cancelButtonText)
string? cancelButtonText
)
{
var viewModel = factory.CreateMessageBoxViewModel();
@@ -45,6 +44,6 @@ public static class MessageBoxViewModelExtensions
public static MessageBoxViewModel CreateMessageBoxViewModel(
this IViewModelFactory factory,
string title,
string message) =>
factory.CreateMessageBoxViewModel(title, message, "CLOSE", null);
}
string message
) => factory.CreateMessageBoxViewModel(title, message, "CLOSE", null);
}

View File

@@ -50,6 +50,5 @@ public class SettingsViewModel : DialogScreen
set => _settingsService.ParallelLimit = Math.Clamp(value, 1, 10);
}
public SettingsViewModel(SettingsService settingsService) =>
_settingsService = settingsService;
}
public SettingsViewModel(SettingsService settingsService) => _settingsService = settingsService;
}

View File

@@ -68,10 +68,7 @@ public class DialogManager : IDisposable
public string? PromptDirectoryPath(string defaultDirPath = "")
{
var dialog = new VistaFolderBrowserDialog
{
SelectedPath = defaultDirPath
};
var dialog = new VistaFolderBrowserDialog { SelectedPath = defaultDirPath };
return dialog.ShowDialog() == true ? dialog.SelectedPath : null;
}
@@ -80,4 +77,4 @@ public class DialogManager : IDisposable
{
_dialogLock.Dispose();
}
}
}

View File

@@ -16,6 +16,4 @@ public abstract class DialogScreen<T> : PropertyChangedBase
}
}
public abstract class DialogScreen : DialogScreen<bool?>
{
}
public abstract class DialogScreen : DialogScreen<bool?> { }

View File

@@ -7,10 +7,10 @@ namespace DiscordChatExporter.Gui.ViewModels.Framework;
public interface IViewModelFactory
{
DashboardViewModel CreateDashboardViewModel();
ExportSetupViewModel CreateExportSetupViewModel();
MessageBoxViewModel CreateMessageBoxViewModel();
SettingsViewModel CreateSettingsViewModel();
}
}

View File

@@ -1,3 +1,3 @@
namespace DiscordChatExporter.Gui.ViewModels.Messages;
public record NotificationMessage(string Text);
public record NotificationMessage(string Text);

View File

@@ -27,7 +27,8 @@ public class RootViewModel : Screen, IHandle<NotificationMessage>, IDisposable
IEventAggregator eventAggregator,
DialogManager dialogManager,
SettingsService settingsService,
UpdateService updateService)
UpdateService updateService
)
{
_viewModelFactory = viewModelFactory;
_dialogManager = dialogManager;
@@ -78,7 +79,8 @@ public class RootViewModel : Screen, IHandle<NotificationMessage>, IDisposable
Notifications.Enqueue(
"Update has been downloaded and will be installed when you exit",
"INSTALL NOW", () =>
"INSTALL NOW",
() =>
{
_updateService.FinalizeUpdate(true);
RequestClose();
@@ -115,11 +117,15 @@ public class RootViewModel : Screen, IHandle<NotificationMessage>, IDisposable
}
// App has just been updated, display the changelog
if (_settingsService.LastAppVersion is not null && _settingsService.LastAppVersion != App.Version)
if (
_settingsService.LastAppVersion is not null
&& _settingsService.LastAppVersion != App.Version
)
{
Notifications.Enqueue(
$"Successfully updated to {App.Name} v{App.VersionString}",
"CHANGELOG", () => ProcessEx.StartShellExecute(App.ChangelogUrl)
"CHANGELOG",
() => ProcessEx.StartShellExecute(App.ChangelogUrl)
);
_settingsService.LastAppVersion = App.Version;
@@ -138,4 +144,4 @@ public class RootViewModel : Screen, IHandle<NotificationMessage>, IDisposable
public void Handle(NotificationMessage message) => Notifications.Enqueue(message.Text);
public void Dispose() => Notifications.Dispose();
}
}

View File

@@ -6,4 +6,4 @@ public partial class DashboardView
{
InitializeComponent();
}
}
}

View File

@@ -8,7 +8,10 @@ public partial class RevealablePasswordBox
nameof(Password),
typeof(string),
typeof(RevealablePasswordBox),
new FrameworkPropertyMetadata(string.Empty, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)
new FrameworkPropertyMetadata(
string.Empty,
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault
)
);
public static readonly DependencyProperty IsRevealedProperty = DependencyProperty.Register(
@@ -34,4 +37,4 @@ public partial class RevealablePasswordBox
{
InitializeComponent();
}
}
}

View File

@@ -6,4 +6,4 @@ public partial class ExportSetupView
{
InitializeComponent();
}
}
}

View File

@@ -6,4 +6,4 @@ public partial class MessageBoxView
{
InitializeComponent();
}
}
}

View File

@@ -14,4 +14,4 @@ public partial class SettingsView
private void DarkModeToggleButton_OnUnchecked(object sender, RoutedEventArgs args) =>
App.SetLightTheme();
}
}

View File

@@ -6,4 +6,4 @@ public partial class RootView
{
InitializeComponent();
}
}
}