Skip to content

Commit

Permalink
Fixes application may crash if file pickers are cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
ronelm2000 committed Oct 4, 2024
1 parent 4fc21d6 commit be7d8f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions Montage.Weiss.Tools.GUI/Extensions/AppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static AppBuilder LogToSerilog(this AppBuilder builder)
{
Log.Logger = new LoggerConfiguration()
.WriteTo.Debug()
.WriteTo.File("wsm-gui.log", Serilog.Events.LogEventLevel.Debug)
.CreateLogger();

Logger.Sink = new SerilogLogSink();
Expand Down
18 changes: 15 additions & 3 deletions Montage.Weiss.Tools.GUI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using SQLitePCL;
using System.Text.RegularExpressions;
using Avalonia.Media;
using Microsoft.EntityFrameworkCore.ChangeTracking;

namespace Montage.Weiss.Tools.GUI.ViewModels;

Expand Down Expand Up @@ -153,14 +154,17 @@ private async Task SaveDeck(CancellationToken token)
DefaultExtension = DeckFiles.Patterns?[0][2..] ?? "ws-dek",
FileTypeChoices = [ DeckFiles ]
});
if (savePath is null)
return;

var deck = new WeissSchwarzDeck
{
Name = DeckName,
Remarks = DeckRemarks,
Ratios = DeckRatioList.ToDictionary(vw => vw.Card, vw => vw.Ratio)
};

var finalPath = Path.Get(savePath!.Path.LocalPath);
var finalPath = Path.Get(savePath.Path.LocalPath);

var localDeckExporter = Container!.GetService<LocalDeckJSONExporter>()!;
await localDeckExporter.Export(deck, progressReporter, finalPath, token);
Expand All @@ -175,7 +179,9 @@ private async Task OpenDeck(CancellationToken token)
Title = "Opening Local Deck...",
FileTypeFilter = [DeckFiles]
});
var firstPath = loadPaths.First();
var firstPath = loadPaths.FirstOrDefault();
if (firstPath is null)
return;

var localDeckParser = Container!.GetService<LocalDeckJSONParser>()!;
var deck = await localDeckParser.Parse(firstPath.Path.AbsolutePath, progressReporter, token);
Expand Down Expand Up @@ -305,7 +311,13 @@ private async Task OpenLocalSet()
if (!filesFolderPath.Exists)
continue;

filesFolderPath.AllFiles().Copy(Path.Current.Add("Images"));
var imagePath = Path.Current.Add("Images");

log.Information("Copying all files");
log.Information("From: {path}", filesFolderPath.FullPath);
log.Information("To: {newPath}", imagePath.FullPath);

filesFolderPath.AllFiles().Copy(imagePath);
}
}

Expand Down

0 comments on commit be7d8f9

Please sign in to comment.