|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using System.IO; |
|
|
|
using System; |
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Avalonia.Controls; |
|
|
|
@ -57,31 +58,25 @@ namespace Avalonia.Diagnostics.Screenshots |
|
|
|
return window!; |
|
|
|
} |
|
|
|
|
|
|
|
protected async override Task<Stream?> GetStream(IControl control) |
|
|
|
protected override async Task<Stream?> GetStream(IControl control) |
|
|
|
{ |
|
|
|
Stream? output = default; |
|
|
|
var result = await GetWindow(control).StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions |
|
|
|
{ |
|
|
|
SuggestedStartLocation = new BclStorageFolder(new DirectoryInfo(ScreenshotsRoot)), |
|
|
|
Title = Title, |
|
|
|
FileTypeChoices = new FilePickerFileType[] { new FilePickerFileType("PNG") { Patterns = new string[] { "*.png" } } } |
|
|
|
FileTypeChoices = new FilePickerFileType[] { new FilePickerFileType("PNG") { Patterns = new string[] { "*.png" } } }, |
|
|
|
DefaultExtension = ".png" |
|
|
|
}); |
|
|
|
|
|
|
|
if (result!=null && !string.IsNullOrWhiteSpace(result.Name)) |
|
|
|
if (result is null) |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
if (!result.CanOpenWrite) |
|
|
|
{ |
|
|
|
var folder = Path.GetDirectoryName(result.Name); |
|
|
|
// Directory information for path, or null if path denotes a root directory or is
|
|
|
|
// null. Returns System.String.Empty if path does not contain directory information.
|
|
|
|
if (!string.IsNullOrWhiteSpace(folder)) |
|
|
|
{ |
|
|
|
if (!Directory.Exists(folder)) |
|
|
|
{ |
|
|
|
Directory.CreateDirectory(folder); |
|
|
|
} |
|
|
|
output = new FileStream(result.Name, FileMode.Create); |
|
|
|
} |
|
|
|
throw new InvalidOperationException("ReadOnly file was opened"); |
|
|
|
} |
|
|
|
return output; |
|
|
|
|
|
|
|
return await result.OpenWriteAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|