Skip to content

Commit

Permalink
chore: Better feedback when drag and drop fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorixon committed Sep 3, 2023
1 parent 8a1463e commit bf47ce0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
28 changes: 20 additions & 8 deletions src/GIMI-ModManager.Core/Services/DragAndDropScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public DragAndDropScanner()
{
}

public IMod Scan(string path)
public DragAndDropScanResult Scan(string path)
{
PrepareWorkFolder();

Expand All @@ -40,15 +40,25 @@ public IMod Scan(string path)
}


var extractedDir = new DirectoryInfo(_workFolder).EnumerateDirectories().FirstOrDefault();
if (extractedDir is null)
throw new Exception("No extracted folder found");

var newMod = new Mod(extractedDir);

newMod.MoveTo(_tmpFolder);
var extractedDirs = new DirectoryInfo(_workFolder).EnumerateDirectories().ToArray();
if (extractedDirs is null || !extractedDirs.Any())
throw new Exception("No valid mod folder found in archive. Loose files are ignored");

return newMod;
var ignoredDirs = new List<DirectoryInfo>();
if (extractedDirs.Length > 1)
ignoredDirs.AddRange(extractedDirs.Skip(1));

var newMod = new Mod(extractedDirs.First());

//newMod.MoveTo(_tmpFolder);

return new DragAndDropScanResult()
{
ExtractedMod = newMod,
IgnoredMods = ignoredDirs.Select(dir => dir.Name).ToArray()
};
}

private void PrepareWorkFolder()
Expand Down Expand Up @@ -138,6 +148,8 @@ public void Dispose()

public class DragAndDropScanResult
{
public IMod Mod { get; set; } = null!;
public IMod ExtractedMod { get; init; } = null!;
public string[] IgnoredMods { get; init; } = Array.Empty<string>();
public string[] IgnoredFiles { get; init; } = Array.Empty<string>();
public string? ThumbnailPath { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ private async Task DragAndDropAsync(IReadOnlyList<IStorageItem>? storageItems)
catch (Exception e)
{
_logger.Error(e, "Error while adding storage items.");
_notificationService.ShowNotification("Error while adding storage items.",
$"An error occurred while adding the storage items. Mod may have been partially copied.\n{e.Message}",
_notificationService.ShowNotification("Drag And Drop operation failed",
$"An error occurred while adding the storage items. Mod may have been partially copied. Reason:\n{e.Message}",
TimeSpan.FromSeconds(5));
}
finally
Expand Down Expand Up @@ -240,8 +240,13 @@ private async Task AddStorageItemFoldersAsync(IReadOnlyList<IStorageItem>? stora
if (storageItem is StorageFile)
{
using var scanner = new DragAndDropScanner();
var mod = scanner.Scan(storageItem.Path);
mod.MoveTo(destDirectoryInfo.FullName);
var extractResult = scanner.Scan(storageItem.Path);
extractResult.ExtractedMod.MoveTo(destDirectoryInfo.FullName);
if (extractResult.IgnoredMods.Any())
App.MainWindow.DispatcherQueue.TryEnqueue(() =>
_notificationService.ShowNotification("Multiple folders detected during extraction, first one was extracted",
$"Ignored Folders: {string.Join(" | ", extractResult.IgnoredMods)}",
TimeSpan.FromSeconds(7)));
continue;
}

Expand Down
3 changes: 2 additions & 1 deletion src/GIMI-ModManager.WinUI/Views/NotificationsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
Grid.Row="1"
IsTextSelectionEnabled="True"
Style="{ThemeResource BodyTextBlockStyle}"
Text="{x:Bind Message}" />
Text="{x:Bind Message}"
TextWrapping="WrapWholeWords" />
<TextBlock
Grid.Row="2"
HorizontalTextAlignment="Right"
Expand Down

0 comments on commit bf47ce0

Please sign in to comment.