internal static async Task ExportFontsToFolderAsync(List <FontVariant> fonts) { FolderPicker picker = new FolderPicker { SuggestedStartLocation = PickerLocationId.DocumentsLibrary }; picker.FileTypeFilter.Add("*"); if (await picker.PickSingleFolderAsync() is StorageFolder folder) { await Task.Run(async() => { ExportNamingScheme scheme = ResourceHelper.AppSettings.ExportNamingScheme; foreach (var font in fonts) { if (DirectWrite.IsFontLocal(font.FontFace)) { string fileName = GetFileName(font, scheme); StorageFile file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); await TryWriteToFileAsync(font, file); } } }); Messenger.Default.Send(new AppNotificationMessage(true, new ExportFontFileResult(folder, true))); } }
public static async void RequestExportFontFile(FontVariant variant) { var scheme = ResourceHelper.AppSettings.ExportNamingScheme; var interop = Utils.GetInterop(); if (DirectWrite.IsFontLocal(variant.FontFace)) { string filePath = GetFileName(variant, scheme); string name = Path.GetFileNameWithoutExtension(filePath); string ext = Path.GetExtension(filePath); if (await PickFileAsync(name, Localization.Get("ExportFontFile/Text"), new[] { ext }, PickerLocationId.DocumentsLibrary) is StorageFile file) { try { bool success = await TryWriteToFileAsync(variant, file); Messenger.Default.Send(new AppNotificationMessage(true, new ExportFontFileResult(success, file))); return; } catch { } } } Messenger.Default.Send(new AppNotificationMessage(true, new ExportFontFileResult(null, false))); }
internal static async Task ExportFontsAsZipAsync(List <FontVariant> fonts, string name) { if (await PickFileAsync(name, "ZIP", new[] { ".zip" }) is StorageFile file) { await Task.Run(async() => { ExportNamingScheme scheme = ResourceHelper.AppSettings.ExportNamingScheme; using var i = await file.OpenStreamForWriteAsync(); i.SetLength(0); using ZipArchive z = new ZipArchive(i, ZipArchiveMode.Create); foreach (var font in fonts) { if (DirectWrite.IsFontLocal(font.FontFace)) { string fileName = GetFileName(font, scheme); ZipArchiveEntry entry = z.CreateEntry(fileName); using IOutputStream s = entry.Open().AsOutputStream(); await DirectWrite.WriteToStreamAsync(font.FontFace, s); } } }); Messenger.Default.Send(new AppNotificationMessage(true, new ExportFontFileResult(true, file))); } }
internal static async Task ExportFontsToFolderAsync(List <FontVariant> fonts) { if (await PickFolderAsync() is StorageFolder folder) { await Task.Run(async() => { ExportNamingScheme scheme = ResourceHelper.AppSettings.ExportNamingScheme; foreach (var font in fonts) { if (DirectWrite.IsFontLocal(font.FontFace)) { string fileName = GetFileName(font, scheme); StorageFile file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting).AsTask().ConfigureAwait(false); await TryWriteToFileAsync(font, file).ConfigureAwait(false); } } }); WeakReferenceMessenger.Default.Send(new AppNotificationMessage(true, new ExportFontFileResult(folder, true))); } }