Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions AssM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Version>1.8.1</Version>
<Version>1.9.0</Version>
<Authors>SubZeroPL</Authors>
<PackageProjectUrl>https://github.com/SubZeroPL/AssM</PackageProjectUrl>
<AssemblyVersion>1.8.1</AssemblyVersion>
<FileVersion>1.8.1</FileVersion>
<AssemblyVersion>1.9.0</AssemblyVersion>
<FileVersion>1.9.0</FileVersion>
<Title>AssM</Title>
<PackageLicenseUrl>https://github.com/SubZeroPL/AssM/blob/master/LICENSE</PackageLicenseUrl>
<RepositoryUrl>https://github.com/SubZeroPL/AssM/</RepositoryUrl>
Expand All @@ -19,17 +19,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.3.10" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.3.10" />
<PackageReference Include="Avalonia.Desktop" Version="11.3.10" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.10" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.10" />
<PackageReference Include="Avalonia" Version="12.0.4" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="12.0.0" />
<PackageReference Include="Avalonia.Desktop" Version="12.0.4" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="12.0.4" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="12.0.4" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.3.10" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.3.17" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.2" />
<PackageReference Include="Markdown.Avalonia" Version="11.0.3-a1"/>
<PackageReference Include="MessageBox.Avalonia" Version="3.3.1.1" />
<PackageReference Include="NLog" Version="6.0.7" />
<PackageReference Include="Markdown.Avalonia" Version="11.0.3" />
<PackageReference Include="MessageBox.Avalonia" Version="12.0.0" />
<PackageReference Include="NLog" Version="6.1.3" />
<PackageReference Include="Octokit" Version="14.0.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Avalonia.Labs
Submodule Avalonia.Labs updated 193 files
58 changes: 54 additions & 4 deletions Classes/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using AssM.Data;
using Avalonia.Threading;
using DiscTools;
using NLog;

namespace AssM.Classes;

public static class Functions
public static partial class Functions
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public static string OutputPath(Game game) => Path.Combine(game.Platform.ToString(), game.Id);
Expand Down Expand Up @@ -229,12 +231,23 @@ public static List<string> GetReadmeFilesInDirectory(string directory)
public static Game? AddGameToList(string imagePath, Configuration configuration, ObservableCollection<Game> gameList)
{
Logger.Debug($"Adding game to list from {imagePath}");
var di = DiscInspector.ScanDisc(imagePath);
var di = DiscInspector.ScanDiscQuick(imagePath);
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract - apparently there are games that have no Id in image (like SLPS-00018)
if (di.Data.SerialNumber == null)
{
Logger.Error($"Failed to add game to list from {imagePath}{Environment.NewLine}Id not present in image");
return null;
// let's try to find the ID manually
var id = ScanForId(imagePath);
if (id != null)
{
di.Data.SerialNumber = id;
di.DetectedDiscType = DetectedDiscType.SonyPS2;
}
else
{
Logger.Error(
$"Failed to add game to list from {imagePath}{Environment.NewLine}Id not present in image");
return null;
}
}

var title = configuration.GetTitleFromCue ? Path.GetFileNameWithoutExtension(imagePath) : di.Data.GameTitle;
Expand All @@ -259,6 +272,43 @@ public static List<string> GetReadmeFilesInDirectory(string directory)

return game;
}

[GeneratedRegex(@"(SL[A-Z]{2}_\d+\.\d+)(?=;)")]
private static partial Regex IdPsRegex();

[GeneratedRegex("""FILE "(.+\.bin)" BINARY""")]
private static partial Regex BinFile();

private static string? ScanForId(string imagePath)
{
if (imagePath.EndsWith(".cue", StringComparison.OrdinalIgnoreCase))
{
var lines = File.ReadAllLines(imagePath);
var match = BinFile().Match(lines[0]);
if (match.Success)
{
var dir = Path.GetDirectoryName(imagePath);
var file = match.Groups[1].Value;
imagePath = Path.Join(dir, file);
}
}
using var fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
var buf = new Span<byte>(new byte[1024 * 8]);
const int backtrack = 15;
var read = fs.Read(buf);
while (read > 0 && read != backtrack)
{
var textId = Encoding.ASCII.GetString(buf);
var matches = IdPsRegex().Match(textId);
if (matches.Success)
{
return matches.Groups[1].Value.Replace('_', '-').Replace(".", "");
}
fs.Seek(-backtrack, SeekOrigin.Current);
read = fs.Read(buf);
}
return null;
}

public static void ProcessJson(Configuration configuration, Game game, Action<double> reportProgress)
{
Expand Down
2 changes: 1 addition & 1 deletion Windows/AddFolderProgressWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</StackPanel>
<Label Name="LabelFolderName">folder name</Label>
<Panel HorizontalAlignment="Center">
<gif:GifImage Source="avares://AssM/Assets/loading.gif" />
<gif:GifImage Name="GifImage" />
</Panel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="5">
<Button Click="CancelButton_OnClick">Cancel</Button>
Expand Down
6 changes: 6 additions & 0 deletions Windows/AddFolderProgressWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using AssM.Data;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Labs.Gif;

namespace AssM.Windows;

Expand All @@ -21,9 +22,13 @@ public partial class AddFolderProgressWindow : Window
{
private readonly BackgroundWorker _worker;

private readonly GifStreamSource _gifStreamSource =
GifStreamSource.FromUriString("avares://AssM/Assets/loading.gif");

public AddFolderProgressWindow()
{
InitializeComponent();
GifImage.Source = _gifStreamSource;
_worker = new BackgroundWorker();
_worker.WorkerReportsProgress = true;
_worker.WorkerSupportsCancellation = true;
Expand Down Expand Up @@ -101,6 +106,7 @@ private void CancelButton_OnClick(object? sender, RoutedEventArgs e)
private void Window_OnClosing(object? sender, WindowClosingEventArgs e)
{
_worker.CancelAsync();
_gifStreamSource.Dispose();
if (!e.IsProgrammatic) e.Cancel = true;
}
}
4 changes: 2 additions & 2 deletions Windows/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@
<TabItem Header="Info">
<StackPanel>
<Label Target="TextTitle" Content="Title"></Label>
<TextBox Name="TextTitle" AcceptsReturn="False" Watermark="Enter game name" KeyUp="TextTitle_OnKeyUp">
<TextBox Name="TextTitle" AcceptsReturn="False" PlaceholderText="Enter game name" KeyUp="TextTitle_OnKeyUp">
</TextBox>
<Label Target="TextDescription" Content="Description"></Label>
<TextBox Name="TextDescription" AcceptsReturn="True" MinLines="5" TextWrapping="Wrap"
Watermark="Enter game description" KeyUp="TextDescription_OnKeyUp">
PlaceholderText="Enter game description" KeyUp="TextDescription_OnKeyUp">
</TextBox>
</StackPanel>
</TabItem>
Expand Down
Loading