Skip to content

Commit

Permalink
v2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
davidxuang committed Feb 25, 2024
1 parent c89c025 commit ad78f57
Show file tree
Hide file tree
Showing 39 changed files with 1,127 additions and 507 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<Version>2.3.1</Version>
<Version>2.4.0</Version>
<Authors>davidxuang</Authors>
<RepositoryUrl>https://github.com/davidxuang/MusicDecrypto</RepositoryUrl>
</PropertyGroup>
Expand Down
8 changes: 4 additions & 4 deletions MusicDecrypto.Avalonia/Controls/MatchDialogContent.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
d:DesignWidth="800" d:DesignHeight="450"
mc:Ignorable="d">

<DataGrid ItemsSource="{Binding Properties}" IsReadOnly="True" CanUserSortColumns="False">
<DataGrid ItemsSource="{Binding Items}" IsReadOnly="True" CanUserSortColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Key}" Header="Source" />
<DataGridTextColumn Binding="{Binding Title}" Header="Title" />
<DataGridTextColumn Binding="{Binding Performers}" Header="Performers" />
<DataGridTextColumn Binding="{Binding Album}" Header="Album" />
<DataGridTextColumn Binding="{Binding Value.Title}" Header="Title" />
<DataGridTextColumn Binding="{Binding Value.Performers}" Header="Performers" />
<DataGridTextColumn Binding="{Binding Value.Album}" Header="Album" />
</DataGrid.Columns>
</DataGrid>
</UserControl>
39 changes: 1 addition & 38 deletions MusicDecrypto.Avalonia/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using Avalonia.Platform.Storage;
using Avalonia.Threading;
using ByteSizeLib;
using FluentAvalonia.UI.Controls;
using MusicDecrypto.Avalonia.Controls;
using MusicDecrypto.Avalonia.Helpers;
using MusicDecrypto.Library;

Expand All @@ -24,7 +20,6 @@ public partial class MainViewModel : ViewModelBase
[GeneratedRegex("^(?:.+ - |\\d+\\. )?(.+) - (.+)$")]
private static partial Regex NameRegex();
private static readonly Regex _regex = NameRegex();
private static readonly SemaphoreSlim _dialogLock = new(1);

private const int _imageWidth = 72;
private readonly int _imageSize;
Expand Down Expand Up @@ -80,8 +75,7 @@ public async ValueTask DecryptFileAsync(Item item)
using var decrypto = DecryptoFactory.Create(
buffer,
Path.GetFileName(item.File.Name),
item.AddMessage,
OnRequestMatchAsync);
item.AddMessage);

item.State = Item.States.Working;
var info = await decrypto.DecryptAsync();
Expand Down Expand Up @@ -124,37 +118,6 @@ public async ValueTask DecryptFileAsync(Item item)
}
}

private static async ValueTask<bool> OnRequestMatchAsync(string message, IEnumerable<DecryptoBase.MatchInfo> properties)
{
await _dialogLock.WaitAsync();
try
{
return await Dispatcher.UIThread.InvokeAsync(async () =>
{
var dialog = new ContentDialog()
{
Title = message,
PrimaryButtonText = "Confirm",
CloseButtonText = "Cancel",
Content = new MatchDialogContent()
{
DataContext = new MatchViewModel(properties)
}
};
return (await dialog.ShowAsync()) == ContentDialogResult.Primary;
});
}
catch
{
return false;
}
finally
{
_dialogLock.Release();
}
}

public class Item(IStorageFile file) : INotifyPropertyChanged, IDisposable
{
private static readonly Bitmap _coverFallback = new(AssetLoader.Open(new Uri("avares://musicdecrypto-avalonia/Assets/MusicNote.png")));
Expand Down
14 changes: 12 additions & 2 deletions MusicDecrypto.Avalonia/ViewModels/MatchViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using MusicDecrypto.Library;

namespace MusicDecrypto.Avalonia.ViewModels;

public class MatchViewModel(IEnumerable<DecryptoBase.MatchInfo> properties) : ViewModelBase
public class MatchViewModel : ViewModelBase
{
public IEnumerable<DecryptoBase.MatchInfo> Properties { get; init; } = properties;
public MatchViewModel(DecryptoBase.MatchInfo local, DecryptoBase.MatchInfo remote)
{
Items = new ObservableCollection<KeyValuePair<string, DecryptoBase.MatchInfo>>
{
KeyValuePair.Create("Local", local),
KeyValuePair.Create("Remote", remote),
};
}

public IEnumerable<KeyValuePair<string, DecryptoBase.MatchInfo>> Items { get; init; }
}
46 changes: 46 additions & 0 deletions MusicDecrypto.Avalonia/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
using System.Threading;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
using Avalonia.Threading;
using FluentAvalonia.UI.Controls;
using FluentAvalonia.UI.Windowing;
using MusicDecrypto.Avalonia.Controls;
using MusicDecrypto.Avalonia.Pages;
using MusicDecrypto.Avalonia.ViewModels;
using MusicDecrypto.Library;

namespace MusicDecrypto.Avalonia.Views;

Expand All @@ -17,6 +22,13 @@ public partial class MainView : UserControl
private Button? _openFilesButton;
private Button? _settingsButton;

private static readonly SemaphoreSlim _dialogLock = new(1);

static MainView()
{
DecryptoBase.OnRequestMatch += OnRequestMatchAsync;
}

public MainView()
{
InitializeComponent();
Expand Down Expand Up @@ -68,4 +80,38 @@ private void OnSettingsButtonClick(object? sender, RoutedEventArgs args)
if (_frameView?.CurrentSourcePageType != typeof(SettingsPage))
_frameView?.Navigate(typeof(SettingsPage));
}

private static async ValueTask<bool> OnRequestMatchAsync(
DecryptoBase sender,
string? message,
(DecryptoBase.MatchInfo, DecryptoBase.MatchInfo) properties)
{
await _dialogLock.WaitAsync();
try
{
return await Dispatcher.UIThread.InvokeAsync(async () =>
{
var dialog = new ContentDialog()
{
Title = message,
PrimaryButtonText = "Confirm",
CloseButtonText = "Cancel",
Content = new MatchDialogContent()
{
DataContext = new MatchViewModel(properties.Item1, properties.Item2)
}
};
return (await dialog.ShowAsync()) == ContentDialogResult.Primary;
});
}
catch
{
return false;
}
finally
{
_dialogLock.Release();
}
}
}
21 changes: 13 additions & 8 deletions MusicDecrypto.Commandline/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ internal sealed class DecryptoCommand : AsyncCommand<DecryptoCommand.Settings>
private static readonly HashSet<string> _extensions = DecryptoFactory.KnownExtensions.Where(e => !_extensive.Contains(e)).ToHashSet();
private static readonly SemaphoreSlim _stdinLock = new(1);

static DecryptoCommand()
{
DecryptoBase.OnRequestMatch += OnRequestMatchAsync;
}

public sealed class Settings : CommandSettings
{
#pragma warning disable CS8618
Expand Down Expand Up @@ -98,8 +103,7 @@ public override async Task<int> ExecuteAsync(CommandContext context, Settings se
using var decrypto = DecryptoFactory.Create(
buffer,
Path.GetFileName(f),
m => logQueue.Enqueue(($"{f}|{m}", LogLevel.Warn)),
OnRequestMatchAsync);
m => logQueue.Enqueue(($"{f}|{m}", LogLevel.Warn)));
var outName = (await decrypto.DecryptAsync()).NewName;
var outPath = Path.Combine(Path.GetDirectoryName(settings.Output ?? f)!, outName);
Expand Down Expand Up @@ -161,20 +165,21 @@ public override async Task<int> ExecuteAsync(CommandContext context, Settings se
}
}

private static async ValueTask<bool> OnRequestMatchAsync(string message, IEnumerable<DecryptoBase.MatchInfo> properties)
private static async ValueTask<bool> OnRequestMatchAsync(
DecryptoBase _,
string? message,
(DecryptoBase.MatchInfo, DecryptoBase.MatchInfo) properties)
{
await _stdinLock.WaitAsync();
try
{
var table = new Table();
table.AddColumns("Source", "Title", "Performers", "Album");
foreach (var item in properties)
{
table.AddRow(item.Key, item.Title, item.Performers, item.Album);
}
table.AddRow("Local", properties.Item1.Title, properties.Item1.Performers, properties.Item1.Album);
table.AddRow("Online", properties.Item2.Title, properties.Item2.Performers, properties.Item2.Album);
AnsiConsole.Write(table);

return AnsiConsole.Confirm(message);
return AnsiConsole.Confirm(message ?? string.Empty);
}
catch
{
Expand Down
2 changes: 1 addition & 1 deletion MusicDecrypto.Library/Cryptography/TEA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace MusicDecrypto.Library.Cryptography;

internal struct Tea
internal readonly struct Tea
{
private const int _sizeBlock = 8;
private const int _sizeKey = 16;
Expand Down
Loading

0 comments on commit ad78f57

Please sign in to comment.