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
6 changes: 3 additions & 3 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.7.0</Version>
<Version>1.7.1</Version>
<Authors>SubZeroPL</Authors>
<PackageProjectUrl>https://github.com/SubZeroPL/AssM</PackageProjectUrl>
<AssemblyVersion>1.7.0</AssemblyVersion>
<FileVersion>1.7.0</FileVersion>
<AssemblyVersion>1.7.1</AssemblyVersion>
<FileVersion>1.7.1</FileVersion>
<Title>AssM</Title>
<PackageLicenseUrl>https://github.com/SubZeroPL/AssM/blob/master/LICENSE</PackageLicenseUrl>
<RepositoryUrl>https://github.com/SubZeroPL/AssM/</RepositoryUrl>
Expand Down
26 changes: 18 additions & 8 deletions Classes/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,18 @@ public static void LoadExistingData(Game game, Configuration configuration, stri
readmePath ??= Path.Combine(configuration.OutputDirectory, OutputPath(game), Constants.ReadmeFile);
if (!File.Exists(readmePath)) game.ReadmeCreated = false;

if (string.IsNullOrWhiteSpace(game.Description) && !game.Modified)
if (!game.Modified)
{
LoadDescriptionFromReadme(readmePath, game);
if (!LoadTitleFromReadme(readmePath, game))
{
Logger.Error($"Failed to load title from {readmePath}");
throw new ProcessingException($"Failed to load title from {readmePath}. Readme file is malformed");
}
}

if (!game.Modified)
if (string.IsNullOrWhiteSpace(game.Description) && !game.Modified)
{
LoadTitleFromReadme(readmePath, game);
LoadDescriptionFromReadme(readmePath, game);
}

LoadTrackInfoFromReadme(readmePath, game);
Expand Down Expand Up @@ -113,17 +117,23 @@ public static void LoadExistingData(Game game, Configuration configuration, stri
Logger.Debug($"Loaded existing data from {readmePath} for game {game.Title}");
}

private static void LoadTitleFromReadme(string readmePath, Game game)
private static bool LoadTitleFromReadme(string readmePath, Game game)
{
Logger.Debug($"Loading title from {readmePath}");
if (!File.Exists(readmePath)) return;
if (game.Modified) return;
if (!File.Exists(readmePath)) return false;
if (game.Modified) return false;
var lines = File.ReadAllLines(readmePath);
var index = Array.FindIndex(lines, line => line.Contains("**Game name:**"));
var endIndex = Array.FindIndex(lines, line => line.Contains("**Game ID:**"));
if (index < 0 || endIndex < 0)
{
Logger.Error($"Failed to load title from {readmePath}. Readme file is malformed");
return false;
}
var title = string.Join("", lines.Skip(index + 1).Take(new Range(1, endIndex - 1))).Trim();
if (!string.IsNullOrEmpty(title)) game.Title = title;
game.ReadmeCreated = true;
return true;
}

private static void LoadDescriptionFromReadme(string readmePath, Game game)
Expand Down
20 changes: 15 additions & 5 deletions Windows/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ private void AddButton_OnClick(object? sender, RoutedEventArgs e)
{
AllowMultiple = true,
Title = "Select images",
FileTypeFilter = [ new FilePickerFileType("All supported formats (*.cue, *.iso)") { Patterns = ["*.cue", "*.iso"] },
FileTypeFilter =
[
new FilePickerFileType("All supported formats (*.cue, *.iso)") { Patterns = ["*.cue", "*.iso"] },
new FilePickerFileType("CUE file (*.cue)") { Patterns = ["*.cue"] },
new FilePickerFileType("ISO file (*.iso)") { Patterns = ["*.iso"] }]
new FilePickerFileType("ISO file (*.iso)") { Patterns = ["*.iso"] }
]
};
var files = GetTopLevel(this)?.StorageProvider.OpenFilePickerAsync(fpo).GetAwaiter().GetResult() ??
new List<IStorageFile>();
Expand Down Expand Up @@ -266,9 +269,16 @@ private void AddReadmes(string directory)
var readmeList = Functions.GetReadmeFilesInDirectory(directory);
foreach (var readme in readmeList)
{
var game = new Game();
Functions.LoadExistingData(game, Configuration, readme);
if (!GameList.Any(g => g.Id.Equals(game.Id))) GameList.Add(game);
try
{
var game = new Game();
Functions.LoadExistingData(game, Configuration, readme);
if (!GameList.Any(g => g.Id.Equals(game.Id))) GameList.Add(game);
}
catch (Exception ex)
{
_logger.Error(ex, $"Failed to load readme {readme}");
}
}

DataGridGameList.CollectionView.Refresh();
Expand Down
Loading