Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes FileSaver filename on Apple #1065

Merged
merged 6 commits into from
Mar 6, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ async Task PickFolderStatic(CancellationToken cancellationToken)
var folderResult = await FolderPicker.PickAsync("DCIM", cancellationToken);
if (folderResult.IsSuccessful)
{
await Toast.Make($"Folder picked: Name - {folderResult.Folder.Name}, Path - {folderResult.Folder.Path}", ToastDuration.Long).Show(cancellationToken);
var filesCount = Directory.EnumerateFiles(folderResult.Folder.Path).Count();
await Toast.Make($"Folder picked: Name - {folderResult.Folder.Name}, Path - {folderResult.Folder.Path}, Files count - {filesCount}", ToastDuration.Long).Show(cancellationToken);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ async Task<string> InternalSaveAsync(string initialPath, string fileName, Stream
{
cancellationToken.ThrowIfCancellationRequested();
var fileManager = NSFileManager.DefaultManager;
var fileUrl = fileManager.GetTemporaryDirectory().Append($"{Guid.NewGuid()}{GetExtension(fileName)}", false);
var tempDirectoryPath = fileManager.GetTemporaryDirectory().Append(Guid.NewGuid().ToString(), true);
var isDirectoryCreated = fileManager.CreateDirectory(tempDirectoryPath, true, null, out var error);
VladislavAntonyuk marked this conversation as resolved.
Show resolved Hide resolved
if (!isDirectoryCreated)
{
throw new Exception(error?.LocalizedDescription ?? "Unable to create temp directory.");
pictos marked this conversation as resolved.
Show resolved Hide resolved
}

var fileUrl = tempDirectoryPath.Append(fileName, false);
await WriteStream(stream, fileUrl.Path ?? throw new Exception("Path cannot be null."), cancellationToken);

cancellationToken.ThrowIfCancellationRequested();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async Task<string> InternalSaveAsync(string initialPath, string fileName, Stream
var file = await filePickerOperation;
if (string.IsNullOrEmpty(file?.Path))
{
throw new FileSaveException("Path doesn't exist.");
throw new FileSaveException("Operation cancelled or Path doesn't exist.");
}

await WriteStream(stream, file.Path, cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void DocumentPickerViewControllerOnWasCancelled(object? sender, EventArgs e)

void DocumentPickerViewControllerOnDidPickDocumentAtUrls(object? sender, UIDocumentPickedAtUrlsEventArgs e)
{
var path = e.Urls[0].AbsoluteString ?? throw new FolderPickerException("Path cannot be null.");
var path = e.Urls[0].Path ?? throw new FolderPickerException("Path cannot be null.");
VladislavAntonyuk marked this conversation as resolved.
Show resolved Hide resolved
taskCompetedSource?.SetResult(new Folder(path, new DirectoryInfo(path).Name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void CancelFolderPickerOperation()
var folder = await folderPickerOperation;
if (folder is null)
{
throw new FolderPickerException("Folder doesn't exist.");
throw new FolderPickerException("Operation cancelled or Folder doesn't exist.");
}

return new Folder(folder.Path, folder.Name);
Expand Down