コード例 #1
0
        public static async Task <(StorageFile File, ConversionStatus Result)> TryConvertAsync(
            StorageFile file, StorageFolder targetFolder = null)
        {
            if (file.FileType.ToLower().EndsWith("woff"))
            {
                StorageFolder folder = targetFolder ?? ApplicationData.Current.TemporaryFolder;
                string        name   = Path.GetFileNameWithoutExtension(file.DisplayName);

                if (targetFolder is not null) // Avoid threading errors with multiple converts to the same target folder
                {
                    name += $"-{_random.Next(1000,100000)}";
                }

                StorageFile newFile = await folder.CreateFileAsync($"{name}.otf", CreationCollisionOption.ReplaceExisting).AsTask().ConfigureAwait(false);

                ConversionStatus result = await TryConvertWoffToOtfAsync(file, newFile).ConfigureAwait(false);

                if (result == ConversionStatus.OK)
                {
                    if (DirectWrite.HasValidFonts(GetAppUri(newFile)))
                    {
                        return(newFile, ConversionStatus.OK);
                    }
                    else
                    {
                        return(default, ConversionStatus.UnspecifiedError);
コード例 #2
0
        public static async Task <(StorageFile File, ConversionStatus Result)> TryConvertAsync(StorageFile file)
        {
            if (file.FileType.ToLower().EndsWith("woff"))
            {
                var folder  = ApplicationData.Current.TemporaryFolder;
                var newFile = await folder.CreateFileAsync(file.DisplayName + ".otf", CreationCollisionOption.ReplaceExisting).AsTask().ConfigureAwait(false);

                ConversionStatus result = await TryConvertWoffToOtfAsync(file, newFile).ConfigureAwait(false);

                if (result == ConversionStatus.OK)
                {
                    if (DirectWrite.HasValidFonts(GetAppUri(newFile)))
                    {
                        return(newFile, ConversionStatus.OK);
                    }
                    else
                    {
                        return(default, ConversionStatus.UnspecifiedError);